我有一个 GitLab 管道,通过使用 OpenID Connect 担任角色来访问 AWS 资源 (
sts:AssumeRoleWithWebIdentity
)。
我可以使用
sub
声明将策略限制为特定项目和分支/标签。这是 GitLab 使用的格式:project_path:{group}/{project}:ref_type:{type}:ref:{branch_name}
我还想使用 JWT 负载中包含的
environment
自定义声明 作为角色信任策略的条件。
我已将
https://gitlab.com
配置为 OIDC 身份提供商。
这是我现在正在执行的信托政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::0123456789:oidc-provider/gitlab.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"gitlab.com:sub": "project_path:my-group/my-project:ref_type:branch:ref:main"
}
}
}
]
}
我想用这样的东西:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::0123456789:oidc-provider/gitlab.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"gitlab.com:sub": "project_path:my-group/my-project:ref_type:branch:ref:main",
"gitlab.com:environment": "production"
}
}
}
]
}
是否可以在信托政策中使用自定义声明?