add garage admin api with token, expose via garage.hantim.net
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
RPC_SECRET=hantim-garage-rpc-secret
|
RPC_SECRET=hantim-garage-rpc-secret
|
||||||
ARGENTO_NODE_ID=hantim-garage-argento-node-id
|
ARGENTO_NODE_ID=hantim-garage-argento-node-id
|
||||||
|
ADMIN_TOKEN=hantim-garage-admin-token
|
||||||
|
|||||||
@@ -22,3 +22,4 @@ index = "index.html"
|
|||||||
|
|
||||||
[admin]
|
[admin]
|
||||||
api_bind_addr = "[::]:3903"
|
api_bind_addr = "[::]:3903"
|
||||||
|
admin_token = "${ADMIN_TOKEN}"
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,6 +105,8 @@ echo "==> Fetching secrets from Bitwarden Secrets Manager..."
|
|||||||
GITEA_TOKEN=$(bws_get "hantim-new-app-script")
|
GITEA_TOKEN=$(bws_get "hantim-new-app-script")
|
||||||
VULTR_API_KEY=$(bws_get "hantim-vultr-api-key")
|
VULTR_API_KEY=$(bws_get "hantim-vultr-api-key")
|
||||||
DEPLOY_KEY=$(bws_get "hantim-deploy-ssh-private-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)
|
DEPLOY_KEY_FILE=$(mktemp)
|
||||||
echo "$DEPLOY_KEY" > "$DEPLOY_KEY_FILE"
|
echo "$DEPLOY_KEY" > "$DEPLOY_KEY_FILE"
|
||||||
@@ -328,6 +330,38 @@ NGINX
|
|||||||
echo "==> Issuing SSL certificate via deploy user..."
|
echo "==> Issuing SSL certificate via deploy user..."
|
||||||
ssh -o StrictHostKeyChecking=accept-new -i "$DEPLOY_KEY_FILE" deploy@"$SERVER_IP" "cert-$APP"
|
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 ---
|
# --- Commit and push ---
|
||||||
|
|
||||||
echo "==> Committing and pushing hantim-server..."
|
echo "==> Committing and pushing hantim-server..."
|
||||||
|
|||||||
Reference in New Issue
Block a user