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

How a US bank modernized its mainframe applications with IBM Consulting and Microsoft Azure

9 min read - As organizations strive to stay ahead of the curve in today's fast-paced digital landscape, mainframe application modernization has emerged as a critical component of any digital transformation strategy. In this blog, we'll discuss the example of a US bank which embarked on a journey to modernize its mainframe applications. This strategic project has helped it to transform into a more modern, flexible and agile business. In looking at the ways in which it approached the problem, you’ll gain insights into…

The power of the mainframe and cloud-native applications 

4 min read - Mainframe modernization refers to the process of transforming legacy mainframe systems, applications and infrastructure to align with modern technology and business standards. This process unlocks the power of mainframe systems, enabling organizations to use their existing investments in mainframe technology and capitalize on the benefits of modernization. By modernizing mainframe systems, organizations can improve agility, increase efficiency, reduce costs, and enhance customer experience.  Mainframe modernization empowers organizations to harness the latest technologies and tools, such as cloud computing, artificial intelligence,…

Modernize your mainframe applications with Azure

4 min read - Mainframes continue to play a vital role in many businesses' core operations. According to new research from IBM's Institute for Business Value, a significant 7 out of 10 IT executives believe that mainframe-based applications are crucial to their business and technology strategies. However, the rapid pace of digital transformation is forcing companies to modernize across their IT landscape, and as the pace of innovation continuously accelerates, organizations must react and adapt to these changes or risk being left behind. Mainframe…

IBM Newsletters

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