These scripts can be used to help migrate your IAM policies to use fine-grained actions (new actions).
These scripts should be run from the payer account of your organization to identify the following affected policies in your organization that use the old IAM actions:
The scripts generate suggestions for new actions that correspond to the old actions used in the policy. You then review the suggestions and use the scripts to add the new actions across all affected polices in your organization.
These scripts provide the following benefits:
Download and install Python 3.
Ensure that you have an IAM principal in your payer account that has the following IAM permissions:
"iam:GetAccountAuthorizationDetails",
"iam:GetPolicy",
"iam:GetPolicyVersion",
"iam:GetUserPolicy",
"iam:GetGroupPolicy",
"iam:GetRolePolicy",
"iam:CreatePolicyVersion",
"iam:DeletePolicyVersion",
"iam:ListPolicyVersions",
"iam:PutUserPolicy",
"iam:PutGroupPolicy",
"iam:PutRolePolicy",
"iam:SetDefaultPolicyVersion",
"organizations:ListAccounts",
"organizations:ListPolicies",
"organizations:DescribePolicy",
"organizations:UpdatePolicy",
"organizations:DescribeOrganization",
"sts:AssumeRole",
"sso:ListInstances",
"sso:ListPermissionSets",
"sso:GetInlinePolicyForPermissionSet",
"sso:DescribePermissionSet",
"sso:PutInlinePolicyToPermissionSet",
"sso:ProvisionPermissionSet",
"sso:DescribePermissionSetProvisioningStatus",
"iam:GetRole",
"iam:ListAttachedRolePolicies"
These are the permissions needed to execute the script. You will be using this IAM principal to configure aws credentials before running the scripts.
Clone the project to your local directory
git clone https://github.com/aws-samples/bulk-policy-migrator-scripts-for-account-cost-billing-consoles.git
Navigate into the project
cd bulk-policy-migrator-scripts-for-account-cost-billing-consoles
[ONLY applicable to Debian/Ubuntu systems] Install python3-venv
This command should only be run if you are using Debian/Ubuntu systems. For all other systems, skip this and move to 4.
sudo apt install -y python3-venv
Setup virtualenv
python3 -m venv venv
Activate virtualenv
source venv/bin/activate
Install dependencies
pip install -r requirements.txt
Navigate to directory containing the scripts
cd policy_migration_scripts/scripts
Configure the credentials using AWS CLI. You can read more about how to do this here.
Credentials can be configured in multiple ways. Regardless of the method that you choose, you must have both AWS credentials
and an AWS Region set before running the scripts. The simplest way is to do this in an interactive manner using AWS CLI
and running aws configure
command to set up your credentials and default region. Follow the prompts, and it will generate
configuration files in the correct locations for you.
Note:
Specifying incorrect region can cause errors during script execution. For e.g. when running the script in China regions,
if the region is set to us-east-1 you will see errors like - The security token included in the request is invalid
.
For China regions, the region value should be either cn-north-1 or cn-northwest-1.
Follow this procedure to create a CloudFormation stack set. The stack set creates an IAM role named BillingConsolePolicyMigratorRole across all member accounts of your organization. This IAM role will be assumed by the payer account during the script execution to access affected policies in the member accounts.
Note: You only need to complete this step once from the management account (payer account).
To create the CloudFormation stack set
For more information, see Creating a stack set on the AWS CloudFormation console in the AWS CloudFormation User Guide.
After CloudFormation creates the stack set, each member account in your organization has BillingConsolePolicyMigratorRole IAM role. The IAM role contains the following permissions:
"iam:GetAccountAuthorizationDetails",
"iam:GetPolicy",
"iam:GetPolicyVersion",
"iam:GetUserPolicy",
"iam:GetGroupPolicy",
"iam:GetRolePolicy",
"iam:CreatePolicyVersion",
"iam:DeletePolicyVersion",
"iam:ListPolicyVersions"
"iam:PutUserPolicy",
"iam:PutGroupPolicy",
"iam:PutRolePolicy",
"iam:SetDefaultPolicyVersion"
To identify affected policies run the identify_affected_policies.py
script
Following input parameters are supported:
python identify_affected_policies.py --all
python identify_affected_policies.py --accounts 111122223333,444455556666,777788889999
python identify_affected_policies.py --accounts-file /path/to/accounts_file.csv
python identify_affected_policies.py --all --exclude-accounts 111111111111,222222222222,333333333333
python identify_affected_policies.py –-action-mapping-config-file /path/to/action_mapping_config.json –-all
python identify_affected_policies.py
After you run the script, it creates two JSON files in an AffectedPolicies<Timestamp> folder:
After you review and refine the suggested replacements, run the update_affected_policies.py
script.
The script takes as argument the absolute path of the directory created by running identify_affected_policies.py script
python update_affected_policies.py --affected-policies-directory /path/to/Affected_Policies_<Timestamp>
The rollback_affected_polices.py
script reverts the changes applied to each affected policy for the specified accounts.
The script removes all Sid
blocks that the update_affected_policies.py
script appended. These Sid
blocks have
the BillingConsolePolicyMigrator#
format.
Following input parameters are supported:
python rollback_affected_policies.py --all
python rollback_affected_policies.py --accounts 111122223333,444455556666,777788889999
python identify_affected_policies.py --accounts-file /path/to/accounts_file.csv
python rollback_affected_policies.py --all --exclude-accounts 111111111111,222222222222,333333333333
python rollback_affected_policies.py
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.
See TROUBLESHOOTING for more information.