Package: cloudsplaining
CloudsplainingCloudsplaining is an AWS IAM Security Assessment tool that identifies violations of least privilege and generates a risk-prioritized HTML report.Example reportDocumentationFor full documentation, please visit theproject on ReadTheDocs.InstallationCheatsheetExample reportOverviewCloudsplaining identifies violations of least privilege in AWS IAM policies and generates a pretty HTML report with a triage worksheet. It can scan all the policies in your AWS account or it can scan a single policy file.It helps to identify IAM actions that do not leverage resource constraints. It also helps prioritize the remediation process by flagging IAM policies that present the following risks to the AWS account in question without restriction:Data Exfiltration (s3:GetObject,ssm:GetParameter,secretsmanager:GetSecretValue)Infrastructure ModificationResource Exposure (the ability to modify resource-based policies)Privilege Escalation (based on Rhino Security Labs research)Cloudsplaining also identifies IAM Roles that can be assumed by AWS Compute Services (such as EC2, ECS, EKS, or Lambda), as they can present greater risk than user-defined roles - especially if the AWS Compute service is on an instance that is directly or indirectly exposed to the internet. Flagging these roles is particularly useful to penetration testers (or attackers) under certain scenarios. For example, if an attacker obtains privileges to executessm:SendCommandand there are privileged EC2 instances with the SSM agent installed, they can effectively have the privileges of those EC2 instances. Remote Code Execution via AWS Systems Manager Agent was already a known escalation/exploitation path, but Cloudsplaining can make the process of identifying theses cases easier. See thesample reportfor some examples.You can also specify a custom exclusions file to filter out results that are False Positives for various reasons. For example, User Policies are permissive by design, whereas System roles are generally more restrictive. You might also have exclusions that are specific to your organization's multi-account strategy or AWS application architecture.MotivationPolicy Sentryrevealed to us that it is possible to finally write IAM policies according to least privilege in a scalable manner. Before Policy Sentry was released, it was too easy to find IAM policy documents that lacked resource constraints. Consider the policy below, which allows the IAM principal (a role or user) to runs3:PutObjecton any S3 bucket in the AWS account:{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:PutObject"],"Resource":"*"}]}This is bad. Ideally, access should be restricted according to resource ARNs, like so:{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:GetObject"],"Resource":"arn:aws:s3:::my-bucket/*"}]}Policy Sentrymakes it really easy to do this. Once Infrastructure as Code developers or AWS Administrators gain familiarity with the tool (which is quite easy to use), we've found that adoption starts very quickly.However, if you've been using AWS, there is probably a very large backlog of IAM policies that could use an uplift. If you have hundreds of AWS accounts with dozens of policies in each, how can we lock down those AWS accounts by programmatically identifying the policies that should be fixed?That's why we wrote Cloudsplaining.Cloudsplaining identifies violations of least privilege in AWS IAM policies and generates a pretty HTML report with a triage worksheet. It can scan all the policies in your AWS account or it can scan a single policy file.InstallationHomebrewbrewtapsalesforce/cloudsplaininghttps://github.com/salesforce/cloudsplaining
brewinstallcloudsplainingPip3pip3install--usercloudsplainingNow you should be able to executecloudsplainingfrom command line by runningcloudsplaining --help.Shell completionTo enable Bash completion, put this in your.bashrc:eval"$(_CLOUDSPLAINING_COMPLETE=sourcecloudsplaining)"To enable ZSH completion, put this in your .zshrc:eval"$(_CLOUDSPLAINING_COMPLETE=source_zshcloudsplaining)"Scanning a single IAM policyYou can also scan a single policy file to identify risks instead of an entire account.cloudsplainingscan-policy-file--input-fileexamples/policies/explicit-actions.jsonThe output will include a finding description and a list of the IAM actions that do not leverage resource constraints.The output will resemble the following:Issue found: Data ExfiltrationActions: s3:GetObjectIssue found: Resource ExposureActions: ecr:DeleteRepositoryPolicy, ecr:SetRepositoryPolicy, s3:BypassGovernanceRetention, s3:DeleteAccessPointPolicy, s3:DeleteBucketPolicy, s3:ObjectOwnerOverrideToBucketOwner, s3:PutAccessPointPolicy, s3:PutAccountPublicAccessBlock, s3:PutBucketAcl, s3:PutBucketPolicy, s3:PutBucketPublicAccessBlock, s3:PutObjectAcl, s3:PutObjectVersionAclIssue found: Unrestricted Infrastructure ModificationActions: ecr:BatchDeleteImage, ecr:CompleteLayerUpload, ecr:CreateRepository, ecr:DeleteLifecyclePolicy, ecr:DeleteRepository, ecr:DeleteRepositoryPolicy, ecr:InitiateLayerUpload, ecr:PutImage, ecr:PutImageScanningConfiguration, ecr:PutImageTagMutability, ecr:PutLifecyclePolicy, ecr:SetRepositoryPolicy, ecr:StartImageScan, ecr:StartLifecyclePolicyPreview, ecr:TagResource, ecr:UntagResource, ecr:UploadLayerPart, s3:AbortMultipartUpload, s3:BypassGovernanceRetention, s3:CreateAccessPoint, s3:CreateBucket, s3:DeleteAccessPoint, s3:DeleteAccessPointPolicy, s3:DeleteBucket, s3:DeleteBucketPolicy, s3:DeleteBucketWebsite, s3:DeleteObject, s3:DeleteObjectTagging, s3:DeleteObjectVersion, s3:DeleteObjectVersionTagging, s3:GetObject, s3:ObjectOwnerOverrideToBucketOwner, s3:PutAccelerateConfiguration, s3:PutAccessPointPolicy, s3:PutAnalyticsConfiguration, s3:PutBucketAcl, s3:PutBucketCORS, s3:PutBucketLogging, s3:PutBucketNotification, s3:PutBucketObjectLockConfiguration, s3:PutBucketPolicy, s3:PutBucketPublicAccessBlock, s3:PutBucketRequestPayment, s3:PutBucketTagging, s3:PutBucketVersioning, s3:PutBucketWebsite, s3:PutEncryptionConfiguration, s3:PutInventoryConfiguration, s3:PutLifecycleConfiguration, s3:PutMetricsConfiguration, s3:PutObject, s3:PutObjectAcl, s3:PutObjectLegalHold, s3:PutObjectRetention, s3:PutObjectTagging, s3:PutObjectVersionAcl, s3:PutObjectVersionTagging, s3:PutReplicationConfiguration, s3:ReplicateDelete, s3:ReplicateObject, s3:ReplicateTags, s3:RestoreObject, s3:UpdateJobPriority, s3:UpdateJobStatusScanning an entire AWS AccountDownloading Account Authorization DetailsWe can scan an entire AWS account and generate reports. To do this, we leverage the AWS IAMget-account-authorization-detailsAPI call, which downloads a large JSON file (around 100KB per account) that contains all of the IAM details for the account. This includes data on users, groups, roles, customer-managed policies, and AWS-managed policies.You must have AWS credentials configured that can be used by the CLI.You must have the privileges to runiam:GetAccountAuthorizationDetails. Thearn:aws:iam::aws:policy/SecurityAuditpolicy includes this, as do many others that allow Read access to the IAM Service.To download the account authorization details, ensure you are authenticated to AWS, then runcloudsplaining'sdownloadcommand:cloudsplainingdownloadIf you prefer to use your~/.aws/credentialsfile instead of environment variables, you can specify the profile name:cloudsplainingdownload--profilemyprofileIt will download a JSON file in your current directory that contains your account authorization detail information.Create Exclusions fileCloudsplaining tool does not attempt to understand the context behind everything in your AWS account. It's possible to understand the context behind some of these things programmatically - whether the policy is applied to an instance profile, whether the policy is attached, whether inline IAM policies are in use, and whether or not AWS Managed Policies are in use.Only you know the context behind the design of your AWS infrastructure and the IAM strategy.As such, it's important to eliminate False Positives that are context-dependent. You can do this with an exclusions file. We've included a command that will generate an exclusions file for you so you don't have to remember the required format.You can create an exclusions template via the following command:cloudsplainingcreate-exclusions-fileThis will generate a file in your current directory titledexclusions.yml.Now when you run thescancommand, you can use the exclusions file like this:cloudsplainingscan--exclusions-fileexclusions.yml--input-fileexamples/files/example.json--outputexamples/files/For more information on the structure of the exclusions file, seeFiltering False PositivesScanning the Authorization Details fileNow that we've downloaded the account authorization file, we can scanallof the AWS IAM policies withcloudsplaining.Run the following command:cloudsplainingscan--exclusions-fileexclusions.yml--input-fileexamples/files/example.json--outputexamples/files/It will create an HTML report likethis:It will also create a raw JSON data file:default-iam-results.json: This contains the raw JSON output of the report. You can use this data file for operating on the scan results for various purposes. For example, you could write a Python script that parses this data and opens up automated JIRA issues or Salesforce Work Items. An example entry is shown below. The full example can be viewed atexamples/files/iam-results-example.json{"example-authz-details":[{"AccountID":"012345678901","ManagedBy":"Customer","PolicyName":"InsecureUserPolicy","Arn":"arn:aws:iam::012345678901:user/userwithlotsofpermissions","ActionsCount":2,"ServicesCount":1,"Actions":["s3:PutObject","s3:PutObjectAcl"],"Services":["s3"]}]}See theexamples/filesfolder for sample output.Filtering False PositivesResource constraints are best practice - especially for system roles/instance profiles - but sometimes, these are by design. For example, consider a situation where a custom IAM policy is used on an instance profile for an EC2 instance that provisions Terraform.In this case, broad permissions are design requirements- so we don't want to include these in the results.You can create an exclusions template via the following command:cloudsplainingcreate-exclusions-fileThis will generate a file in your current directory titledexclusions.yml.The default exclusions file looks like this:# Policy names to exclude from evaluation# Suggestion: Add policies here that are known to be overly permissive by design, after you run the initial report.policies:-"AWSServiceRoleFor*"-"*ServiceRolePolicy"-"*ServiceLinkedRolePolicy"-"AdministratorAccess"# Otherwise, this will take a long time-"service-role*"-"aws-service-role*"# Don't evaluate these roles, users, or groups as part of the evaluationroles:-"service-role*"-"aws-service-role*"users:-""groups:-""# Read-only actions to include in the results, such as s3:GetObject# By default, it includes Actions that could lead to Data Exfiltrationinclude-actions:-"s3:GetObject"-"ssm:GetParameter"-"ssm:GetParameters"-"ssm:GetParametersByPath"-"secretsmanager:GetSecretValue"# Write actions to include from the results, such as kms:Decryptexclude-actions:-""Make any additions or modifications that you want.Underpolicies, list the path of policy names that you want to exclude.If you want to exclude a role titledMyRole, listMyRoleorMyR*in theroleslist.You can follow the same approach forusersandgroupslist.Now when you run thescancommand, you can use the exclusions file like this:cloudsplainingscan--exclusions-fileexclusions.yml--input-fileexamples/files/example.json--outputexamples/files/Scanning Multiple AWS AccountsIf your IAM user or IAM role hassts:AssumeRolepermissions to a common IAM role across multiple AWS accounts, you can use thescan-multi-accountcommand.This diagram depicts how the process works:Note: If you are new to setting up cross-account access, check outthe official AWS Tutorial on Delegating access across AWS accounts using IAM roles. That can help you set up the architecture above.First, you'll need to create the multi-account config file. Run the following command:cloudsplainingcreate-multi-account-config-file\-omulti-account-config.ymlThis will generate a file calledmulti-account-config.ymlwith the following contents:accounts:default_account:123456789012prod:123456789013test:123456789014Note: Observe how the format of the file above includesaccount_name: accountID. Edit the file contents to match your desired account name and account ID. Include as many account IDs as you like.For the next step, let's say that:We have a role in the target accounts that is calledCommonSecurityRole.The credentials for your IAM user are under the AWS Credentials profile calledscanning-user.That user hassts:AssumeRolepermissions to assume theCommonSecurityRolein all your target accounts specified in the YAML file we created previously.You want to save the output to an S3 bucket calledmy-results-bucketUsing the data above, you can run the following command:cloudsplainingscan-multi-account\-cmulti-account-config.yml\--profilescanning-user\--role-nameCommonSecurityRole\--output-bucketmy-results-bucketNote that if you run the above without the--profileflag, it will execute in the standardAWS Credentials order of precedence(i.e., Environment variables, credentials profiles, ECS container credentials, then finally EC2 Instance Profile credentials).Cheatsheet# Download authorization detailscloudsplainingdownload# Download from a specific AWS profilecloudsplainingdownload--profilesomeprofile# Scan Authorization detailscloudsplainingscan--input-filedefault.json# Scan Authorization details with custom exclusionscloudsplainingscan--input-filedefault.json--exclusions-fileexclusions.yml# Scan Policy Filescloudsplainingscan-policy-file--input-fileexamples/policies/wildcards.json
cloudsplainingscan-policy-file--input-fileexamples/policies/wildcards.json--exclusions-fileexamples/example-exclusions.yml# Scan Multiple Accounts# Generate the multi account config filecloudsplainingcreate-multi-account-config-file-oaccounts.yml
cloudsplainingscan-multi-account-caccounts.yml-rTargetRole--output-directory./FAQWill it scan all policies by default?No, it will only scan policies that are attached to IAM principals.Will the download command download all policy versions?Not by default. If you want to do this, specify the--include-non-default-policy-versionsflag. Note that thescantool does not currently operate on non-default versions.I followed the installation instructions but can't execute the program via command line at all. What do I do?This is likely an issue with your PATH. Your PATH environment variable is not considering the binary packages installed bypip3. On a Mac, you can likely fix this by entering the command below, depending on the versions you have installed. YMMV.exportPATH=$HOME/Library/Python/3.7/bin/:$PATHI followed the installation instructions, but I am receiving aModuleNotFoundErrorthat saysNo module named policy_sentry.analysis.expand. What should I do?Try upgrading to the latest version of Cloudsplaining. This error was fixed in version 0.0.10.ReferencesPolicy SentrybyKinnaird McQuadeat SalesforceParliamentbyScott PiperatSummit Routeand Duo Labs.AWS Privilege Escalation MethodsbySpencer Gietzenat Rhino Security LabsUnderstanding Access Level Summaries within Policy SummariesLeveraging next-generation blockchain-based AI across multiple service meshes to transparently automate multi-cloud IAM wizardry :mage_man: