You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GithubActions调用sts:AssumeRoleWithWebIdentity权限被拒求助

排查GitHub Actions连接AWS IAM角色时的AccessDenied错误

从你提供的CloudTrail日志和IAM信任策略对比来看,核心问题在于仓库名称的拼写不匹配:

  • 日志中userIdentity.userName显示实际请求的身份sub为:repo:TheLastAurora/cs2023_g7:ref:refs/heads/main
  • 但你的IAM信任策略中StringLike条件设置的sub匹配规则是:repo:TheLastAurora/cs20231_g7:*

两者的仓库名存在差异(cs2023_g7 vs cs20231_g7),导致AWS判定该请求不符合信任策略的条件,返回AccessDenied错误。

修复方案

修改IAM信任策略中的sub匹配规则,将错误的仓库名修正为实际的仓库名,更新后的策略如下:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::<arn-code>:oidc-provider/token.actions.githubusercontent.com"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringLike": {
                    "token.actions.githubusercontent.com:sub": "repo:TheLastAurora/cs2023_g7:*"
                },
                "ForAllValues:StringEquals": {
                    "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
                }
            }
        }
    ]
}

额外检查点

  • 确认GitHub Actions变量IAM_ROLE中的角色ARN,与CloudTrail日志里requestParameters.roleArn完全一致
  • 核对AWS_REGION变量值,需与日志显示的us-east-1匹配
  • 验证AWS IAM中配置的GitHub OIDC提供者ARN,确保账号ID部分无错误

内容的提问来源于stack exchange,提问作者Vitor L.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 19:53:11