Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 19 additions & 5 deletions security.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -210,15 +219,20 @@ 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.

## Your part

- 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)).
Expand Down
115 changes: 114 additions & 1 deletion selfhostit
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}"
}

Expand Down Expand Up @@ -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 <<EOF
$($SUDO "$DOCKER" inspect -f "$f" "$id")
EOF
name=${name#/}
echo " $name ($image)"
case $image in *tailscale*) tailscale=1 ;; *) tailscale= ;; esac

# Reachable from where?
# shellcheck disable=SC2016 # a Go template, not shell
ports=$($SUDO "$DOCKER" inspect -f '{{range $p, $b := .HostConfig.PortBindings}}{{range $b}}{{.HostIp}}:{{.HostPort}} {{end}}{{end}}' "$id")
ports=${ports% }
open=
for b in $ports; do
case $b in 127.*|\[::1\]:*|::1:*) ;; *) open="$open ${b#:}" ;; esac
done
if [ "$netmode" = host ]; then
if [ -n "$tailscale" ]; then ok "host network (Tailscale needs it to reach the apps)"
else warn "uses the host network: reachable on every address of this machine"; fi
elif [ -n "$open" ]; then
warn "port open to your network, not only this machine:$open (see https://github.com/selfhostit/docs/blob/main/security.md)"
elif [ -n "$ports" ]; then ok "only reachable from this machine: $ports"
else ok "no ports published"; fi

# Who it runs as, and what it may do
uids=$($SUDO "$DOCKER" top "$id" -o pid,uid 2>/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
Expand All @@ -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
20 changes: 18 additions & 2 deletions updates-and-backups.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.

Expand All @@ -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

Expand Down
Loading