Repository navigation
Make devops-security runnable against a contributor's own AWS account #196
Copy link
Copy link
Closed
Labels
complexity: mediumfeature: maintenancerole: DevOps Engineersize: 3ptCan be done in 13-18 hoursCan be done in 13-18 hours
Milestone
Description
Overview
We need to make this Terraform runnable against a contributor's own AWS account, because that is how we ask people to test changes here. Today it only works against the Hack for LA account: the import blocks and the CloudTrail resources both name account 035866691871.
Action Items
- Delete
terraform/imports.tfand remove theimportblocks fromaws-custom-policies-legacy.tf,aws-groups-legacy.tfandaws-users-legacy.tf(18 blocks in total). Keep theresourceblocks. All 18 targets are already in state, so in the Hack for LA account these blocks do nothing. In any other account they make Terraform try to import resources that don't exist. - Add a root variable
iam_only(bool, defaulttrue) and setcount = var.iam_only ? 0 : 1on all 11 resources incloudtrail.tf. Update any reference between them to use[0]. These are the only resources in the repo that aren't IAM, and their bucket names are global and already taken, so they can't be created in another account.- No
movedblocks are needed. Terraform treats an existing object as instance[0]whencountis added to it.
- No
- Add
lifecycle { prevent_destroy = true }to bothaws_cloudtrailresources and bothaws_s3_bucketresources. This is required, not optional. Because the default istrue, any run against the Hack for LA account that forgets to setiam_only = falsewould plan to destroy both audit trails. This includes a localterraform planby a lead. Withprevent_destroy, that plan errors instead. - In both
.github/workflows/terraform-plan.yamland.github/workflows/terraform-apply.yaml, addvariables: iam_only = falseto thedflookstep'swith:block. - In
aws-groups.tf, replace the hardcodedarn:aws:iam::035866691871:policy/ManageAccessKeysonaws_iam_group_policy_attachment.manageAccessKeyswithaws_iam_policy.manage_access_keys.arn. It is the same ARN in our account, so the plan should not change, but in any other account the hardcoded one fails. - Document for contributors that a test run needs no
iam_onlysetting, and what it will create in their account. That includes every declared IAM user, theops-leadsgroup withAdministratorAccess, and the GitHub Actions OIDC provider, which fails withEntityAlreadyExistsif their account already has one. Also document that anyone running against the Hack for LA account must pass-var iam_only=false. - Before merging, confirm the PR's CI plan reads 0 to add, 0 to change, 0 to destroy. That is the evidence the Hack for LA account is untouched.
- After the PR merges, confirm the
Terraform apply (OIDC)run onmainsucceeds with no changes, and that both trails still exist:aws cloudtrail describe-trails --region us-west-2.
Resources/Instructions
- Files:
terraform/imports.tf,terraform/cloudtrail.tf,terraform/aws-groups.tf(the ARN was at line 25 when written; line numbers may drift, so search for035866691871), the threeterraform/*-legacy.tffiles, and both workflow files above. - How the imports got here: Created resources and import statements to import ops-leads #157, Bring the remaining IAM users under Terraform #180, Import the two CloudTrail trails and their log buckets #193.
dflook/terraform-planvariablesinput: https://github.com/dflook/terraform-github-actions/tree/main/terraform-plan#variables- Terraform
prevent_destroy: https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#prevent_destroy
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
complexity: mediumfeature: maintenancerole: DevOps Engineersize: 3ptCan be done in 13-18 hoursCan be done in 13-18 hours
Type
Projects
- StatusShow more project fieldsDone
Activity