-
Notifications
You must be signed in to change notification settings - Fork 313
rgw/iam: customer managed policy #646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,3 +53,4 @@ markers = | |
| user_policy | ||
| versioning | ||
| webidentity_test | ||
| policy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1451,6 +1451,138 @@ def test_account_user_policy_allow(iam_root): | |
| # something other than AccessDenied | ||
| retry_on('AccessDenied', 10, client.list_buckets) | ||
|
|
||
| # IAM Customer Managed Policy | ||
| @pytest.mark.policy | ||
| @pytest.mark.iam_account | ||
| def test_create_policy(iam_root): | ||
| name = make_iam_name('create-policy') | ||
| path = get_iam_path_prefix() | ||
| policy_document = { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Action": [ | ||
| "s3:GetObject", | ||
| "s3:ListBucket" | ||
| ], | ||
| "Resource": [ | ||
| "arn:aws:s3:::mybucket", | ||
| "arn:aws:s3:::mybucket/*" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| policy = iam_root.create_policy( | ||
| PolicyName=name, | ||
| PolicyDocument=json.dumps(policy_document), | ||
| Description='Read-only access to mybucket', | ||
| Path=path, | ||
| Tags=[ | ||
| {"Key": "Perms", "Value": "READ"}, | ||
| {"Key": "Principle", "Value": "S3"} | ||
| ] | ||
| ) | ||
| assert policy['Policy']['PolicyName'] == name | ||
| assert policy['Policy']['Path'] == path | ||
|
|
||
| # Cleanup | ||
| iam_root.delete_policy(PolicyArn=policy['Policy']['Arn']) | ||
|
Comment on lines
+1489
to
+1490
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once we support |
||
|
|
||
| @pytest.mark.policy | ||
| @pytest.mark.iam_account | ||
| def test_create_duplicate_policy(iam_root): | ||
| name = make_iam_name('duplicate-policy') | ||
| path = get_iam_path_prefix() | ||
| policy_document = { | ||
| "Version": "2012-10-17", | ||
| "Statement": [{ | ||
| "Effect": "Allow", | ||
| "Action": ["s3:ListBucket"], | ||
| "Resource": ["arn:aws:s3:::example"] | ||
| }] | ||
| } | ||
|
|
||
| policy = iam_root.create_policy( | ||
| PolicyName=name, | ||
| PolicyDocument=json.dumps(policy_document), | ||
| Path=path | ||
| ) | ||
| policy_arn = policy['Policy']['Arn'] | ||
|
|
||
| try: | ||
| with pytest.raises(iam_root.exceptions.EntityAlreadyExistsException): | ||
| iam_root.create_policy( | ||
| PolicyName=name, | ||
| PolicyDocument=json.dumps(policy_document), | ||
| Path=path | ||
| ) | ||
| finally: | ||
| iam_root.delete_policy(PolicyArn=policy_arn) | ||
|
|
||
| @pytest.mark.policy | ||
| @pytest.mark.iam_account | ||
| def test_get_policy(iam_root): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can add a get test for a non existent policy. |
||
| name = make_iam_name('get-policy') | ||
| path = get_iam_path_prefix() | ||
| policy_document = { | ||
| "Version": "2012-10-17", | ||
| "Statement": [{ | ||
| "Effect": "Allow", | ||
| "Action": ["s3:ListBucket"], | ||
| "Resource": ["arn:aws:s3:::mybucket"] | ||
| }] | ||
| } | ||
|
|
||
| policy = iam_root.create_policy( | ||
| PolicyName=name, | ||
| PolicyDocument=json.dumps(policy_document), | ||
| Path=path | ||
| ) | ||
| policy_arn = policy['Policy']['Arn'] | ||
|
|
||
| fetched = iam_root.get_policy(PolicyArn=policy_arn) | ||
|
|
||
| assert fetched['Policy']['PolicyName'] == name | ||
| assert fetched['Policy']['Arn'] == policy_arn | ||
|
|
||
| # Cleanup | ||
| iam_root.delete_policy(PolicyArn=policy_arn) | ||
|
|
||
| @pytest.mark.policy | ||
| @pytest.mark.iam_account | ||
| def test_delete_policy(iam_root): | ||
| name = make_iam_name('delete-policy') | ||
| path = get_iam_path_prefix() | ||
| policy_document = { | ||
| "Version": "2012-10-17", | ||
| "Statement": [{ | ||
| "Effect": "Allow", | ||
| "Action": ["s3:ListBucket"], | ||
| "Resource": ["arn:aws:s3:::mybucket"] | ||
| }] | ||
| } | ||
|
|
||
| policy = iam_root.create_policy( | ||
| PolicyName=name, | ||
| PolicyDocument=json.dumps(policy_document), | ||
| Path=path | ||
| ) | ||
| policy_arn = policy['Policy']['Arn'] | ||
|
|
||
| iam_root.delete_policy(PolicyArn=policy_arn) | ||
|
|
||
| with pytest.raises(iam_root.exceptions.NoSuchEntityException): | ||
| iam_root.get_policy(PolicyArn=policy_arn) | ||
|
|
||
| @pytest.mark.policy | ||
| @pytest.mark.iam_account | ||
| def test_delete_nonexistent_policy(iam_root): | ||
| main_arn = iam_root.get_user()['User']['Arn'] | ||
| account_id = main_arn.removeprefix('arn:aws:iam::').removesuffix(':root') | ||
| fake_arn = f"arn:aws:iam::{account_id}:policy/NonExistentPolicy" | ||
| with pytest.raises(iam_root.exceptions.NoSuchEntityException): | ||
| iam_root.delete_policy(PolicyArn=fake_arn) | ||
|
|
||
| def group_list_names(client, **kwargs): | ||
| p = client.get_paginator('list_groups') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call this
managed_policy?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbodley overall related to this SPIKE can we call
managed_policyinstead ofpolicyorcustomer_managed_policy?but there is other existing features related
managed_policyin will that create any confusion?rgw_rest_user_policy.cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but AWS presents it as
policywhile create, delete, get etc