1
0

github actions で OIDCでAWSを認証しようとしたらエラーがNot authorized to perform

Posted at

概要

この記事を参考にgithub actions で OIDCでAWSを認証しようとしたら以下のエラー

Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity

解決策

以下の部分が良くなかった

                "StringEquals": {
                    "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
                }

IAMロールの信頼されたエンティティを以下に修正

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::${AWSアカウント}:oidc-provider/token.actions.githubusercontent.com"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringLike": {
                    "token.actions.githubusercontent.com:sub": "repo:${githubリポジトリ}:*"
                }
            }
        }
    ]
}

最後に

このポリシー条件は、GitHub Actionsから送られたOIDCトークンの aud クレームが sts.amazonaws.com と等しい場合にのみ、sts:AssumeRoleWithWebIdentity アクションを許可するという意味です。これにより、トークンが確かにAWSのSTSを対象として発行されたものであることを確認しています。

aud クレームは、トークンが使用されるべき対象(オーディエンス)を示します。

それが異なっていた?

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0