-
Notifications
You must be signed in to change notification settings - Fork 15
SimulatePrincipalpolicy:: Python SDK does not work with regular expressions #729
Comments
Hi @amitdwivedi-broadcom - as mentioned here, these two issues you opened are related and involve the underlying SimulatePrincipalPolicy API. We will likely need to forward this issue to the IAM service team for review as they own and maintain the IAM APIs. But first I think we need a little more information to provide to them. Could you share the specific command or code snippet, in addition to debug logs, to help us better understand this issue? If you're using the CLI command you can add |
here is my sample code policySourceArns = "arn:aws:iam::xxxxxxxx:role/cloudsoc_ct_role_effectivepermissions" permission = [result["EvalActionName"] for result in retval["EvaluationResults"] if result['EvalDecision'] == 'implicitDeny'] print("" * 10) |
Thanks @amitdwivedi-broadcom - and can you also share the logs, which you can get by adding |
/usr/bin/env /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 /Users/ad731973/.vscode/extensions/ms-python.debugpy-2024.4.0-darwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher 56132 -- /Users/ad731973/Desktop/myfiles/voice.py content-type:application/x-www-form-urlencoded; charset=utf-8 content-type;host;x-amz-date All Permissions ['s3:GetObject'] Denied Permissions ['s3:GetObject'] Screenshot of Policy - GetObject should have gotten Allowed permission, but since this has regex "arn:aws:s3:::*" its not working, if i changed that to only * it works.. |
Hi @amitdwivedi-broadcom thanks for following up and providing more info. I'm wondering if the issue here is with your resource ARN format. Here is documentation related to that: https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-arn-format.html. As described there, I think you might be looking for Also I noticed that the Boto3 version from your logs (1.26.51) is quite old. The latest version per the CHANGELOG is 1.34.94. We recommend using a more recent version for access to the latest updates/fixes. |
i did the changes in policy and updated the boto3 but i still get the same result. Boto log:: content-type:application/x-www-form-urlencoded; charset=utf-8 content-type;host;x-amz-date All Permissions ['s3:GetObject'] Denied Permissions ['s3:GetObject'] |
Thanks for following up and sharing that info. I'm not sure what the issue is here but may be missing something. I'm going to reach out to the IAM team to try and get more information. Will also transfer this to our cross-SDK repository because as mentioned earlier this issue involves the API which is used across SDKs. (ref: P128030960) |
sure thanks. Any update on this? its already 3 weeks |
Hey @tim-finnigan we are waiting for an update on this, do let us know, I'm Priyanka from Amit's team and I will be following up on this. |
Hey @tim-finnigan, do we have any update on this, we are waiting on this since more than a month now. |
Hey @tim-finnigan , do we have any update on this? |
Hey @tim-finnigan we are waiting for an update on this! |
Hey @tim-finnigan we are waiting for an update on this! |
@amitdwivedi-broadcom @PC-BRCM we are still waiting to hear back from the IAM team regarding this issue. It would be helpful if you could share the full updated IAM policy that you're using so that we can share that with the team. |
Hi @tim-finnigan Do we have any ETA for the same? Its been more than a month we are waiting to hear on this? |
Thanks for your patience. Have you reviewed this documentation? https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html#policies-simulator-using-api Specifically this part: Please make sure you have the necessary IAM permissions. If still seeing an issue, please share your complete debug logs (with sensitive info redacted) by adding |
Hey @tim-finnigan if you see Amit's policy in the decsription it already had these actions, which we tried and Amit has attached logs as well |
Hey @tim-finnigan here is my policy |
In the above policy, you can see for one block regular expression work for us, but for these action it is not working and we have to use * inspite of RegEx, can you help us here? |
@PC-BRCM The empty string here makes this policy invalid: |
Thats a * |
"Resource": [ |
That produces another error: Can you try this policy? Note the fixes for both instances of {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetAccelerateConfiguration",
"s3:GetAnalyticsConfiguration",
"s3:GetBucket*",
"s3:GetEncryptionConfiguration",
"s3:GetInventoryConfiguration",
"s3:GetLifecycleConfiguration",
"s3:GetMetricsConfiguration",
"s3:GetObjectAcl",
"s3:GetObjectVersionAcl",
"s3:GetReplicationConfiguration",
"s3:ListAllMyBuckets",
"cloudtrail:DescribeTrails",
"cloudtrail:GetTrailStatus",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:PutObjectAcl",
"s3:PutObjectVersionAcl",
"s3:ListBucket",
"s3:PutBucketNotification"
],
"Resource": [
"arn:aws:s3:::*"
],
"Effect": "Allow",
"Sid": "Stmt1396502506000"
},
{
"Action": [
"s3:GetBucketAcl",
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:PutBucketAcl",
"s3:PutBucketNotification",
"s3:ListAllMyBuckets"
],
"Resource": "*",
"Effect": "Allow",
"Sid": "Stmt1396502644000EDIT"
},
{
"Sid": "VisualEditor14",
"Action": [
"iam:GetContextKeysForPrincipalPolicy",
"iam:SimulatePrincipalPolicy"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
|
Let me share the policy json |
So I have attached two policy, working where in for following action Resources [ * ] works for us but why is RegEx not working is the question ? |
Hey @tim-finnigan my query is not around the error in policy, the policy is working for us and dont have any syntax error, its the * which is not coming in the comment here as its with escape character. |
Hi - @PC-BRCM the S3 User Guide notes here:
So I would expect that to work. Can you provide the following for us to root cause:
The code/logs shared here earlier are incomplete. |
@tim-finnigan can you also let us know if these permissions are deprecated now? SNS:Receive and "s3:GetPublicAccessBlock" -- these are invalid action, I can see these as invalid action while adding to policy, do we have new permissions for the same? |
Hey @tim-finnigan did you get a chance to look into above query we asked? |
Can you provide the info I requested above? There is no SNS "Receive" API. For S3 you are probably looking for GetBucketPublicAccessBlock permissions as mentioned in https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetPublicAccessBlock.html |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Describe the bug
Simulate policy API which helps us to check the effective permission for role is not working if the policy associated with role has regex like arn:aws::s3:* for resource or any such regex. It still gives that the permission is denied for actions which has resources associated with.
Problem in Python AWS SDK
API: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam/paginator/SimulatePrincipalPolicy.html
example::
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"iam:GetContextKeysForCustomPolicy",
"iam:GetContextKeysForPrincipalPolicy",
"iam:SimulateCustomPolicy",
"iam:SimulatePrincipalPolicy"
],
"Effect": "Allow",
"Resource": "arn:aws::s3:*"
}
]
}
Expected Behavior
For a given role and the policy mentioned above we should get allowed effect for actions mentioned in the policy, however we get denied as effect. if we change "Resource": "arn:aws::s3:" to "Resource": "" this works as expected
Current Behavior
For a given role and the policy mentioned above we should get allowed effect for actions mentioned in the policy, however we get denied as effect. if we change "Resource": "arn:aws::s3:" to "Resource": "" this works as expected
Reproduction Steps
Create a policy and a role
The policy should have regex in Resource field
Write a POC using simulatePrinciplePolicy using this role and policy you created
Possible Solution
Ideally "arn:aws::s3:*" should be treated as * and it should give the same result
Additional Information/Context
No response
CLI version used
na
Environment details (OS name and version, etc.)
Ubuntu
The text was updated successfully, but these errors were encountered: