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

[Bug]: internal CA certificate mechanism does not work with non-root user #464

Closed
gaeljw opened this issue Nov 15, 2023 · 4 comments · Fixed by #538
Closed

[Bug]: internal CA certificate mechanism does not work with non-root user #464

gaeljw opened this issue Nov 15, 2023 · 4 comments · Fixed by #538
Labels
bug Something isn't working

Comments

@gaeljw
Copy link

gaeljw commented Nov 15, 2023

Please add the exact image (with tag) that you are using

eclipse-temurin:11-jre-jammy

Please add the version of Docker you are running

N/A

What happened?

As per the documentation "Can I add my internal CA certificates to the truststore?" and following implementation of #293 and #392, I wanted to mount my internal CA certificate in a container at runtime.

The issue is that the internal CA certificate is not taken into account, an error is raised at start time:

cp: cannot create regular file '/usr/local/share/ca-certificates/mycert.pem': Permission denied

From my first investigation, this is related to the fact that we use a non-root user whereas the internal CA handling can only work if the running user is root.

Simplified Dockerfile:

FROM eclipse-temurin:11-jre-jammy

RUN addgroup --system my_user && adduser --system --shell /bin/false --no-create-home --ingroup my_user --uid 999 my_user
USER 999

WORKDIR /app

# Copy some JAR file in /app/lib

CMD java -cp "/app/conf:/app/lib/* "my.package.MyMainClass"

And run with the following command:

podman run -v ./mycert.pem:/certificates/mycert.pem -e USE_SYSTEM_CA_CERTS=1 myImageName

Commenting out the directive to run as non-root makes it work.

In a Kubernetes context where non-root is enforced, it makes the feature unusable.

However I don't know if this even possible to make it work as non-root. If not, I guess we should at least document it.

Relevant log output

No response

@gaeljw gaeljw added the bug Something isn't working label Nov 15, 2023
@gaeljw
Copy link
Author

gaeljw commented Nov 15, 2023

In the meantime, we switched to use the "good old" way of configuring the trustore with a java opt -Djavax.net.ssl.trustStore=/certificates/bundle.jks and mounting a JKS rather than the PEM file.

@gdams
Copy link
Member

gdams commented Nov 21, 2023

@rassie any ideas?

@rassie
Copy link
Contributor

rassie commented Nov 21, 2023

It's a good thing this feature is opt-in, I guess. Kubernetes being mostly non-root is a good point which I didn't have in mind when developing the PR.

Currently, we are explicit about using system CA store for JRE's trust store, just like openjdk images used to do. This is basically a two-step-process: add certificates to system CA store first and then use those certificates in JRE store. The first step is inherently something that requires root permissions, since we are updating a system CA store. The second step also currently requires root user, since the /opt/java/openjdk/lib/security/cacerts file belongs to root and thus cannot be updated by user.

Both steps should still probably be possible in a non-privileged container -- there are valid reasons for updating the system CA store even without any JRE context and same reasons are valid for updating JRE's trust store. I'm not quite sure what would be the best way to proceed, but at least for the latter part, creating and using a trust store at a different filesystem location could be the way, but it doesn't help with system CA store.

@danielthieleog
Copy link

Workaround:
You could additionally install a tool like su-exec in the docker image and prepend it to the command.
You would run the container as root.
It updates certificates running the default entrypoint.
Then the command starts your application with su-exec with user and group whatever you want.

rassie added a commit to rassie/containers-1 that referenced this issue Apr 22, 2024
This patch includes several improvements and simplifications in CA certificate handling:

* Support for CA certificates in containers running as a non-root user
* Support for CA certificates in containers running with read-only filesystem
* Unification of Docker entrypoint scripts into one
* Entrypoint script now exports CACERT environment variable to point to the used truststore file

Docs updates at https://github.com/docker-library/official-images/ pending.

Possibly fixes: adoptium#464
rassie added a commit to rassie/containers-1 that referenced this issue Apr 22, 2024
This patch includes several improvements and simplifications in CA certificate handling:

* Support for CA certificates in containers running as a non-root user
* Support for CA certificates in containers running with read-only filesystem
* Unification of Docker entrypoint scripts into one
* Entrypoint script now exports CACERT environment variable to point to the used truststore file

Docs updates at https://github.com/docker-library/official-images/ pending.

Possibly fixes: adoptium#464
rassie added a commit to rassie/containers-1 that referenced this issue Apr 23, 2024
This patch includes several improvements and simplifications in CA certificate handling:

* Support for CA certificates in containers running as a non-root user
* Support for CA certificates in containers running with read-only filesystem
* Unification of Docker entrypoint scripts into one
* Entrypoint script now exports CACERT environment variable to point to the used truststore file

Docs updates at https://github.com/docker-library/official-images/ pending.

Possibly fixes: adoptium#464
rassie added a commit to rassie/containers-1 that referenced this issue May 8, 2024
This patch includes several improvements and simplifications in CA certificate handling:

* Support for CA certificates in containers running as a non-root user
* Support for CA certificates in containers running with read-only filesystem
* Unification of Docker entrypoint scripts into one
* Entrypoint script now exports CACERT environment variable to point to the used truststore file

Docs updates at https://github.com/docker-library/official-images/ pending.

Possibly fixes: adoptium#464
tellison pushed a commit that referenced this issue May 9, 2024
* Rework CA certificate support to allow rootless containers

This patch includes several improvements and simplifications in CA certificate handling:

* Support for CA certificates in containers running as a non-root user
* Support for CA certificates in containers running with read-only filesystem
* Unification of Docker entrypoint scripts into one
* Entrypoint script now exports CACERT environment variable to point to the used truststore file

Docs updates at https://github.com/docker-library/official-images/ pending.

Possibly fixes: #464

* Update Dockerfiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants