GithubHelp home page GithubHelp logo

aws-solutions / account-assessment-for-aws-organizations Goto Github PK

View Code? Open in Web Editor NEW
27.0 16.0 10.0 2 MB

Account Assessment for AWS Organizations programmatically scans all AWS accounts in an AWS Organization for identity-based and resource-based policies with Organization-based conditions.

License: Apache License 2.0

Shell 2.75% TypeScript 30.43% JavaScript 0.30% Python 66.11% HTML 0.27% CSS 0.14%
aws-organizations aws-solutions

account-assessment-for-aws-organizations's Introduction

Account Assessment for AWS Organizations

Account Assessment for AWS Organizations programmatically scans all AWS accounts in an AWS Organization for identity-based and resource-based policies with Organization-based conditions.

πŸš€Solution Landing Page

Note: For any relevant information outside the scope of this readme, please refer to the solution landing page and implementation guide.

Table of content

Solution Overview

Architecture

The default deployment of solution pre-packaged template deploys following infrastructure in your account.

Installing pre-packaged solution template

Parameters


Customization

Setup

  • Python Prerequisite: python=3.9 | pip3=21.3.1
  • Javascript Prerequisite: node=v18.10.0 | npm=8.19.2

Clone the repository and make desired code changes.

git clone aws-solutions/account-assessment-for-aws-organizations

Note: Following steps have been tested under above pre-requisites

File Structure

β”œβ”€β”€ deployment/                             - contains build scripts, deployment templates, and dist folders for staging assets.
  β”œβ”€β”€ cdk-solution-helper/                  - helper function for converting CDK output to a format compatible with the AWS Solutions pipelines.
  β”œβ”€β”€ build-open-source-dist.sh             - builds the open source package with cleaned assets and builds a .zip file in the /open-source folder for distribution to GitHub
  β”œβ”€β”€ build-s3-dist.sh                      - builds the solution and copies artifacts to the appropriate /global-s3-assets or /regional-s3-assets folders.
  β”œβ”€β”€ build-lambdas.sh                      - builds and packages the lambda code only
β”œβ”€β”€ source/   
  β”œβ”€β”€ account-assessment-solution.ts        - the CDK app that wraps your solution.
  β”œβ”€β”€ lambda/                               - the source code for the solution's lambda functions
    β”œβ”€β”€ requirements.txt
    β”œβ”€β”€ testing_requirements.txt            - python test dependency file
    β”œβ”€β”€ assessment_runner/                  - job management microservice
    β”œβ”€β”€ aws/
    β”œβ”€β”€ services                            - low-level clients to interact with AWS Services
        └── utils/
    β”œβ”€β”€ delegated_admins/                   - delegated admin scan microservice
    β”œβ”€β”€ deploy_webui/                       - lambda-backed custom resource to deploy solution WebUI to S3
    β”œβ”€β”€ resource_based_policy/              - IAM policies scan microservice
        β”œβ”€β”€ step_functions_lambda/
        └── supported_configuration/
    β”œβ”€β”€ tests/
    β”œβ”€β”€ trusted_access_enabled_services/    - Trusted AWS Services scan microservice
    └── utils/
   β”œβ”€β”€ bin
       └──  account-assessment-solution.ts     - the main CDK stack for your solution.
   β”œβ”€β”€ lib
     β”œβ”€β”€ account-assessment-hub-stack.ts    - the hub CDK stack.
     β”œβ”€β”€ account-assessment-spoke-stack.ts  - the spoke CDK stack.
     β”œβ”€β”€ app-register.ts                    - integrates Hub and Spoke stacks with AppRegistry
     β”œβ”€β”€org-management-account-stack.ts     - the AWS Organizations Management CDK stack.
     └── components                         - hub stack resources grouped into constructs for better maintainability 
      β”œβ”€β”€ api.ts                            - resources related to API Gateway
      β”œβ”€β”€ cognito-authenticator.ts          - resources related to authentication
      β”œβ”€β”€ job-history-component.ts          - DynamoDB table and Lambda functions related to the job management microservice
      β”œβ”€β”€ resource-based-policy-component.ts - Lambda functions related to the resouce based policy microservice
      β”œβ”€β”€ resource-based-policy-state-machine.ts - custom resource to deploy solution WebUI to S3
      β”œβ”€β”€ simple-assessment-component.ts    - generic set of DynamoDB table and Lambda functions for all microservices.
      β”œβ”€β”€ web-ui-deployer.ts                - custom resource to deploy solution WebUI to S3
      └── web-ui-hosting.ts                 - resources to host the web ui in S3
  β”œβ”€β”€ webui                                 - react app that serves as user interface for this solution
  β”œβ”€β”€ test/
    β”œβ”€β”€ __snapshots__/
β”œβ”€β”€ cdk-solution-test.ts                    - example unit and snapshot tests for CDK project.
  β”œβ”€β”€ cdk.json                              - config file for CDK.
  β”œβ”€β”€ jest.config.js                        - config file for unit tests.
  β”œβ”€β”€ package.json                          - package file for the CDK project.
  β”œβ”€β”€ README.md                             - doc file for the CDK project.
  β”œβ”€β”€ run-all-tests.sh                      - runs all tests within the /source folder. Referenced in the buildspec and build scripts.
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .viperlightignore                       - Viperlight scan ignore configuration  (accepts file, path, or line item).
β”œβ”€β”€ .viperlightrc                           - Viperlight scan configuration.
β”œβ”€β”€ buildspec.yml                           - main build specification for CodeBuild to perform builds and execute unit tests.
β”œβ”€β”€ CHANGELOG.md                            - required for every solution to include changes based on version to auto-build release notes.
β”œβ”€β”€ CODE_OF_CONDUCT.md                      - standardized open source file for all solutions.
β”œβ”€β”€ CONTRIBUTING.md                         - standardized open source file for all solutions.
β”œβ”€β”€ LICENSE.txt                             - required open source file for all solutions - should contain the Apache 2.0 license.
β”œβ”€β”€ NOTICE.txt                              - required open source file for all solutions - should contain references to all 3rd party libraries.
β”œβ”€β”€ README.md                               - required file for all solutions.

Unit Test

Run unit tests to make sure added customization passes the tests.

cd ./source
chmod +x ./run-all-tests.sh
./run-all-tests.sh
cd ..

βœ… Ensure all unit tests pass. Review the generated coverage report

Build

To build your customized distributable follow given steps.

  • Configure the solution name, version number and bucket name as environment variables
  • At deployment time, the webui distributable will be copied from DIST_OUTPUT_BUCKET to the created hosting bucket. Replace solutions-features by your own bucket name, if you make changes to the web ui.
SOLUTION_NAME=AccountAssessment
DIST_OUTPUT_BUCKET=solutions-features
VERSION=custom001
  • Build the distributable using build-s3-dist.sh
cd ./deployment
chmod +x ./build-s3-dist.sh
./build-s3-dist.sh $DIST_OUTPUT_BUCKET $SOLUTION_NAME $VERSION
cd ..
  • If you customized the web ui, upload the folder webui from deployment/regional-s3-assets to your own s3 bucket. Replace solutions-features in package.json by yor own bucket name.

Deploy

Determine the parameter values that you want to deploy the stacks with:

  • DeploymentNamespace: An arbitrary value that is shared by Hub Stack and OrgMgmt Stack and Spoke Stack.
  • CognitoDomainPrefix: An arbitrary, globally unique value to prefix the login page url.
  • UserEmail: The email address for the first Cognito User which the deployment creates.
  • AllowListedIPRanges: CIDR blocks to permit API access. To allow any IP, use 0.0.0.0/1,128.0.0.0/1
  • HubAccountId: The AccountId of your AWS Account you are deploying the Hub Stack to.

PROFILE_HUB, PROFILE_SPOKE, PROFILE_ORG_MGMT are the AWS CLI profiles on your machine that determines AccountId and Region to deploy to. We recommend to choose an account as PROFILE_HUB that is different from your Org Management Account. Each account in your AWS Organization that you intend to scan wit this solution is a spoke account and needs a deployment of the spoke template.

In case your accounts have not been bootstrapped for cdk yet, run:

cd ./source
npm run bootstrap -- --profile <PROFILE_HUB>
npm run bootstrap -- --profile <PROFILE_SPOKE>
npm run bootstrap -- --profile <PROFILE_ORG_MGMT>
cd ..

