S3 Bucket Policy not working for SSO Federated user

0

Hi All , I want to restrict access to a particular s3 bucket for all the user who login through sso by assuming a particular iam role .

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Deny",
			"Principal": "*",
			"Action": [
				"s3:ListBucket",
				"s3:GetObject",
				"s3:DeleteObject"
			],
			"Resource": [
				"arn:aws:s3:::{bucket-name}",
				"arn:aws:s3:::{bucket-name}/*"
			],
			"Condition": {
				"ArnNotEquals": {
					"aws:PrincipalArn": "arn:aws:sts::{Account-ID}:assumed-role/{AssumedRoleName}/*"
				}
			}
		}
	]
}

But this restricts access for user who login through other roles also. What am i doing wrong here?

  • Your ARN looks to be off. Can you verify the role ARN? i.e. arn:aws:iam::1234567890:role/MY_ROLE

2개 답변
1
수락된 답변

To adjust your policy to restrict access to a particular S3 bucket for users logging in through SSO by assuming a specific IAM role, while ensuring it doesn't restrict access for users logging in through other roles, you can use the ${aws:userid} variable. This variable allows you to create conditions based on the unique combination of the role and the user assuming the role.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Deny",
            "Principal": "*",
            "Action": [
                "s3:ListBucket",
                "s3:GetObject",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::{bucket-name}",
                "arn:aws:s3:::{bucket-name}/*"
            ],
            "Condition": {
                "StringNotLike": {
                    "aws:userid": "{role-id}:{user-name}"
                }
            }
        }
    ]
}

In this policy, replace {bucket-name} with your bucket name, {role-id} with the role ID of the specific IAM role, and {user-name} with the user name or a wildcard pattern matching the users who assume this role. The aws:userid variable combines the role ID and the user's unique name (or session name) in the format role-id:user-name.

If this has resolved your issue or was helpful, accepting the answer would be greatly appreciated. Thank you!

profile picture
전문가
답변함 4달 전
  • We need to use StringNotLike here . But the initial problem was solved . Thanks

1

Hey Mina, in your suggested policy, I guess you'll need to change the effect to "Allow", to only allow the user with the role attached to access the S3 bucket, or change the condition to be "StringNotLike".

Shams
답변함 4달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