Skip to content

fix(auth): keep the JWT signing key in a dedicated volume - #149

Merged
BaaRai merged 1 commit into
mainfrom
fix/jwt-key-volume
Nov 4, 2026
Merged

BaaRai merged 1 commit into
mainfrom
fix/jwt-key-volume

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Summary

The JWT signing key was written next to the executable (/app in the image), which lives in the container's writable layer. Every container rebuild generated a new key and signed all users out.

This PR keeps the key out of data/ (the file manager root, see df50c28) and stores it in a dedicated volume.

  • ARTEX_JWT_KEY_DIR selects the key directory. Default is the base dir, so non-Docker installs are unchanged.
  • Docker: ./keys:/app/keys, ARTEX_JWT_KEY_DIR=/app/keys, VOLUME declared in the Dockerfile.
  • Existing key is migrated from data/jwt.key, then from the base dir. An existing key is never overwritten. A key shorter than 32 bytes is now a startup error.

Upgrade (Docker)

One-time logout. Before recreating the container, copy the current key out:

mkdir -p keys
docker cp artex-artex-1:/app/jwt.key ./keys/jwt.key

Without this step, a new key is generated and users must log in again.

Testing

  • go build ./..., go vet, gofmt on changed files: clean.
  • go test ./server -run TestLoadOrCreateJWTKey: migration from data dir and base dir, generation, no overwrite.
  • Not run: the Docker image build and a container smoke test.

Notes

The server wrote jwt.key to the executable's directory, /app in the
image, so it lived in the container's writable layer and every container
rebuild generated a new key and signed all users out.

- ARTEX_JWT_KEY_DIR selects the key directory (default: config.BaseDir(),
  unchanged for non-Docker installs). docker-compose.yml sets it to
  /app/keys and bind-mounts ./keys there; the Dockerfile declares the
  volume. The key stays out of data/, which the file manager browses.
- loadOrCreateJWTKey creates the directory (0700). When keyDir/jwt.key is
  missing it migrates dataDir/jwt.key, then BaseDir()/jwt.key (mode 0600,
  old file removed), otherwise generates a new key. An existing key is
  never overwritten; a short one is now a startup error.
- .gitignore and .dockerignore exclude keys/.
- README and CHANGELOG updated; the 0.5.0 known issue is removed.
@BaaRai
BaaRai merged commit 248d9d9 into main Nov 4, 2026
4 checks passed
@BaaRai BaaRai mentioned this pull request Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant