Skip to content

Commit

Permalink
Add support for SELinux systems
Browse files Browse the repository at this point in the history
  • Loading branch information
YtvwlD committed Jan 21, 2025
1 parent 0eff362 commit 50ee540
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
26 changes: 26 additions & 0 deletions lib/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ setupProxy() {
export HTTPS_PROXY_HOST HTTPS_PROXY_PORT HTTPS_PROXY_FULL_URL
}

checkAndSetSelinux() {
# This is needed for the systemd service to start on SELinux systems.
if ! command -v sestatus > /dev/null 2>&1; then
echo "SELinux not available; nothing to do"
return
fi
if ! sestatus | grep "SELinux status:" | grep enabled > /dev/null; then
echo "SELinux disabled; nothing to do"
return
fi
current_mode="$(sestatus | grep 'Current mode:' | tr -s ' ' | cut -d' ' -f 3)"
echo "SELinux is active and ${current_mode}, checking for labels..."
# TODO: perhaps split this into checkSelinux (without the need for root) and setSelinux (needing root)
# "stat /srv/docker/bridgehead/bridgehead --printf %C" could be used for a check that doesn't need root
exitIfNotRoot
labels_for_srv="$(semanage fcontext --list | grep -e ^/srv)"
echo "Found the following labels for /srv:"
echo "${labels_for_srv}"
if ! echo "${labels_for_srv}" | grep -e ^/srv/docker/bridgehead/bridgehead > /dev/null; then
echo "Adding a label for /srv/docker/bridgehead/bridgehead..."
semanage fcontext --add --type bin_t /srv/docker/bridgehead/bridgehead
fi
restorecon -v /srv/docker/bridgehead/bridgehead # this survives a reboot
# TODO: check if this survives updates
}

exitIfNotRoot() {
if [ "$EUID" -ne 0 ]; then
log "ERROR" "Please run as root"
Expand Down
1 change: 1 addition & 0 deletions lib/install-bridgehead.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
source lib/functions.sh

exitIfNotRoot
checkAndSetSelinux

if [ $# -eq 0 ]; then
log "ERROR" "Please provide a Project as argument"
Expand Down
3 changes: 3 additions & 0 deletions minimal/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ services:
ports:
- 80:80
- 443:443
security_opt:
# allow access to the docker socket on systems with SELinux
- "label:type:container_runtime_t"
volumes:
- /etc/bridgehead/traefik-tls:/certs:ro
- ../lib/traefik-configuration/:/configuration:ro
Expand Down
12 changes: 4 additions & 8 deletions minimal/modules/dnpm-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ services:
ALL_PROXY: http://forward_proxy:3128
TLS_CA_CERTIFICATES_DIR: ./conf/trusted-ca-certs
ROOTCERT_FILE: ./conf/root.crt.pem
secrets:
- proxy.pem
depends_on:
- "forward_proxy"
volumes:
- /etc/bridgehead/trusted-ca-certs:/conf/trusted-ca-certs:ro
- /srv/docker/bridgehead/ccp/root.crt.pem:/conf/root.crt.pem:ro
- /srv/docker/bridgehead/ccp/root.crt.pem:/conf/root.crt.pem:ro,Z
# secrets don't seem to allow us to specify Z
- /etc/bridgehead/pki/${SITE_ID}.priv.pem:/run/secrets/proxy.pem:ro

dnpm-beam-connect:
depends_on: [ dnpm-beam-proxy ]
Expand All @@ -41,7 +41,7 @@ services:
volumes:
- /etc/bridgehead/trusted-ca-certs:/conf/trusted-ca-certs:ro
- /etc/bridgehead/dnpm/local_targets.json:/conf/connect_targets.json:ro
- /srv/docker/bridgehead/minimal/modules/dnpm-central-targets.json:/conf/central_targets.json:ro
- /srv/docker/bridgehead/minimal/modules/dnpm-central-targets.json:/conf/central_targets.json:ro,Z
labels:
- "traefik.enable=true"
- "traefik.http.routers.dnpm-connect.rule=PathPrefix(`/dnpm-connect`)"
Expand All @@ -53,7 +53,3 @@ services:
dnpm-echo:
image: docker.verbis.dkfz.de/cache/samply/bridgehead-echo:latest
container_name: bridgehead-dnpm-echo

secrets:
proxy.pem:
file: /etc/bridgehead/pki/${SITE_ID}.priv.pem

0 comments on commit 50ee540

Please sign in to comment.