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

Add example that runs Caddy in the network namespace of rootless Podman. Use a systemd system service (configured with User=) #21

Closed
eriksjolund opened this issue Nov 24, 2024 · 0 comments · Fixed by #22

Comments

@eriksjolund
Copy link
Owner

Add an example that runs Caddy in a systemd system service that is configured with the systemd directive User=

This makes it possible to use Caddy as an HTTP reverse proxy for a rootless Podman custom network.
Caddy as well as the containers running in the custome network will be running rootless.
Systemd system manager (which runs as root) creates a socket for Caddy so there is no need to lower
the kernel parameter ip_unprivileged_port_start to use port 80 and 443.

Caddy should run in the network namespace of rootless Podman.

It looks like there are three possible alternative implementation ideas

  • Alternative 1. use
    ExecStart=podman unshare --rootless-netns ...
    
  • Alternative 2. use
     ExecStart=bash -c "exec nsenter \
        --preserve-credentials \
        --net=/proc/$(cat $XDG_RUNTIME_DIR/containers/networks/aardvark-dns/aardvark.pid)/ns/net \
        --user=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/user \
        --mount=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/mnt \
        /usr/local/bin/caddy run --environ --config /srv/caddy/Caddyfile"
    
  • Alternative 3. use
    ExecStart=podman run --rm ...
    
    For details, see support User= in systemd for running rootless services containers/podman#20573
    Not officially supported by the Podman project.

Reference:

eriksjolund added a commit that referenced this issue Nov 24, 2024
The implementation makes use of

ExecStart=bash -c "exec nsenter \
    --preserve-credentials \
    --net=/proc/$(cat $XDG_RUNTIME_DIR/containers/networks/aardvark-dns/aardvark.pid)/ns/net \
    --user=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/user \
    --mount=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/mnt \
    /usr/local/bin/caddy run --environ --config /srv/caddy/Caddyfile"

Fixes: #21

Signed-off-by: Erik Sjölund <[email protected]>
eriksjolund added a commit that referenced this issue Nov 24, 2024
The implementation makes use of

ExecStart=bash -c "exec nsenter \
    --preserve-credentials \
    --net=/proc/$(cat $XDG_RUNTIME_DIR/containers/networks/aardvark-dns/aardvark.pid)/ns/net \
    --user=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/user \
    --mount=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/mnt \
    /usr/local/bin/caddy run --environ --config /srv/caddy/Caddyfile"

Fixes: #21

Signed-off-by: Erik Sjölund <[email protected]>
eriksjolund added a commit that referenced this issue Nov 24, 2024
The implementation makes use of

ExecStart=bash -c "exec nsenter \
    --preserve-credentials \
    --net=/proc/$(cat $XDG_RUNTIME_DIR/containers/networks/aardvark-dns/aardvark.pid)/ns/net \
    --user=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/user \
    --mount=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/mnt \
    /usr/local/bin/caddy run --environ --config /srv/caddy/Caddyfile"

Fixes: #21

Signed-off-by: Erik Sjölund <[email protected]>
eriksjolund added a commit that referenced this issue Nov 24, 2024
The implementation makes use of

ExecStart=bash -c "exec nsenter \
    --preserve-credentials \
    --net=/proc/$(cat $XDG_RUNTIME_DIR/containers/networks/aardvark-dns/aardvark.pid)/ns/net \
    --user=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/user \
    --mount=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/mnt \
    /usr/local/bin/caddy run --environ --config /srv/caddy/Caddyfile"

Fixes: #21

Signed-off-by: Erik Sjölund <[email protected]>
eriksjolund added a commit that referenced this issue Nov 24, 2024
The implementation makes use of

ExecStart=bash -c "exec nsenter \
    --preserve-credentials \
    --net=/proc/$(cat $XDG_RUNTIME_DIR/containers/networks/aardvark-dns/aardvark.pid)/ns/net \
    --user=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/user \
    --mount=/proc/$(cat $XDG_RUNTIME_DIR/libpod/tmp/pause.pid)/ns/mnt \
    /usr/local/bin/caddy run --environ --config /srv/caddy/Caddyfile"

Fixes: #21

Signed-off-by: Erik Sjölund <[email protected]>
eriksjolund added a commit that referenced this issue Nov 28, 2024
Related to
#21

Signed-off-by: Erik Sjölund <[email protected]>
eriksjolund added a commit that referenced this issue Nov 28, 2024
Related to
#21

Signed-off-by: Erik Sjölund <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant