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

toolkit: surface potentially risky changes and enforce confirmation #978

Closed
eladb opened this issue Oct 21, 2018 · 6 comments · Fixed by #1240
Closed

toolkit: surface potentially risky changes and enforce confirmation #978

eladb opened this issue Oct 21, 2018 · 6 comments · Fixed by #1240
Assignees
Labels
ops-excellence Operational Excellence package/tools Related to AWS CDK Tools or CLI ui Related to CLI User Interface issues

Comments

@eladb
Copy link
Contributor

eladb commented Oct 21, 2018

"cdk diff" should surface to the user any changes to IAM permissions in a very explicit way. Users should be able to see exactly which permissions were added or removed from their app.

This is particularly important when using 3rd party construct libraries, it's important to ensure that any permissions changes are clearly visible to the user.

We should also consider requiring an explicit interactive approval for permission changes in "cdk deploy". Something like:

$ cdk deploy
Please confirm that the following permissions will be added:
- sqs:SendMessage on <ARN> will be granted to <PRINCIPAL>
- dynamodb:PutObject on <ARN> will be granted to <PRINCIPAL>
Please confirm (Y/N) or use -y for non-interactive experience [N]: 
@RomainMuller
Copy link
Contributor

RomainMuller commented Oct 23, 2018

That's beautiful in theory but coming up with messaging that is clear in the general case will be challenging (NotPrincipal, NotAction, what does * on <ARN> will be granted to <PRINCIPAL> mean - do we expand to the list of all valid actions? ...).

Also, this brings you zero benefits if you're not using the cdk toolkit for deploying...

@eladb
Copy link
Contributor Author

eladb commented Oct 23, 2018

clear in the general case

I don't think we need "general" messaging, I think we need deep understanding of IAM policies and very specific messaging as to what has changed. It's going to be a set of heuristics that we understand and we can always fall back to showing a nice JSON diff of statements or fragments we don't understand.

Also, this brings you zero benefits if you're not using the cdk toolkit for deploying...

I think this should actually part of the synthesizer, which is needed whether you deploy via the toolkit or not.

@rix0rrr rix0rrr self-assigned this Oct 24, 2018
@eladb eladb changed the title cdk diff: special treatment for IAM permissions cdk diff: surface potentially risky changes and enforce confirmation Oct 25, 2018
@eladb eladb changed the title cdk diff: surface potentially risky changes and enforce confirmation toolkit: surface potentially risky changes and enforce confirmation Oct 25, 2018
@rix0rrr rix0rrr added the package/tools Related to AWS CDK Tools or CLI label Nov 6, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 7, 2018

Extra highlight (summary) of cross-account (or even public) permissions.

@eladb eladb added the ui Related to CLI User Interface issues label Nov 13, 2018
@fulghum fulghum assigned eladb and unassigned rix0rrr Nov 13, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 13, 2018

My plan was to annotate all attributes that encode sensitive data (IAM policies and Security Group) in the spec, half-manually and half-automatically.

We can then look up the annotations for every attribute after generating the diff, and then doing something intelligent with the diffs based on the annotation type (such as collect into a summary table).

I have some code around this, let me know if you want it.

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 19, 2018

@eladb I'm ready to pick this up again if you're busy doing other things.

My plan is to add a summary table to every deployment that looks somewhat like this:

Resource Actions Principal Other
+ ${/stack/Construct/MyResource.Arn}/* s3:GetObject, s3:PutObject ${/stack/Construct/MyRole.Arn} Condition: { ... }
+ * logs:CreateLogs ${/stack/Construct/MyLambda/Role.Arn}
+ ${/stack/Queue.Arn} sqs:PublishMessages arn:aws:us-west-5:123456789012:root Condition: { ResourceArn:{ arn:aws:us-west-5:123456789012:topic:HelloTopic }}
- ${/stack/SomeResource.Arn} arn:aws:us-west-5:123456789012:root NotAction: ["re:Source", "re:Delete"]

The diff will be done before every deployment, and the table will be shown and needs to be acknowledged if there are differences in it.

@eladb
Copy link
Contributor Author

eladb commented Nov 19, 2018

Looks great @rix0rrr!

How are we going to handle acknowledgement in CI/CD? I sense we need some way to "store" the acknowledgement. Feels like a a more general purpose mechanism for "diff ack" that we can implement. Perhaps in a separate PR, so maybe in the meantime, this can just be in the output of "diff"?

@eladb eladb removed their assignment Nov 20, 2018
rix0rrr added a commit that referenced this issue Nov 23, 2018
Add awareness of potentially risky permissions changes to the
cfnspec and diff tool, and surface those changes in an easily
digestible format.

This is an initial commit.

Feature TODO:

- [ ] Recognize AWS::Lambda::Permission objects
- [ ] Recognize managed policies
- [ ] Add support for SecurityGroup rules
- [ ] Reverse engineer construct paths from logical IDs
- [ ] Apply same logic to format inline diffs for IAM policy
  property updates.
- [ ] Automatically diff and confirm statement additions on every
  'deploy'.

Quality TODO:

- [ ] property tests on statement equality, parsing
- [ ] tests on 'uncfn' routines
- [ ] Replace CLI table library in aws-cdk to be the same as
  this one (supports newlines in cells and generally looks better).

Fixes #978.
@rix0rrr rix0rrr self-assigned this Nov 27, 2018
rix0rrr added a commit that referenced this issue Dec 10, 2018
Add awareness of potentially risky permissions changes to the
cfnspec and diff tool, and surface those changes in an easily
digestible format.

Control feature using `--require-approval` command-line flag or `requireApproval`
field in `cdk.json`. Also see http://bit.ly/cdk-2EhF7Np

This is an initial version, and there will be future changes to this feature.

Fixes #978, fixes #1299.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ops-excellence Operational Excellence package/tools Related to AWS CDK Tools or CLI ui Related to CLI User Interface issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants