Noust is a free (AGPL) Python 3.10+ CLI and FastAPI service that deploys web apps onto Linux servers. It runs as root, so a few classes of bugs are expensive. The project ended up with four rules, each enforced by a test, and each one exists because its absence shipped a real bug:

  1. Nothing runs a process except one module. Only core/runner.py may import subprocess. Argv only, never a shell, timeouts mandatory, secrets through env= or input= (never argv, which every local user can read in ps). The test suite’s conftest makes any real process call fail, so code that bypasses the runner can’t even be tested. --dry-run lives there too, which is why it can’t be honoured in one path and ignored in another.
  2. except Exception only at an error boundary, and it must log. There used to be 302 of them, 149 silent; that’s how calls to methods that didn’t exist shipped for whole releases. mypy blocks CI.
  3. One implementation of each thing. The web API is a client of the same managers the CLI uses, never a second implementation.
  4. Guards at the chokepoint. Unit ownership is checked in the service manager, read-only SQL is enforced by the database server, escaping by the template engine.

The contributing guide explains each one with the bug behind it: https://github.com/Perkybeet/noust/blob/main/CONTRIBUTING.md

Interested in how others structure similar tools.

  • chakli@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    3 days ago

    Secrets shouldn’t go through env either, it would be visible to other root processes

    It also shouldn’t run as root imo, only elevate when required

    • Perkybeet@lemmus.orgOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      3 days ago

      Fair on both counts, with one distinction.

      On secrets: argv is readable by every local user (/proc/<pid>/cmdline is world-readable), while the environment is readable only by the same UID and by root. So the rule is about not leaking to unprivileged users on the box; against root nothing holds, since root can read the process’s memory anyway. You’re right that env has its own cost (children inherit it), so where a client takes a secret from a 0600 file or on stdin, that’s what is used, and env is for the clients that only offer that, like PGPASSWORD for pg_dump.

      On root: the service does run as root, because its job is writing nginx sites, systemd units and certificates and installing packages. What never runs as root is anything that comes from a repository: installs, builds and deploy hooks run as an unprivileged account inside a sandboxed transient systemd unit, and each app runs as its own system user. An unprivileged front with a small privileged helper would be tighter; that isn’t how it works today.