Documents in a bucket of Garage, still encrypted by the app
CI / secret scan (push) Successful in 4s
CI / fmt, clippy, tests (push) Successful in 52s

Asked for on November 19, 2026: the uploaded files land in an S3 bucket of
the fleet's Garage instead of a directory on cnx01, as the fleet's other
apps keep theirs. The app encrypts each file exactly as before (AES-256-GCM
under a key from HKDF, the document's id authenticated), so the bucket holds
the same VISADOC1 files and Garage never sees a key or a document in the
clear. Garage's SSE-C stays off: its key would come from the same secret.

src/s3.rs is a small S3 client on reqwest and ring, as in proplan: SigV4
(checked against AWS's two published examples), path-style PUT, GET, HEAD,
DELETE and ListObjectsV2 page by page, three attempts when the server is
away or busy. It asks before it writes, so no object is replaced; it sends
If-None-Match: * as well, which Garage 2.5 ignores (seen in tests/garage.rs).

The store (src/files.rs) keeps the files as documents/<id>.vdoc in the
bucket, or as <id>.vdoc in a directory for development and the tests. Its
calls are async now. VISA_S3_BUCKET, _ENDPOINT, _REGION and _ACCESS_KEY_ID
name the bucket, the secret comes from VISA_S3_SECRET_ACCESS_KEY_FILE or the
credential s3-secret; the bucket and a directory together are refused. At
the start the app checks the bucket in the background and only warns.

New commands: `visa files-migrate --from DIR` copies the files of a
directory into the store, each opened and compared with its upload before
and after, and may run again; `visa files-mirror --to DIR` makes a
directory hold exactly the bucket's files, still encrypted, for the
backups, and a restore is files-migrate from it.

Tests: an S3 server inside the test process that checks every request's
signature and pages its listings (tests/common/fake_s3.rs); uploads, views,
downloads and deletions through it, the check finding swapped, missing and
stray objects, the move from a directory (again, missing, other bytes,
damaged), the mirror and a restore from it, a busy server and a wrong key.
tests/garage.rs runs the store against Garage 2.5.0, the version cnx01 runs,
which scripts/dev-garage.sh starts in Docker; VISA_DEV_S3=1 scripts/dev.sh
runs the dev server on it. The 14 demo documents moved into it with
files-migrate and a browser upload landed there.
This commit is contained in:
grabowski committed 2026-11-19 20:35:32 +07:00
1 parent 17426dba12
commit 0370e0154f
20 files changed
+2558 -218

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
# A Garage in Docker for local development and tests/garage.rs, the version
# cnx01 runs (dxflrs/garage:v2.5.0), on 127.0.0.1:3920: bucket visa-documents
# with the key visa-dev. It writes .dev/garage.env (git ignores .dev/) with
# the VISA_TEST_S3_* settings; the key's secret goes to .dev/s3-secret and
# never to the terminal. Run it again at any time: it starts what is stopped
# and keeps what exists.
#
# bash scripts/dev-garage.sh
# . .dev/garage.env && cargo test garage # the store against Garage
# VISA_DEV_S3=1 bash scripts/dev.sh # the dev server on the bucket
set -euo pipefail
cd "$(dirname "$0")/.."
NAME=visa-garage
PORT=${VISA_GARAGE_PORT:-3920}
BUCKET=visa-documents
mkdir -p .dev/garage
if ! docker inspect "$NAME" >/dev/null 2>&1; then
rpc=$(od -An -N32 -tx1 /dev/urandom | tr -d ' \n')
cat >.dev/garage/garage.toml <<EOF
metadata_dir = "/var/lib/garage/meta"
data_dir = "/var/lib/garage/data"
db_engine = "sqlite"
replication_factor = 1
rpc_bind_addr = "[::]:3901"
rpc_public_addr = "127.0.0.1:3901"
rpc_secret = "$rpc"
[s3_api]
s3_region = "garage"
api_bind_addr = "[::]:3900"
EOF
# Docker Desktop wants a Windows path from Git Bash
conf="$(cd .dev/garage && (pwd -W 2>/dev/null || pwd))/garage.toml"
docker run -d --name "$NAME" -p "127.0.0.1:$PORT:3900" \
-v "$conf:/etc/garage.toml" dxflrs/garage:v2.5.0 >/dev/null
else
docker start "$NAME" >/dev/null
fi
g() { docker exec -e RUST_LOG=warn "$NAME" /garage "$@"; }
for _ in $(seq 30); do
g status >/dev/null 2>&1 && break
sleep 1
done
if ! g layout show 2>/dev/null | grep -q 'dc1'; then
node=$(g status 2>/dev/null | awk '/^[0-9a-f]{16}/ {print $1; exit}')
g layout assign -z dc1 -c 1G "$node" >/dev/null
g layout apply --version 1 >/dev/null
fi
g bucket info "$BUCKET" >/dev/null 2>&1 || g bucket create "$BUCKET" >/dev/null
id=$(cat .dev/s3-key-id 2>/dev/null || true)
if [ -z "$id" ] || [ ! -s .dev/s3-secret ] || ! g key info "$id" >/dev/null 2>&1; then
out=$(g key create visa-dev)
awk -F': *' 'tolower($1) ~ /key id/ {print $2; exit}' <<<"$out" | tr -d '\r\n ' >.dev/s3-key-id
(umask 077 && awk -F': *' 'tolower($1) ~ /secret key/ {print $2; exit}' <<<"$out" |
tr -d '\r\n ' >.dev/s3-secret)
id=$(cat .dev/s3-key-id)
fi
g bucket allow --read --write --owner "$BUCKET" --key "$id" >/dev/null
cat >.dev/garage.env <<EOF
export VISA_TEST_S3_ENDPOINT=http://127.0.0.1:$PORT
export VISA_TEST_S3_BUCKET=$BUCKET
export VISA_TEST_S3_ACCESS_KEY_ID=$id
export VISA_TEST_S3_SECRET_FILE=.dev/s3-secret
EOF
echo "Garage on http://127.0.0.1:$PORT, bucket $BUCKET, key ${id:0:8}... (secret in .dev/s3-secret, $(wc -c <.dev/s3-secret) characters)"
echo "settings: . .dev/garage.env"