The first time you create your account, you need to create some initial steps:
-
Create a root account
- With a long long generated password
- Put password policy
- Add MFA to user
- Deactivate all regions in Account Settings
- Store the account id from https://console.aws.amazon.com/billing/home?#/account
pass insert -m keytwine/aws/root/account_id
- Enable IAM User and Role Access to Billing Information
-
Run the script
./scripts/generate_TerraformInitRestricted_policy.sh $(pass keytwine/aws/root/account_id)
and manually create the policyTerraformInitRestricted
with the output. It allows API usage and restricts by IP and time for 1h:TerraformInitRestricted
. Maybe a little bit paranoid, but it is free to have :). -
Create
terraform-init
user:- Programatic access only
- Attach the policy
TerraformInitRestricted
- Store the credentials:
cat <<EOF | pass insert -m -f keytwine/aws/root/terraform-init.credentials.sh
export [email protected]
export AWS_ACCESS_KEY_ID=FOFOFOFOFOFOOOOFOFO
export AWS_SECRET_ACCESS_KEY=BARBARBARBARBARBAR
EOF
- Run terraform. The output will print the new credentials for your users.
eval $(keytwine/aws/root/terraform-init.credentials.sh)
./run_terraform.sh init-backend
./run_terraform.sh init
./run_terraform.sh apply
You will get an output with the credentials of each user.
-
Now you can disable this bootstrap init user account:
- Disable the terraform-init AWS keys by running:
./scripts/self_lock_aws_access_key.sh
- Optionally delete the user and policy using the console.
- Disable the terraform-init AWS keys by running:
-
Finally: Configure the new users:
- Send the output of the terraform to each user.
- Each user can now login in the console: https://keytwine-root.signin.aws.amazon.com/console and:
- Change the password
- Add a MFA device in IAM > Users > username > MFA
In order to add a new subaccount:
- In the consolidated login, create a new subaccount: https://console.aws.amazon.com/organizations/home?#/accounts
- Set the "IAM role name" to something like
subaccount-admin
- Set the "IAM role name" to something like
- In the code: add a new variable with the subaccount ID: variables.tf, run-terraform.sh, provider.tf...
- Add the call to the subaccount module in
subaccount_<name>.tf
- Include the parameters
terraform_assume_role = "subaccount-admin"
for the first run, as the roleadmin
does not exist.
- Include the parameters
- Run
./run-terraform.sh apply
Once the account is setup, you can:
- Remove the
terraform_assume_role = "subaccount-admin"
so it would start using the roleadmin
- Remove the role
subaccount-admin
form the subaccount, for instance:
awssts admin@keytwine-sandbox
aws iam delete-role-policy
--role-name subaccount-admin
--policy-name AdministratorAccess
aws iam delete-role
--role-name subaccount-admin