Skip to content
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

Add --resource-type flag to policy_sentry query action-table command #261

Merged
merged 4 commits into from
Oct 20, 2020
Merged

Add --resource-type flag to policy_sentry query action-table command #261

merged 4 commits into from
Oct 20, 2020

Conversation

reetasingh
Copy link
Contributor

@reetasingh reetasingh commented Oct 18, 2020

What does this PR do?

Address #255 with the Bonus Points

  1. Adding --resource-type flag to policy_sentry query action-table
  2. Removing --wildcard-only flag from policy_sentry query action-table
  3. Adding method get_actions_matching_arn_type
  4. Modifying method get_actions_with_arn_type_and_access_level
  5. Adding unit tests for the new methods added and methods modified
  6. Adding integration tests for new --resource-type flag

What gif best describes this PR or how it makes you feel?

ALT

Completion checklist

@reetasingh reetasingh changed the title Feature Add --resource-type flag to policy_sentry query action-table command Oct 18, 2020
def get_actions_with_arn_type_and_access_level(
service_prefix, resource_type_name, access_level
):
def get_actions_matching_arn_type(service_prefix, resource_type_name):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new method added

@reetasingh
Copy link
Contributor Author

@kmcquade let me know your thoughts on this PR

results = []

if resource_type_name == '*':
return get_actions_at_access_level_that_support_wildcard_arns_only(service_prefix, access_level)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for resource_type_name == '*' calling the existing get_actions_at_access_level_that_support_wildcard_arns_only method

"""
if resource_type_name == '*':
return get_actions_that_support_wildcard_arns_only(service_prefix)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for resource_type_name == '*' calling the existing get_actions_that_support_wildcard_arns_only method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this way the get_actions_matching_arn_type will support both the case where resource_type_name='' or not ''

service_prefix_data = get_service_prefix_data(service_prefix)
results = []

for action_name, action_data in service_prefix_data["privileges"].items():
if action_data["access_level"] == access_level:
if service_prefix == "all":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if resource_type_name !='*'


if resource_type_name == '*':
return get_actions_at_access_level_that_support_wildcard_arns_only(service_prefix, access_level)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if resource_type_name !='*' this block will be executed

@reetasingh
Copy link
Contributor Author

OutPut:

(venv) reetasingh-ltm8:policy_sentry reetasingh$ policy_sentry query action-table  --help
Usage: policy_sentry query action-table [OPTIONS]

  Query the Action Table from the Policy Sentry database

Options:
  --service TEXT                  Filter according to AWS service.  [required]
  --name TEXT                     The name of IAM Action. For example, if the
                                  action is "iam:ListUsers", supply
                                  "ListUsers" here.

  --access-level [read|write|list|tagging|permissions-management]
                                  Filter according to CRUD levels. Acceptable
                                  values are read, write, list, tagging,
                                  permissions-management

  --condition TEXT                Supply a condition key to show a list of all
                                  IAM actions that support the condition key.

  --resource-type TEXT            Supply a resource type to show a list of all
                                  IAM actions that support the resource type.

  --fmt [yaml|json]               Format output as YAML or JSON. Defaults to
                                  "yaml"

  -v, --verbosity LVL             Either CRITICAL, ERROR, WARNING, INFO or
                                  DEBUG

  --help                          Show this message and exit.
(venv) reetasingh-ltm8:policy_sentry reetasingh$ 

@reetasingh
Copy link
Contributor Author

(venv) reetasingh-ltm8:policy_sentry reetasingh$ policy_sentry query action-table --service ssm --access-level write --resource-type parameter
Using the Local IAM definition: /Users/reetasingh/.policy_sentry/iam-definition.json. To leverage the bundled definition instead, remove the folder $HOME/.policy_sentry/
ssm WRITE actions that have the resource type PARAMETER:
[
    "ssm:DeleteParameter",
    "ssm:DeleteParameters",
    "ssm:LabelParameterVersion",
    "ssm:PutParameter"
]
(venv) reetasingh-ltm8:policy_sentry reetasingh$ policy_sentry query action-table --service secretsmanager --access-level list --resource-type '*'
Using the Local IAM definition: /Users/reetasingh/.policy_sentry/iam-definition.json. To leverage the bundled definition instead, remove the folder $HOME/.policy_sentry/
secretsmanager LIST actions that have the resource type *:
[
    "secretsmanager:ListSecrets"
]

@reetasingh
Copy link
Contributor Author

(venv) reetasingh-ltm8:policy_sentry reetasingh$ policy_sentry query action-table --service secretsmanager  --resource-type '*'
Using the Local IAM definition: /Users/reetasingh/.policy_sentry/iam-definition.json. To leverage the bundled definition instead, remove the folder $HOME/.policy_sentry/
IAM actions under secretsmanager service that have the resource type *:
[
    "secretsmanager:GetRandomPassword",
    "secretsmanager:ListSecrets"
]
(venv) reetasingh-ltm8:policy_sentry reetasingh$ 

@reetasingh
Copy link
Contributor Author

(venv) reetasingh-ltm8:policy_sentry reetasingh$ policy_sentry query action-table --service secretsmanager  --resource-type '*' --access-level read
Using the Local IAM definition: /Users/reetasingh/.policy_sentry/iam-definition.json. To leverage the bundled definition instead, remove the folder $HOME/.policy_sentry/
secretsmanager READ actions that have the resource type *:
[
    "secretsmanager:GetRandomPassword"
]

@reetasingh
Copy link
Contributor Author

venv) reetasingh-ltm8:policy_sentry reetasingh$ policy_sentry query action-table --service ssm --resource-type parameter
Using the Local IAM definition: /Users/reetasingh/.policy_sentry/iam-definition.json. To leverage the bundled definition instead, remove the folder $HOME/.policy_sentry/
IAM actions under ssm service that have the resource type parameter:
[
    "ssm:AddTagsToResource",
    "ssm:DeleteParameter",
    "ssm:DeleteParameters",
    "ssm:GetParameter",
    "ssm:GetParameterHistory",
    "ssm:GetParameters",
    "ssm:GetParametersByPath",
    "ssm:LabelParameterVersion",
    "ssm:ListTagsForResource",
    "ssm:PutParameter",
    "ssm:RemoveTagsFromResource"
]

@kmcquade
Copy link
Collaborator

@reetasingh this looks awesome!

I'm good to merge this. But first - can you modify your PR so it updates the documentation for the query action-table section? https://policy-sentry.readthedocs.io/en/latest/querying/action-table/

@reetasingh
Copy link
Contributor Author

@reetasingh reetasingh added the enhancement New feature or request label Oct 20, 2020
@kmcquade kmcquade merged commit 8bb7a70 into salesforce:master Oct 20, 2020
saikirankv pushed a commit to saikirankv/policy_sentry that referenced this pull request Nov 18, 2020
…and (salesforce#261)

* add resource type flag in query action-table

* add unit test

* updating doc for resource-type param
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:signed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants