AWS SSO and RDS (rds-db:connect) using ${identitystore:UserName} doesn't work?

I have a policy like so that works properly:

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Sid”: “VisualEditor0”,
“Effect”: “Allow”,
“Action”: “rds-db:connect”,
“Resource”: [
“arn:aws:rds-db:::dbuser:*/me@domain.com”
]
}
]
}

But when I change the resource to use ${identitystore:UserName} instead of hard-coded email it’s not working:

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Sid”: “VisualEditor0”,
“Effect”: “Allow”,
“Action”: “rds-db:connect”,
“Resource”: [
“arn:aws:rds-db:::dbuser:*/${identitystore:UserName}”
]
}
]
}

- Output from `aws identitystore list-user` shows the UserName as ‘me@domain.com’

- when I rewrite it to use a hard-coded db username, but add a condition clause like this, it also doesn’t work:

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Sid”: “VisualEditor0”,
“Effect”: “Allow”,
“Action”: “rds-db:connect”,
“Resource”: [
“arn:aws:rds-db:::dbuser:*/my@mydomain.com”
],
“Condition”:{
“StringEquals”:{
“identitystore:UserName”:[
“me@mydomain.com”
]
}
}
}
]
}

What am I missing?

Relevant documentation:

https://docs.aws.amazon.com/singlesignon/latest/userguide/using-predefined-attributes.html

https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-username

These are for inline policies on a permission set btw.

The identity store variable you linked is for UserId, not username. Have you tried with Identitystore:UserID?

I just had a play with this and it looks like UserId is a string that you can get through the console or via DescribeUsers

my created userId looks like “94675ee75f-0d7ae612-0639-485c-97c4-1b8bf896abce”

https://.console.aws.amazon.com/singlesignon/identity/home?region=#!/users

Yes. But UserName is the other one that can be used.

I’ll try a condition with the userId

hmmm … it did work, I was matching against UserName on the condition.

This is kind of a gross thing to have to do for RDS :frowning:

Hi from the future, did you get this working? Or what did you end up doing instead?

Nope had to do it differently

But what did you do?

{
"Action": "rds-db:connect",
"Effect": "Allow",
"Resource": "arn:aws:rds-db:*:*:dbuser:*/${aws:PrincipalTag/DBUserName}",
"Sid": "IamRdsConnect"
}

I used my saml claim to add theDBUserName
Use custom attributes for Attribute-Based Access Control (ABAC) with Microsoft Entra ID and AWS IAM Identity Center