Skip to content

Ubi with runit #150

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

Merged
merged 2 commits into from
Oct 14, 2019
Merged

Ubi with runit #150

merged 2 commits into from
Oct 14, 2019

Conversation

welshDoug
Copy link
Contributor

Overview

This PR supersedes #146 to contribute the latest UBI based container, which now makes use of runit to start/stop the CouchDB process. The docker entry point has been adapted so custom parameters can be passed to couch as with the other CouchDB Dockerfiles.

Also, includes changes necessary for Red Hat Certification:

  • licenses folder
  • Specific labels
  • couchdb user moved to root group
  • runit can be launched by any userid

@kocolosk
Copy link
Member

Cool. Can you explain the reasoning behind the root group and the use of unit in this way?

@welshDoug
Copy link
Contributor Author

Sure, the root group use is based on OpenShift advice specifically: For an image to support running as an arbitrary user, directories and files that may be written to by processes in the image should be owned by the root group and be read/writable by that group. Files to be executed should also have group execute permissions.

OpenShift will run the container with a UID that also belongs to the root group, so assigning file permissions to the root group ensures that at execute time the user will have the required permissions.

The container expects to be run as an arbitrary user that starts the runit service, this uses chpst to run the couchdb process as the couchdb user.

The runit setup is based on the CouchDB docs. With the main tweak being that while a default run file is provided, the docker entry point can also lay down a custom run file if the user wants to run couchdb with specific parameters. This is for compatibility with existing Dockerfiles.

io.openshift.min-cpu="1"

# Add CouchDB user account to make sure the IDs are assigned consistently
# CouchDB user added to root group for OpenShift support
Copy link
Member

Choose a reason for hiding this comment

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

# cases where some of these ownership and permissions issues are non-fatal
# (e.g. a config file owned by root with o+r is actually fine), and we don't
# to be too aggressive about crashing here ...
find /opt/couchdb \! \( -user couchdb -group 0 \) -exec chown -f couchdb:0 '{}' +
Copy link
Member

Choose a reason for hiding this comment

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

so this entrypoint (which is the default) doesn't support arbitrary UIDs? Does that work in OpenShift?

Copy link
Member

Choose a reason for hiding this comment

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

This is precisely the line that caused other users significant pain. Please review prior bugs filed on this repository, especially #109 and #110. I would prefer not to re-introduce this bug.

wohali
wohali previously requested changes Aug 12, 2019
Copy link
Member

@wohali wohali left a comment

Choose a reason for hiding this comment

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

See comments

# cases where some of these ownership and permissions issues are non-fatal
# (e.g. a config file owned by root with o+r is actually fine), and we don't
# to be too aggressive about crashing here ...
find /opt/couchdb \! \( -user couchdb -group 0 \) -exec chown -f couchdb:0 '{}' +
Copy link
Member

Choose a reason for hiding this comment

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

This is precisely the line that caused other users significant pain. Please review prior bugs filed on this repository, especially #109 and #110. I would prefer not to re-introduce this bug.

@wohali
Copy link
Member

wohali commented Aug 26, 2019

@willholley if you can help out here vis a vis the chmod/chown changes in the other PR I just approved, we can get this merged, too.

@welshDoug
Copy link
Contributor Author

@wohali I've had Wills help in pulling the chmod/chown changes into this PR, are there any other changes you think are necessary?

@wohali
Copy link
Member

wohali commented Sep 30, 2019

@kocolosk can i get one final PR review on this from you please with special attention to the chmod/chown stuff? thanks :)

@wohali wohali dismissed their stale review September 30, 2019 17:11

Dismissing my own concerns

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.

Once those minor issues with configuration file permissions are addressed (possibly just through a comment) I think this is good to merge.

# Setup directories and permissions for config. Technically these could be 555 and 444 respectively
# but we keep them as 755 and 644 for consistency with CouchDB defaults and the dockerfile_entrypoint.
find /opt/couchdb/etc -type d ! -perm 0755 -exec chmod -f 0775 '{}' +; \
find /opt/couchdb/etc -type f ! -perm 0644 -exec chmod -f 0664 '{}' +; \
Copy link
Member

Choose a reason for hiding this comment

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

Should the check here be looking for 0775 / 0664 instead of 0755 / 0644? Looks like it might have been an oversight in the switch to the root group.

# changes will be applied to the "docker.ini" file below, but we set 644
# for the sake of consistency.
find /opt/couchdb/etc -type d ! -perm 0755 -exec chmod -f 0755 '{}' +
find /opt/couchdb/etc -type f ! -perm 0644 -exec chmod -f 0644 '{}' +
Copy link
Member

Choose a reason for hiding this comment

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

So this will end up removing g+w from the config files and directories if we're starting up as root. I ... suppose that's fine. Perhaps it's worth a comment as it is a discrepancy from the Dockerfile? Also, not sure the comment about docker.ini is accurate in this case as the file has been reordered so docker.ini is already created above (and will have its permissions modified here).

@welshDoug
Copy link
Contributor Author

@kocolosk good spot with the permissions :-) I've made those changes and cleaned up the git history a bit

Installs CouchDB 2.3.1 via the official rpm.

To build:
```
$ cd 2.3.1
$ docker build . -f ubi7/Dockerfile
```

Move the ubi-based Dockerfile into its own top level
folder, similar to the couchperuser variant. This makes integration
with existing build scripts/processes simpler though means a bit
of duplication of config files between the different base images.

Update UBI based image to use runit instead of gosu to launch CouchDB.

Also, includes changes necessary for Red Hat Certification:
- licenses folder
- Specific labels
- couchdb user moved to root group
- runit can be launched by any userid
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.

All good once the comments match the code ;)

# Check we own everything in /opt/couchdb. Matches the command in dockerfile_entrypoint.sh
find /opt/couchdb \! \( -user couchdb -group 0 \) -exec chown -f couchdb:0 '{}' +; \
# Setup directories and permissions for config. Technically these could be 555 and 444 respectively
# but we keep them as 755 and 644 for consistency with CouchDB defaults and the dockerfile_entrypoint.
Copy link
Member

Choose a reason for hiding this comment

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

Comment is outdated here

# Do the same thing for configuration files and directories. Technically
# CouchDB only needs read access to the configuration files, except "docker.ini"
# (created above) as that is where all online changes will be writted.
# But we set 644 for the sake of consistency.
Copy link
Member

Choose a reason for hiding this comment

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

Outdated comment again (664 not 644).

@willholley willholley merged commit 00e1ee8 into apache:master Oct 14, 2019
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.

4 participants