Repository navigation
Conversation
- core-dev.tf/core-prod.tf: add gke/gcve service accounts to KMS restricted admins - variables.tf: extend service_accounts type with optional gke/gcve keys - vpc-sc.tf: preserve enforced perimeter status when dry_run=true - outputs.tf: restrict local file permissions to 0600, add kms_key_name to uploaded tfvars - destroy.sh: replace eval injection with printf -v for safe variable assignment - create_e2e_sandbox.sh: fix typo tocuh to touch
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
刚 force push 了 erraform fmt 修复 Repository Lint(for_each map key 对齐)。CI 会重新跑。 |
|
Hi, I just signed the Google Contributor License Agreement (CLA). Could someone please re-run the \cla/google\ check? Thanks! |
aghassemlouei
left a comment
There was a problem hiding this comment.
Running terraform plan on fast/stages-aw/3-security and checking the shell updates for #371 surfaced three issues documented inline:
fast/stages-aw/3-security/core-dev.tfstill retainsvar.service_accounts.project-factory-prodinsidelocal.dev_kms_restricted_admins, continuing to grant the production project-factory service accountroles/cloudkms.adminon development KMS keys.fast/stages-aw/3-security/outputs.tflooks up a nonexistentdefaultkey onmodule.prod-sec-kms[keys(module.prod-sec-kms)[0]]forgoogle_storage_bucket_object.tfvars, which silently evaluates tonulland references Stage 3's security KMS keyring instead of Stage 0's automation outputs bucket KMS key.scripts/destroy.shpasses${stage_id}_DESTROYEDand$var_nametoprintf -vwithout validating identifier syntax, and items 4 and 5 of #371 insa_lockdown.sh,validation.sh,scripts/restore.sh, andgenerate-mocks.shremain open while the description usesFixes #371.without the.github/pull_request_template.mdsections.
| var.service_accounts.data-platform-dev, | ||
| var.service_accounts.project-factory-dev, | ||
| var.service_accounts.project-factory-prod | ||
| var.service_accounts.project-factory-prod, | ||
| var.service_accounts.gke-dev, | ||
| var.service_accounts.gcve-dev, |
There was a problem hiding this comment.
var.service_accounts.project-factory-prod is still present in local.dev_kms_restricted_admins, which continues granting the production project-factory service account roles/cloudkms.admin on development KMS keys per item 1 of #371. Remove var.service_accounts.project-factory-prod from core-dev.tf so dev_kms_restricted_admins contains only development service accounts:
| var.service_accounts.data-platform-dev, | |
| var.service_accounts.project-factory-dev, | |
| var.service_accounts.project-factory-prod | |
| var.service_accounts.project-factory-prod, | |
| var.service_accounts.gke-dev, | |
| var.service_accounts.gcve-dev, | |
| var.service_accounts.data-platform-dev, | |
| var.service_accounts.project-factory-dev, | |
| var.service_accounts.gke-dev, | |
| var.service_accounts.gcve-dev, |
| bucket = var.automation.outputs_bucket | ||
| name = "tfvars/3-security.auto.tfvars.json" | ||
| content = jsonencode(local.tfvars) | ||
| kms_key_name = try(module.prod-sec-kms[keys(module.prod-sec-kms)[0]].keys.default.id, null) |
There was a problem hiding this comment.
try(module.prod-sec-kms[keys(module.prod-sec-kms)[0]].keys.default.id, null) has three issues:
var.kms_keysdefaults to{}and has no guaranteeddefaultkey entry, sokms_key_namesilently evaluates tonullduringterraform plan.keys(module.prod-sec-kms)[0]selects whichever KMS location sorts first lexicographically, such asglobalorus, which mismatches the regional location ofvar.automation.outputs_bucket.var.automation.outputs_bucketlives in the Stage 0 automation projectvar.automation.project_id, whose Cloud Storage service agent holdsroles/cloudkms.cryptoKeyEncrypterDecrypteron Stage 0'sgcskeyprojects/${var.automation.project_id}/locations/${var.regions.primary}/keyRings/gcs/cryptoKeys/gcsused by0-bootstrapand1-resman, not on Stage 3'sprod-sec-kmskeys.
| log_info "Marking $stage_id as complete..." | ||
| # Update current session variable | ||
| eval "${stage_id}_DESTROYED=true" | ||
| printf -v "${stage_id}_DESTROYED" "true" |
There was a problem hiding this comment.
Guard stage_id here and var_name in prompt_val at lines 424 and 428 with [[ "$stage_id" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] before calling printf -v, since printf -v evaluates array subscripts inside non-validated variable names in Bash.
Fixes #371.
Summary
This PR addresses security and functional defects in
fast/stages-aw/3-securityand repository automation scripts.Changes Made
Stage 3 Security (Terraform)
variables.tf: Extended
service_accountsobject type with optionalgke-dev,gke-prod,gcve-dev,gcve-prodkeys usingoptional(string, null).core-dev.tf: Added
var.service_accounts.gke-devandvar.service_accounts.gcve-devtodev_kms_restricted_adminslist so GKE and GCVE service accounts receive KMS admin permissions on development keys.core-prod.tf: Added
var.service_accounts.gke-prodandvar.service_accounts.gcve-prodtoprod_kms_restricted_adminslist so GKE and GCVE service accounts receive KMS admin permissions on production keys.vpc-sc.tf: Changed
statusfrom(!dry_run ? local.vpc_sc_perimeter : null)to alwayslocal.vpc_sc_perimeter. This preserves the enforced perimeter status when dry_run mode is enabled, preventing accidental removal of VPC Service Controls protection.outputs.tf: Changed
file_permissionfrom"0644"to"0600"on the local tfvars file, and addedkms_key_nameto thegoogle_storage_bucket_objectresource so uploaded tfvars are encrypted with CMEK.Scripts (Bash)
scripts/destroy.sh: Replaced all 3 instances of
evalwithprintf -vfor safe variable assignment, preventing potential command injection from interactive user input.tools/create_e2e_sandbox.sh: Fixed typo
tocuh→touch.Security Impact