如何配置AWS OIDC策略以支持多个GitHub Actions仓库?
支持多个GitHub仓库通过OIDC访问AWS的IAM策略修改方法
在IAM角色的信任策略中,不能重复使用同一个条件键(比如token.actions.githubusercontent.com:sub),正确的做法是将多个仓库的匹配规则放在数组中。
修改后的策略示例如下:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::<id>: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:username/myrepo:*", "repo:username/myrepo2:*", "repo:another-user/their-repo:*" ] } } } ] }
关键说明:
- 将原有的单个字符串值替换为数组,每个元素对应一个仓库的匹配规则
- 数组中的每个条目格式保持和原规则一致:
repo:<GitHub用户名>/<仓库名>:* - 可以添加任意数量的仓库条目,只要符合格式要求
内容的提问来源于stack exchange,提问作者Ymi
相关产品推荐
相关产品推荐

