-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Tighten up write permissions in Docker image #70635
Changes from 5 commits
9ef552b
000e018
0327e44
6217e57
a1bf983
6b6b847
e13ae49
4a0482d
12e455a
4ed7857
01d3a6b
90b01ff
735a20c
45e7c91
c5675be
c8a617d
53c07d6
ba89e79
31acf7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ RUN set -eux ; \\ | |
sha256sum -c \${tini_bin}.sha256sum ; \\ | ||
rm \${tini_bin}.sha256sum ; \\ | ||
mv \${tini_bin} /bin/tini ; \\ | ||
chmod +x /bin/tini | ||
chmod 0555 /bin/tini | ||
|
||
<% } else if (docker_base == 'iron_bank') { %> | ||
################################################################################ | ||
|
@@ -62,7 +62,7 @@ FROM ${base_image} AS builder | |
# `tini` is a tiny but valid init for containers. This is used to cleanly | ||
# control how ES and any child processes are shut down. | ||
COPY tini /bin/tini | ||
RUN chmod 0755 /bin/tini | ||
RUN chmod 0555 /bin/tini | ||
|
||
<% } else { %> | ||
|
||
|
@@ -168,7 +168,7 @@ RUN set -e ; \\ | |
sha256sum -c "\${TINI_BIN}.sha256sum" ; \\ | ||
rm "\${TINI_BIN}.sha256sum" ; \\ | ||
mv "\${TINI_BIN}" /rootfs/bin/tini ; \\ | ||
chmod +x /rootfs/bin/tini ; \\ | ||
chmod 0555 /rootfs/bin/tini ; \\ | ||
curl --retry 10 -L -o /rootfs/bin/busybox \\ | ||
"https://busybox.net/downloads/binaries/\${BUSYBOX_VERSION}-defconfig-multiarch-musl/busybox-\${BUSYBOX_ARCH}" ; \\ | ||
chmod +x /rootfs/bin/busybox | ||
|
@@ -233,7 +233,7 @@ COPY ${bin_dir}/transform-log4j-config-${version}.jar /tmp/ | |
|
||
# 1. Configure the distribution for Docker | ||
# 2. Ensure directories are created. Most already are, but make sure | ||
# 3. Apply correct permissions | ||
# 3. Apply correct permissions. The `bin` dir needs to be writable because plugins can (in theory) install their own commands | ||
# 4. Move the distribution's default logging config aside | ||
# 5. Generate a docker logging config, to be used by default | ||
# 6. Apply more correct permissions | ||
|
@@ -244,7 +244,7 @@ COPY ${bin_dir}/transform-log4j-config-${version}.jar /tmp/ | |
# examine the contents of the image under any UID:GID | ||
RUN sed -i -e 's/ES_DISTRIBUTION_TYPE=tar/ES_DISTRIBUTION_TYPE=docker/' bin/elasticsearch-env && \\ | ||
mkdir -p config/jvm.options.d data logs plugins && \\ | ||
chmod 0775 config config/jvm.options.d data logs plugins && \\ | ||
chmod 0775 bin config config/jvm.options.d data logs plugins && \\ | ||
mv config/log4j2.properties config/log4j2.file.properties && \\ | ||
jdk/bin/java -jar /tmp/transform-log4j-config-${version}.jar config/log4j2.file.properties > config/log4j2.properties && \\ | ||
chmod 0660 config/elasticsearch.yml config/log4j2*.properties && \\ | ||
|
@@ -288,8 +288,8 @@ RUN ${package_manager} update --setopt=tsflags=nodocs -y && \\ | |
|
||
RUN groupadd -g 1000 elasticsearch && \\ | ||
adduser -u 1000 -g 1000 -G 0 -d /usr/share/elasticsearch elasticsearch && \\ | ||
chmod 0775 /usr/share/elasticsearch && \\ | ||
chown -R 1000:0 /usr/share/elasticsearch | ||
chmod 0755 /usr/share/elasticsearch && \\ | ||
chown -R 0:0 /usr/share/elasticsearch | ||
|
||
<% } else { %> | ||
|
||
|
@@ -305,15 +305,15 @@ COPY --from=rootfs /rootfs / | |
RUN addgroup -g 1000 elasticsearch && \\ | ||
adduser -D -u 1000 -G elasticsearch -g elasticsearch -h /usr/share/elasticsearch elasticsearch && \\ | ||
addgroup elasticsearch root && \\ | ||
chmod 0775 /usr/share/elasticsearch && \\ | ||
chgrp 0 /usr/share/elasticsearch | ||
chmod 0755 /usr/share/elasticsearch && \\ | ||
chown -R 0:0 /usr/share/elasticsearch | ||
|
||
<% } %> | ||
|
||
ENV ELASTIC_CONTAINER true | ||
|
||
WORKDIR /usr/share/elasticsearch | ||
COPY --from=builder --chown=1000:0 /usr/share/elasticsearch /usr/share/elasticsearch | ||
COPY --from=builder --chown=0:0 /usr/share/elasticsearch /usr/share/elasticsearch | ||
|
||
<% if (docker_base == "ubi" || docker_base == "iron_bank") { %> | ||
COPY --from=builder --chown=0:0 /bin/tini /bin/tini | ||
|
@@ -330,10 +330,15 @@ COPY ${bin_dir}/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh | |
# 4. Replace OpenJDK's built-in CA certificate keystore with the one from the OS | ||
# vendor. The latter is superior in several ways. | ||
# REF: https://github.com/elastic/elasticsearch-docker/issues/171 | ||
# 5. Tighten up permissions on the ES home dir (the permissions of the contents are handled earlier) | ||
# 6. Make it possible for a user in the `elasticsearch` group to write to certain directories | ||
RUN chmod g=u /etc/passwd && \\ | ||
chmod 0775 /usr/local/bin/docker-entrypoint.sh && \\ | ||
chmod 0555 /usr/local/bin/docker-entrypoint.sh && \\ | ||
find / -xdev -perm -4000 -exec chmod ug-s {} + && \\ | ||
ln -sf /etc/pki/ca-trust/extracted/java/cacerts /usr/share/elasticsearch/jdk/lib/security/cacerts | ||
ln -sf /etc/pki/ca-trust/extracted/java/cacerts /usr/share/elasticsearch/jdk/lib/security/cacerts && \\ | ||
chmod 0755 /usr/share/elasticsearch && \\ | ||
chgrp 1000 bin && \\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does bin need to be group owned by the running user? The files all are o+rx right? |
||
chgrp -R 1000 config data logs plugins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the plugins dir need to be grouped for the running user? |
||
|
||
EXPOSE 9200 9300 | ||
|
||
|
@@ -376,7 +381,9 @@ RUN mkdir /licenses && cp LICENSE.txt /licenses/LICENSE | |
COPY LICENSE /licenses/LICENSE.addendum | ||
<% } %> | ||
|
||
USER elasticsearch:root | ||
<% /* We used to set `elasticsearch:root` but by specifying the group, it caused the user that Docker runs */ %> | ||
<% /* the container with to **only** have that group, and not the `elasticsearch` group as well. */ %> | ||
USER elasticsearch | ||
|
||
# Our actual entrypoint is `tini`, a minimal but functional init program. It | ||
# calls the entrypoint we provide, while correctly forwarding signals. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,14 +37,16 @@ public enum Fileness { | |
Directory | ||
} | ||
|
||
public static final Set<PosixFilePermission> p775 = fromString("rwxrwxr-x"); | ||
public static final Set<PosixFilePermission> p770 = fromString("rwxrwx---"); | ||
public static final Set<PosixFilePermission> p755 = fromString("rwxr-xr-x"); | ||
public static final Set<PosixFilePermission> p750 = fromString("rwxr-x---"); | ||
public static final Set<PosixFilePermission> p660 = fromString("rw-rw----"); | ||
public static final Set<PosixFilePermission> p444 = fromString("r--r--r--"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now unused right? |
||
public static final Set<PosixFilePermission> p555 = fromString("r-xr-xr-x"); | ||
public static final Set<PosixFilePermission> p600 = fromString("rw-------"); | ||
public static final Set<PosixFilePermission> p644 = fromString("rw-r--r--"); | ||
public static final Set<PosixFilePermission> p660 = fromString("rw-rw----"); | ||
public static final Set<PosixFilePermission> p664 = fromString("rw-rw-r--"); | ||
public static final Set<PosixFilePermission> p600 = fromString("rw-------"); | ||
public static final Set<PosixFilePermission> p750 = fromString("rwxr-x---"); | ||
public static final Set<PosixFilePermission> p755 = fromString("rwxr-xr-x"); | ||
public static final Set<PosixFilePermission> p770 = fromString("rwxrwx---"); | ||
public static final Set<PosixFilePermission> p775 = fromString("rwxrwxr-x"); | ||
|
||
private final Fileness fileness; | ||
private final String owner; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rpm/deb packages setup ownership so that the group is the elasticsearch user, which is readable but not writable. Can we just keep the original permissions defined in the distribution and fix the ownership?