With the values determined above, run the following commands:

cd ./source
npm run deploy -- --parameters DeploymentNamespace=<NAMESPACE> --parameters CognitoDomainPrefix=<PREFIX> --parameters UserEmail=<EMAIL>  --parameters AllowListedIPRanges=<IP-RANGES> --profile <PROFILE_HUB>
npm run deploySpoke -- --parameters DeploymentNamespace=<NAMESPACE> --parameters HubAccountId=<HUB_ACCOUNT_ID> --profile <PROFILE_SPOKE>
npm run deployOrgMgmt -- --parameters DeploymentNamespace=<NAMESPACE> --parameters HubAccountId=<HUB_ACCOUNT_ID> --profile <PROFILE_ORG_MGMT>
cd ..

Faster development cycles

Once you have built and deployed the complete solution once, you may want to shorten the cycle times for iterative development.

Frontend development

  • Download the file aws-exports-generated.json from your WebUIHostingBucket that was created during the first deployment.
  • Place the file in /source/webui/public
  • Replace the generated values of the following properties in the file to point to localhost:
"redirectSignIn": "http://localhost:3000/",
"redirectSignOut": "http://localhost:3000/",

Start the web ui react app locally. It will use Cognito and API Gateway in your Hub Account as the backend.

cd ./source/webui
npm run start

Backend development

When you make changes to the lambda function code only (source/lambda), you may want to package and deploy the lambda code without building the webui. For that, run the following commands with the parameter values determined above:

cd ./source
npm run buildLambdaAndDeploy -- --parameters DeploymentNamespace=<NAMESPACE> --parameters CognitoDomainPrefix=<PREFIX> --parameters UserEmail=<EMAIL>  --parameters AllowListedIPRanges=<IP-RANGES> --profile <PROFILE_HUB>
cd ..

This will replace the file deployment/regional-s3-assets/lambda.zip from your initial build with a new package of your modified source code and its dependencies, retaining deployment/regional-s3-assets/webui from the initial build.

CDK development

Should you make changes to the CDK app code only, and neither webui nor lambda code, it is sufficient to run:

cd ./source
npm run deploy -- --parameters DeploymentNamespace=<NAMESPACE> --parameters CognitoDomainPrefix=<PREFIX> --parameters UserEmail=<EMAIL>  --parameters AllowListedIPRanges=<IP-RANGES> --profile <PROFILE_HUB>
cd ..

This will update your hub stack with the changed resources, but use the unchanged webui and lambda code in deployment/regional-s3-assets from the initial build.


Collection of operational metrics

This solution collects anonymized operational metrics to help AWS improve the quality and features of the solution. For more information, including how to disable this capability, please see the implementation guide.


License

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at

http://www.apache.org/licenses/

or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and limitations under the License.

account-assessment-for-aws-organizations's People

Contributors

aijunpeng avatar amazon-auto avatar gockle avatar groverlalit avatar gsingh04 avatar jrgaray27 avatar tbelmega avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

account-assessment-for-aws-organizations's Issues

Potential Failed-by-Default ECR policy test case for resource-based policy scan

Describe the bug
The provided mock_data provides a failed-by-default test cases for tests/test_resource_based_policy/test_ecr_policy_for_organizations_dependency.py, due to the limitation of ECR repository name, that are not supposed to contain any capital letter. The following mock data is the cause of this bug on file ./source/lambda/tests/test_resource_based_policy/mock_data.py:189-191 :

    {
        "MockResourceName": "ResourceWithNoPolicy",
    }

To Reproduce
Run the ./source/run-all-tests.sh for custom-build of this solution, without an change to the repository code after exporting a valid AWS_REGION environment value (eg. us-west-1).

Expected behavior
There should not have a false-by-default test case from the given mock_data, but fail by misconfiguration or wrongly modified IaC code.

Example Patch
Add the .lower() function on the following code block to make the resource name into non-capital letter.

# ./source/lambda/tests/test_resource_based_policy/test_ecr_policy_for_organizations_dependency.py:35-37
ecr_client.create_repository(
    repositoryName=policy_object.get('MockResourceName').lower()
)

Please complete the following information about the solution:

  • Version: v1.0.4 [e.g. v1.0.0]

To get the version of the solution, you can look at the description of the created CloudFormation stack.

For example, "(SO0217) - The AWS CloudFormation hub template for deployment of the Account Assessment for AWS Organisations, Version: v1.0.0".

  • Region: us-west-1 [e.g. us-east-1]
  • Was the solution modified from the version published on this repository? No
  • If the answer to the previous question was yes, are the changes available on GitHub? NA
  • Have you checked your service quotas for the sevices this solution uses? NA
  • Were there any errors in the CloudWatch Logs? NA

Screenshots
Screenshot 2023-08-30 at 14 49 23
Screenshot 2023-08-30 at 14 50 30

Additional context

Add discovery and reporting for RAM shares

Is your feature request related to a problem? Please describe.
The tool perform discovery on a number of resources that could/would be impacted by the migration of accounts between instances of AWS Organizations. However, it does have a blind spot for RAM shared resources.

This problem has been compounded by a security improvement that was introduced last years, where resources shared explicitly by an account id as the principle are treated differently depending on whether the (at the time of share creation) the provider and subscriber AWS accounts are within the same organizations.

This means that even where a a share is explicitly between two linked account s within an organizations and without RAM being enabled as a trusted services in organizations the share would be impacted when one or other participant moves outside of the organization.

Describe the feature you'd like
To add reporting of RAM shared resources? both Org/OU id based shares but alls account id based. Since they are treated differently for accounts within the same org and when account migrate the shares dis-associate or disappear (r53).

Additional context
Reach out for additional context.

Queries to services do not return all resources because paging is not being used

Describe the bug
When working on accounts with large numbers of resources in a given service, only a portion of the resources are returned in the query. For example, if we have more than 100 IAM roles, the query will return only the first 100, as this is the default limit of the list_roles method page of the iam service in boto3. (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam/client/list_roles.html). This goes for other resources like IAM Policies, secrets in Secrets Manager, KMS Keys, SNS Topics, etc...

To Reproduce
Take an account over 100 IAM roles and start a Resource-Based Policies scan. You will only see the first 100 IAM roles.

Expected behavior
View all IAM roles in the account

Please complete the following information about the solution:

  • [v1.0.2] Version:

To get the version of the solution, you can look at the description of the created CloudFormation stack.

For example, "(SO0217) - The AWS CloudFormation hub template for deployment of the Account Assessment for AWS Organisations, Version: v1.0.0".

  • [us-east-1] Region: [e.g. us-east-1]
  • [no] Was the solution modified from the version published on this repository?
  • [n/a] If the answer to the previous question was yes, are the changes available on GitHub?
  • [n/a] Have you checked your service quotas for the sevices this solution uses?
  • [no] Were there any errors in the CloudWatch Logs?

Screenshots
If applicable, add screenshots to help explain your problem (please DO NOT include sensitive information).

Additional context
Add any other context about the problem here.
I collected the information I needed using a personal script and applied paging whenever the resource allowed. e.g:

#Get IAM roles
...
    resource_list = []
    paginator = client.get_paginator('list_roles')
    page_iterator = paginator.paginate()
    for page in page_iterator:
      for item in page.get('Roles'):
        if item is not None:
          resource_list.append(item)
....
if resource_list is not None:
    try:
      for resource in resource_list:
....

opensearch.describe_domains does not allow more than 5 at a time

Describe the bug
The opensearch.describe_domains call to does not allow more than 5 at a time

To Reproduce
Test in an account which has more than 5 domains

Expected behavior
Is able to enumerate and analyze the policies for all domains in the account/region - Does not return {"Error": {"Message": "Please provide a maximum of 5 domain names to describe.", "Code": "ValidationException"}, "

Please complete the following information about the solution:

  • v1.0.2

Additional context

$ aws opensearch list-domain-names --output text --query 'DomainNames[].[DomainName, EngineType]'  
search1	OpenSearch
search2	OpenSearch
es-search3	Elasticsearch
es-search4	Elasticsearch
es-diag5	Elasticsearch
search6	OpenSearch
es-diag7	Elasticsearch
es-search8	Elasticsearch

$ aws opensearch describe-domains --domain-names search1 search2 es-search3 es-search4 es-diag5 search6 --output text --query 'DomainStatusList[].[DomainName]'

An error occurred (ValidationException) when calling the DescribeDomains operation: Please provide a maximum of 5 domain names to describe.

$ aws opensearch describe-domains --domain-names search1 search2 es-search3 es-search4 es-diag5  --output text --query 'DomainStatusList[].[DomainName]'
search1
search2
es-search3
es-search4
es-diag5

Autodetect regions

Use case
In a large org with many accounts optional regions are enabled only in several dozens accounts and we don't necessarily have a list, If we run for all optional regions, we get lots of errors (several hundreds of accounts report 4-5 errors about regions not being present)

Auto detect what regions to scan
Would like the code to operate in all regions which are enabled for the specific account

Additional context
Above implies we make a call to ec2.describe_regions for each account and this is what determines which regions are scanned

10 character namespace is not usable with regions that have long name

Describe the bug
The management stack cannot deploy because the role name is too long.

The solution states that the namespace can be up to 10 characters. The management stack template uses the namespace to create role on line 176:

Namespace 1234567890 in region ap-southeast-2 turns into 1234567890-ap-southeast-2-AccountAssessment-OrgManagementStackRole which results in role name of 66 characters and throws the following error:

1 validation error detected: Value '1234567890-ap-southeast-2-AccountAssessment-OrgManagementStackRole' at 'roleName' failed to satisfy constraint: Member must have length less than or equal to 64 (Service: AmazonIdentityManagement; Status Code: 400; Error Code: ValidationError; Request ID: 84ca7ec9-43c3-44a4-8e5f-1e2ddda7e599; Proxy: null)

To Reproduce
Select a namespace that has 10 characters.

Expected behavior
Management stack should be deployed without validation errors.

Please complete the following information about the solution:

  • v1.0.1

To get the version of the solution, you can look at the description of the created CloudFormation stack.

For example, "(SO0217) - The AWS CloudFormation hub template for deployment of the Account Assessment for AWS Organisations, Version: v1.0.1".

  • Region: ap-southeast-2
  • Was the solution modified from the version published on this repository? No
  • If the answer to the previous question was yes, are the changes available on GitHub? N/A
  • Have you checked your service quotas for the sevices this solution uses? N/A
  • Were there any errors in the CloudWatch Logs? No

Solution Web-UI doesn't work due to CORS violations and 403 Errors

Describe the bug
After deploying the solution, a blank red banner appears at the top of the page, buttons do not seem to function, and the browser console is full of errors, all related to Cross-Origin-Resource-Sharing policy.

The web-UI url is https://(MYRANDOMSTRING).cloudfront.net/

but multiple references on the page point to https://(SOMEOTHERRANDOMSTRING).execute-api.us-east-1.amazonaws.com/prod/* and there is no associated CORS header to allow this.

To Reproduce
Deploy The solution from the Console using the link from the documentation, enter parameters. Visit Web UI cloudfront URI from the Cloudformation Stack Outputs

Expected behavior
No CORS errors. Buttons, UI, API functioning when visiting from the cloudfront.net url.

Please complete the following information about the solution:

  • [v1.0.5 ] Version: [e.g. v1.0.0]

To get the version of the solution, you can look at the description of the created CloudFormation stack.

For example, "(SO0217) - The AWS CloudFormation hub template for deployment of the Account Assessment for AWS Organisations, Version: v1.0.0".

  • [ us-east-1] Region: [e.g. us-east-1]
  • [ no] Was the solution modified from the version published on this repository?
  • If the answer to the previous question was yes, are the changes available on GitHub?
  • [ no] Have you checked your service quotas for the sevices this solution uses?
  • [ no] Were there any errors in the CloudWatch Logs?
  • There are some 403s from hitting the endpoints directly, but I think that was me debugging before I noticed CORS errors in the console. CORS would've blocked visiting the endpoint from the embedded src tags before making a request.

Screenshots
If applicable, add screenshots to help explain your problem (please DO NOT include sensitive information).
Console error
image

Additional context
I configured the solution to deploy in a single account, if that means anything. I omitted the two org/account IDs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.