September 3, 2020 By Henrik Loeser 3 min read

A Python script for insights into IAM Access Groups and Policies.

I am the owner of an IBM Cloud account with multiple users. To organize teamwork, I followed best practices for organizing users, teams, applications and made use of the IBM Cloud IAM (Identity and Access Management) capabilities. 

With users, service IDs, access groups, and access policies in place, I wondered how to get insights into per-user privileges and the scope of service ID permissions. Sure, I could use the IBM Cloud console (UI) or the Command Line Interface (CLI), but why not test the API (Application Programming Interface) for some customized reporting?

In this blog, I am going to quickly introduce the needed IAM concepts, then take a look at the IBM Cloud REST API. Thereafter, I discuss the Python script, how to use it, and how to customize the code for your needs. The script is available on GitHub.

Sample policy showing Administrator role on a service ID as resource.

IAM access groups and policies

As the name implies, IBM Cloud IAM (Identity and Access Management) is the core component of IBM Cloud to handle identities and manage their access to resources. Identities include regular users as well as service IDs, which can be used by applications, tool(chain)s, and more.

To grant access to a resource, an administrator can create a policy for a user or service ID and assign roles on that type of service and its instances. These policies are called authorizations. Roles are a set of service-specific privileges (security attributes). To simplify administration and easily grant the same privileges to users and service IDs, access groups can be used to bundle the authorizations. Thus, an access group combines users, service IDs, and access policies. Users can be part of several access groups.

As a consequence, an identity can have many associated policies—assigned directly (authorizations) or through access groups of which the identity is member.

IBM Cloud APIs

IBM Cloud offers APIs for its platform and services. The documentation portal has the API & SDK reference library. There, in the Platform category, you find the IAM Identity Services, IAM Policy Management, and the IAM Access Groups APIs. They can be utilized to do the following:

  • Turn an IAM API key into an IAM authentication token (Identity).
  • Retrieve information about the account associated with the API key (Identity).
  • Obtain the list of access groups for the account or identity (Access Groups).
  • Return details on all the policies identified by attributes like the related access group or assigned identity (Policy Management).

Policies within an IAM Access Group with Viewer, Administrator, and Editor roles on different resources.

Retrieve access privileges

The Python script for the policy report makes use of the above mentioned APIs and implements exactly those four steps. It can be used to retrieve the policies for the entire account or only a specified identity (i.e., user or service ID).

After reading in the API key, it turns it into an IAM bearer token and retrieves the associated account_id, then first fetches the access groups related to the identity or the entire account. For each group, it fetches and prints the policies. Thereafter, all policies directly related to the identity are retrieved and printed. All that is needed is an API key and (optionally) the IAM ID of the user or service ID. The GitHub repository has instructions on how to create the API key and obtain the IAM IDs for users and service IDs.


The script prints policy information as plain text. But the JSON source could be easily integrated into other tools, turned into a graph (using Graphviz), or combined further with information about services and their instances. The first step is done by turning an API key into a list of access policies.

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn

Was this article helpful?

More from Cloud

Enhance your data security posture with a no-code approach to application-level encryption

4 min read - Data is the lifeblood of every organization. As your organization’s data footprint expands across the clouds and between your own business lines to drive value, it is essential to secure data at all stages of the cloud adoption and throughout the data lifecycle. While there are different mechanisms available to encrypt data throughout its lifecycle (in transit, at rest and in use), application-level encryption (ALE) provides an additional layer of protection by encrypting data at its source. ALE can enhance…

Attention new clients: exciting financial incentives for VMware Cloud Foundation on IBM Cloud

4 min read - New client specials: Get up to 50% off when you commit to a 1- or 3-year term contract on new VCF-as-a-Service offerings, plus an additional value of up to USD 200K in credits through 30 June 2025 when you migrate your VMware workloads to IBM Cloud®.1 Low starting prices: On-demand VCF-as-a-Service deployments begin under USD 200 per month.2 The IBM Cloud benefit: See the potential for a 201%3 return on investment (ROI) over 3 years with reduced downtime, cost and…

The history of the central processing unit (CPU)

10 min read - The central processing unit (CPU) is the computer’s brain. It handles the assignment and processing of tasks, in addition to functions that make a computer run. There’s no way to overstate the importance of the CPU to computing. Virtually all computer systems contain, at the least, some type of basic CPU. Regardless of whether they’re used in personal computers (PCs), laptops, tablets, smartphones or even in supercomputers whose output is so strong it must be measured in floating-point operations per…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters