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.

Conclusions

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?
YesNo

More from Cloud

Fortressing the digital frontier: A comprehensive look at IBM Cloud network security services

6 min read - The cloud revolution has fundamentally transformed how businesses operate. Its superior scalability, agility and cost-effectiveness have made it the go-to platform for organizations of all sizes. However, this shift to the cloud has introduced a new landscape of ever-evolving security threats. Data breaches and cyberattacks continue to hit organizations, making robust cloud network security an absolute necessity. IBM®, a titan in the tech industry, recognizes this critical need, provides a comprehensive suite of tools and offers unmatched expertise to fortify…

How well do you know your hypervisor and firmware?

6 min read - IBM Cloud® Virtual Private Cloud (VPC) is designed for secured cloud computing, and several features of our platform planning, development and operations help ensure that design. However, because security in the cloud is typically a shared responsibility between the cloud service provider and the customer, it’s essential for you to fully understand the layers of security that your workloads run on here with us. That’s why here, we detail a few key security components of IBM Cloud VPC that aim…

New IBM study: How business leaders can harness the power of gen AI to drive sustainable IT transformation

3 min read - As organizations strive to balance productivity, innovation and environmental responsibility, the need for sustainable IT practices is even more pressing. A new global study from the IBM Institute for Business Value reveals that emerging technologies, particularly generative AI, can play a pivotal role in advancing sustainable IT initiatives. However, successful transformation of IT systems demands a strategic and enterprise-wide approach to sustainability. The power of generative AI in sustainable IT Generative AI is creating new opportunities to transform IT operations…

IBM Newsletters

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