Add support for socket activation#40
Conversation
|
@skeeto Does this seems like a reasonable change to you? |
4ba224f to
f926a13
Compare
|
Hmm, I didn't realize systemd supported this kind of socket activation.
I thought it only supported "inetd-style" activation on standard input,
which is pointless for Endlessh. The official systemd documentation is
very unclear, and I'm not convinced that this is actually supported as
written. If it *is* supported, I'd like to accept this feature, but the
PR needs more work.
Have you tested this and does it actually work? Is the listening socket
(not the connection socket) *actually* passed as standard input? I can't
find documentation saying this is the case. Further, the "@" in the name
suggests this is an "Accept=yes" service (multiple instances,
inetd-style), but it's actually an "Accept=no" service. I couldn't
figure out how to install and run as a systemd service, so I couldn't
test it myself. I also don't understand how "ListenStream=%i" works
since I can't find any documentation about the "%i".
Assuming I can successfully verify that socket activation indeed works
correctly as shown, the new option must be better integrated before I'd
accept these changes. Rather than a new variable in main(), it should
appear in "struct config" along with the other options, accessible as
both a command line switch and in the config file (maybe something like
SocketActivation yes/no?). Rather than bool — I dislike C99 _Bool /
stdbool.h — add "int flags" and designate a flag bit for this option.
The new option must also be documented in the man page. But before you
worry about any of that, I want to confirm this style of socket
activation actually works.
Note: Anything to do with sd_listen_fds(3) is a non-starter.
|
I'm quite sure this is an intended functionality (and even the default, as I would have to give
Yes, it is running on my laptop currently (on port 22). You can see it in action, but here is the gist of it:
Yes. The example above (with 2 clients handled by the same endlessh process) wouldn't work otherwise.
All that the It is a bit confusing, because socket units with
Sure, this was only a first go in the hopes of clarifying what's needed for socket activation.
I avoided making it settable in the config file, specifically because it only makes sense for the caller of
I'm... not particularly keen on |
|
Thank you for taking the time to explain all this. Everything is making more sense. The confusing part of the documentation is
This is neither So my next question is: How do I use this? Here's what I tried on your branch (Debian Buster): I'm stumped at this point. |
Thanks for being patient about this. I'm glad it makes more sense now.
Yeah, that's indeed pretty confusing. :/
At that point, you need After that, I should probably add some relationship between
Yeah, starting the service when the socket isn't present doesn't make sense (though Sorry for the incomplete/confusing instructions on how to test it; since I tested those changes with a local build of the Debian package, things got automatically reloaded and such upon reinstall/upgrade >_>' |
- Namespaces (esp. user namespaces) have been a big source of privilege-escalation vulnerabilities in the past. - `personality(2)` provides access to complex, legacy emulation code. - Realtime scheduling can be abused to DoS the host by consuming all available CPU time.
f926a13 to
29e7db0
Compare
|
@skeeto I just updated the feature branch to solve the merge conflict, and while I was at it added some improvements to the systemd unit that I was experimenting with locally. Were you able to confirm this works as desired? |
|
Ping? |
| MemoryDenyWriteExecute=true | ||
| SystemCallArchitectures=native | ||
| SystemCallFilter=@basic-io @file-system @io-event @network-io @signal | ||
| SystemCallFilter=arch_prctl brk mprotect ~socket |
There was a problem hiding this comment.
fwiw my version of systemd (v245.4) complains about ~socket: /etc/systemd/system/endlessh@.service:42: Failed to parse system call, ignoring: ~socket
There was a problem hiding this comment.
Good call, thanks for catching this; looks like I cannot combine whitelist and blacklist in this way >_>'
There was a problem hiding this comment.
You can, but the ~ operator applies per line, not per whitespace-separated item. This should work better:
SystemCallFilter=@basic-io @file-system @io-event @network-io @signal
SystemCallFilter=arch_prctl brk mprotect
SystemCallFilter=~socket
(Many services shipped by systemd start with an allowlist and then add SystemCallFilter=~@privileged to filter out privileged syscalls again, for instance.)
| [Unit] | ||
| Description=Endlessh SSH Tarpit | ||
| Documentation=man:endlessh(1) | ||
| Requires=network-online.target |
There was a problem hiding this comment.
fwiw the only thing you need to have systemctl start endlessh@2222 work is Requires=endlessh@%i.socket here -- systemd will automatically pull the socket in then.
|
This worked well for me and it obviated the need for #21 . ListenStream supports IP's, IP/port, sockets, etc. so it's very flexible. I made an array of the listens I wanted in a puppet class and a loop to deploy them. Slick! https://www.freedesktop.org/software/systemd/man/systemd.socket.html |
-i) to expect a socket onstdin.endlessh@.{service,socket})to support socket activation on arbitrary ports.
-iis specified on the command-line and a portwas explicitely configured (either by config file or CLI argument).
endlessh.service) to use socketactivation, or remove it outright.
Rationale
started with.