Is this mail something I should be concerned about?
from theselfhoster@sopuli.xyz to selfhosted@lemmy.world on 13 Aug 11:59
https://sopuli.xyz/post/31980037

When I sshed into my server today, it said I had mail. I checked /var/mail/{myuser} and got a mail from caddy. The title was “SECURITY information for {hostname}”. The message was this.

caddy : user NOT in sudoers ; PWD=/ ; USER=root ; COMMAND=/usr/bin/tee /usr/local/share/ca-certificates/Caddy_Local_Authority_-_2025_ECC_Root_31435960950297150297199787413716908247066220.crt

I’m still learning this self-hosting thing, I know enough to set stuff up but I still know barely anything about security, and the message looks kinda scary, so I would like to know what it means, thanks in advance. Note that I was messing around with Caddy and stuff yesterday, so maybe that has something to do with it, but I’m not sure.

#selfhosted

threaded - newest

rtxn@lemmy.world on 13 Aug 12:09 next collapse

I can’t believe it. The incident has actually been reported!


I don’t use Caddy, but it seems like it tried to generate and write a TLS certificate into /usr/local, but didn’t have the necessary permissions. Basically it tried to use sudo tee … to write a file. Is Caddy running in a container? If it is, you might need to create a volume at /usr/local/share/ca-certificates. If not in a container, you’ll need to grant the caddy user write permissions in that directory.

But to answer your question directly, it’s not a cause for concern. You’re not getting hacked, it’s just a configuration error.

sugar_in_your_tea@sh.itjust.works on 14 Aug 02:07 collapse

Caddy should never run sudo IMO, I think it’s also a software bug.

dgdft@lemmy.world on 14 Aug 22:01 collapse

What would be the correct way for caddy to run actions like this that require elevated permissions, in your view?

sugar_in_your_tea@sh.itjust.works on 14 Aug 23:28 collapse

Don’t require elevated permissions. Either grant the user it runs as permission to that dir, or instruct it to use a different dir that it has access to. Services should have the least permissions possible.

dgdft@lemmy.world on 14 Aug 23:49 collapse

That’s how it already works — Caddy doesn’t require elevated privileges in general. You can toss a binary + config + certs anywhere in the homedir and it’ll go fine if you bind to a non-privileged port.

But users want software to do stuff like help set up certs and serve on ports 80 & 443, so what better option is there than to limit scope of execution by doing pinhole actions with sudo?

sugar_in_your_tea@sh.itjust.works on 15 Aug 02:02 collapse

what better option is there than to limit scope of execution by doing pinhole actions with sudo?

For binding privileged ports like 80 and 443, use CAP_NET_BIND_SERVICE. For access to protected directories, adjust permissions.

At no point should sudo be necessary, that’s how you get security vulnerabilities.

dgdft@lemmy.world on 15 Aug 02:51 collapse

What kind of vulnerabilities are you worried about from such a sudo call?

I guess this is my point of confusion: If the caddy service account has write access to the config and certs, isn’t that a weaker security posture than having them owned by root?

sugar_in_your_tea@sh.itjust.works on 15 Aug 03:26 collapse

If the caddy service account has write access to the config and certs, isn’t that a weaker security posture than having them owned by root?

I’m much less worried about an attacker messing w/ my certs (that’s a pretty sophisticated attack) and more worried about privilege escalation where the attacker gets root access. Caddy is intended to be externally facing, so it’ll be getting the brunt of the attacks (like this one that attacks HTTP 1.1). If someone is able to find an exploit to allow remote code execution, being able to run commands with sudo is a pretty big deal.

That’s a big part of why I run my services in containers, and also why I’m switching from Docker to Podman. Docker runs everything as root by default, and it’s a pain to run things as non-root. Podman runs everything as an underprivileged user by default, which forces the admin to configure it properly. If an attacker is able to break out of Docker, it’ll have root access to the system, whereas if an attacker breaks out of Podman, they’ll just have whatever that user’s permission is.

If I’m going to expose something to the internet, I want to make sure it’s properly configured to reduce the chances of getting a rootkit or something.

jrgd@lemmy.zip on 13 Aug 12:10 next collapse

You’re likely looking for this docs section for Caddy. The failure is the automated request to populate Caddy’s root CA cert to the host system, but obviously failed as it doesn’t have root permissions. As the docs state, if you intend to use the local HTTPS functionality of Caddy, you can manually run caddy trust privileged in order to populate the Caddy root CA cert manually. If you intend to disable the local HTTPS functionality (such as if you’re running Caddy behind a http reverse proxy), you can ignore the mail message.

theselfhoster@sopuli.xyz on 13 Aug 12:18 collapse

Thanks for clearing my anxieties :) Sometimes I feel an irrational fear that perhaps someone has broken into my server because of my lack of security knowledge, so having that mail come in was very anxiety inducing.

Tetsuo@jlai.lu on 13 Aug 12:16 next collapse

Yeah I think it’s just a false alarm.

I would suggest looking into how sudoers works. I might just be that you asked caddy to do something that required root and forgot to sudo the command ?

Still double check the timestamp and verify that it was when you tinkered. Use “history” to look for previous commands and maybe the timestamp ?

The way I see it something (probably caddy) wanted to check a TLS certificate and had to concatenate all the certificate authorities to check if an adequate CA was there. And it failed to access what looks like a local CA that is autosigned ? Still worth checking your CA has adequate / similar permission as the others.

some_guy@lemmy.sdf.org on 15 Aug 04:40 collapse

If you have anything exposed, scripts and bots are testing your server all day, every day. So long as you’ve got proper security in place, ignore the failed attempts.