【发布时间】:2022-05-10 03:18:57
【问题描述】:
嘿,我正在尝试跨帐户访问某个角色。 我有 2 个帐户:prod 和 non-prod。 和prod 帐户中的bucket,我试图将文件从非prod 角色写入到那里,该角色用作k8s 集群中的服务帐户。
在我配置的 prod 帐户中: 具有以下策略的角色(对存储桶的读写访问权限):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListObjectsInBucket",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::test2"
]
},
{
"Sid": "AllObjectActions",
"Effect": "Allow",
"Action": "s3:*Object",
"Resource": [
"arn:aws:s3:::test2/*"
]
}
]
}
以及以下信任:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::non-prod-AccountID:role/name-of-the-non-prod-role"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}
在我配置的非 prod 中:
具有以下政策的角色:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::prod-Account-ID:role/prod-role-name"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}
并信任如下:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::non-prod-accountID:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/1111111111111111111"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.us-east-1.amazonaws.com/id/1111111111111111111:sub":
"system:serviceaccount:name-space:name-of-the-service-account"
}
}
}
]
}
serviceAccount 注释是:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::non-prod-AccountID:role/non-prod-role-name
使用非产品角色的服务帐户从 pod 内部运行命令时:
aws s3 cp hello.txt s3://test2/hello.txt
我有:
upload failed: ./hello.txt to s3://test2/hello.txt An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
顺便说一下,集群在另一个帐户(devops 帐户)中,如果它相关,肯定将 OIDC 提供者身份添加到非产品和产品帐户作为身份提供者。
【问题讨论】:
-
嗨 talms1 欢迎来到 SO。您没有在问题中包含
ServiceAccount的注释。我也很想知道您是否将Action更改为没有前导通配符,它是否开始起作用?最后,不要忽视aws --debug s3 cp的强大功能,以了解 awscli 的想法。祝你好运 -
我的 serviceAccount 注释是:注释:#eks.amazonaws.com/role-arn:arn:aws:iam::non-prod-AccountID:role/non-prod-role-name。你的意思是s3政策的行动?没关系,我什至可以放 s3FullAcess 策略,仍然有同样的错误。
-
我认为您的“BTW”节是整个问题:您没有将“devops”帐户包含在任何这些信任关系中。您可以通过manually running
sts assume-role-with-web-identity使用--web-identity-token "$(cat /var/run/secrets/eks.amazonaws.com/serviceaccount/token)"自行确认这一点
标签: amazon-web-services kubernetes amazon-s3 roles service-accounts