有人可以解释一下为什么我的 OIDC 从 GitHub Actions 登录到 AWS 不起作用吗?
我在 AWS 控制台中创建了 OIDC 提供商。
我的角色具有信任关系:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::852523567171:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:sub": "repo:headincloud/hic-public-dns:*",
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
}
}
}
]
}
这应该允许所有分支机构通过 OIDC 访问 AWS,不是吗?
我的GitHub操作如下:
name: preview-changes
on:
push:
branches:
- main
jobs:
up:
name: Preview
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::852523567171:role/github-actions-dns
aws-region: eu-west-1
需要明确的是:列出的 ARN 是正确的。
不过,我在 Github Action 中遇到了这个错误:
Error: Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity
我的设置中到底缺少什么?
找到解决方案,并在此发布以防其他人偶然发现此问题。
在条件下使用
*
时,需要使用StringLike
代替StringEquals
。