![[小ネタ]GitHub ActionsでAssumeRoleするOIDCプロバイダのIssuerURLとオーディエンスの指定が変更されました](https://devio2023-media.developers.io/wp-content/uploads/2019/07/github-eyecatch.png)
[小ネタ]GitHub ActionsでAssumeRoleするOIDCプロバイダのIssuerURLとオーディエンスの指定が変更されました
この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
9月に話題となったGitHub ActionsでAWS Credentials が不要でAssumeRoleできるようになりましたが、OIDCプロバイダのIssuerURLが変更になりました。
突然の実行エラー
当初は以下のCloudFormationテンプレートでIAMロールを作成して10/8くらいまで動いていました。
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  RepoName:
    Type: String
    Default: example-nakahara/cfn-cicd
Resources:
  Role:
    Type: AWS::IAM::Role
    Properties:
      RoleName: github-actions-role
      ManagedPolicyArns: [arn:aws:iam::aws:policy/ReadOnlyAccess]
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Action: sts:AssumeRoleWithWebIdentity
            Principal:
              Federated: !Ref GithubOidc
            Condition:
              StringLike:
                token.actions.githubusercontent.com:sub: !Sub repo:${RepoName}:*
  GithubOidc:
    Type: AWS::IAM::OIDCProvider
    Properties:
      Url: https://token.actions.githubusercontent.com
      ClientIdList: [sigstore]
      ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
Outputs:
  Role:
    Value: !GetAtt Role.Arn      
週明け10/11にGitHubActionsを実行したところ、 could not establish AWS credentials; please run 'aws configure' or choose a profile とエラーがでて実行できなくなりました。
AWSから公式アナウンスされている機能では無いので原因がわからずにSNSを調べていると、GitHubの中の人のツイートを見つけました。
@sethvargo Heads up that the issuer url and audience are changing today for GitHub Actions OIDC. The new URL will be https://t.co/9XrBRxYQoh and default audience will be the repo owner url.
— Chris Patterson (@chrisrpatterson) October 6, 2021
OIDCプロバイダのIssuerURLが変更されたこと、オーディエンスの指定がリポジトリのオーナーURLとなったようです。↑のCloudFormationテンプレートを参考にしたサイトも変更されていました。(ありがとう!)
Parameters:
  GithubOrg:
    Type: String
    Default: example-nakahara
  FullRepoName:
    Type: String
    Default: example-nakahara/cfn-cicd
Resources:
  Role:
    Type: AWS::IAM::Role
    Properties:
      RoleName: github-actions-role
      ManagedPolicyArns: [arn:aws:iam::aws:policy/ReadOnlyAccess]
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Action: sts:AssumeRoleWithWebIdentity
            Principal:
              Federated: !Ref GithubOidc
            Condition:
              StringLike:
                token.actions.githubusercontent.com:sub: !Sub repo:${FullRepoName}:*
  GithubOidc:
    Type: AWS::IAM::OIDCProvider
    Properties:
      Url: https://token.actions.githubusercontent.com
      ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
      ClientIdList: 
        - !Sub https://github.com/${GithubOrg}
Outputs:
  Role:
    Value: !GetAtt Role.Arn 
Parametersと AWS::IAM::OIDCProvider のClientIdListがリポジトリのオーナーURLに変わってますね。
まとめ
ブログ執筆時点でも、AWSから公式アナウンスされていない無い機能なのでまだまだ変更があるかもしれないということも考慮して利用しましょう。












