<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: blazeclan-akeshpatil</title>
    <description>The latest articles on Forem by blazeclan-akeshpatil (@blazeclanakeshpatil).</description>
    <link>https://forem.com/blazeclanakeshpatil</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F924670%2Fd1a8cdfc-246b-4145-a33b-b0b6eebb2710.png</url>
      <title>Forem: blazeclan-akeshpatil</title>
      <link>https://forem.com/blazeclanakeshpatil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/blazeclanakeshpatil"/>
    <language>en</language>
    <item>
      <title>Accelerate and Automate AWS IAM Identity Center Operations using Python.</title>
      <dc:creator>blazeclan-akeshpatil</dc:creator>
      <pubDate>Wed, 05 Apr 2023 16:32:10 +0000</pubDate>
      <link>https://forem.com/blazeclanakeshpatil/accelerate-and-automate-aws-iam-identity-center-operations-using-python-3ma8</link>
      <guid>https://forem.com/blazeclanakeshpatil/accelerate-and-automate-aws-iam-identity-center-operations-using-python-3ma8</guid>
      <description>&lt;p&gt;We all know that AWS IAM Identity Center (successor to AWS Single Sign-On) helps us securely create or connect workforce identities and manage their access centrally across AWS accounts and applications. IAM Identity Center is the recommended approach for workforce authentication and authorization on AWS for organizations of any size and type. In my career, I have seen customers having multi-account landing zone setup including 100+ AWS accounts and most of them used AWS IAM Identity Center to manage access to all these AWS accounts. While helping customers to manage IAM Identity Center, I found that if I need to associate new permissions set to all the accounts, I have to traverse through each and every OU, select individual AWS account in an OU and assign permissions set to the account. Using Click-Ops this is very difficult for the team who is managing Identity Center operations. This is where I found an opportunity to automate this process and, hence posting this blog.&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS Services Used
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;AWS Identity Center (successor to AWS Single Sign-On)&lt;/li&gt;
&lt;li&gt;AWS Organizations&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;Before we understand this automation, let's understand the steps involved in managing access through AWS Identity Center. I am assuming that you have completed AWS Identity Center setup, if not then please go through these&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/singlesignon/latest/userguide/get-started-prereqs-considerations.html" rel="noopener noreferrer"&gt;Pre-requisites and considerations&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An AWS account with AWS Organizations enabled. If you don’t have an account, sign up at &lt;a href="https://aws.amazon.com" rel="noopener noreferrer"&gt;https://aws.amazon.com&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic knowledge of Python.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/singlesignon/latest/userguide/prereqs.html" rel="noopener noreferrer"&gt;IAM Identity Center prerequisites.&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An identity provider (IAM Identity Center or one of the supported identity providers).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;System with Python libraries to execute Python program.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Walkthrough
&lt;/h3&gt;

&lt;p&gt;This automation project uses an excel sheet to source data for mapping permission sets and users/group to an account, organization unit (OU) or all the accounts in an OU. I recommend that you manage the IAM Identity Center identity on the group level as a best practice, every workforce user should be part of a group.­­­&lt;/p&gt;

&lt;p&gt;Main steps:&lt;/p&gt;

&lt;p&gt;Step 1: Clone the GitHub repository.&lt;br&gt;
Step 2: Update CSV file with required data.&lt;br&gt;
Step 3: Update AWS account details in the program file.&lt;br&gt;
Step 4: Install Python libraries for program execution.&lt;br&gt;
Step 5: Execute Python Program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Clone the GitHub repository.&lt;/strong&gt;&lt;br&gt;
Clone URL: &lt;br&gt;
&lt;code&gt;https://github.com/blazeclan-akeshpatil/aws-iam-identity-center-ops-automation.git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Clone the GitHub repository to your local system. This repository contains example data files that you can use to update permission sets and users/groups to account(s). You can modify the example data with your own account IDs or OUs and resource names.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Update CSV file with required data&lt;/strong&gt;&lt;br&gt;
This automation use CSV as a source of data and perform Identity center operations accordingly. You can find this CSV in the code at following path&lt;br&gt;
&lt;code&gt;file/Identity Center Access Management.xlsx&lt;/code&gt;&lt;br&gt;
This CSV contains two worksheets. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data&lt;/strong&gt; - This is master data of AWS Organization and includes following tables. Please refer following screen shot for your reference&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs0ian28ddyfrwbisob98.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs0ian28ddyfrwbisob98.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each table has a purpose in this sheet&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Targets&lt;/strong&gt;- Permission sets and users/groups can be associated with either specific &lt;code&gt;ACCOUNT&lt;/code&gt; or all the accounts in an &lt;code&gt;OU&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OU Name&lt;/strong&gt; - Values are in the form &lt;code&gt;OU_NAME[ORGANIZATION_UNIT_ID]&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ACCOUNTS&lt;/strong&gt; - Values are in the form &lt;code&gt;ACCOUNT_NAME[ACCOUNT_NUMBER]&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OPERATIONS&lt;/strong&gt;- &lt;code&gt;Add&lt;/code&gt; or &lt;code&gt;Update&lt;/code&gt; or &lt;code&gt;Delete&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Identity Map&lt;/strong&gt; - This worksheet provides source data for this automation and accordingly permission sets and users/groups will be associated with AWS accounts on AWS Identity Center
Please refer following screen shot for your understanding.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7e2c0fwgp4pmeu8mea9x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7e2c0fwgp4pmeu8mea9x.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the description to understand this CSV better&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Row 2 : Associate permissions set &lt;code&gt;AWSPowerUser&lt;/code&gt; to user &lt;code&gt;abcd@example.com&lt;/code&gt; on &lt;code&gt;Sandbox&lt;/code&gt; OU&lt;/li&gt;
&lt;li&gt;Row 3 : Associate permissions set &lt;code&gt;ReadOnlyAccess&lt;/code&gt; to group &lt;code&gt;AuditorsGroup&lt;/code&gt; on &lt;code&gt;Sandbox&lt;/code&gt; account&lt;/li&gt;
&lt;li&gt;Row 4 : Associate permissions set &lt;code&gt;AdministratorAccess&lt;/code&gt; to group &lt;code&gt;AdministratorsGroup&lt;/code&gt; on &lt;code&gt;ALL&lt;/code&gt; accounts in an organization except management account of an organization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's take another example to understand various functionalities of this automation&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgv8te909tz47emw5sphn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgv8te909tz47emw5sphn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the description of the above snippet to understand this automation much better&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Row 2 - Delete association of user &lt;code&gt;abcd@example.com&lt;/code&gt; and permissions set &lt;code&gt;AWSPowerUser&lt;/code&gt; from all the accounts in &lt;code&gt;Sandbox&lt;/code&gt; OU&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Row 3 - Delete association of group &lt;code&gt;AuditorsGroup&lt;/code&gt; and permissions set &lt;code&gt;ReadOnlyUser&lt;/code&gt; from &lt;code&gt;Sandbox&lt;/code&gt; account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Row 4 - Associate permissions set &lt;code&gt;AuditorsPolicy&lt;/code&gt; and group &lt;code&gt;AuditorsGroup&lt;/code&gt; on &lt;code&gt;ALL&lt;/code&gt; accounts in an organization except management account of an organization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Please note, this program is stateless meaning it won't impact any other associations of permission sets and users/groups to AWS accounts. It just considers data from Excel sheet and perform associations/de-associations accordingly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 3 - Update AWS account details in the program file&lt;/strong&gt;&lt;br&gt;
To execute this automation, we have to update AWS resource details in a configuration file. You can find this configuration file in the this code at path &lt;code&gt;config/aws_properties.py&lt;/code&gt;&lt;br&gt;
Please refer following snippet and the comments on each property for your reference&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhzj8cqvqtvunadpono3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhzj8cqvqtvunadpono3c.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Install Python libraries for program execution.&lt;/strong&gt;&lt;br&gt;
To install Python libraries, I have included &lt;code&gt;requirements.txt&lt;/code&gt;in the code. You can find this file at root location in the source code. We need to install following libraries for successful execution of this program&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. boto3
2. pandas
3. awsretry
4. numpy
5. openpyxl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assuming you can run pip command on your system, go to the project root directory and execute following command to install these libraries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Execute Python Program&lt;/strong&gt;&lt;br&gt;
Assuming that you have right credentials and system requirements to execute this code, update credentials in &lt;code&gt;~./aws/credentials&lt;/code&gt; file or if you are running it on &lt;code&gt;Amazon EC2&lt;/code&gt; then make sure that you have IAM role with sufficient permissions associated with the instance&lt;br&gt;
To execute the program, go to root directory of the project and execute following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python local_handler.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This program print all the actions performed during execution and you can expects logs like below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2dlm6do3gut6ytfpmjtn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2dlm6do3gut6ytfpmjtn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>automation</category>
      <category>python</category>
    </item>
  </channel>
</rss>
