Skip to content

fix: change permissions on package universally#4462

Merged
sriram-mv merged 9 commits intoaws:developfrom
sriram-mv:sam_package_perms
Dec 10, 2022
Merged

fix: change permissions on package universally#4462
sriram-mv merged 9 commits intoaws:developfrom
sriram-mv:sam_package_perms

Conversation

@sriram-mv
Copy link
Contributor

@sriram-mv sriram-mv commented Dec 6, 2022

Which issue(s) does this change fix?

  • Remove chance of deployment failure due to wrong permissions on zip packaging.

Why is this change necessary?

How does it address the issue?

  • Changes permissions more universally such that AWS Lambda is able to invoke the handler.

What side effects does this change have?

  • Potential side affect of escalation of privileges of files to be zipped.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sriram-mv sriram-mv requested a review from a team as a code owner December 6, 2022 19:39
@sriram-mv sriram-mv requested review from jfuss and moelasmar December 6, 2022 19:39
@sriram-mv sriram-mv marked this pull request as draft December 7, 2022 17:48
@sriram-mv sriram-mv marked this pull request as ready for review December 8, 2022 01:05
local_path,
uploader,
extension,
zip_method=make_zip_with_lambda_permissions if resource_id in LAMBDA_LOCAL_RESOURCES else make_zip,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a check on just lambda specific resources.

else:
self.assertEqual(permission_bits, 0o100644)
else:
self.assertEqual(permission_bits, 0o100755)
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be miss reading this but looks like if you are not on windows, all permissions are 755? Shouldn't there be a directory vs file check here too?

Copy link
Contributor Author

@sriram-mv sriram-mv Dec 8, 2022

Choose a reason for hiding this comment

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

I have kept the permissions as-is because of the previous change on windows increased the permissions overall, it did not matter if it was a directory or a file.

Copy link
Contributor

Choose a reason for hiding this comment

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

ooo.. You did an if not, which I missed. I find the opposite to be more readable, if windows: blah else: everything else.

Up to you on updating but I at least understand it now. :)

os.remove(zipfile_name)
test_file_creator.remove_all()

def test_make_zip_lambda_resources(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have tests that verify each resource we are doing this to and another one for the unsupported ones? I would rather over test this to ensure no escalation for resources we don't intend too (now and the future).

At the same note, Can we have a test that also verifies local permissions are not escalated? The code looks correct to me but just want to have a good suite of tests surrounding this change.

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 every lambda resource: https://github.com/aws/aws-sam-cli/pull/4462/files#diff-756169fa4653144117b5d40b30eb21a08c4b4a19ab93d0029a0d69afa2e9a692R342 we test that we are only ever hitting make_zip_with_lambda_permissions

@sriram-mv sriram-mv enabled auto-merge (squash) December 9, 2022 23:36
@sriram-mv sriram-mv merged commit 7585e11 into aws:develop Dec 10, 2022
jfuss added a commit to jfuss/aws-sam-cli that referenced this pull request Jan 20, 2023
jfuss added a commit to jfuss/aws-sam-cli that referenced this pull request Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants