I tested the policy in my own account and received the same error as you, this would occur whether I supplied a UserID from a IAM Identity Store in the same organization or another organization.
I did some further testing in my own environment to find a workaround and you can potentially make use of the Condition Key "aws:userId" [1] to allow access to the s3 bucket. The condition key "aws:userId" allows you to restrict the access to the Identity Center(IDC) Username and the role it assumes in the other account, see the example policy below:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "UserID",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": "arn:aws:s3:::mybucket/*",
"Condition": {
"StringLike": {
"aws:userId": "AROAJI4AVV3EXAMPLEID:SSOUserName"
}
}
}
]
}
In the above policy GetObject is restricted the specific IAM Role that has been assumed by the IDC User. The aws:userID condition key value has the following format: UNIQUE-ROLE-ID:ROLE-SESSION-NAME.
To obtain the UNIQUE-ROLE-ID, you can use the get-role cli command [2], this will need to be run from the account which is trying to access the s3 bucket in your account. The role name can be found in the IAM console and will be the following format "AWSReservedSSO_PermissionSetID_RandomizedCharectors":
iam get-role –role-name ROLE-NAME.
From the output, the UNIQUE-ROLE-ID will be the RoleId string, which begins with AROA.
To ROLE-SESSION-NAME will be equal to the username that the user used to sign into AWS Identity Center. You can also confirm the Username by viewing the user in the IAM Identity Center in the other account.
I would also suggest reviewing the following blog post [3] which goes into more detail about using aws:userId with s3 bucket policies.
[1] AWS global condition context keys - aws:userid - https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-userid
[2] get-role - https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/get-role.html
[3] How to Restrict Amazon S3 Bucket Access to a Specific IAM Role - https://aws.amazon.com/blogs/security/how-to-restrict-amazon-s3-bucket-access-to-a-specific-iam-role/
Relevant content
- asked 2 years ago
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 6 months ago
Hi Michael, many thanks for your response.
I also connected with AWS business support on this (looks like you are also in support) and they reported the same behavior (i.e. error when attempting to use
identitystore:UserId
). They did add one note, which is that it seems we can move through the error (i.e. proceed with creating the policy even with the UI-failing JSON) anyway. I haven't had time to test that approach. Zooming out a bit, this does look like a policy validation bug in the AWS console - hopefully it will get resolved soon.The information you've provided is excellent and very helpful - appreciate you elaborating on how to obtain the UNIQUE-ROLE-ID - thanks again!