How to apply wildcards (?) in IAM policy in principal tag?

Viewed 378

I am trying to ABAC( Attribute-Based Access Control) in my application. In AWS, S3 object has a tag, the key is custom:kypha and the value is 'hello'. A user token has same attribute custom:kypha, but it has value 'hi-hello-welcome', Now I want S3 object tag key-value match with this user token attribute key-value pair bcz it has 'hello' in its value.

For achieving this, I have written IAM policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "s3:GetObject*",
            "Resource": "arn:aws:s3:::*",
            "Condition": {
                "StringLike": {
                    "s3:ExistingObjectTag/custom:kypha": "${aws:PrincipalTag/custom:kypha}"
                }
            }
        }
    ]
}

and following this: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html which says about wildcard

StringLike

Case-sensitive matching. The values can include a multi-character match wildcard (*) and a single-character match wildcard (?) anywhere in the string.

Based on the suggestion in comment. Below are the examples for clarification, that clear my requirements:

In S3, I have a file pharma.csv which has Tag: Key-custom:kypha Value-hello

Now a user (from Cognito) want to access this file, which has attributes in token -- custom:kypha='hi-hello-welcome'

User should be able to access the file as it has 'hello' in 'hi-hello-welcome'. But my above policy is not working here. It saying Access Denied.

Note: I am using ABAC: https://www.youtube.com/watch?v=tAUmz94O2Qo&t=280s

If I say the same thing in SQL, I want this: SELECT * FROM Customers WHERE CustomerName LIKE '%or%';

0 Answers
Related