我有一個主賬戶用戶,我想允許訪問子賬戶S3存儲桶。我已經安裝了下面的堆棧在我的子賬戶設置IAM用戶/角色的跨賬戶訪問權限
AWSTemplateFormatVersion : '2010-09-09'
Description: 'Skynet stack to allow admin account deploying user to access S3'
Parameters:
AccountId:
Type: String
Description: Account ID of admin account (containing user to allow)
Username:
Type: String
Description: Username to be allowed access
BucketPrefix:
Type: String
Description: Bucket to be allowed (prefix appended with -{AccountId}-{Region})
Resources:
CrossAccountRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
AWS:
- !Sub arn:aws:iam::${AccountId}:user/${Username}
Path:/
Policies:
- PolicyName: skynet-s3-delegate
PolicyDocument:
Statement:
- Effect: Allow
Action:
- s3:ListBucket
- s3:GetObject
Resource: "*"
但我發現,當我嘗試承擔該角色,我仍然得到一個錯誤:
aws s3 cp skynet-lambda.zip s3://skynet-lambda-TARGET_ACCOUNT_ID-ap-southeast-1 --profile skynetci-cross-account
An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::MAIN_ACCOUNT_ID:user/circleci-skynet is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::TARGET_ACCOUNT_ID:role/StackSet-df0e85b0-d6fd-47bf-a0bb-CrossAccountRole-1EW45TXEFAY0D
爲什麼這麼考慮我已經對用戶有以下政策
{
"Effect": "Allow",
"Action": [
"sts:AssumeRole"
],
"Resource": "arn:aws:iam::TARGET_ACCOUNT_ID:role/StackSet-df0e85b0-d6fd-47bf-a0bb-CrossAccountRole-1EW45TXEFAY0D"
}
因此,與原來的不同是InstanceProfile部分?我查找了它,並且它被認爲與EC2實例一起使用? Isit在沒有EC2的情況下正確使用?實際情況是什麼?這聽起來只是一個角色? 它如何比較S3存儲桶方法? –
是的,這是正確的。我從我的桌面進行測試。S3 bucket方法是實現相同目標的另一種方式。注意:我把你的cloudformation模板,然後糾正它,因爲這是你的問題要求。 –
謝謝你的替代方法。看起來像大多數人我喜歡使用S3桶政策路線。我想我會用它來代替。不知怎的,它更直觀。就像在這種情況下,我並不真正瞭解實例配置文件的功能 –