-
-
Notifications
You must be signed in to change notification settings - Fork 5
Run Docker images with reduced privileges #1034
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
Open
jviotti
wants to merge
4
commits into
main
Choose a base branch
from
docker-no-privileges
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,11 +76,33 @@ RUN mkdir -p /usr/share/sourcemeta/one \ | |
|
|
||
| FROM debian:trixie-slim | ||
|
|
||
| # `gosu` lets the runtime entrypoint drop from root to the | ||
| # unprivileged service account. We deliberately don't set `USER` on | ||
| # this image so build-time `RUN` instructions (including those in | ||
| # downstream consumer Dockerfiles) keep executing as root, matching | ||
| # the well-trodden Postgres/Redis/MySQL pattern. | ||
| # | ||
| # `libcap2-bin` provides `setcap`, used below to grant the server | ||
| # binary `CAP_NET_BIND_SERVICE` so the dropped service account can | ||
| # bind privileged ports (below 1024) if the operator chooses to run | ||
| # without a separate TLS terminator in front of the image. | ||
| RUN apt-get --yes update && apt-get install --yes --no-install-recommends \ | ||
| openssl-provider-fips \ | ||
| gosu libcap2-bin openssl-provider-fips \ | ||
| && apt-get clean && rm -rf /var/lib/apt/lists/* | ||
| COPY --from=builder /etc/ssl/openssl.cnf /etc/ssl/openssl.cnf | ||
|
|
||
| # Create the unprivileged service account before the package purge | ||
| # below removes `passwd` (and with it `useradd`). The account lives | ||
| # in `/etc/passwd` after this point and survives the purge. The UID | ||
| # sits above the typical 1000-range dev user (so host-mounted volumes | ||
| # can be mapped unambiguously) and outside the Debian system-user | ||
| # range (1-999) reserved for daemons. | ||
| ARG SOURCEMETA_ONE_UID=10001 | ||
| RUN groupadd --system --gid "${SOURCEMETA_ONE_UID}" sourcemeta \ | ||
| && useradd --system --uid "${SOURCEMETA_ONE_UID}" \ | ||
| --gid "${SOURCEMETA_ONE_UID}" \ | ||
| --no-create-home --shell /usr/sbin/nologin sourcemeta | ||
|
|
||
| # Commercial editions require a paid license | ||
| # See https://one.sourcemeta.com/commercial/ | ||
|
|
||
|
|
@@ -109,6 +131,13 @@ COPY --from=builder /usr/share/sourcemeta/one \ | |
| RUN ldd /usr/bin/sourcemeta-one-index | ||
| RUN ldd /usr/bin/sourcemeta-one-server | ||
|
|
||
| # File capabilities are filesystem extended attributes that do not | ||
| # survive a cross-stage `COPY --from=builder`, so the capability has | ||
| # to be applied here in the runtime stage after the binary lands. | ||
| # `+ep` puts the capability in both the permitted and effective sets | ||
| # of the process at exec time. | ||
| RUN setcap cap_net_bind_service+ep /usr/bin/sourcemeta-one-server | ||
|
|
||
| # Verify that the index binary uses system OpenSSL for cryptography | ||
| RUN ldd /usr/bin/sourcemeta-one-index | grep libcrypto | ||
| # Verify that the OpenSSL FIPS provider is configured and present | ||
|
|
@@ -142,6 +171,20 @@ COPY docker/wrapper-index.sh /usr/bin/sourcemeta | |
| COPY docker/wrapper-server.sh /usr/bin/sourcemeta-server | ||
| COPY docker/transaction-overlayfs.sh /usr/bin/sourcemeta-transaction-overlayfs | ||
|
|
||
| # Pre-create the output directory and hand it to the service account | ||
| # so the runtime server can read through it (and the optional | ||
| # transactional re-index path can write through it) without | ||
| # elevation. The chown is non-recursive to keep blast-radius bounded | ||
| # if a build-arg override ever pointed the path at the rootfs root, | ||
| # and we normalize via `realpath` so values like `/..`, `/foo/..`, or | ||
| # symlinks that resolve to `/` are rejected too. | ||
| RUN test -n "${SOURCEMETA_ONE_OUTPUT}" \ | ||
| && mkdir -p "${SOURCEMETA_ONE_OUTPUT}" \ | ||
| && resolved_output="$(realpath "${SOURCEMETA_ONE_OUTPUT}")" \ | ||
| && test "${resolved_output}" != "/" \ | ||
| && chown sourcemeta:sourcemeta "${resolved_output}" \ | ||
| && chmod 775 "${resolved_output}" | ||
|
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. P2: The new Prompt for AI agents |
||
|
|
||
| ENV SOURCEMETA_ONE_PORT=8000 | ||
| HEALTHCHECK --interval=1s --timeout=2s --start-period=1s --retries=10 CMD grep -qE \ | ||
| "^\s*[0-9]+:\s+[0-9A-F]+:$(printf '%04X' $SOURCEMETA_ONE_PORT)\s+[0-9A-F:]+\s+0A\s" \ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.