No description
  • Shell 90.7%
  • Dockerfile 5.4%
  • Go 3.4%
  • Makefile 0.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Arnaud Véron a2fec3f4a5
All checks were successful
/ version (push) Successful in 21s
/ build (push) Successful in 57s
Bump plakar to 1.1.8, cap rclone concurrency in staged pulls
plakar 1.1.8 is a security rebuild with Go 1.26.10 (crypto/x509 fix),
with no functional change from 1.1.7.

The staged copy ran rclone with --transfers 8 --checkers 16. Over sftp,
rclone opens one ssh connection per concurrent operation, up to ~64
per Kloset, and the overlapping handshakes exceeded the default sshd
MaxStartups (10): the puller endpoint dropped ~50 connections per
night, hidden by rclone retries. 4 transfers and 4 checkers keep at
most 8 connections open. A local bench (panubo sshd, 200 ms latency)
went from 6 drops to none, at the cost of a slower copy.
2026-11-25 09:20:00 +01:00
.forgejo/workflows Build the image with kaniko 2026-09-29 23:16:12 +02:00
bin Bump plakar to 1.1.8, cap rclone concurrency in staged pulls 2026-11-25 09:20:00 +01:00
patches Patch the sftp plugin so that the repository lock can be refreshed 2026-10-01 08:08:47 +02:00
test Restore with -quiet 2026-10-03 14:38:05 +02:00
.dockerignore Initial import: plakar-osvc image with Forgejo Actions build 2026-09-29 23:03:55 +02:00
Dockerfile Bump plakar to 1.1.8, cap rclone concurrency in staged pulls 2026-11-25 09:20:00 +01:00
Makefile Bump plakar to 1.1.8, cap rclone concurrency in staged pulls 2026-11-25 09:20:00 +01:00
README.md Bump plakar to 1.1.8, cap rclone concurrency in staged pulls 2026-11-25 09:20:00 +01:00

plakar-osvc

Plakar for OpenSVC services, in one image with two roles:

  • backup: a sidecar run by an OpenSVC task, backing up a mounted tree to a remote sftp Kloset, created on first use.
  • pull: a third-site puller mirroring remote Klosets into isolated local Klosets that the backed-up services cannot reach.

Configuration

No config file. The container reads /etc/plakar ($PLAKAR_CONF), typically OpenSVC sec keys projected into a shm volume. The role follows from its content:

identity                    ssh private key                          both roles
host_key                    "<host> <type> <key>" of the sftp server both roles

url                         sftp://<user>@<host>/<path>              backup role
passphrase                  Kloset passphrase                        backup role

sources/<name>/url          remote Kloset url                        pull role
sources/<name>/passphrase   remote Kloset passphrase                 pull role

discover/url                sftp://<user>@<host>[:port] endpoint     pull role
discover/passphrases/<account>/<kloset>   Kloset passphrase          pull role

For a non-standard ssh port, the host in host_key is [host]:port.

Backup role: accounts and Kloset names

The Kloset url is url, with /$PLAKAR_KLOSET appended when that variable is set. Since a shm volume can project keys from different secs to fixed paths, the service configuration decides where credentials come from:

  • a dedicated account: a sec per service holding a full url;
  • a namespace account: a common sec holding identity, host_key and a base url, each task naming its Kloset with PLAKAR_KLOSET, so that one account holds several Klosets; passphrase may come from the common sec or from a per-service one.

A missing Kloset is created with passphrase. Creation is only attempted when the Kloset cannot be opened, and plakar refuses to create over a non-empty directory, so an existing Kloset is never replaced (wrong passphrase, network error).

Pull role

Each sources/<name> is one remote Kloset, pulled with plakar sync from into $KLOSET_ROOT/<name> (default /kloset), created on first pull with the source passphrase: each owner can restore from the mirror with their own passphrase, and only with it. Several Klosets of one account are several sources. The puller key is added to each account's authorized keys on the sftp server, restricted to the puller host:

from="<puller host IP>" ssh-ed25519 AAAA... plakar-puller

Discovery of every Kloset of every account

With discover/url, each run lists /<account>/backups/<kloset>/CONFIG on that endpoint (the sftp.opensvc.com layout) in one sftp session, and pulls every Kloset found into $KLOSET_ROOT/<account>/<kloset>, with the passphrase discover/passphrases/<account>/<kloset>. A Kloset found without a passphrase is reported and fails the run, the others are still pulled: a new account or Kloset cannot go unnoticed. Its source name is <account>/<kloset>, its plakar store <account>__<kloset> (plakar store names allow letters, digits, - and _ only). sources/ and discover/ can be used together.

The endpoint is a read-only view of every account: a second sshd, in the netns of the users' one, on another port, the data mounted read-only, one account whose session runs as root (it reads the files of every account) with ChrootDirectory /data, ForceCommand internal-sftp -R, PermitRootLogin prohibit-password, AllowUsers puller, and its key restricted with from=. test/e2e.sh builds one. host_key then names the port: [host]:2222 <type> <key>.

sync from only reads the source, so the puller key is best given a read-only account: with the sftp server forcing internal-sftp, an authorized_keys command= cannot make one key read-only, but an alias account sharing the owner uid can, with ForceCommand internal-sftp -R and the owner chroot in its Match User block. ACLs do not work: plakar creates some directories 0700.

Commands

backup role:
  backup [OPTIONS] [PATH...]  plakar backup OPTIONS PATH (default /data), creating the Kloset if missing
  check                       plakar check the Kloset
  list                        list snapshots
  prune [-apply] [-no-maintenance] FILTERS...
                              plakar prune keeping the snapshots matched by FILTERS, dry run
                              unless -apply, then plakar maintenance unless -no-maintenance
  maintenance                 plakar maintenance
  restore SNAPSHOT[:PATH] DIR plakar restore into DIR, SNAPSHOT may be latest
  plakar ARGS...              plakar with the Kloset declared as @kloset

pull role:
  pull [NAME...]              create missing local Klosets and sync them from their source
  check [NAME...]             plakar check the local Klosets
  list                        declared sources and local Kloset state
  prune [-apply] [-no-maintenance] FILTERS...
                              plakar prune every local Kloset, same filters and dry run as
                              the backup role, then plakar maintenance unless -no-maintenance
  maintenance [NAME...]       plakar maintenance of the local Klosets
  plakar ARGS...              plakar with @NAME the local Kloset, @src-NAME its source

prune filters (see plakar-query(7)) select the snapshots to keep, e.g. -days 14 -per-day 1 -weeks 8 -per-week 1 -months 12 -per-month 1 keeps one snapshot per day over 14 days, per week over 8 weeks and per month over 12 months. Without filters plakar refuses to prune. maintenance frees the space of deleted snapshots after a 7 days grace delay; it reads the whole Kloset, so a daily prune -apply -no-maintenance with a weekly maintenance avoids that cost every night.

In the pull role, sync from copies every source snapshot missing locally: keep the mirror retention at least as long as the source one, or pruned mirror snapshots are pulled again. A longer one makes the mirror a longer history.

sync from re-imports every file of a snapshot through the source store: over sftp, one range read after another, so that its duration grows with the number of files rather than with the new data (1 h 36 min every night for a Kloset of 125k files, 50 s for the same sync between local Klosets). PULL_MODE=staged splits the pull: rclone first copies the encrypted Kloset files into $STAGING_ROOT/<source> (default /staging, a persistent volume), in parallel and only the files that are new (Kloset files never change once written: sizes are compared), then sync from reads that local copy. The packfiles are copied before and after the states, so that a backup committing during the copy never leaves a state without its packfiles. The mirror keeps its own retention: a deletion on the backup server only reaches the staging copy. The staging copy holds encrypted data only and can be deleted at any time.

restore SNAPSHOT restores the snapshot tree relative to its root, the common parent of the backed-up paths: backup /data/app restores app content directly into DIR, backup /backup/x /secrets restores backup/x/... and secrets/.... SNAPSHOT:PATH restores the content of PATH into DIR.

Logs: every long operation (open, backup, sync, check, prune, maintenance, restore) logs its duration (backup: took 13m15s), and every PLAKAR_PROGRESS seconds (default 60, 0 for none) a progress line: elapsed time, bytes read and written by the plakar processes (files, cache and pipes to the plugins) and network traffic of the container, as totals and as rates over the last interval:

2026-10-01T12:33:19Z backup: 5m00s read 6.1 GiB (21.0 MiB/s), written 120.3 MiB (0.4 MiB/s), net in 1.2 MiB (4.0 KiB/s), net out 98.5 MiB (0.3 MiB/s)

A step that reads at disk speed waits on the source, one whose network rate is high on the network, one where both are low on plakar itself (CPU, latency of the sftp round trips). backup, sync and restore run with -quiet: one line per file floods the logs, errors and the summary are still reported.

Exit status: 0 success, 1 failure (pull: some source failed, the others were still pulled), 2 configuration error. In the pull role, a per-source lock (/kloset/.<name>.lock) prevents overlapping pulls.

Users and volumes

The image user is plakar (uid/gid 10001, --build-arg PUID=).

  • backup: to read files of any owner, run as root with only the read capability, over read-only mounts: --user 0 --cap-drop ALL --cap-add DAC_READ_SEARCH. The plakar cache then falls back to $HOME/.cache/plakar unless PLAKAR_CACHE points to a writable directory; a persistent cache speeds up incremental backups.
  • restore: to restore owners and modes, run as root with only the file capabilities, over a writable mount: --user 0 --cap-drop ALL --cap-add CHOWN --cap-add FOWNER --cap-add DAC_OVERRIDE.
  • pull: run as plakar, with /etc/plakar readable, /kloset and /var/cache/plakar writable by uid 10001. Keep the cache persistent: it holds the Klosets state, rebuilt from the remote on every run otherwise.

ssh requires identity to be mode 0600, owned by the running user.

OpenSVC examples (to validate)

Backup sidecar in the service owning the data, after an application dump:

[volume#plakar]
type = shm
name = {name}-plakar
secrets = plakar/identity:/identity plakar/host_key:/host_key plakar/url:/url {name}/plakar_passphrase:/passphrase
perm = 600
size = 1m

[task#backup]
type = docker
image = <registry>/plakar-osvc:1.1.8
rm = true
user = 0
run_args = --cap-drop ALL --cap-add DAC_READ_SEARCH
environment = PLAKAR_KLOSET={name}
volume_mounts = data/backup:/data/backup:ro data/app:/data/app:ro {name}-plakar:/etc/plakar:ro
command = backup -tag {namespace}/{name} /data
schedule = 02:30

Puller on the third site:

[volume#conf]
type = shm
name = {name}-conf
secrets = {name}/identity:/identity {name}/host_key:/host_key {name}/sources/*:/sources/
user = 10001
perm = 600
size = 1m

[task#pull]
type = docker
image = <registry>/plakar-osvc:1.1.8
command = pull
volume_mounts = {name}-conf:/etc/plakar:ro {name}-kloset:/kloset {name}-cache:/var/cache/plakar
schedule = @60

Build and test

make build            # plakar-osvc:<plakar version>
make test             # end-to-end and lock refresh tests, need docker

The image is built from the upstream plakar release tarball, checked against the release checksums: upstream does not publish a public container image. The sftp plugin is built from its source tag (SFTP_VERSION, default v1.1.6, of PlakarKorp/integrations) with patches/ applied, and installed with -allow-unsigned, since plakar pkg add of prebuilt plugins requires a plakar.io login. The plugin needs Go >= 1.26 to build and runs ssh(1), hence openssh-client.

patches/sftp-posix-rename.patch: kloset refreshes its repository lock every 5 minutes by writing it again, and cancels an operation that could not refresh it for 10 minutes. Upstream, the sftp plugin writes files with an SFTP v3 RENAME of a temporary file, which fails on an existing target: the refresh always failed, and any backup, restore or maintenance running longer than 10 minutes was cancelled ("lock refresher: failed to refresh the repository lock"). The patch uses posix-rename@openssh.com, which replaces the target. test/lock-refresh.sh puts the same lock twice against panubo/sshd with the upstream plugin (the second put fails) and with the patch (it succeeds).

plakar extracts each plugin package once into the cache dir and reuses the extracted copy while the plugin name and version stay the same, so that a persistent cache would keep running the plugin of a previous image (the patched plugin keeps its upstream version). plakar-osvc records the checksum of each package in <cache>/plugin-sums/ and drops an extracted copy that does not come from the package of the running image.

test/e2e.sh runs a quay.io/panubo/sshd server and checks:

  • backup: Kloset creation, one account holding two Klosets, a dedicated account, reuse on the next run, reading root/uid 1000/uid 70 private files as root with only DAC_READ_SEARCH, a wrong passphrase never replacing a Kloset, configuration errors, check, restore of a path of the latest snapshot and of a full older snapshot keeping owners and modes, prune dry run and -apply keeping the latest snapshot;
  • pull: every Kloset of every account, no-op second pull, incremental pull, check, mirror content equal to the source, isolation between owners, unknown source, a failing source not stopping the others, prune of every mirror keeping the latest snapshot without pulling pruned ones again;
  • discover: a read-only puller endpoint, every Kloset of every account found, one without passphrase failing without stopping the others, no-op second pull, check, prune, content of another uid's 0600 file, no write possible through the endpoint.