Skip to content

Non root docker#11323

Merged
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
phlax:non-root-docker
Jun 4, 2020
Merged

Non root docker#11323
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
phlax:non-root-docker

Conversation

@phlax
Copy link
Member

@phlax phlax commented May 26, 2020

Commit Message:

Allow envoy to run as non-root user in Docker container, Fixes #11311

Additional description:

  • creates a non-root user in docker recipes
  • installs su-exec and requirements for usermod and groupmod
  • updates the docker entrypoint to use su-exec

Unfortunately su-exec is not currently packaged in debian, so i had to compile the binary

An alternative would be to use gosu but its signififcantly larger

Risk Level: low/medium
The main risk is from compiling the su-exec binary for the debian build
Its not clear to me if these recipes are intended for ci or production - if the latter then introducing su-exec has more significant security implications
Testing:
Docs Changes: I could not find any docs relating to running with Docker
Release Notes: n/a

@phlax phlax force-pushed the non-root-docker branch 4 times, most recently from da8729d to d877580 Compare May 26, 2020 17:45
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need update if you do add --no-cache below.

Copy link
Member Author

Choose a reason for hiding this comment

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

seems not. removed

@lizan
Copy link
Member

lizan commented May 29, 2020

can you merge master? that will fix the CI

@phlax phlax force-pushed the non-root-docker branch from d877580 to 0d5fe1a Compare May 29, 2020 11:45
@phlax
Copy link
Member Author

phlax commented May 29, 2020

done

@phlax phlax force-pushed the non-root-docker branch 2 times, most recently from a26c616 to b62d97b Compare May 30, 2020 16:59
@phlax phlax force-pushed the non-root-docker branch from b62d97b to 1389cd0 Compare June 1, 2020 08:37
Copy link
Member

Choose a reason for hiding this comment

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

What if a user want to run Envoy as root? Non-root user cannot listen on well-known ports. Setting ENVOY_UID to 0 will fail at usermod.

Copy link
Member Author

Choose a reason for hiding this comment

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

this has been updated, so if ENVOY_UID=0 it follows the existing exec codepath and avoids usermod, su-exec etc

@phlax phlax force-pushed the non-root-docker branch 2 times, most recently from 337fa99 to 018d2bc Compare June 2, 2020 19:48
@phlax
Copy link
Member Author

phlax commented Jun 2, 2020

@lizan i have updated the PR and rebased to master.

lmk if there are any further changes that you would like

Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

Thanks, this is in right direction. Can you add a release note as well? It should be noted that users have to set ENVOY_UID=0 to get old behavior.

@phlax phlax force-pushed the non-root-docker branch from b9da5c4 to 2f2b6d3 Compare June 2, 2020 20:27
@phlax
Copy link
Member Author

phlax commented Jun 2, 2020

release note added

Copy link
Member

Choose a reason for hiding this comment

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

alphabetical order, that's why format CI fails

@phlax phlax force-pushed the non-root-docker branch from 2f2b6d3 to 51c30be Compare June 2, 2020 21:37
lizan
lizan previously approved these changes Jun 4, 2020
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Small question, thank you!

/wait

Copy link
Member

Choose a reason for hiding this comment

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

What is the default here? If not set somehow by default should this default to "0"? I think by default we will enter this statement but the string will be empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

thats correct. The default is to use the envoy user with the uid/gid that is set at build time

Copy link
Member

Choose a reason for hiding this comment

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

Where are these env variables set?

Copy link
Member Author

Choose a reason for hiding this comment

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

they are runtime env vars for the container - so they can be set eg on the docker command line or in a compose file etc

Copy link
Member

Choose a reason for hiding this comment

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

It's not clear that this now has to be set. Can we please change this so that the default stays wat it was and we document how to set the right variables? By default I don't think this makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

in the default case nothing should need to be set and all should work as it does now - save for the fact that process inside the container doesnt run as root.

The cases where you would want to set these vars are:

  • opening well-known ports inside the container and running as root - containers kind of negate the need to ever do this
  • setting a specific uid/gid to get the correct permissions on in or out sockets

my own opinion is that it is better to not run as root by default. Im happy to make whatever changes others feel necessary though

Copy link
Member

Choose a reason for hiding this comment

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

If both of these env vars are empty strings which would be the defualt, do the commands even work?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep for sure.

the default case is that ENVOY_UID is not set - ie also not set to 0

in this case it goes into this code block, but as ENVOY_UID is not set (same with gid) it goes straight to

     su-exec envoy "${@}"

Copy link
Member

Choose a reason for hiding this comment

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

Ah OK, gotcha. Alright thanks for the explanation. LGTM.

@mattklein123 mattklein123 self-assigned this Jun 4, 2020
@mattklein123
Copy link
Member

Oops sorry can you merge master?

/wait

Signed-off-by: Ryan Northey <ryan@synca.io>
Signed-off-by: Ryan Northey <ryan@synca.io>
@phlax
Copy link
Member Author

phlax commented Jun 4, 2020

done

Signed-off-by: Ryan Northey <ryan@synca.io>
@phlax phlax force-pushed the non-root-docker branch from 3f062e2 to 0d020df Compare June 4, 2020 16:33
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@phlax
Copy link
Member Author

phlax commented Jun 4, 2020

its not obvious to me why ci is failing - the error seems to be here

ERROR: The project you're trying to build requires Bazel 3.1.0 (specified in /Users/runner/runners/2.169.1/work/1/s/.bazelversion), but it wasn't found in /usr/local/Cellar/bazel/3.2.0/libexec/bin.

im wondering if i need to do anything to get tests passing

@lizan
Copy link
Member

lizan commented Jun 4, 2020

@phlax no your fault, don't worry :)

@mattklein123 mattklein123 merged commit e8a2d1e into envoyproxy:master Jun 4, 2020
@phlax phlax deleted the non-root-docker branch June 26, 2020 07:52
kenju added a commit to kenju/service-mesh-patterns that referenced this pull request Jul 5, 2020
because we cannot bind to 80 port for envoy
since envoyproxy/envoy#11323

envoyproxy/envoy#11506
yashwant121 pushed a commit to yashwant121/envoy that referenced this pull request Jul 24, 2020
Allow envoy to run as non-root user in Docker container.

Signed-off-by: Ryan Northey <ryan@synca.io>
Signed-off-by: yashwant121 <yadavyashwant36@gmail.com>
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.

Allow envoy to run as non-root user in docker container

3 participants