コンテンツにスキップ

OIDCを利用したWorkflow

例としてGitHubを使用する

sequenceDiagram
  autonumber
    participant ga as GitHub Actions
    participant g as GitHub
    participant s as AWS STS
    participant s3 as AWS S3

    ga->>ga: Workflow開始
    ga->>g: OIDC Token要求
    g->>g: JWT TOken発行
    g->>s: Token送信
    s->>s: Token検証
    s->>s: 一次認証情報発行
    s->>ga: 一次認証情報を返却
    ga->>s3: s3 sync

IDプロバイダーで、OIDCのプロバイダーを増やすことができる。

aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.com \
--thumbprint-list 6938fd4d98bab03faadb97b34396831e3780aea1

thumbprintの取得は公開されているものがほとんど。

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowS3Sync",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::aucnet-infra-portal",
"arn:aws:s3:::aucnet-infra-portal/*"
]
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:your-org/your-repo:*"
}
}
}
]
}
  • token.actions.githubusercontent.com:sub
    • repo:your-org/your-repo:ref:refs/heads/main