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

Custom asset bundling for lambda using docker results in output code that is owned by root #8489

Closed
imtiazmangerah opened this issue Jun 11, 2020 · 0 comments · Fixed by #8492
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. in-progress This issue is being actively worked on. needs-triage This issue or PR still needs to be triaged.

Comments

@imtiazmangerah
Copy link

The custom asset bundling feature released in v1.45 -(#7898) results in output from the docker image that is owned by root (or the user that executes the commands in the docker container in general).

This is unexpected, and could be a problem if a user does not have root access on the machine to clean up the cdk.out folder.

Reproduction Steps

bundling_options = core.BundlingOptions(image=aws_lambda.Runtime.PYTHON_3_7.bundling_docker_image,
                                        command=[
                                            'bash', '-c',
                                            'pip install -r requirements.txt -t /asset-output && rsync -r . /asset-output',
                                        ])
source_code = aws_lambda.Code.from_asset('src/test', bundling=bundling_options)


handler = aws_lambda.Function(self, f"{self.id}-TestBundling",
                              function_name=f"{self.id}-TestBundling",
                              handler=f'handlers.test',
                              runtime=aws_lambda.Runtime.PYTHON_3_7,
                              code=source_code)

Error Log

executing ls -la in the output folder yeilds the following as an example

-rw-r--r--  1 root   root     573 Jun 11 06:03 handlers.py

Environment

  • CLI Version :1.45.0 (build 0cfab15)
  • Framework Version:1.45.0
  • Node.js Version:v12.0.0
  • **OS :Debian 10.4
  • Language (Version):Python 3.7.6

Other

As per discussion on #7898, passing -u $UID:$UID as part of dockerArgs in packages/@aws-cdk/core/lib/bundling.ts might be the solution.


This is 🐛 Bug Report

@imtiazmangerah imtiazmangerah added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 11, 2020
jogold added a commit to jogold/aws-cdk that referenced this issue Jun 11, 2020
Get `uid` and `gid` of current user and pass it to `docker run` to avoid
running the container as `root`.

On Windows, `docker` always runs as the current user so we can skip
this.

Fixes aws#8489
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Jun 11, 2020
@SomayaB SomayaB added the @aws-cdk/core Related to core CDK functionality label Jun 11, 2020
@mergify mergify bot closed this as completed in #8492 Jun 11, 2020
mergify bot pushed a commit that referenced this issue Jun 11, 2020
Get `uid` and `gid` of current user and pass it to `docker run` to avoid
running the container as `root`. On Windows, use `1000:1000` as default.

Add `user` to `BundlingOptions`.

Fixes #8489


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. in-progress This issue is being actively worked on. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants