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 support for per-stage IAM policy files #272

Merged
merged 5 commits into from
Apr 3, 2017

Conversation

jamesls
Copy link
Member

@jamesls jamesls commented Apr 3, 2017

This reworks some of the existing IAM policy logic to properly be "stage aware":

  • If you disable autogen policy, then we'll look for a .chalice/policy-<stage>.json file.
  • You can change this value by using the newly added iam_policy_file
  • To ease upgrading, if you're deploying to the dev, stage we'll also check .chalice/policy.json (the pre-existing filename) if there's no .chalice/policy-dev.json file.

Note that this builds on #271, so you'll see that diff as well until #271 is merged.

Also, I'll be sending a follow up PR that adds docs/upgrade notes for all the package related changes.

jamesls added 4 commits March 31, 2017 16:50
This is handled by .chalice/deployed.json.
To accomplish this, I had to update the signature of the
API Gateway deployer to pass in the deployed lambda_arn, which
is needed for the swagger document.  I was considering using
the "existing resources" object, but it's not clear if allowing
a partially hydrated deployed resources object is a good idea or not.
For now I'm just explicitly passing in the data I need from
previous deployement steps (just the lambda_arn).
Allows us to add more functionality in the future without having
to mess with the signature.
This is may potentially get more involved once we account for
multiple files.  This object all the logic out of coordinating
with the policy generation code into its own class.
This allows the ApplicationPolicyHandler to focus solely on
whether or not we should be loading policy files (and from where).
Previously there was only a single .chalice/policy.json file
that you could specify.

Now you can provide a stage specific policy file to control
this value.  The default value for this file is
.chalice/policy-<stage>.json, but to help with migration
the .chalice/policy.json file is still supported for the
dev stage if the .chalice/policy-dev.json file does not
exist.
@codecov-io
Copy link

codecov-io commented Apr 3, 2017

Codecov Report

Merging #272 into package will increase coverage by 0.11%.
The diff coverage is 88.88%.

Impacted file tree graph

@@             Coverage Diff             @@
##           package     #272      +/-   ##
===========================================
+ Coverage    85.75%   85.87%   +0.11%     
===========================================
  Files           17       18       +1     
  Lines         1664     1678      +14     
  Branches       201      202       +1     
===========================================
+ Hits          1427     1441      +14     
  Misses         184      184              
  Partials        53       53
Impacted Files Coverage Δ
chalice/config.py 97.29% <100%> (ø) ⬆️
chalice/policy.py 91.78% <100%> (+1.78%) ⬆️
chalice/package.py 96.96% <100%> (-0.14%) ⬇️
chalice/deploy/deployer.py 73.84% <84.44%> (+0.4%) ⬆️
chalice/cli/__init__.py 74.85% <0%> (ø)
chalice/__init__.py 100% <0%> (+24.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76bd8e1...f83b636. Read the comment docs.

Copy link
Contributor

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

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

Looks good. Just had a couple of comments. Also I am not sure why the lambda arn removal stuff is still showing up in the diff even though you already merged it .

LambdaDeploymentPackager(),
ApplicationPolicyHandler(osutils),
# TODO: remove duplication here.
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you miss a todo here? Seems like you can share the instance of the policy generator.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ended up being removed due to refactoring in the env var PR (https://github.com/awslabs/chalice/pull/273/files#diff-7637287bcfcc038a2e99fb26ac726348R32)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good

assert generated == json.loads(previous_policy)


def test_can_provide_stage_specific_policy_for_other_stage(app_policy,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a test for when autogen_policy is True, but the stage is not dev? Looks like you have one for when the stage is dev, but not when it is the non default stage.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just pushed a commit that adds a test for this case.

Copy link
Contributor

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

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

🚢

@jamesls jamesls merged commit f83b636 into aws:package Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants