My personal AWS account setup - IAM Identity Center, temporary credentials and sandbox account
Tags: aws, security
Published: 2024-05-23 21:26:29

I work on AWS projects every day and have access to internal and customer AWS accounts. But I also manage some personal AWS accounts.  They are useful for several reasons:

- I can run personal AWS applications, such as the smart home application I built.
- I can test new features, e.g. it was very helpful to learn about the CDK pipeline when it was introduced. I was able to create the accounts as suggested in the documentation. Later I was able to apply my knowledge to the customer project.
- If I have some permission issues, I can try to replicate the problem in my personal AWS accounts without any restrictions.
I can try new services that are only available in organizational root accounts, such as AWS Identity Center.

Of course, I want to run the AWS account in a secure and convenient way. So I decided to manage the accounts as described in this article.

## Account structure and AWS Organizations
Like a business, I created an [AWS organization](https://aws.amazon.com/organizations/) to manage my accounts. I'm using these accounts:
- Root account, which owns the organization
- Dev, Test, and Prod accounts to develop, test, and run my application
- [Pipeline account](https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html#best-practices-organization), which contains an AWS CodePipeline to deploy to Dev, Int, Prod
- Sandbox account for testing new stuff (gets nuked after testing)

![AWS Account structure with Root, Dev, Test, Prod, Pipeline and Sandbox account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0catbyig2e1w702581qq.png)

## User management and authentication using AWS Identity Center
I'm sure AWS IAM user management was great when it first launched. Now, [AWS IAM Identity Center](https://aws.amazon.com/iam/identity-center/) has more features and is easier to use. For example, it provides an easy-to-use interface to access all accounts and roles. Or it has improved [MFA capabilities](https://docs.aws.amazon.com/singlesignon/latest/userguide/mfa-types.html#mfa-types-apps), such as support for Apple's TouchID. That is why I chose AWS Identity Center. It is set up in the AWS Organizations root account and connects to all accounts in the organization.

When you open AWS IAM Identity Center, you can see the accounts and roles you can assume:
![AWS IAM Identity Center](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytfkm5337k18xe72d29b.png)

## Temporary credentials and Leapp
AWS IAM Identity Center provides temporary credentials by default, which is a good security choice. It supports [SSO integration](https://docs.aws.amazon.com/cli/latest/userguide/sso-configure-profile-token.html#sso-configure-profile-token-auto-sso) with AWS CLI or manual download of access key, secret access key, and session token.

Personally, I prefer to use [Leapp](https://www.leapp.cloud/), a tool that supports secure cloud access in multi-account environments. Recently, the company behind Leapp announced the end of the commercial version. The [open source version](https://github.com/Noovolari/leapp) still exists and can be used.

Leapp displays all AWS accounts/roles that are configured in AWS Identity Center. If you select an account, the credentials can be used in the CLI. You can override the default profile so you don't have to pass a `--profile` parameter. Or, you can configure a name profile.

![Leapp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3najrg6a3s7gudo2qv9t.png)

## Nuking the sandbox account
When I'm learning a new AWS service or testing a complex scenario, I'm not always using infrastructure as code. In this case, it takes a long time to manually clean up an AWS account and delete all (expensive) resources.

To improve this process, I use [aws-nuke](https://github.com/rebuy-de/aws-nuke), which automatically deletes all AWS resources in an AWS account. **Be careful with this tool**. The first time I used it, it also deleted the configurations required for IAM Identity Center. So I couldn't login anymore.

aws-nuke supports filters to exclude resources that should not deleted. I created filters to exclude the IAM Identity Center configuration and resources created during AWS CDK bootstrapping. I ended up with these filters:
```yaml
presets:
  common:
    filters:
      IAMRole:
      - "OrganizationAccountAccessRole"
      - type: glob
        value: "cdk-hnb659fds-*"
      - type: glob
        value: "AWSReservedSSO_AdministratorAccess_*"
      IAMRolePolicyAttachment:
      - "OrganizationAccountAccessRole -> AdministratorAccess"
      - type: glob
        value: "AWSReservedSSO_AdministratorAccess_* -> AdministratorAccess"
      - type: glob
        value: "cdk-hnb659fds-*"
      IAMRolePolicy:
      - type: glob
        value: "cdk-hnb659fds-*"
      IAMSAMLProvider:
      - type: glob
        value: "arn:aws:iam::*:saml-provider/AWSSSO_*_DO_NOT_DELETE"
      S3Bucket:
      - type: glob
        value: "s3://cdk-hnb659fds-assets*"
      SSMParameter:
      - "/cdk-bootstrap/hnb659fds/version"
      CloudFormationStack:
      - CDKToolkit
      ECRRepository:
      - type: glob
        value: "Repository: cdk-hnb659fds-container-assets-*"
```

## Summary
This setup works very well for me. AWS IAM Identity Center is great for managing users and logging into AWS accounts. Leapp is very helpful when using CLI credentials. However, it's not the only option as AWS IAM Identity Center offers other options as well. I regularly use the sandbox account when testing or learning about AWS services. By deleting everything with aws-nuke, I can easily start with an empty AWS account - and of course, I don't have to pay for unused resources.