all 13 comments

sorted by: hot top controversial new old
[–] 30 points 2 days ago* (last edited 2 days ago) (8 children)

Adding a user to the docker group is equivalent with granting it passwordless root privileges, never do that unless you know precisely why and understand the risks involved.

On the positive side, forbidding password-based auth, installing and using a firewall and locking down the root account is good advice

  • source
  • hideshow 8 child comments
  • [–] 6 points 2 days ago (7 children)

    Getting whatever you can (likely most, or all) into rootless podman, preferably with SELinux is worthwhile. Docker is a security nightmare.

  • source
  • parent
  • hideshow 7 child comments
  • [–] 3 points 2 days ago (6 children)

    I have a whole bunch of docker compose declared containers running on my server how much of an investment do you think it’d be to podman? I don’t like how insecure docker is but it seems like a pain to move.

  • source
  • parent
  • hideshow 6 child comments
  • [–] 5 points 2 days ago* (last edited 2 days ago) (2 children)

    Not going to lie, there is pain, but maintenance is much nicer. I've gotten to the point where I can just convert docker-compose to quadlet by eye, the syntax is familiar if you know systemd.

    https://github.com/containers/podlet can be pointed at a docker-compose and spits out quadlets. It's been a while but last I used it, it would get it right 80%+ of the time on complex things and get you 85%+ there when it failed. There's also podman-compose which is a crutch but can establish compatibility. /usr/libexec/podman/quadlet -dryrun -user is a useful diagnostic when conversions break.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 2 days ago (1 child)

    Sometimes I feel like a poser Linux user because I don’t know systemd at all lol. I guess it’s probably because it’s technically my secondary os. But yeah I’ll look into changing stuff this weekend. I’ve been having issues with tangled, and I want to self hosting my password manager so it’s a good time to just put in a bunch of effort into everything. I’m hoping that podman will also be a bit more ergonomic.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 2 days ago (2 children)

    Honestly the issue is docker was never designed to be a security boundary. Docker is always from the beginning a way to deploy application without conflicting shared library requirements. Looser than isolation of VM, but also not as hard as every other existing solution at that time (dedicated chroot, static linking, appimage, flatpak)

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 2 days ago (1 child)

    Yeah makes sense. I originally just went with docker because I didn’t want to bother to learn new stuff since spending hours solving issues at work made me less inclined to want to do the same at home when I just want to actual maybe work on “fun” stuff. Same reason I still use nginx instead of caddy. But I have seen increasingly more projects that use podman instead of docker so maybe I can still be lazy ish with my self hosting and get some security.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 2 days ago

    That's the fun part. Podman skills transfer better to kubernetes if that's your end goal. Docker compose has a different format than what a kubernetes YAML expect. So you do get a bit safer container model AND devops skills

  • source
  • parent
  • [–] 7 points 2 days ago (2 children)

    I would add changing the SSH port to one that isn't 22. This isn't any more secure, but does tamp down on automated scanner traffic.

  • source
  • hideshow 2 child comments
  • [–] 1 point 2 days ago

    Bookmarked 🥰

  • source
  • 40 comments in c/linux@lemmy.ml view that post
    [–] 34 points 2 days ago* (3 children)

    sudo apt update && sudo apt upgrade -y
    should be
    sudo apt update && sudo apt full-upgrade -y

    also for

    echo "PASTE_YOUR_PUBLIC_KEY_HERE" | ssh your_username@your_server_ip "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

    why not just use ssh-copy-id ?

    edit: added more thoughts

  • source
  • hideshow 3 child comments
  • [–] [S] 13 points 2 days ago

    You're completely right on both counts, full-upgrade handles dependency shifts properly without leaving packages held back, and ssh-copy-id is much cleaner. Updated the guide to reflect both.

  • source
  • parent
  • [–] 3 points 2 days ago (1 child)

    I love ssh-copy-id, but end up doing it manually about half the time anyway. I've tried integrating it into build scripts and find what the op did more reliable.

    Could just be me though... it is Linux, and there a dozen ways to skin Linus. We all have our assholes and opinions.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 2 days ago

    I’ve tried integrating it into build scripts In a script I would also write out all the commands I want to run. After all, ssh-copy-id is a shell script itself. For instructions for someone to run interactively, I think ssh-copy-id makes the most sense.

  • source
  • parent
  • [–] 53 points 2 days ago (21 children)

    I really appreciate the effort but... how to say it?... it might be useful to make sure you understand a topic before trying to teach it to others :)

    Some notes:

    Create a Non-Root Administrative User

    Not as important as most people think (local privilege escalation is a thing, and it's also quite easy for your user to alias sudo to something that will capture your password the next time you type it).

    Basically: if an hostile actor gets a shell on your server, you are fucked anyway.

    sudo usermod -aG docker your_username

    This is the same as being root. Yep, the very same thing you went that whole length to avoid :)

    Automate Maintenance with a System Update Script

    Look into unattended upgrades. Also... it's not automation if you have to run a script manually :)

  • source
  • hideshow 21 child comments
  • [–] 14 points 2 days ago* (last edited 15 hours ago) (8 children)

    Not today, satan.

    Passwordless root allows you to require another factor of authentication on the off chance you didn’t set up key only ssh login like the top of the guide says. That second factor is the administrator account name. Now you can make this as generic as you want but assuming your non root admin account isn’t named “administrator” or “admin” then you just increased the security of your system.

    Suggesting that because privilege escalation exists there is no difference between a user and root is absurd on the face of it. Privesc requires vulnerable versions of vulnerable packages with the specific circumstances present that allow pre and post exploitation actions. In case you were operating under the assumption that most privesc goes from local administrator to root, usually you’re going from some relatively unprivileged user account that handles a service up to root and that’s harder than just invoking sudo.

    You would still want to roll over your credentials and restore from backups but “safe cracking tools exist so just leave the cash register deposits in plain view on a shelf behind the desk” isn’t a strong argument for password root.

    E: @talkingpumpkin@lemmy.world correctly pointed out that a nonstandard admin account name isn’t a second factor. It’s more like an additional secret.

  • source
  • parent
  • hideshow 8 child comments
  • [–] 3 points 1 day ago (1 child)

    A "secret" administrator account name is not a second authentication factor: it's just another "something you know", basically the same as using a slightly longer password.

    On top of that, account names are generally not treated with the same confidentiality passwords or private keys are treated with: while you can trust that software and collaborators will not leak a password or private key, you cannot make the same assumption about usernames.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 19 hours ago

    Yeah that was a bad choice of words on my part.

    Consider though that everything I handle with a public facing ip gets 69 million attempts to login as “root”, “admin”, “docker” and everything else under the sun but not even once has someone tried to login as my admin user. It’s acting as more than a slightly longer password.

  • source
  • parent
  • [–] 1 point 1 day ago (5 children)

    It's nice that your system has layers, but when the cutworms get on your onion they can still spoil the whole thing.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 1 point 19 hours ago (4 children)

    Sure, onions can go all the way bad. I’d rather put my special thing inside an onion than an apple.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 1 point 10 hours ago (3 children)

    Apples, Onions, Chocolate Mousse, I'd rather have any of them inside a bomb-proof safe.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 1 point 8 hours ago (2 children)

    I’m gonna go out on a limb here and liken the encrypted shell access that requires an additional secret just to have one’s password considered closer to the bombproof safe than to a food item.

    A metaphor is nice but actually completing it is what puts it above mere allusion.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 7 hours ago (1 child)

    I’m gonna go out on a limb here and liken the encrypted shell access that requires an additional secret to two secrets written on a sticky note instead of one...

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 7 hours ago

    Are you now making an argument against password ssh or against obscurity altogether?

    If it’s the former I’m on your side. Key ssh with passwords turned off defeated the recent asterisk mess if anyone was unfortunate enough to be relying on musl ssh.

  • source
  • parent
  • [–] 8 points 2 days ago* (2 children)

    Exactly, you shouldnt add your user to Docker and you should run your Docker containers as your user or another limited user rather than the default root.

    Be very selective with whether you expose your docker socket to any container. I just give Beszel Read Only. Gives me container perfs and flags updates.

    For the update script, you can just make it a cron job. Id add that to the guide. A daily update and weekly backup cron job is my setup.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 20 hours ago* (1 child)

    Use podman instead, it doesn't need root. And putting the docker socket in ro mode doesn't help at all, because ro is for files, while this here is a connection.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 12 points 2 days ago (5 children)

    Of course privilege escalation exists, but why roll out the red carpet on an attacker that managed to get shell access? Maybe in the time that they take to figure out that privilege escalation you have the time to detect the attack and defend against them

  • source
  • parent
  • hideshow 5 child comments
  • [–] 9 points 2 days ago (3 children)

    If someone put a script on your server that tried to do privilege escalation you should just assume it was successful and act accordingly. It doesn’t really change what should happen.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 3 points 2 days ago (2 children)

    replacing or reimaging it automatically when you see something like this feels like overkill.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 16 points 1 day ago (3 children)

    I'll have to find the post again (it was somewhere here on Lemmy) but UFW does not apply to docker containers.

    Docker bypasses UFW because it uses iptables and UFW doesn't support firewall zones.

    Any docker/podman ports not bound to localhost will be publicly accessible even if you have a block rule on UFW.

    There are some wacky script workarounds but the real solution is to install & use a proper firewall like firewalld (firewall-cmd command) and not the joke utilities of Canonical/Ubuntu (ufw, netplan, etc).

    At which point you might as well chuck Ubuntu into the trash since you'd be replacing a bunch if its defaults anyway, and just stick with Debian or another quality stable distro like OpenSUSE.

  • source
  • hideshow 3 child comments
  • [–] 2 points 22 hours ago

    Wouldn't docker do the same with firewalld?

    It acknowledges that it exists and just still uses it's own rules. You'd still have to configure it, configuration is just less stupid than ufw with docker.

    My question is, who thought this was acceptable behavior at docker?

  • source
  • parent
  • [–] 14 points 2 days ago*

    More Docker hardening*

    Consider rootless docker or Podman. If that is not for you:

    * Note that these tips are less "fire-and-forget, sane defaults" and can be much more finicky. Whether they work well depends on the service in question. They may break container deployments and are often a matter of trial and error until you get them just right. (Feel free to hit me up on details; if I happen to be running the same services as you are, I may be able to tell you what works and what doesn't.)

  • source
  • [–] 13 points 1 day ago

    sudo apt install sudo

    stares motherfuckerly

  • source
  • [–] 13 points 2 days ago*

    I recommend self hosting something like a NTFY server to send you texts if certain events happen, like someone logging in. You can also log those events on a different server.

  • source
  • [–] 6 points 1 day ago

    Turn off ipv4. Many bots do not scan ipv6.

  • source
  • [–] [S] 5 points 2 days ago (1 child)

    Editor's Note & Update

    Following some comments on this guide, a couple of key clarifications are worth adding:

    Docker Permissions & Rootless Containers: A few eagle-eyed readers rightly pointed out that adding your user to the  docker  group is functionally equivalent to giving yourself root-level access to the host machine (since container runtimes run with root privileges).

    I have updated to remove that shortcut. While container security can go much deeper (such as setting up rootless Docker or Podman), this guide focuses on keeping things simple as a solid quick-start baseline for security.

    System Updates, while fully automated background upgrades have their place, many admins including myself prefer a hands-on approach. Running a script manually and using  needrestart  gives you deliberate control over when services are recycled and ensures you aren't caught off guard by unexpected reboots.

    Thanks you all for reading and I always welcome any feedback on my work.

  • source
  • hideshow 1 child comment
  • [–] 3 points 1 day ago

    I'm going to take exception right here:

    "Install Essential Administrative Tools"

    The first thing you do to lock down a server is: Uninstall everything that is non-essential.

    Do you need any wireless access to the server? If not, remove all WiFi, Bluetooth, and other wireless support from the kernel (block the modules).

    Do you need anyone to be able to plug in a USB dongle that can bridge to ethernet? Or anything else?

    Remove support for everything you don't need first, un-necessary attack surface is the first foot-gun.

    Are these administrative tools all essential? Keep / install what you need, sudo apt purge the rest.

    Do you know WTF you're doing with Docker containers and firewalls / iptables? The thing to do is learn how that really works, before getting your application servers / containers up on the open internet.

    Do you know what un-necessary attack surfaces exist within your container images? That's another step toward a hardened system - know what you're running, know what that means, and

    above all else: run as little as possible.

  • source
  • parent
  • [–] 5 points 2 days ago*

    Good guide as a base. Few thought...

    I'd use unattended-upgrades instead of the script. A long know mehod and does similar, and the script doesn't reboot for a kernel CVE. I'd pair it alongside out-of-band console and an uptime check.

    Fail2ban needs rsyslog enabled (or proper logging) or it silently reads nothing.

    And lastly Journald needs retention set, or you can loose logs in reboots.

    Also I'm not sure if 'core' is enough anymore for a public operating and accessed server, but it's absolutely vital as a start.

  • source
  • [–] 2 points 19 hours ago

    Is router side firewall (yes my home server is just a laptop on WiFi😔) only exposing HTTP/HTTPS ports connected to Caddy enough?

  • source
  • [–] 3 points 2 days ago

    You missed the first step: port knocking.

    If there is no way to connect without having a cert or port sequence; then only the real threats show up in your logs.

  • source
  • [–] 1 point 1 day ago

    Setup a dummy SSH daemon, instant black hole for a random span of 2~6 weeks for any IP that attempts to login as root.

  • source