0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHub ActionsのOIDCトークンの形式が変更されていてAssume Roleが失敗した話

0
Posted at

GitHub ActionsでECSへのデプロイを自動化しようとIAMロールの設定を行いテスト実行をしたところエラーが出たので記録として残します。

何を設定したらエラーがでたのか

新しく作成したGitHubリポジトリでGitHub Actionsを使用したECSへのCI/CD設定を行っていました。
この設定は過去に何度も行ったことがあり設定のテンプレートもあったので使いまわしていたところエラーが発生しました。

エラーを修正する前は以下のブログで作成しているIAMと同じ内容で信頼ポリシーの設定を行っていました。

JSONだとこんな感じ

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

上記のIAMロールを使用してテスト実行してみたところ以下のエラーが発生しました。

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

原因

以下のブログに記載されている通り、セキュリティ強化のため2026/07/15以降に作成されたGitHubリポジトリではsubクレームの内容が変更されていました。

All repositories created after July 15, 2026 will automatically use the new immutable subject claim format.

今まではsubクレームは以下の形式だったのですが、新しいリポジトリでは「repo:octocat@123456/my-repo@456789:ref:refs/heads/main」のような形に変更されています。

"repo:${OrgID}/${RepoName}:*"

そのため信頼ポリシーを以下のように変更していないと条件が一致せずAssumeRoleに失敗してしまいます。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::AWSアカウントID:oidc-provider/token.actions.githubusercontent.com"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringLike": {
                    "token.actions.githubusercontent.com:sub": "repo:${OrgID}@12345/${RepoName}@67890*"
                }
            }
        }
    ]
}

subクレームの確認方法

対象のGitHubリポジトリからSettingsをクリックして画面左中央くらいにあるActionsからOIDCをクリックすると以下のようにDefault subject claim prefixが確認できます。
この値をコピーして信頼ポリシーで使用すれば解決です。
スクリーンショット 2026-09-26 140500.png

さいごに

過去に実施したことのある設定でも期間が開いたら設定見直しておかないと駄目だなと思いました。
ここら辺のOIDC周りは理解が浅いのでお作法のように設定を入れている部分もあったのでそこはもう少し深堀していきたいところではあります。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?