Adding ca-certificates to a Tomcat Docker container run with a designated user
up vote
0
down vote
favorite
I have a Docker volume mounted directly to the /usr/local/share/ca-certificates -folder.
certificate-folder:/usr/local/share/ca-certificates:ro
I'm using Tomcat for this setup, but a similar issue could be encountered with other frameworks as well. Base of the Dockerfile is like this:
FROM tomcat:8.5-jre8
# other Dockerfile configuration
CMD ["/start.sh"]
With start.sh containing key lines
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
catalina.sh run
Issue with this setup is that it works as long as I'm running the container as root user. However, if I try to change to a designated user at the end of the Dockerfile with something like this
ENV TOMCAT_USER="tomcat"
TOMCAT_UID="8080"
TOMCAT_GROUP="tomcat"
TOMCAT_GID="8080"
RUN groupadd -r --gid $TOMCAT_GID $TOMCAT_GROUP &&
useradd -r --uid $TOMCAT_UID --gid $TOMCAT_GID $TOMCAT_USER
RUN chown -R $TOMCAT_USER:$TOMCAT_GROUP /usr/local/tomcat
USER $TOMCAT_USER
So:
- Because the shell script is being run as $TOMCAT_USER, it can't run "update-ca-certificates" to install the certificates.
- Because certificates aren't added inside Dockerfile, update-ca-certificates can't be run inside Dockerfile.
Because of this I'm eventually getting SSL issues like this
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
So what would be the correct way to approach this kind of issue if I still wish to run the container as a designated $TOMCAT_USER?
docker ssl tomcat ssl-certificate dockerfile
add a comment |
up vote
0
down vote
favorite
I have a Docker volume mounted directly to the /usr/local/share/ca-certificates -folder.
certificate-folder:/usr/local/share/ca-certificates:ro
I'm using Tomcat for this setup, but a similar issue could be encountered with other frameworks as well. Base of the Dockerfile is like this:
FROM tomcat:8.5-jre8
# other Dockerfile configuration
CMD ["/start.sh"]
With start.sh containing key lines
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
catalina.sh run
Issue with this setup is that it works as long as I'm running the container as root user. However, if I try to change to a designated user at the end of the Dockerfile with something like this
ENV TOMCAT_USER="tomcat"
TOMCAT_UID="8080"
TOMCAT_GROUP="tomcat"
TOMCAT_GID="8080"
RUN groupadd -r --gid $TOMCAT_GID $TOMCAT_GROUP &&
useradd -r --uid $TOMCAT_UID --gid $TOMCAT_GID $TOMCAT_USER
RUN chown -R $TOMCAT_USER:$TOMCAT_GROUP /usr/local/tomcat
USER $TOMCAT_USER
So:
- Because the shell script is being run as $TOMCAT_USER, it can't run "update-ca-certificates" to install the certificates.
- Because certificates aren't added inside Dockerfile, update-ca-certificates can't be run inside Dockerfile.
Because of this I'm eventually getting SSL issues like this
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
So what would be the correct way to approach this kind of issue if I still wish to run the container as a designated $TOMCAT_USER?
docker ssl tomcat ssl-certificate dockerfile
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a Docker volume mounted directly to the /usr/local/share/ca-certificates -folder.
certificate-folder:/usr/local/share/ca-certificates:ro
I'm using Tomcat for this setup, but a similar issue could be encountered with other frameworks as well. Base of the Dockerfile is like this:
FROM tomcat:8.5-jre8
# other Dockerfile configuration
CMD ["/start.sh"]
With start.sh containing key lines
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
catalina.sh run
Issue with this setup is that it works as long as I'm running the container as root user. However, if I try to change to a designated user at the end of the Dockerfile with something like this
ENV TOMCAT_USER="tomcat"
TOMCAT_UID="8080"
TOMCAT_GROUP="tomcat"
TOMCAT_GID="8080"
RUN groupadd -r --gid $TOMCAT_GID $TOMCAT_GROUP &&
useradd -r --uid $TOMCAT_UID --gid $TOMCAT_GID $TOMCAT_USER
RUN chown -R $TOMCAT_USER:$TOMCAT_GROUP /usr/local/tomcat
USER $TOMCAT_USER
So:
- Because the shell script is being run as $TOMCAT_USER, it can't run "update-ca-certificates" to install the certificates.
- Because certificates aren't added inside Dockerfile, update-ca-certificates can't be run inside Dockerfile.
Because of this I'm eventually getting SSL issues like this
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
So what would be the correct way to approach this kind of issue if I still wish to run the container as a designated $TOMCAT_USER?
docker ssl tomcat ssl-certificate dockerfile
I have a Docker volume mounted directly to the /usr/local/share/ca-certificates -folder.
certificate-folder:/usr/local/share/ca-certificates:ro
I'm using Tomcat for this setup, but a similar issue could be encountered with other frameworks as well. Base of the Dockerfile is like this:
FROM tomcat:8.5-jre8
# other Dockerfile configuration
CMD ["/start.sh"]
With start.sh containing key lines
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
catalina.sh run
Issue with this setup is that it works as long as I'm running the container as root user. However, if I try to change to a designated user at the end of the Dockerfile with something like this
ENV TOMCAT_USER="tomcat"
TOMCAT_UID="8080"
TOMCAT_GROUP="tomcat"
TOMCAT_GID="8080"
RUN groupadd -r --gid $TOMCAT_GID $TOMCAT_GROUP &&
useradd -r --uid $TOMCAT_UID --gid $TOMCAT_GID $TOMCAT_USER
RUN chown -R $TOMCAT_USER:$TOMCAT_GROUP /usr/local/tomcat
USER $TOMCAT_USER
So:
- Because the shell script is being run as $TOMCAT_USER, it can't run "update-ca-certificates" to install the certificates.
- Because certificates aren't added inside Dockerfile, update-ca-certificates can't be run inside Dockerfile.
Because of this I'm eventually getting SSL issues like this
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
So what would be the correct way to approach this kind of issue if I still wish to run the container as a designated $TOMCAT_USER?
docker ssl tomcat ssl-certificate dockerfile
docker ssl tomcat ssl-certificate dockerfile
asked Nov 21 at 13:26
mpartan
734522
734522
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
As update-ca-certificates
needs root permissions to update the certificates in /etc/ssl/certs
, I only see three possible approaches (and one working solution − the third one below):
Remove
update-ca-certificates
from your entrypoint and add aRUN update-ca-certificates
command before the lineUSER $TOMCAT_USER
. (However, you are using a volume which won't be available at build time, so this couldn't work…)Give
sudo
permissions (with no password) to your$TOMCAT_USER
, and replaceupdate-ca-certificates
withsudo update-ca-certificates
. (However, this solution may be unsatisfactory from a security perspective…)
Remove
USER $TOMCAT_USER
from your Dockerfile; keepCMD ["/start.sh"]
, orENTRYPOINT ["/start.sh"]
if you prefer; and rely on the gosu tool, whose main use case precisely consists in downgrading from root to a non-privileged user, while enjoying better behavior than sudo w.r.t. TTY and signal forwarding.
You'll just need to install
gosu
by doing for example:
RUN apt-get update -y -q &&
DEBIAN_FRONTEND=noninteractive
apt-get install -y -q --no-install-recommends gosu
(as
tomcat:8.5-jre8
is based on Debian) and use it by writing:
start.sh
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
gosu $TOMCAT_UID:$TOMCAT_GID catalina.sh run
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
As update-ca-certificates
needs root permissions to update the certificates in /etc/ssl/certs
, I only see three possible approaches (and one working solution − the third one below):
Remove
update-ca-certificates
from your entrypoint and add aRUN update-ca-certificates
command before the lineUSER $TOMCAT_USER
. (However, you are using a volume which won't be available at build time, so this couldn't work…)Give
sudo
permissions (with no password) to your$TOMCAT_USER
, and replaceupdate-ca-certificates
withsudo update-ca-certificates
. (However, this solution may be unsatisfactory from a security perspective…)
Remove
USER $TOMCAT_USER
from your Dockerfile; keepCMD ["/start.sh"]
, orENTRYPOINT ["/start.sh"]
if you prefer; and rely on the gosu tool, whose main use case precisely consists in downgrading from root to a non-privileged user, while enjoying better behavior than sudo w.r.t. TTY and signal forwarding.
You'll just need to install
gosu
by doing for example:
RUN apt-get update -y -q &&
DEBIAN_FRONTEND=noninteractive
apt-get install -y -q --no-install-recommends gosu
(as
tomcat:8.5-jre8
is based on Debian) and use it by writing:
start.sh
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
gosu $TOMCAT_UID:$TOMCAT_GID catalina.sh run
add a comment |
up vote
2
down vote
As update-ca-certificates
needs root permissions to update the certificates in /etc/ssl/certs
, I only see three possible approaches (and one working solution − the third one below):
Remove
update-ca-certificates
from your entrypoint and add aRUN update-ca-certificates
command before the lineUSER $TOMCAT_USER
. (However, you are using a volume which won't be available at build time, so this couldn't work…)Give
sudo
permissions (with no password) to your$TOMCAT_USER
, and replaceupdate-ca-certificates
withsudo update-ca-certificates
. (However, this solution may be unsatisfactory from a security perspective…)
Remove
USER $TOMCAT_USER
from your Dockerfile; keepCMD ["/start.sh"]
, orENTRYPOINT ["/start.sh"]
if you prefer; and rely on the gosu tool, whose main use case precisely consists in downgrading from root to a non-privileged user, while enjoying better behavior than sudo w.r.t. TTY and signal forwarding.
You'll just need to install
gosu
by doing for example:
RUN apt-get update -y -q &&
DEBIAN_FRONTEND=noninteractive
apt-get install -y -q --no-install-recommends gosu
(as
tomcat:8.5-jre8
is based on Debian) and use it by writing:
start.sh
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
gosu $TOMCAT_UID:$TOMCAT_GID catalina.sh run
add a comment |
up vote
2
down vote
up vote
2
down vote
As update-ca-certificates
needs root permissions to update the certificates in /etc/ssl/certs
, I only see three possible approaches (and one working solution − the third one below):
Remove
update-ca-certificates
from your entrypoint and add aRUN update-ca-certificates
command before the lineUSER $TOMCAT_USER
. (However, you are using a volume which won't be available at build time, so this couldn't work…)Give
sudo
permissions (with no password) to your$TOMCAT_USER
, and replaceupdate-ca-certificates
withsudo update-ca-certificates
. (However, this solution may be unsatisfactory from a security perspective…)
Remove
USER $TOMCAT_USER
from your Dockerfile; keepCMD ["/start.sh"]
, orENTRYPOINT ["/start.sh"]
if you prefer; and rely on the gosu tool, whose main use case precisely consists in downgrading from root to a non-privileged user, while enjoying better behavior than sudo w.r.t. TTY and signal forwarding.
You'll just need to install
gosu
by doing for example:
RUN apt-get update -y -q &&
DEBIAN_FRONTEND=noninteractive
apt-get install -y -q --no-install-recommends gosu
(as
tomcat:8.5-jre8
is based on Debian) and use it by writing:
start.sh
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
gosu $TOMCAT_UID:$TOMCAT_GID catalina.sh run
As update-ca-certificates
needs root permissions to update the certificates in /etc/ssl/certs
, I only see three possible approaches (and one working solution − the third one below):
Remove
update-ca-certificates
from your entrypoint and add aRUN update-ca-certificates
command before the lineUSER $TOMCAT_USER
. (However, you are using a volume which won't be available at build time, so this couldn't work…)Give
sudo
permissions (with no password) to your$TOMCAT_USER
, and replaceupdate-ca-certificates
withsudo update-ca-certificates
. (However, this solution may be unsatisfactory from a security perspective…)
Remove
USER $TOMCAT_USER
from your Dockerfile; keepCMD ["/start.sh"]
, orENTRYPOINT ["/start.sh"]
if you prefer; and rely on the gosu tool, whose main use case precisely consists in downgrading from root to a non-privileged user, while enjoying better behavior than sudo w.r.t. TTY and signal forwarding.
You'll just need to install
gosu
by doing for example:
RUN apt-get update -y -q &&
DEBIAN_FRONTEND=noninteractive
apt-get install -y -q --no-install-recommends gosu
(as
tomcat:8.5-jre8
is based on Debian) and use it by writing:
start.sh
#!/usr/bin/env bash
update-ca-certificates
# other startup related tasks
gosu $TOMCAT_UID:$TOMCAT_GID catalina.sh run
edited Nov 21 at 22:30
answered Nov 21 at 22:24
ErikMD
1,9051318
1,9051318
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413071%2fadding-ca-certificates-to-a-tomcat-docker-container-run-with-a-designated-user%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown