From a421ecc83725f29f4481a3b934c5ed53d59f007f Mon Sep 17 00:00:00 2001 From: Timothy Kim Date: Thu, 19 Mar 2026 17:19:03 -0400 Subject: [PATCH] add garage admin api with token, expose via garage.hantim.net --- docker/garage/.env.keys | 1 + docker/garage/garage.toml | 1 + docker/nginx/conf.d/garage.hantim.net.conf | 30 +++++++++++++++++++ tools/new-app.sh | 34 ++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 docker/nginx/conf.d/garage.hantim.net.conf diff --git a/docker/garage/.env.keys b/docker/garage/.env.keys index 0a4d652..36e9b0c 100644 --- a/docker/garage/.env.keys +++ b/docker/garage/.env.keys @@ -1,2 +1,3 @@ RPC_SECRET=hantim-garage-rpc-secret ARGENTO_NODE_ID=hantim-garage-argento-node-id +ADMIN_TOKEN=hantim-garage-admin-token diff --git a/docker/garage/garage.toml b/docker/garage/garage.toml index 658987d..5af9f87 100644 --- a/docker/garage/garage.toml +++ b/docker/garage/garage.toml @@ -22,3 +22,4 @@ index = "index.html" [admin] api_bind_addr = "[::]:3903" +admin_token = "${ADMIN_TOKEN}" diff --git a/docker/nginx/conf.d/garage.hantim.net.conf b/docker/nginx/conf.d/garage.hantim.net.conf new file mode 100644 index 0000000..e1f8e69 --- /dev/null +++ b/docker/nginx/conf.d/garage.hantim.net.conf @@ -0,0 +1,30 @@ +# Garage admin API +server { + listen 80; + listen [::]:80; + server_name garage.hantim.net; + + location /.well-known/acme-challenge/ { + root /var/www/certbot; + } + + location / { + return 301 https://garage.hantim.net$request_uri; + } +} + +server { + listen 443 ssl; + listen [::]:443 ssl; + http2 on; + server_name garage.hantim.net; + + ssl_certificate /etc/letsencrypt/live/garage.hantim.net/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/garage.hantim.net/privkey.pem; + + add_header Strict-Transport-Security "max-age=63072000; preload" always; + + location / { + proxy_pass http://garage:3903; + } +} diff --git a/tools/new-app.sh b/tools/new-app.sh index 5c47fe3..e74258c 100755 --- a/tools/new-app.sh +++ b/tools/new-app.sh @@ -105,6 +105,8 @@ echo "==> Fetching secrets from Bitwarden Secrets Manager..." GITEA_TOKEN=$(bws_get "hantim-new-app-script") VULTR_API_KEY=$(bws_get "hantim-vultr-api-key") DEPLOY_KEY=$(bws_get "hantim-deploy-ssh-private-key") +GARAGE_ADMIN_TOKEN=$(bws_get "hantim-garage-admin-token") +GARAGE_MEDIA_KEY_ID=$(bws_get "hantim-garage-media-key-id") DEPLOY_KEY_FILE=$(mktemp) echo "$DEPLOY_KEY" > "$DEPLOY_KEY_FILE" @@ -328,6 +330,38 @@ NGINX echo "==> Issuing SSL certificate via deploy user..." ssh -o StrictHostKeyChecking=accept-new -i "$DEPLOY_KEY_FILE" deploy@"$SERVER_IP" "cert-$APP" +# --- Create Garage media bucket --- + +GARAGE_API="https://garage.hantim.net" +GARAGE_AUTH="Authorization: Bearer $GARAGE_ADMIN_TOKEN" + +echo "==> Creating Garage media bucket for $APP..." +BUCKET_RESP=$(curl -s -X POST "$GARAGE_API/v2/CreateBucket" \ + -H "$GARAGE_AUTH" \ + -H "Content-Type: application/json" \ + -d "{\"globalAlias\": \"$APP\"}") + +BUCKET_ID=$(echo "$BUCKET_RESP" | jq -r '.id') +if [ -z "$BUCKET_ID" ] || [ "$BUCKET_ID" = "null" ]; then + echo "Error: Failed to create bucket" + echo "$BUCKET_RESP" + exit 1 +fi + +echo " Allowing media-key access..." +curl -sf -X POST "$GARAGE_API/v2/AllowBucketKey" \ + -H "$GARAGE_AUTH" \ + -H "Content-Type: application/json" \ + -d "{\"bucketId\": \"$BUCKET_ID\", \"accessKeyId\": \"$GARAGE_MEDIA_KEY_ID\", \"permissions\": {\"read\": true, \"write\": true, \"owner\": false}}" > /dev/null + +echo " Enabling website access..." +curl -sf -X POST "$GARAGE_API/v2/UpdateBucket?id=$BUCKET_ID" \ + -H "$GARAGE_AUTH" \ + -H "Content-Type: application/json" \ + -d '{"websiteAccess": {"enabled": true, "indexDocument": "index.html"}}' > /dev/null + +echo " Bucket '$APP' ready" + # --- Commit and push --- echo "==> Committing and pushing hantim-server..."