Skip to content

Deploying a Garage 3-node S3 cluster on Ubuntu 22.04 (production-ready)

Stand up a hardened Garage S3-compatible storage cluster on Ubuntu 22.04 — 3-node layout with zones, Let's Encrypt TLS on S3 + K2V, systemd hardening.

You’ve been asked to provide an S3-compatible store that survives a single host failure, on three modest VMs rather than a heavy distributed cluster. The Garage README is short, you download the binary on each of the three nodes, you start them, and they form a cluster — but six weeks later, you discover the layout was never assigned (so writes silently fell on whichever node first answered), the S3 API on :3900 was speaking plain HTTP because nothing terminates TLS in front of it, the RPC port :3901 was reachable from the public internet because no firewall rule was ever added, and the application service account has the full admin token in its config file.

What’s happening

A Garage deployment that is actually production-ready needs more than the binary plus a config. The cluster has to have a real layout — each node assigned to a zone (typically the AZ or rack) and a capacity in bytes — committed via garage layout apply before any data is written, because Garage will accept writes against an empty layout and produce a cluster that has no replica strategy. The S3 API and the K2V API (Garage’s key-value side-channel) both need TLS in front, because S3 clients refuse plain HTTP by default and customer access keys are not the kind of secret you send in the clear. The RPC port that nodes use to talk to each other must be firewalled to the cluster’s private subnet only — exposing it is the equivalent of exposing PostgreSQL. The admin token in garage.toml is root-equivalent and must be readable only by the garage user. Every node needs its data volume on XFS with noatime, capacity headroom, and a periodic garage repair scrub to catch silent corruption before it becomes a restore problem. None of these are individually critical. They compound — skip them and the cluster is “S3-compatible” in name only.

How to verify

After install, on each node, the listeners should look like this:

ss -lntp | grep -E ':(3900|3901|3902|443)\b'
# 127.0.0.1:3900   garage  (S3 API, behind nginx)
# 10.0.0.x:3901    garage  (RPC, cluster subnet only)
# 127.0.0.1:3902   garage  (K2V API, behind nginx)
# 0.0.0.0:443      nginx   (S3 + K2V proxy with TLS)

The RPC port :3901 must be on the cluster’s private interface, never 0.0.0.0. Cluster status and layout:

garage status
# Healthy nodes: 3/3

garage layout show
# Current cluster layout: version N
# node ... zone <z> capacity <bytes>

A scrub run against the local data directory:

garage repair --yes scrub

If garage status shows fewer than 3 healthy nodes or garage layout show reports no layout, the cluster is not ready for writes regardless of what s3cmd ls returned.

The fix

Save the script below as /root/setup-garage-ubuntu22.sh, then run it on each of the three nodes (with GARAGE_NODE_INDEX set to 1, 2, 3). It performs the full installer flow on a fresh Ubuntu 22.04 VM: base update, kernel/network tuning, file limits, UFW with the RPC port restricted to the cluster CIDR, SSH hardening with root key preserved, unattended-upgrades, XFS on the data drive with noatime, the Garage static binary into /usr/local/bin, a garage system user, /etc/garage.toml with the cluster shared secret + admin token + per-zone metadata, a systemd unit with LimitNOFILE=64000, nginx in front of :3900 and :3902 with Let’s Encrypt TLS, and an idempotent layout assignment that you run from node 1 once all three are connected.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Garage 3-node clean VM installer
### Run on each of the three nodes with GARAGE_NODE_INDEX=1|2|3
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs and configures Garage + nginx + Let's Encrypt
### No local backups; assumes VM-level backup
### Reboot remains manual

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${GARAGE_NODE_INDEX:?set GARAGE_NODE_INDEX=1|2|3}"
: "${GARAGE_VERSION:=v1.0.1}"
: "${GARAGE_CLUSTER_CIDR:=10.0.0.0/24}"
: "${GARAGE_DOMAIN_S3:=s3.example.com}"
: "${GARAGE_DOMAIN_K2V:=k2v.example.com}"
: "${LE_EMAIL:=ops@example.com}"
: "${GARAGE_DATA_DRIVE:=/dev/vdb}"
: "${GARAGE_RPC_SECRET:=}"
: "${GARAGE_ADMIN_TOKEN:=}"

if [[ -z "${GARAGE_RPC_SECRET}" || -z "${GARAGE_ADMIN_TOKEN}" ]]; then
  echo "GARAGE_RPC_SECRET and GARAGE_ADMIN_TOKEN must be the SAME on all 3 nodes."
  echo "Generate once with:"
  echo "  openssl rand -hex 32"
  exit 1
fi

NODE_IP="$(hostname -I | awk '{print $1}')"

echo
echo "========================================"
echo "Garage Ubuntu 22.04 Setup (node ${GARAGE_NODE_INDEX})"
echo "========================================"
echo

export DEBIAN_FRONTEND=noninteractive

echo "==> Updating base OS"
apt-get update
apt-get -y upgrade

echo "==> Installing base packages"
apt-get -y install \
  vim curl wget ca-certificates gnupg2 chrony fail2ban \
  unattended-upgrades apt-listchanges \
  ufw lsof tcpdump dnsutils net-tools \
  xfsprogs nginx

echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true

echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-garage.conf <<'SYSCTL'
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 10240 65535

vm.swappiness = 10
vm.dirty_ratio = 20
vm.dirty_background_ratio = 5

kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL
sysctl --system

echo "==> Setting file limits"
cat > /etc/security/limits.d/99-garage.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
garage soft nofile 64000
garage hard nofile 64000
LIMITS

echo "==> Configuring UFW (RPC restricted to cluster CIDR)"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow from ${GARAGE_CLUSTER_CIDR} to any port 3901 proto tcp
ufw --force enable

echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)

set_sshd_option() {
  local key="$1" value="$2"
  if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
    sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
  else
    echo "${key} ${value}" >> /etc/ssh/sshd_config
  fi
}

set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4

sshd -t
systemctl restart sshd

echo "==> Configuring fail2ban for SSH"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban

echo "==> Configuring unattended-upgrades"
dpkg-reconfigure -f noninteractive unattended-upgrades

echo "==> Preparing data drive (XFS, noatime)"
if [[ ! -b "${GARAGE_DATA_DRIVE}" ]]; then
  echo "Data drive ${GARAGE_DATA_DRIVE} not present. Aborting."
  exit 1
fi

if ! blkid "${GARAGE_DATA_DRIVE}" | grep -q 'TYPE="xfs"'; then
  mkfs.xfs -f -L "garage" "${GARAGE_DATA_DRIVE}"
fi

UUID="$(blkid -s UUID -o value ${GARAGE_DATA_DRIVE})"
mkdir -p /var/lib/garage/data /var/lib/garage/meta
if ! grep -q "${UUID}" /etc/fstab; then
  echo "UUID=${UUID}  /var/lib/garage/data  xfs  defaults,noatime,nofail  0  0" >> /etc/fstab
fi
mount /var/lib/garage/data

echo "==> Creating garage user"
if ! id garage >/dev/null 2>&1; then
  useradd -r -M -d /var/lib/garage -s /sbin/nologin garage
fi
chown -R garage:garage /var/lib/garage

echo "==> Installing Garage ${GARAGE_VERSION}"
if [[ ! -f /usr/local/bin/garage ]]; then
  curl -fsSLo /tmp/garage.tar.gz \
    "https://garagehq.deuxfleurs.fr/_releases/${GARAGE_VERSION}/x86_64-unknown-linux-musl/garage.tar.gz"
  tar -xzf /tmp/garage.tar.gz -C /usr/local/bin garage || cp /tmp/garage /usr/local/bin/garage
  chmod +x /usr/local/bin/garage
fi

echo "==> Writing /etc/garage.toml"
cat > /etc/garage.toml <<TOML
metadata_dir = "/var/lib/garage/meta"
data_dir = "/var/lib/garage/data"

db_engine = "lmdb"

replication_mode = "3"

compression_level = 2

rpc_bind_addr = "${NODE_IP}:3901"
rpc_public_addr = "${NODE_IP}:3901"
rpc_secret = "${GARAGE_RPC_SECRET}"

[s3_api]
s3_region = "ca-qc-1"
api_bind_addr = "127.0.0.1:3900"
root_domain = ".${GARAGE_DOMAIN_S3}"

[k2v_api]
api_bind_addr = "127.0.0.1:3902"

[admin]
api_bind_addr = "127.0.0.1:3903"
admin_token = "${GARAGE_ADMIN_TOKEN}"
TOML
chown root:garage /etc/garage.toml
chmod 640 /etc/garage.toml

echo "==> Writing systemd unit"
cat > /etc/systemd/system/garage.service <<'UNIT'
[Unit]
Description=Garage S3-compatible distributed storage
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=garage
Group=garage
ExecStart=/usr/local/bin/garage server
LimitNOFILE=64000
Restart=on-failure
RestartSec=10s
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/lib/garage

[Install]
WantedBy=multi-user.target
UNIT

systemctl daemon-reload

echo "==> Starting Garage"
systemctl enable --now garage

echo "==> Waiting for Garage S3 API on :3900"
for i in {1..30}; do
  if ss -lntp | grep -q '127.0.0.1:3900'; then break; fi
  sleep 1
done

echo "==> Issuing Let's Encrypt cert"
apt-get -y install certbot python3-certbot-nginx

cat > /etc/nginx/sites-available/garage.conf <<NGINXCONF
server {
    listen 80;
    server_name ${GARAGE_DOMAIN_S3} ${GARAGE_DOMAIN_K2V} *.${GARAGE_DOMAIN_S3};
    location / { return 404; }
}
NGINXCONF
ln -sf /etc/nginx/sites-available/garage.conf /etc/nginx/sites-enabled/garage.conf
rm -f /etc/nginx/sites-enabled/default
systemctl enable --now nginx
nginx -t && systemctl reload nginx

certbot certonly --nginx -n --agree-tos -m "${LE_EMAIL}" \
  -d "${GARAGE_DOMAIN_S3}" -d "*.${GARAGE_DOMAIN_S3}" -d "${GARAGE_DOMAIN_K2V}" \
  || certbot certonly --nginx -n --agree-tos -m "${LE_EMAIL}" \
       -d "${GARAGE_DOMAIN_S3}" -d "${GARAGE_DOMAIN_K2V}"

echo "==> Writing real nginx site"
cat > /etc/nginx/sites-available/garage.conf <<NGINXCONF
server {
    listen 80;
    server_name ${GARAGE_DOMAIN_S3} ${GARAGE_DOMAIN_K2V};
    return 301 https://\$host\$request_uri;
}

server {
    listen 443 ssl http2;
    server_name ${GARAGE_DOMAIN_S3};

    ssl_certificate     /etc/letsencrypt/live/${GARAGE_DOMAIN_S3}/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/${GARAGE_DOMAIN_S3}/privkey.pem;

    add_header Strict-Transport-Security "max-age=31536000" always;

    client_max_body_size 0;
    proxy_buffering off;
    proxy_request_buffering off;

    location / {
        proxy_pass http://127.0.0.1:3900;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
    }
}

server {
    listen 443 ssl http2;
    server_name ${GARAGE_DOMAIN_K2V};

    ssl_certificate     /etc/letsencrypt/live/${GARAGE_DOMAIN_S3}/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/${GARAGE_DOMAIN_S3}/privkey.pem;

    add_header Strict-Transport-Security "max-age=31536000" always;

    client_max_body_size 0;

    location / {
        proxy_pass http://127.0.0.1:3902;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
    }
}
NGINXCONF

nginx -t && systemctl reload nginx

echo
echo "========================================"
echo "DONE (node ${GARAGE_NODE_INDEX})"
echo "========================================"
echo
echo "Services:"
systemctl is-active garage nginx chronyd fail2ban || true
echo
echo "Listeners:"
ss -lntp | grep -E ':(443|3900|3901|3902|3903)\b' || true
echo
echo "Local node id:"
garage node id
echo
echo "Cluster status:"
garage status || true
echo
echo "Once all 3 nodes are up, from node 1 run:"
echo "  garage layout assign -z zone-a -c 1T <node-id-1>"
echo "  garage layout assign -z zone-b -c 1T <node-id-2>"
echo "  garage layout assign -z zone-c -c 1T <node-id-3>"
echo "  garage layout apply --version 1"
echo
echo "Then create your first access key and bucket:"
echo "  garage key new --name app-key"
echo "  garage bucket create app-data"
echo "  garage bucket allow --read --write --owner app-data --key app-key"
echo
echo "S3 endpoint:  https://${GARAGE_DOMAIN_S3}"
echo "K2V endpoint: https://${GARAGE_DOMAIN_K2V}"

Make it executable and run it on each of the three nodes:

chmod 700 /root/setup-garage-ubuntu22.sh

# Generate once, use on all 3 nodes:
export GARAGE_RPC_SECRET=$(openssl rand -hex 32)
export GARAGE_ADMIN_TOKEN=$(openssl rand -hex 32)

GARAGE_NODE_INDEX=1 \
GARAGE_DOMAIN_S3=s3.example.com \
GARAGE_DOMAIN_K2V=k2v.example.com \
LE_EMAIL=ops@example.com \
/root/setup-garage-ubuntu22.sh

After all three nodes are up, run the garage layout assign / apply block from node 1 to commit the cluster layout, then create the first access key with garage key new --name app-key and the first bucket. The admin token in /etc/garage.toml is never to be embedded in application configs — applications get a per-purpose access key with scoped bucket permissions.

Run Garage inside a Stack Harbor-managed environment with capacity alerting, scheduled garage repair scrub, and quarterly restore drills: Cloud Compute →.