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

fix(kernel): tarball unpacking does not behave like 'npm install' #1766

Merged
merged 3 commits into from
Jul 1, 2020

Conversation

RomainMuller
Copy link
Contributor

In it's wisdom, npm install does override the process' umask to
0o022 before unpackging the tarball, to ensure the produced install
has the kind of permissions that one would expect, regardless of the
system-configured umask.

Because @jsii/kernel did not reproduce this behavior, loaded libraries
could be unpacked with unexpectedly tight permissions, leading to weird
issues when those files were used in contexts that required those
permissions. For example, this is the cause of aws/aws-cdk#8233.

Fixes #1765


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

In it's wisdom, `npm install` does override the process' `umask` to
`0o022` before unpackging the tarball, to ensure the produced install
has the kind of permissions that one would expect, regardless of the
system-configured `umask`.

Because `@jsii/kernel` did not reproduce this behavior, loaded libraries
could be unpacked with unexpectedly tight permissions, leading to weird
issues when those files were used in contexts that required those
permissions. For example, this is the cause of aws/aws-cdk#8233.

Fixes #1765
@RomainMuller RomainMuller self-assigned this Jun 30, 2020
@RomainMuller RomainMuller requested a review from a team June 30, 2020 11:09
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jun 30, 2020
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Test

@RomainMuller RomainMuller requested a review from eladb June 30, 2020 11:36
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 9d67800
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

const originalUmask = process.umask(0o022);
try {
// untar the archive to its final location
tar.extract({
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use the built-in support in the tar library.

One of these options should help:

  • portable Omit metadata that is system-specific: ctime, atime, uid, gid, uname, gname, dev, ino, and nlink. Note that mtime is still included, because this is necessary for other time-based operations. Additionally, mode is set to a "reasonable default" for most unix systems, based on a umask value of 0o22.
  • mode The mode to set on the created file archive

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel portable is the right one to use here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those options are specific to the create operation and this is the extract operation.

The only "built-in" option available is the umask option to tar.extract, however that is "internal" (and not exposed in the d.ts which is why I decided against using that).

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay sorry my mistake.

@mergify
Copy link
Contributor

mergify bot commented Jul 1, 2020

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Jul 1, 2020
@mergify mergify bot merged commit 2dc1b21 into master Jul 1, 2020
@mergify mergify bot deleted the rmuller/fix-unpack-perms branch July 1, 2020 10:41
@mergify
Copy link
Contributor

mergify bot commented Jul 1, 2020

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kernel "load" results in surprising file permissions
3 participants