How to Use IAM Identity Center APIs to Audit and Manage Application Assignments
Tags: aws, iam, awsidentitycenter, api
Published: 2023-12-20 18:51:00


<!-- wp:paragraph -->
<p>Do you know what importance the IAM Identity Center holds? If not, don’t worry! Stay with us, and we will guide you through everything regarding this. For starters, let us discuss what this center does. Consider the IAM Identity Center a literal center where all your workforce users are connected or created. The access of these connected users to various AWS applications and accounts is managed centrally by you.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>AWS Managed Applications</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>For instance, you want to use any AWS application and want only specific users and groups to have permission to access that application. What would you do? The simplest solution here is to configure AWS-managed applications so you can work directly with the IAM Identity Center within your chosen application’s console. Previously, all the work was done manually by assigning users and groups to an application using the IAM Identity Center console. Following the latest trends, you can now use IAM Identity Center APIs to automate this task to enhance efficiency.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>An account assignment API is used to automate the task of multi-account access and auditing access assigned to specific users. One can use this API using the permission sets of the IAM Identity Center. New and latest APIs offer much more than you can imagine. What if I say you can programmatically control the authority to assign applications to the users and related groups with these new APIs? Convenient. In addition to this, automated workflows can also easily be created for audit.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The AWS-managed applications don’t have to go anywhere else to access the information regarding users and groups. Their task has been made easier with the help of the IAM Identity Center. If you want to dive deep into AWS-managed applications, let’s take the example of Amazon Redshift.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The workflow goes like this: you use the <a href="https://sudoconsultants.com/aws-security-best-practices-for-iamdentity-and-access-management/">IAM</a> Identity Center to configure Redshift as a managed application. Whenever any user tries to access the database, mapping memberships defined in the IAM Identity Center and Redshift database takes place, which helps grant specific permissions. This approach will remove the burden of manually setting database-object permissions for every user. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>IAM Identity Center and Amazon Redshift Integration</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The assignment and removal tasks of all users and groups will be automated once you successfully integrate the IAM Identity Center and Amazon Redshift. For this, you will need to use two APIs.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>Delete Application Assignment</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Create Application Assignment</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>Prerequisites</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In order to assign a group to Amazon Redshift and delete that group assignment as well, you will need to use Identity Center APIs by keeping in mind the following prerequisites.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><a href="https://docs.aws.amazon.com/SetUp/latest/UserGuide/setup-enableIdC.html">Enable IAM Identity Center</a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>For your identity data, use Identity Store</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>In case of external identity provider, the processes of user creation and deletion must be handled</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>You will need to provide an explicit assignment as soon as you <a href="https://docs.aws.amazon.com/redshift/latest/mgmt/redshift-iam-access-control-idp-connect.html">make IAM Identity Center the identity source of Amazon Redshif</a>t. APIs or Identity Center console can make this explicit assignment task easier</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Install the version 2 of AWS CLI and configure it accordingly as it will be helpful in calling Identity Center application assignment API</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>Steps</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The below mentioned steps will lead you to a successful procedure.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading"><strong>STEP 1 - Acquire Identity Center’s Instance Information</strong></h3>
<!-- /wp:heading -->

<!-- wp:code -->
<pre class="wp-block-code"><code>aws sso-admin list-instances</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>After running this command you will have the Amazon Resource Name. Along with this the identity store ID of your current instance will also be shown to you.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You will get the output like this.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{

  "Instances": &#91;

      {

          "InstanceArn": "YourAmazonResourceName",

          "IdentityStoreId": "YourInstanceStoreID",

          "OwnerAccountId": "YourAccountDetails",

          "Name": "YourInstanceName",

          "CreatedDate": "CreationDateOfYourInstance",

          "State": {

              "Name": "ACTIVE"

          },

          "Status": "ACTIVE"

      }

  ],

  "NextToken": &lt;&lt;TOKEN>>

}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p><strong>On Console&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>On AWS Console you can acquire Identity Center’s instance information by navigating to <strong>dashboard :</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://lh7-us.googleusercontent.com/SbmUQbh21BZK37c3w86JEqmfx-whcSyU1gohNNzeWA9qSFKSW-t6ZJACp8rkJMqL1uSGa5mHoNYPITV47msXJNbTp6d3sNc1mnT9kwNQYbvL9fpcrCqUfiDv5hH3GRpn-80Noxc--Y-rfBdyw4F73gs" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading"><strong>STEP 2 - Creating Group and User in Identity Store</strong></h3>
<!-- /wp:heading -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><strong>For existing group</strong></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>It might be possible that you already have a group created in your Identity Store. If this is so, you only need to know the group ID of the already formed group. You can do this by the following command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>aws identitystore get-group-id --identity-store-id “<em>YourInstanceStoreID</em>” –alternate-identifier “GroupName”</code></pre>
<!-- /wp:code -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><strong>For creating a new user</strong></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>If you are new and haven’t created any user yet then you can do so by utilizing the IdentityStoreId from the previous step.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>aws identitystore create-user --identity-store-id “<em>YourInstanceStoreID</em>” --user-name "YourUserName" --emails Value="YourUserName@example.com",Type="Work",Primary=true —display-name "My User" —name FamilyName="User",GivenName="My"</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>This will be the relevant output.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{

             "UserId": "********-****-****-****-************", (In this format)

             "IdentityStoreId": "YourInstanceStoreID"

}</code></pre>
<!-- /wp:code -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><strong>For creating a new group</strong></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>If you don’t have any pre-existing groups made then you can create one for yourself.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>aws identitystore create-group --identity-store-id “<em>YourInstanceStoreID</em>”  --display-name engineering</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>This will be the relevant output.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{

    "GroupId": "********-****-****-****-************", (In this format)

    "IdentityStoreId": "YourInstanceStoreID"

}</code></pre>
<!-- /wp:code -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><strong>Adding user to the group</strong></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>To add users to any specific group, run the below-mentioned command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>aws identitystore create-group-membership --identity-store-id “<em>YourInstanceStoreID</em>” --group-id ********-****-****-****-************ --member-id UserId=********-****-****-****-************</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>This will be the relevant output.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{

    "MembershipId":"********-****-****-****-************", (In this format)

    "IdentityStoreId": "YourInstanceStoreID"

}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p><strong>On Console&nbsp;</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Navigate to either the users or groups and you can create the new one’s there and add the required information:</p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://lh7-us.googleusercontent.com/qxxRZsugIpsf14wdCKVRMbsV3tePVx5SD3NeTth9UgLEfTNGiVw8bpPP9NI1nfTV9S43-9VapSgRweIEyZkSK1jhYhpkOjUKfXV0a3OCnrxj6_zZehZwr8JRlS1ZrqIFu6peV4hmufCtuHZsKuXO8Qc" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://lh7-us.googleusercontent.com/t6CI2tvHQzVCs_Ddu0kvjakdEQbbA5OHRGNiKjvGzEExjojiqKKsfq8DX17L3auHI_j7YOWcSyKEWCiwqxIPz6N7b346dMN7mzYSARA5ig2xiqiYImf8UZTDN4KuSqYw2WPoZF4EDIrzIaBqzFN-2_s" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading"><strong>STEP 3 - Acquire Application’s ARN</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In order to determine the ARN of your application, run the following command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>aws sso-admin list-applications --instance-arn "arn:aws:sso:::instance/ssoins-****************"</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>You may be using more than one application at a time. To deal with this situation, you need to use the filter flag. Select the application you want the information for, and you will be ready.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In case of a single application (Amazon Redshift in this case), the output should be something like this.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{

    "ApplicationArn": "arn:aws:sso:::instance/ssoins-****************/apl-***************",

    "ApplicationProviderArn": "arn:aws:sso::aws:applicationProvider/Redshift",

         "Name": "Amazon Redshift",

    "InstanceArn": "arn:aws:sso:::instance/ssoins-****************",

    "Status": "DISABLED",

         "PortalOptions": {

        "Visible": true,

        "Visibility": "ENABLED",

        "SignInOptions": {

            "Origin": "IDENTITY_CENTER"

         }

         },

    "AssignmentConfig": {

        "AssignmentRequired": true

         },

         "Description": "Amazon Redshift",

    "CreatedDate": "2023-10-09T10:48:44.496000-07:00"

}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p><strong>On Console:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can directly navigate to settings in IAM Console and copy <strong>identity store ID and arn&nbsp; :</strong></p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://lh7-us.googleusercontent.com/G-JBl-zov7NBQAGtFm5UpOs_kHvAIqK1dBjA13zAEED1-gNCzEe3QoxAvYc5cQ_Jhp83SZRTDXen0O1zYhD1t3VuTyB3i-TlATCkHA5VvqBpKn5lKj4sgvRn9mdoz4tm4aiA84KqQ1qIkHZX6h-NPWc" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://lh7-us.googleusercontent.com/hjtr006fr9gKqr-_vOPh1puCl-p455DRKLFCkD0mJHn-Exnh8N4tJt_ewFtvj5YYlPsfXGUqpnx5ZVOxjHWgyR0XnTY9K4wWCPH8VBc_n2i1TnQc9qY59fUdpE0v3TrBSvm7Q9F2csp3xG7cKnqVhQ4" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading"><strong>STEP 4 - Adding Group to the Application (Amazon Redshift)</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>At this stage, the Amazon Redshift application is being managed by IAM Identity Center so you can easily add a group to this application.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>aws sso-admin create-application-assignment --application-arn "arn:aws:sso:::instance/ssoins-****************/apl-***************" --principal-id "********-****-****-****-************" --principal-type "GROUP"</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Well, the good news is that your group has been added to the Redshift application but of course with default permissions. To grant further permissions, you will have to create roles.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://lh7-us.googleusercontent.com/a8bgPqdaIQLX33RlKtlao8POUzZY_IC8_gXvjxyf_dBIQsnA5wR8twe35_cPcrpAqhnlKHT2CEmueWgR7QSn8gfAfQJxipqnnlMDP31AQse7IYl7MN8zzPwvYs4_GlGCT-nebsAfRmhSQgC2nQgTaGU" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:image -->
<figure class="wp-block-image"><img src="https://lh7-us.googleusercontent.com/sh9WnvKe5bGDkdHAhhWl5IGHf7qNNv3ePAve6AABeh0CPsyDdECdwR6mihaITC_TjJHHES1cpM2O1A4neqhU3PUMNztBduJxNxqtQjrT0nntUGvBKyDVa11RRl8PgRBqGHquul1dwF7cYJvxb0yeb-U" alt=""/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p><strong>Creating roles in Amazon Redshift</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To create roles in Amazon Redshift you have to connect to your cluster and run relevant SQL commands. There are two options to do this.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>Use query editor version 2 to connect to Amazon Redshift</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Use python tools, JDBC (Java Database Connectivity), or ODBC (Open Database Connectivity) to connect to Amazon Redshift</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>The public schemas of databases provide users with create and usage permissions by default. If you want to stop the users from creating a new object in the public schema, use the REVOKE command to do so. You can also create roles by running the following command.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>CREATE ROLE &lt;identitycenternamespace:rolename>;</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>You must specify the group name you created in the IAM Identity Center in the role name. After successfully integrating the Amazon Redshift and I AM Identity Center, you will be assigned an IdentityProviderNamespace.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading"><strong>STEP 5 - Removing Application Assignment</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If you don’t want the group to have access to the Redshift application, then you can do so. But remember one thing: the group will remain a part of the IAM Identity Center.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Reviewing the application’s documentation after you add or remove any user or group is recommended. It is also essential to remove the corresponding roles from the Amazon Redshift application. To do this, use the DROP role command.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Auditing User and Group Access to Application</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The latest API also helps you with auditing application assignments. ListApplicationAssignments is the new API using which you can see the currently assigned groups to the Amazon Redshift application.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>aws sso-admin list-application-assignments --application-arn arn:aws:sso::****************:application/ssoins-****************/apl-**************** </code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The relevant output will be shown to you.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{

    "ApplicationAssignments": &#91;

         {

"ApplicationArn": "arn:aws:sso::****************:application/ssoins-****************/apl-****************",

        "PrincipalId": "********-****-****-****-************",

        "PrincipalType": "GROUP"

         }

         ]

}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>But this is the output for a single application. If you have multiple applications running then create a script and run it periodically in AWS Lambda function. You can also refer to the <a href="https://aws.amazon.com/blogs/security/use-iam-identity-center-apis-to-audit-and-manage-application-assignments/">documentation of this process</a> out there.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>Conclusion</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In this informative article, you came across the process of using IAM Identity Center APIs to add and remove users and groups from the application. Moreover, you learned about the integration of Amazon Redshift with the IAM Identity Center. We hope you acquired sufficient knowledge about the automation of IAM Identity Center. Stay tuned with us to know more and get your cloud queries and troubles fixed with the help of SUDO Consultants!</p>
<!-- /wp:paragraph -->