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

Make it easier to add extra policy statements #72

Closed
simonw opened this issue Jun 30, 2022 · 10 comments
Closed

Make it easier to add extra policy statements #72

simonw opened this issue Jun 30, 2022 · 10 comments
Labels
enhancement New feature or request research

Comments

@simonw
Copy link
Owner

simonw commented Jun 30, 2022

The current --policy option lets you set a custom policy, but leaves it to you to define one.

I find myself wanting to mix in the following to the policy that I use, for s3-ocr:

https://docs.aws.amazon.com/textract/latest/dg/security_iam_id-based-policy-examples.html#security_iam_async-actions

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "textract:StartDocumentTextDetection",
                "textract:StartDocumentAnalysis",
                "textract:GetDocumentTextDetection",
                "textract:GetDocumentAnalysis"
            ],
            "Resource": "*"
        }
    ]
}

Would be nice if there was a neat way to do this.

@simonw simonw added enhancement New feature or request research labels Jun 30, 2022
@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

One option would be to support multiple --statement options, each of which can be either a chunk of JSON or some kind of shortcut that indicates one of a number of pre-baked patterns.

Could support --statement textract:all or --statement textract:async as shortcuts.

@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

I need a better feeling for what other kinds of shortcuts might be useful.

@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

https://aws.amazon.com/blogs/security/back-to-school-understanding-the-iam-policy-grammar/ says:

There are five core types of elements that you can use in your policy. Some are required and some are optional. Let's walk through them.

  1. Effect (Required) -- specifies whether the statement will explicitly allow ("Allow") or deny ("Deny") access. These are the only two values that are valid in this element.
  2. Action* (Required) -- describes the type of access that should be allowed or denied.
  3. Resource* (Required) -- specifies the object or objects that the statement covers.
  4. Principal* (Optional) -- specifies the user, account, service, or other entity that is allowed or denied access to a resource. Principals can only be used for resource-based policies. For policies within IAM, the policy is attached to the Principal it applies to.
  5. Condition (Optional) -- lets you specify conditions for when a policy is in effect.

So Effect, Action and Resource are required.

@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

I'm tempted to say that --statement action:name-of-action is a shortcut for adding a Effect: Allow, Action: Action, Resource: * statement.

@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

I have a full list (I think) of potential actions here: https://iam-definitions.vercel.app/iam/privileges

@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

Alternative design: --allow-action 'textract:*' which would add this:

[
    {
        "Effect": "Allow",
        "Action": ["textract:*"],
        "Resource": "*"
    }
]

But given that, what would the shortcut be if you didn't want to use "Resource": "*"?

Maybe --allow-action-on-resource <action> <resource> could be supported too?

@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

I'm just going to implement --statement <json> which takes the full block of JSON and --allow-action <action> which adds an allow block on resource * for that specified action.

If you pass --allow-action multiple times they will all be bundled in the same statement.

I'm not going to implement shortcut templates, because I don't have a good idea for what they should be - and textract:* is a good enough solution for the moment.

@simonw simonw changed the title Make it easier to add extra statements Make it easier to add extra policy statements Jun 30, 2022
@simonw simonw closed this as completed Jun 30, 2022
@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

I decided to just implement --statement for the moment, and not to implement that --allow-action idea.

@simonw
Copy link
Owner Author

simonw commented Jun 30, 2022

I tested this like so and it worked:

s3-credentials create simonw-ocr-demo-bucket --statement '{
  "Effect": "Allow",
  "Action": "textract:*",
  "Resource": "*"
}' -c > ocr.json

Then tested like so:

s3-credentials put-object simonw-ocr-demo-bucket github-octoverse-2020-community-report.pdf ~/Downloads/2020-reports/github-octoverse-2020-community-report.pdf -a ocr.json
s3-ocr start simonw-ocr-demo-bucket -a ocr.json --all
s3-ocr status simonw-ocr-demo-bucket -a ocr.json
s3-ocr index simonw-ocr-demo-bucket /tmp/github-index.db -a ocr.json
datasette /tmp/github-index.db -p 8525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request research
Projects
None yet
Development

No branches or pull requests

1 participant