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

Support for FD passing / socket activation (systemd and others) #2485

Closed
VannTen opened this issue Mar 2, 2023 · 1 comment
Closed

Support for FD passing / socket activation (systemd and others) #2485

VannTen opened this issue Mar 2, 2023 · 1 comment
Labels
request Request for new functionality

Comments

@VannTen
Copy link

VannTen commented Mar 2, 2023

Is your feature request motivated by a concrete problem? Please describe.

I'm trying to use https://github.com/ogarcia/rockpass (based on Rocket) on my server.
To increase the level of isolation proposed by this project, I wanted to run it in a private network namespace, using socket activation to cross the boundary. (systemd.exec see 'PrivateNetwork').
This would work by letting systemd manage the socket / port binding, and passing the fd to the process.
Instead I currently use systemd-socket-proxyd, which basically do a poor man socket activation on services not supporting it. It works, but with race conditions happening on the first request.

To correctly support that use case, Rocket would have to be able to listen on a file descriptor passed by a parent process (typically, systemd, inetd, s6) instead of binding by itself on a port or socket.

Why this feature can't or shouldn't live outside of Rocket

I'm not sure.
I have a very limited understanding of the scope of Rocket, but from reading some other issues PRs (see context), this sounds like something which is a bit difficult to plug-in.
Open to alternatives solutions I haven't think of.

Ideal Solution

Use https://github.com/Kixunil/systemd_socket
If I get the documentation right, this allows to to pass something like "systemd://socket_name" as the bind address and be done with it.

Alternatives Considered

However, the interface would be specific to systemd, which might be a bad thing. An explicit configuration might be a better option (gives an explicit fd number to use), together with https://doc.rust-lang.org/std/net/struct.TcpListener.html#impl-From%3COwnedFd%3E-for-TcpListener ?

Potential problems

  • I've no idea how this would interact with things like TLS, but this could be a problem.

Additional Context

I think the following issues are relevant:

The setup which prompted this, if anyone wants to look

Caddyfile

# I use Caddy for automatic https.
#
# https://caddyserver.com/docs/caddyfile
#
# https://caddyserver.com/docs/caddyfile/concepts#addresses
{
	admin off
}

https://lesspass.my.domain {
    route {
	@rockpass {
		path /auth*
		path /passwords*
	}
	reverse_proxy @rockpass unix//run/proxy-to-rockpass
    respond 404
    }
}
# /usr/lib/systemd/system/rockpass.service
[Unit]
Description=A small and ultrasecure Lesspass database server written in Rust
Documentation=https://github.com/ogarcia/rockpass/blob/master/README.md
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
DynamicUser=yes
StateDirectory=rockpass
ExecStart=/usr/bin/rockpass
Environment=ROCKPASS_PORT=8000
PrivateNetwork=true
# [email protected]
[Unit]
Requires=%N.socket %i.service
After=%N.socket %i.service
JoinsNamespaceOf=%i.service

[Service]
ExecStart=/usr/lib/systemd/systemd-socket-proxyd 127.0.0.1:8000 # This is inside the net namespace of rockpass
PrivateTmp=yes
PrivateNetwork=yes

[Install]
WantedBy=multi-user.target
# /[email protected]
[Socket]
ListenStream=%t/proxy-to-%i

[Install]
WantedBy=sockets.target
@VannTen VannTen added the request Request for new functionality label Mar 2, 2023
@SergioBenitez
Copy link
Member

I believe this would be covered by #1070. If we could pass a TcpListener directly to Rocket, instead of Rocket requiring that it be the creator, that would enable this use-case without any systemd specific effort. I think this is something we should prioritize for 0.6, so I'll milestone that issue. I'll close this one as a result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Request for new functionality
Projects
None yet
Development

No branches or pull requests

2 participants