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

allow running as arbitrary uid #151

Merged
merged 4 commits into from
Sep 2, 2019
Merged

allow running as arbitrary uid #151

merged 4 commits into from
Sep 2, 2019

Conversation

willholley
Copy link
Member

Overview

Enables the CouchDB container to run as a non-root / user-specified uid. For now, I've only modified the 2.3.1 container but if the approach is accepted we can easily backport it.

Specifically, this:

  • Adds guards around entrypoints commands that require root (as suggested in Make UID & GID configurable #147)
  • Broadens permissions within the container filesystem to allow access by non-couchdb users.
  • Adds an example to the documentation which specifies --user.

Testing recommendations

Build the container locally:

docker build -t couchdb:2.3.1 2.3.1

Run the container as a custom user

docker run --user <user> --name mycouch -p 5984:5984 -d couchdb:2.3.1

or, run the container as a custom user with a mounted data volume:

mkdir /Users/<user>/temp/couchdb-data
docker run --user <user> --name mycouch -v /Users/<user>/temp/couchdb-data:/opt/couchdb/data -p 5984:5984 -d couchdb:2.3.1

Verify Couch is working:

curl localhost:5984

GitHub issue number

Fixes #147

Related Pull Requests

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes;

@willholley willholley force-pushed the custom_uid branch 2 times, most recently from ac99989 to 9a3af1d Compare August 13, 2019 12:11
@wohali
Copy link
Member

wohali commented Aug 13, 2019

Hey @willholley , will review this later today. Looks like dev is failing for other reasons, making Travis fail. Do you have time to lend a hand?

@wohali
Copy link
Member

wohali commented Aug 13, 2019

@kocolosk you've been doing the reviews in this space, care to have a look?

@kocolosk
Copy link
Member

Will do

Copy link
Member

@kocolosk kocolosk left a comment

Choose a reason for hiding this comment

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

I think the changes in the docker-entrypoint make sense -- we're basically putting the onus on the user to have all permissions configured correctly if they want to run under a custom UID.

I do worry that skipping the chown in the Dockerfile will have an impact on startup times per #131. Is there a problem with keeping that line in there?

2.3.1/Dockerfile Show resolved Hide resolved
@willholley
Copy link
Member Author

Hey @willholley , will review this later today. Looks like dev is failing for other reasons, making Travis fail. Do you have time to lend a hand?

hopefully this is fixed in #152

 * Adds guards around entrypoints commands that require root
 * Broaden permissions within the container filesystem to allow
   access by non-couchdb users.
 * Added an example to the documentation which specifies `--user`.
@wohali
Copy link
Member

wohali commented Aug 23, 2019

@willholley I'd like to merge this but @kocolosk 's comment is still unaddressed. We need to not reintroduce a regression here. Can you help? Thanks.

@willholley
Copy link
Member Author

@wohali I added back the chmod line in the Dockerfile which I think addresses @kocolosk's comments. I've also normalised the whitespace to use 4 spaces everywhere.

@wohali
Copy link
Member

wohali commented Aug 26, 2019

@willholley merge at your convenience!

I'll need to update the official docs upstream with your change, too, once this lands.

2.3.1/Dockerfile Outdated
find /opt/couchdb/etc -type d ! -perm 0755 -exec chmod -f 0755 '{}' +; \
find /opt/couchdb/etc -type f ! -perm 0644 -exec chmod -f 0644 '{}' +; \
# only local.d needs to be writable for the docker_entrypoint.sh
chmod -f 0777 /opt/couchdb/etc/local.d
Copy link

Choose a reason for hiding this comment

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

I would recommend moving this whole block up into the RUN line that creates /opt/couchdb in the first place while you're at it/here (there are some edge cases around chmod/chown in a separate layer on some graph drivers).

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks @tianon - I've pushed another commit which does this. @wohali @kocolosk probably best to have another quick review before merging.

Copy link
Member

Choose a reason for hiding this comment

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

see his latest comment, looks like another change is req'd

Copy link
Member Author

Choose a reason for hiding this comment

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

ok - suggested change has been pushed

willholley added a commit that referenced this pull request Aug 27, 2019
There are some edge cases around chmod/chown in a separate layer
on some graph drivers, so it's safer to keep this all in a single
`RUN` block.

Refs #151
willholley added a commit that referenced this pull request Aug 28, 2019
There are some edge cases around chmod/chown in a separate layer
on some graph drivers, so it's safer to keep this all in a single
`RUN` block.

Refs #151
There are some edge cases around chmod/chown in a separate layer
on some graph drivers, so it's safer to keep this all in a single
`RUN` block.

Refs #151
Copy link
Member

@kocolosk kocolosk left a comment

Choose a reason for hiding this comment

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

LGTM

@willholley willholley merged commit 6011918 into master Sep 2, 2019
@willholley willholley deleted the custom_uid branch September 2, 2019 08:14
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.

Make UID & GID configurable
4 participants