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?

AWS CDKを使用したOIDCベースのIAMロール設定

Last updated at Posted at 2025-03-30

AWS CDKを使用してGitHub Actionsなどの外部システムがAWSのロールを引き受けるために、OIDC (OpenID Connect) を使用する設定方法について、整理した内容です

OIDCプロバイダの作成

まず、OpenID Connect (OIDC) プロバイダを作成し、外部認証システム(例:GitHub、Googleなど)とAWS間の認証を接続します。

例えば、GitHub Actionsを使用する場合、GitHubのOIDCプロバイダのURLを使用してAWSでプロバイダを設定します。

GitHubのOIDCプロバイダURLは https://token.actions.githubusercontent.com です。

IAMロールの作成

IAMロールを作成し、そのロールに信頼ポリシーを設定して、外部認証システムがそのロールを引き受けることができるようにします。

信頼ポリシーには sts:AssumeRoleWithWebIdentity 権限が必要です。

外部システムで作成された Web Identity Token を使用してロールを引き受けることができます。

信頼ポリシー例(GitHub Actions用)
以下はGitHub Actionsで使用するOIDC信頼ポリシーの例です:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::****:oidc-provider/token.actions.githubusercontent.com"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringLike": {
                    "token.actions.githubusercontent.com:sub": "repo:your-username/your-repository-name/*:*"
                }
            }
        }
    ]
}

arn:aws:iam::****:oidc-provider/token.actions.githubusercontent.com: GitHub Actions OIDCプロバイダのARNです。

StringLike 条件を使用して、特定のGitHubリポジトリの sub 値を確認します。

ロールにポリシーを付与

作成したロールに必要な権限を付与します。例えば、AdministratorAccess ロールを付与することができます。

  • ロールに AdministratorAccess ポリシーを付与して、そのロールを引き受けたシステムがAWSリソースを制御できるようにします。
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?