diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml new file mode 100644 index 0000000..4751d1b --- /dev/null +++ b/.github/workflows/scorecard.yml @@ -0,0 +1,32 @@ +# OpenSSF Scorecard: an outside, automated check of this repository's security practices +# (pinned Actions, token permissions, branch protection, scanning, signed releases...). +# The score is public at https://scorecard.dev and shown as a badge in the README. +name: Scorecard + +on: + push: + branches: [main] + schedule: + - cron: '23 4 * * 1' + workflow_dispatch: + +permissions: read-all + +jobs: + scorecard: + runs-on: ubuntu-latest + permissions: + security-events: write # to show the findings in the Security tab + id-token: write # to publish the results to scorecard.dev + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ossf/scorecard-action@fa7117db83c52d787ae5a89f350999701505d78e # v2.5.0 + with: + results_file: results.sarif + results_format: sarif + publish_results: true + - uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 + with: + sarif_file: results.sarif diff --git a/security.md b/security.md index ceb8dd1..a0d4a0e 100644 --- a/security.md +++ b/security.md @@ -39,6 +39,7 @@ and a published advisory after each fix ([policy](https://github.com/selfhostit/ | Content Security Policy (`script-src 'self'`), `nosniff`, `frame-ancestors 'none'` and a same-origin referrer, so injected scripts and outside resources don't load | `backend/app/headers.go` in each app | | Discreet reminders (Flowy, off by default): notifications only say "Reminder from Flowy", for a lock screen others can see | Flowy settings, `discreet_reminders` | | Nightly database backups, the last 7 kept, and a guide to restore one | [Updates and backups](updates-and-backups.md#backups) | +| `selfhostit check` shows, for each app on your machine, whether it is open to your network, runs as root, has a writable filesystem or the Docker socket, is out of date, or has no recent backup | [Updates and backups](updates-and-backups.md#check-your-install-selfhostit-check) | ## Can I put the apps on the internet? @@ -104,8 +105,11 @@ All of this is PocketBase's standard behavior, which the apps keep. jobs that publish images or releases get more. - Every third-party Action is pinned to a full commit hash, not a movable tag. - [Dependabot](https://docs.github.com/code-security/dependabot) keeps the Actions up to date - in every repository, and in the apps built on plasto also the Go, npm, Python and Docker - dependencies. + in every repository, and in every app also the Go, npm and Docker dependencies (and + Python, in the apps with workers). +- [OpenSSF Scorecard](https://scorecard.dev) checks each repository's security practices + every week and on every push to `main`; the score is public and shown as a badge in each + README. - Images are published to [ghcr.io/selfhostit](https://github.com/orgs/selfhostit/packages) for amd64, arm64 and armv7. A release (`v1.2.3`, with notes in each app's `CHANGELOG.md`) moves the major version tag (`:1`), which installs follow; changes on `main` only go to @@ -114,6 +118,10 @@ All of this is PocketBase's standard behavior, which the apps keep. workflow run, repository and commit built it. Check one with the [GitHub CLI](https://cli.github.com): `gh attestation verify oci://ghcr.io/selfhostit/flowy:1 --repo selfhostit/flowy`. +- Every published image also carries a software bill of materials (SBOM, SPDX): the list + of every package inside it, so you can check an image against a new vulnerability + yourself: + `docker buildx imagetools inspect ghcr.io/selfhostit/flowy:1 --format '{{ json .SBOM }}'`. ## What you are trusting @@ -126,8 +134,9 @@ Being honest about this matters more than sounding safe. either is harmless: someone who took over the maintainer's GitHub account could still publish a bad release. - **Docker and the host.** The containers are locked down, but Docker itself runs as root, - and anyone with access to the machine can read `pb_data`. The data on disk is not - encrypted, so encrypt backups that leave the machine and wipe the disk before you sell it. + and anyone with access to the machine can read `pb_data`. The apps don't encrypt their + data on disk, so encrypt the disk itself where you can (see [Your part](#your-part)), + encrypt backups that leave the machine, and wipe the disk before you sell it. - **Tailscale**, if you use it, to keep your private network private. Turn on two-factor sign-in for your Tailscale account and only share the machine with people you trust. Its container follows Tailscale's `stable` image. @@ -210,7 +219,6 @@ These are planned, in roughly this order: - A "sign out everywhere" button in every app (Flowy has it), for a lost phone. - Two-step sign-in, for anyone who puts an app on a public address. -- An OpenSSF Scorecard run on each repository. - An independent security review. If you do one, please share what you find through the reporting route above; findings and fixes will be published as advisories. @@ -218,7 +226,13 @@ These are planned, in roughly this order: - Keep the apps updated: `selfhostit update all` or the installer again ([Updates and backups](updates-and-backups.md)). +- Run `selfhostit check` now and then: it flags an app that is open to your network, out + of date, or without a recent backup ([how](updates-and-backups.md#check-your-install-selfhostit-check)). - Keep a backup somewhere else, encrypted. +- Encrypt the disk the apps are on, so a stolen machine or disk doesn't give away their + data: on Linux, choose disk encryption (LUKS) when you install it; on a Synology, keep the + apps on an encrypted volume or shared folder; on a Raspberry Pi, the SD card can't easily + be encrypted, so keep the Pi somewhere safe. - Don't forward ports to the apps; use Tailscale, or your own reverse proxy with HTTPS and the admin UI (`/_/`) blocked. - Restore a backup once, to know it works ([how](updates-and-backups.md#restore-a-backup)). diff --git a/selfhostit b/selfhostit index efaae37..b55a2d4 100755 --- a/selfhostit +++ b/selfhostit @@ -5,6 +5,7 @@ # selfhostit update splitwiz flowy several apps in one go # selfhostit update all every app folder that has a compose file # selfhostit list apps found and the image each one runs +# selfhostit check [app...] a security check of every app, or the ones named # # Each app is a folder holding a docker-compose.yml, in the same parent folder # the installer uses: /volume1/docker on a Synology, ~/selfhostit elsewhere. @@ -22,7 +23,7 @@ DOCKER=$(command -v docker 2>/dev/null || true) if [ "$(id -u)" -eq 0 ] || "$DOCKER" info >/dev/null 2>&1; then SUDO=; else SUDO=sudo; fi usage() { - sed -n '3,7s/^# \{0,1\}//p' "$0" + sed -n '3,8s/^# \{0,1\}//p' "$0" exit "${1:-0}" } @@ -87,6 +88,108 @@ update_one() { echo } +# --- selfhostit check --------------------------------------------------------- +# Read-only: it inspects the running containers and the backup folder, and asks +# ghcr.io which image a tag points at now. It changes nothing. + +warned=0 +ok() { echo " ok $*"; } +warn() { echo " WARN $*"; warned=1; } + +# The digest a ghcr.io tag points at now, or nothing if it can't be found out. +remote_digest() { + command -v curl >/dev/null || return 0 + repo=${1#ghcr.io/}; tag=${repo##*:}; repo=${repo%:*} + [ "$tag" != "$repo" ] || tag=latest + token=$(curl -fsS "https://ghcr.io/token?scope=repository:$repo:pull" 2>/dev/null | + sed -n 's/.*"token":"\([^"]*\)".*/\1/p') || return 0 + [ -n "$token" ] || return 0 + curl -fsSI -H "Authorization: Bearer $token" \ + -H 'Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json' \ + "https://ghcr.io/v2/$repo/manifests/$tag" 2>/dev/null | + tr -d '\r' | awk -F': ' 'tolower($1) == "docker-content-digest" {print $2}' +} + +check_container() { + id=$1 + f='{{.Name}}|{{.Config.Image}}|{{.Image}}|{{.HostConfig.Privileged}}|{{.HostConfig.ReadonlyRootfs}}|{{.HostConfig.NetworkMode}}|{{.HostConfig.CapDrop}}|{{.HostConfig.SecurityOpt}}' + IFS='|' read -r name image image_id privileged readonly netmode capdrop secopt </dev/null | awk 'NR > 1 {print $2}' | sort -u | tr '\n' ' ') + uids=${uids% } + case " $uids " in + *" 0 "*) if [ -n "$tailscale" ]; then ok "runs as root (Tailscale needs it)" + else warn "a process runs as root inside the container"; fi ;; + " ") echo " ? couldn't see which user it runs as" ;; + *) ok "runs as a normal user (uid $uids)" ;; + esac + if [ "$privileged" = true ]; then warn "privileged container: it has full access to this machine"; fi + if [ -z "$tailscale" ]; then + case $capdrop in *ALL*|*all*) ok "drops all Linux capabilities (cap_drop: [ALL])" ;; *) warn "keeps Docker's default Linux capabilities (no cap_drop: [ALL])" ;; esac + case $secopt in *no-new-privileges*) ok "can't gain new privileges" ;; *) warn "can gain new privileges (no no-new-privileges)" ;; esac + if [ "$readonly" = true ]; then ok "read-only filesystem"; else warn "writable filesystem (no read_only: true)"; fi + fi + if $SUDO "$DOCKER" inspect -f '{{range .Mounts}}{{.Source}} {{end}}' "$id" | grep -q 'docker\.sock'; then + warn "has the Docker socket: it can control every container on this machine" + fi + + # Up to date? + case $image in + ghcr.io/*) + want=$(remote_digest "$image") + have=$($SUDO "$DOCKER" image inspect -f '{{range .RepoDigests}}{{.}} {{end}}' "$image_id" 2>/dev/null) + if [ -z "$want" ]; then echo " ? couldn't ask ghcr.io for the newest $image" + else + case " $have" in + *"@$want "*) ok "runs the newest $image" ;; + *) warn "a newer $image is out: selfhostit update ${app}" ;; + esac + fi ;; + esac +} + +check_one() { + app=$1 + dir=$ROOT/$app + compose_file "$dir" >/dev/null || { echo "selfhostit: no compose file in $dir" >&2; return 1; } + cd "$dir" || return 1 + echo "== $app" + ids=$(dc ps -q 2>/dev/null) + if [ -z "$ids" ]; then warn "not running"; echo; return 0; fi + for id in $ids; do check_container "$id"; done + + # Backups: PocketBase makes one every night into pb_data/backups + if [ -d pb_data ]; then + newest=$($SUDO find pb_data/backups -name '*.zip' -mtime -2 2>/dev/null | sort | tail -n 1) + if [ -n "$newest" ]; then ok "a backup from the last 2 days: ${newest#pb_data/backups/}" + else warn "no backup in pb_data/backups from the last 2 days (https://github.com/selfhostit/docs/blob/main/updates-and-backups.md#backups)"; fi + [ -z "$newest" ] || echo " note that backup is on this disk; keep an encrypted copy somewhere else too" + fi + echo +} + cmd=${1:-} [ $# -gt 0 ] && shift case $cmd in @@ -110,6 +213,16 @@ case $cmd in printf '%-16s %s\n' "$app" "$imgs" done ;; + check) + # shellcheck disable=SC2046 # app folder names have no spaces + [ $# -gt 0 ] || set -- $(apps) + [ -z "$SUDO" ] || sudo true + for app in "$@"; do + ( check_one "$app" && exit "$warned" ) || warned=1 + done + if [ "$warned" = 1 ]; then echo "Some checks need a look: see WARN above."; exit 1; fi + echo "All checks passed." + ;; ''|-h|--help|help) usage ;; *) echo "selfhostit: unknown command '$cmd'" >&2; usage 2 >&2 ;; esac diff --git a/updates-and-backups.md b/updates-and-backups.md index b5dd313..e756d4d 100644 --- a/updates-and-backups.md +++ b/updates-and-backups.md @@ -49,6 +49,20 @@ Synology, `~/selfhostit` elsewhere), and works for any folder there with a `~/.profile`. It uses `sudo` when your user can't reach Docker directly, and asks for the password once. Run the `curl` line again to get a newer version of the command. +### Check your install: `selfhostit check` + +```sh +selfhostit check # every app +selfhostit check flowy # one app +``` + +For each running container it says whether it is reachable only from this machine or open +to your network, runs as a normal user or as root, drops Linux capabilities, can gain new +privileges, has a read-only filesystem, has the Docker socket, and runs the newest image of +its tag (it asks ghcr.io, without pulling anything). For each app it also says whether there +is a nightly backup from the last two days. It changes nothing. Anything to look at is +marked `WARN`, and then it exits with status 1, so you can run it from a scheduled task. + On a Synology without SSH: Container Manager > Image, select the app's image and choose **Update**, then Project > the app > Action > **Build**. @@ -74,8 +88,10 @@ Tailscale key, which lets whoever has it join your tailnet as that machine. age -d selfhostit-2026-11-05.tar.gz.age | tar xzf - # to restore it ``` -Selling or throwing away the machine or its SD card? Delete the apps' folders and wipe the -disk first; the data on it is not encrypted. +The apps don't encrypt their data on disk, so encrypt the disk itself where you can: choose +disk encryption (LUKS) when you install Linux, or keep the apps on an encrypted volume or +shared folder on a Synology. Selling or throwing away the machine or its SD card? Delete the +apps' folders and wipe the disk first. ## Restore a backup