Skip to content

fix(infra): secret 読み取り Deny を自アカウントの parameter に絞る - #109

Merged
yook11 merged 1 commit into
mainfrom
fix/ci-deny-scope-ssm
Aug 4, 2026
Merged

fix(infra): secret 読み取り Deny を自アカウントの parameter に絞る#109
yook11 merged 1 commit into
mainfrom
fix/ci-deny-scope-ssm

Conversation

@yook11

@yook11 yook11 commented Aug 4, 2026

Copy link
Copy Markdown
Owner

問題

terraform-apply ロールで踏み台 (enable_db_bastion=true) を apply すると、AMI 参照で落ちる。

Error: reading SSM Parameter (/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64):
AccessDeniedException: User: .../vector-ci-terraform-apply/yook is not authorized to perform:
ssm:GetParameter ... with an explicit deny in an identity-based policy

  with data.aws_ssm_parameter.bastion_ami[0], on bastion.tf line 173

NoSecretValues の Deny が Resource: "*" なので、AWS が公開している /aws/service/* まで巻き込んでいた。この ARN は arn:aws:ssm:ap-northeast-1::parameter/aws/service/... で account 部が空だが、* には含まれる。

これまで踏み台は WorkloadAdministrator で生やしていたため露見しなかった。#107 で人間の経路を CI ロールへ寄せたことで表に出た。CI が踏み台を apply する場合も同じ箇所で落ちる。

変更内容

SSM の Deny だけ Resource を自アカウント所有の parameter に絞る。

ssm:GetParameter*        -> arn:aws:ssm:*:<account>:parameter/*
secretsmanager / kms     -> "*" のまま

秘密は全て自アカウントの parameter (/vector/*) にあるので、射程は変わらない。公開パラメータ (AMI ID など) には秘密が無い。

あわせて、4 つの policy に重複していた Deny 文を local.secret_read_statements へ括り出す。同じ契約・同じ変更理由を持つ重複なので、片方だけ直る状態を作らない。

検証

terraform validate / fmt 済み。plan は 0 to add, 4 to change, 0 to destroy で、4 policy とも Deny 文が 1 つ → 2 つに分かれるだけ。

apply 後、踏み台の apply が通ることを実機で確認する。

🤖 Generated with Claude Code

NoSecretValues が Resource "*" だったため、AWS が公開する
/aws/service/ami-amazon-linux-latest/* まで巻き込んでいた。account 部が空の
ARN なので `*` に含まれ、bastion の AMI 参照 (data.aws_ssm_parameter) が
terraform-apply で AccessDenied になる。

これまで踏み台は admin で生やしていたため露見しなかった。人間の経路を CI ロールへ
寄せたことで表に出たもので、CI が bastion を apply する場合も同じ箇所で落ちる。

SSM だけ Resource を arn:aws:ssm:*:<account>:parameter/* に絞る。秘密は全て
自アカウントの parameter にあるので射程は変わらない。secretsmanager と kms は
"*" のまま。4 policy で重複していた Deny 文を locals へ括り出す。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@yook11
yook11 merged commit 83ade25 into main Aug 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant