Bạn muốn workload ở Account B access vào s3 hay bitbucket của account A


root@LP11-D7891:~# aws sts get-caller-identity
{
"UserId": "AIDATU2QSHIISHPLW6PRV",
"Account": "250887682577",
"Arn": "arn:aws:iam::25088768XXXX:user/nim"
}
root@LP11-D7891:~# aws s3 ls s3://access-s3-from-other-account
2022-09-22 23:04:38 348 dev.yaml
root@LP11-D7891:~# aws sts get-caller-identity
{
"UserId": "AIDATU2QSHIISHPLW6PRV",
"Account": "250887682577",
"Arn": "arn:aws:iam::25088768XXXX:user/nim"
}
root@LP11-D7891:~# aws s3 ls s3://access-s3-from-other-account
2022-09-22 23:04:38 348 dev.yaml
root@LP11-D7891:~# aws sts get-caller-identity { "UserId": "AIDATU2QSHIISHPLW6PRV", "Account": "250887682577", "Arn": "arn:aws:iam::25088768XXXX:user/nim" } root@LP11-D7891:~# aws s3 ls s3://access-s3-from-other-account 2022-09-22 23:04:38 348 dev.yaml


{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::31336350XXXX:user/CloudOpsAutomation"
},
"Action": "*",
"Resource": "arn:aws:s3:::access-s3-from-other-account/*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::31336350XXXX:user/CloudOpsAutomation"
},
"Action": "*",
"Resource": "arn:aws:s3:::access-s3-from-other-account/*"
}
]
}
{ "Version": "2012-10-17", "Statement": [ { "Sid": "Statement1", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::31336350XXXX:user/CloudOpsAutomation" }, "Action": "*", "Resource": "arn:aws:s3:::access-s3-from-other-account/*" } ] }
Giờ mình tiền hành run command và kiểm tra access S3 từ other account
root@LP11-D7891:~# aws sts get-caller-identity --profile k8s-nimtechnology-staging
{
"UserId": "AIDAUR5PLRU2IBJ6C54JW",
"Account": "31336350XXXX",
"Arn": "arn:aws:iam::31336350XXXX:user/CloudOpsAutomation"
}
root@LP11-D7891:~# aws s3 ls s3://access-s3-from-other-account --profile k8s-nimtechnology-staging
2022-09-22 23:04:38 348 dev.yaml
root@LP11-D7891:~/demo-kms# aws s3 cp s3://access-s3-from-other-account/dev.yaml . --profile k8s-nimtechnology-staging
download: s3://access-s3-from-other-account/dev.yaml to ./dev.yaml
root@LP11-D7891:~# aws sts get-caller-identity --profile k8s-nimtechnology-staging
{
"UserId": "AIDAUR5PLRU2IBJ6C54JW",
"Account": "31336350XXXX",
"Arn": "arn:aws:iam::31336350XXXX:user/CloudOpsAutomation"
}
root@LP11-D7891:~# aws s3 ls s3://access-s3-from-other-account --profile k8s-nimtechnology-staging
2022-09-22 23:04:38 348 dev.yaml
root@LP11-D7891:~/demo-kms# aws s3 cp s3://access-s3-from-other-account/dev.yaml . --profile k8s-nimtechnology-staging
download: s3://access-s3-from-other-account/dev.yaml to ./dev.yaml
root@LP11-D7891:~# aws sts get-caller-identity --profile k8s-nimtechnology-staging { "UserId": "AIDAUR5PLRU2IBJ6C54JW", "Account": "31336350XXXX", "Arn": "arn:aws:iam::31336350XXXX:user/CloudOpsAutomation" } root@LP11-D7891:~# aws s3 ls s3://access-s3-from-other-account --profile k8s-nimtechnology-staging 2022-09-22 23:04:38 348 dev.yaml root@LP11-D7891:~/demo-kms# aws s3 cp s3://access-s3-from-other-account/dev.yaml . --profile k8s-nimtechnology-staging download: s3://access-s3-from-other-account/dev.yaml to ./dev.yaml
nếu bạn gặp lỗi: fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
root@LP11-D7891:~/demo-kms# aws s3 cp s3://access-s3-from-other-account/dev.yaml ./ --profile k8s-nimtechnology-staging
fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
root@LP11-D7891:~/demo-kms# aws s3 cp s3://access-s3-from-other-account/dev.yaml ./ --profile k8s-nimtechnology-staging
fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
root@LP11-D7891:~/demo-kms# aws s3 cp s3://access-s3-from-other-account/dev.yaml ./ --profile k8s-nimtechnology-staging fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
thi bạn kiểm tra lại Resource đã được cấu hình chính sác chưa?
mình ví dụ bạn muốn download file s3://access-s3-from-other-account/dev.yaml
nhưng bạn lại set là “Resource”: “arn:aws:s3:::access-s3-from-other-account”
==> thì bạn sẽ bị lỗi fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden