Git over SSH for Forgejo and Gitea (tcp_ports) (#27)

This commit is contained in:
michael authored and GitHub committed 2026-11-22 19:47:21 -05:00
1 parent 7b6851c023
commit f3157b71f3
9 files changed
+72 -15

No files matched your search

+1 -1
View File
@@ -1 +1 @@
4968f029cc143be3e4145383e6442f1ec7abd119
63af6fc046feb06ef94d5e3cdba826a500ff52d3
+3 -1
View File
@@ -95,8 +95,10 @@ jobs:
run: |
export HARBOR_DATA_DIR=$RUNNER_TEMP/h HARBOR_RUNTIME=fake HARBOR_BASE_DOMAIN=pods.test
export HARBOR_CAPACITY_CPU_MILLIS=8000 HARBOR_CAPACITY_MEMORY_MB=8192 HARBOR_CAPACITY_STORAGE_MB=65536
# public TCP ports for recipes with tcp_ports, as on the servers
export HARBOR_PUBLIC_PORTS=20000-20099 HARBOR_TCP_DOMAIN=tcp.pods.test
# the runner's sudo ignores -E, so pass the settings explicitly
H="HARBOR_DATA_DIR=$HARBOR_DATA_DIR HARBOR_RUNTIME=$HARBOR_RUNTIME HARBOR_BASE_DOMAIN=$HARBOR_BASE_DOMAIN HARBOR_CAPACITY_CPU_MILLIS=$HARBOR_CAPACITY_CPU_MILLIS HARBOR_CAPACITY_MEMORY_MB=$HARBOR_CAPACITY_MEMORY_MB HARBOR_CAPACITY_STORAGE_MB=$HARBOR_CAPACITY_STORAGE_MB"
H="HARBOR_DATA_DIR=$HARBOR_DATA_DIR HARBOR_RUNTIME=$HARBOR_RUNTIME HARBOR_BASE_DOMAIN=$HARBOR_BASE_DOMAIN HARBOR_CAPACITY_CPU_MILLIS=$HARBOR_CAPACITY_CPU_MILLIS HARBOR_CAPACITY_MEMORY_MB=$HARBOR_CAPACITY_MEMORY_MB HARBOR_CAPACITY_STORAGE_MB=$HARBOR_CAPACITY_STORAGE_MB HARBOR_PUBLIC_PORTS=$HARBOR_PUBLIC_PORTS HARBOR_TCP_DOMAIN=$HARBOR_TCP_DOMAIN"
export HARBOR_TOKEN=$(sudo env $H /tmp/harbord token create ci | grep -o 'hbr_[A-Za-z0-9_-]*')
# As on the servers, the node only runs images on its allowlist, and the control plane
# sets that list from the catalog. A name the node won't take fails here, not in production.
+10
View File
@@ -32,6 +32,7 @@ Cottage how to run it:
| `default_resources`, `min_resources` | `cpu_millis`, `memory_mb`, `storage_mb` |
| `volumes` | named volumes to hand to a non-root user: `data: { uid: 1000, gid: 1000, mode: "0750" }` |
| `parameters` | settings people can see or change; secrets are generated (`generate: random32`, `random16` or `hex32`) |
| `tcp_ports` | at most two ports the app needs besides HTTPS, for protocols with their own authentication such as SSH: `[{ name: ssh, service: app, port: 2222 }]` |
Each parameter has a `key`, `label` and `type` (`string`, `int`, `bool` or `choice` with `choices`), and
may set `default`, `secret`, `generate`, `editable` (the owner can change it later), `group` (fields
@@ -42,6 +43,15 @@ app's own words: `${SMTP_SECURITY_IS_TLS:+ssl}${SMTP_SECURITY_IS_STARTTLS:+tls}`
parameter it sets `<KEY>_IS_EMPTY=true`, so `${SMTP_HOST_IS_EMPTY:+log}${SMTP_HOST:+smtp}` gives `log`
while no SMTP server is set and `smtp` once one is.
### Ports besides HTTPS
Web traffic reaches every app through Cottage's proxy. An app that also needs another port, such as
a Git host's SSH server, lists it under `tcp_ports`. Cottage gives each app a public port of its own
for it and sets two variables, so the app can show the right address: `HARBOR_TCP_HOST` (a host name
that reaches the server directly) and `HARBOR_PORT_<NAME>` (the port, e.g. `HARBOR_PORT_SSH`). The
app's IP allowlist and blocklist apply to the port, and it stays closed until the owner finishes setup.
Only use it for protocols that sign people in themselves. Forgejo's recipe is an example.
### Outgoing mail
Apps send mail through the owner's own mail provider (for example their email host, or a sending
+1 -1
View File
@@ -6,7 +6,7 @@ Sign-ups are off, so nobody else can make an account. Add people under **Site ad
## Your first repository
Choose **+ → New repository**, or **+ → New migration** to bring one over from GitHub, GitLab, Gitea or another forge, with its issues and pull requests. Clone and push over HTTPS. SSH isn't available on Cottage; create an access token under **Settings → Applications** to use as your Git password.
Choose **+ → New repository**, or **+ → New migration** to bring one over from GitHub, GitLab, Gitea or another forge, with its issues and pull requests. Clone and push over SSH or HTTPS. For SSH, add your public key under **Settings → SSH / GPG Keys**; the clone button shows the app's own SSH address and port ([more](https://cottage.host/docs/ssh)). For HTTPS, create an access token under **Settings → Applications** to use as your Git password.
Forgejo sends notifications and password resets by email once you fill in the **Email** settings for the app in your Cottage dashboard with your mail provider's details ([how](https://cottage.host/docs/email)). Notifications always show up in the bell menu too.
+12 -4
View File
@@ -3,13 +3,17 @@ x-harbor:
slug: forgejo
name: Forgejo
description: Self-hosted software forge.
version: "17.0.2-c2"
version: "17.0.2-c3"
primary: { service: app, port: 3000 }
health_path: /api/healthz
default_resources: { cpu_millis: 500, memory_mb: 512, storage_mb: 10240 }
min_resources: { cpu_millis: 250, memory_mb: 256, storage_mb: 2048 }
volumes:
data: { uid: 1000, gid: 1000, mode: "0750" }
# Git over SSH: the built-in SSH server (port 2222 in the rootless image) on a public port
# of its own. Cottage passes the address in HARBOR_TCP_HOST and HARBOR_PORT_SSH.
tcp_ports:
- { name: ssh, service: app, port: 2222 }
parameters:
- { key: SECRET_KEY, label: Secret key, type: string, secret: true, generate: random32 }
- { key: ADMIN_PASSWORD, label: Admin password, type: string, secret: true, generate: random32 }
@@ -45,9 +49,13 @@ services:
FORGEJO__server__DOMAIN: ${HARBOR_HOSTNAME}
FORGEJO__server__ROOT_URL: ${HARBOR_PUBLIC_URL}/
FORGEJO__server__HTTP_PORT: "3000"
# Only HTTPS reaches the app, so clone over HTTPS.
FORGEJO__server__DISABLE_SSH: "true"
FORGEJO__server__START_SSH_SERVER: "false"
# Git over SSH with the app's built-in server. Clone URLs show the public address
# Cottage gives it, not the port the server listens on inside the container.
FORGEJO__server__DISABLE_SSH: "false"
FORGEJO__server__START_SSH_SERVER: "true"
FORGEJO__server__SSH_LISTEN_PORT: "2222"
FORGEJO__server__SSH_DOMAIN: ${HARBOR_TCP_HOST}
FORGEJO__server__SSH_PORT: ${HARBOR_PORT_SSH}
FORGEJO__service__DISABLE_REGISTRATION: ${DISABLE_REGISTRATION}
# Mail through the owner's provider; off while no SMTP server is set.
FORGEJO__mailer__ENABLED: ${SMTP_HOST:+true}
+1 -1
View File
@@ -6,7 +6,7 @@ Sign-ups are off, so nobody else can make an account. Add people under **Site Ad
## Your first repository
Choose **+ → New Repository**, or **+ → New Migration** to bring one over from GitHub, GitLab or another Git host, with its issues and pull requests. Clone and push over HTTPS. SSH isn't available on Cottage; create an access token under **Settings → Applications** to use as your Git password.
Choose **+ → New Repository**, or **+ → New Migration** to bring one over from GitHub, GitLab or another Git host, with its issues and pull requests. Clone and push over SSH or HTTPS. For SSH, add your public key under **Settings → SSH / GPG Keys**; the clone button shows the app's own SSH address and port ([more](https://cottage.host/docs/ssh)). For HTTPS, create an access token under **Settings → Applications** to use as your Git password.
Gitea sends notifications and password resets by email once you fill in the **Email** settings for the app in your Cottage dashboard with your mail provider's details ([how](https://cottage.host/docs/email)). Notifications always show up in the bell menu too.
+12 -4
View File
@@ -3,13 +3,17 @@ x-harbor:
slug: gitea
name: Gitea
description: Self-hosted Git service.
version: "28.4.0-c2"
version: "28.4.0-c3"
primary: { service: app, port: 3000 }
health_path: /api/healthz
default_resources: { cpu_millis: 500, memory_mb: 512, storage_mb: 10240 }
min_resources: { cpu_millis: 250, memory_mb: 256, storage_mb: 2048 }
volumes:
data: { uid: 1000, gid: 1000, mode: "0750" }
# Git over SSH: the built-in SSH server (port 2222 in the rootless image) on a public port
# of its own. Cottage passes the address in HARBOR_TCP_HOST and HARBOR_PORT_SSH.
tcp_ports:
- { name: ssh, service: app, port: 2222 }
parameters:
- { key: SECRET_KEY, label: Secret key, type: string, secret: true, generate: random32 }
- { key: ADMIN_PASSWORD, label: Admin password, type: string, secret: true, generate: random32 }
@@ -47,9 +51,13 @@ services:
GITEA__server__DOMAIN: ${HARBOR_HOSTNAME}
GITEA__server__ROOT_URL: ${HARBOR_PUBLIC_URL}/
GITEA__server__HTTP_PORT: "3000"
# Only HTTPS reaches the app, so clone over HTTPS.
GITEA__server__DISABLE_SSH: "true"
GITEA__server__START_SSH_SERVER: "false"
# Git over SSH with the app's built-in server. Clone URLs show the public address
# Cottage gives it, not the port the server listens on inside the container.
GITEA__server__DISABLE_SSH: "false"
GITEA__server__START_SSH_SERVER: "true"
GITEA__server__SSH_LISTEN_PORT: "2222"
GITEA__server__SSH_DOMAIN: ${HARBOR_TCP_HOST}
GITEA__server__SSH_PORT: ${HARBOR_PORT_SSH}
GITEA__service__DISABLE_REGISTRATION: ${DISABLE_REGISTRATION}
# Mail through the owner's provider; off while no SMTP server is set.
GITEA__mailer__ENABLED: ${SMTP_HOST:+true}
+17 -2
View File
@@ -38,6 +38,17 @@ env = {
"HARBOR_HOSTNAME": "localhost",
"HARBOR_PUBLIC_URL": f"http://127.0.0.1:{port}",
}
# public TCP ports (tcp_ports): servers assign one from a range and give the host that
# reaches it; here each gets a free local port, published on 127.0.0.1
tcp = []
for t in x.get("tcp_ports") or []:
with socket.socket() as s:
s.bind(("127.0.0.1", 0))
tcp.append((t["name"], t["service"], t["port"], s.getsockname()[1]))
if tcp:
env["HARBOR_TCP_HOST"] = "localhost"
for name, _, _, pub in tcp:
env[f"HARBOR_PORT_{name.upper()}"] = str(pub)
for p in x.get("parameters") or []:
if p.get("generate"):
env[p["key"]] = GEN[p["generate"]]()
@@ -56,12 +67,15 @@ with open(os.path.join(work, "env"), "w") as f:
override = {"services": {}}
for name, svc in cfg["services"].items():
o = {"security_opt": ["no-new-privileges:true"]}
ports = [f"127.0.0.1:{pub}:{cport}" for _, svc_name, cport, pub in tcp if svc_name == name]
if name == primary["service"]:
o["ports"] = [f"127.0.0.1:{port}:{primary['port']}"]
ports.insert(0, f"127.0.0.1:{port}:{primary['port']}")
if res.get("memory_mb"):
o["mem_limit"] = f"{res['memory_mb']}m"
if res.get("cpu_millis"):
o["cpus"] = res["cpu_millis"] / 1000
if ports:
o["ports"] = ports
mounts = []
for m in svc.get("volumes") or []:
if m.get("type") == "volume" and m.get("source") in owned:
@@ -78,4 +92,5 @@ parts = []
for name, o in owned.items():
parts.append(f"{name}:{o.get('uid', 0)}:{o.get('gid', 0)}:{o.get('mode', '0755')}")
with open(os.path.join(work, "plan.sh"), "w") as f:
f.write(f"port={port}\nhealth={shlex.quote(health)}\nowned={shlex.quote(' '.join(parts))}\n")
tcp_list = " ".join(f"{n}:{pub}" for n, _, _, pub in tcp)
f.write(f"port={port}\nhealth={shlex.quote(health)}\nowned={shlex.quote(' '.join(parts))}\ntcp={shlex.quote(tcp_list)}\n")
+15 -1
View File
@@ -31,7 +31,8 @@ trap cleanup EXIT INT TERM
docker compose -f "$dir/template.yml" config --format json --no-interpolate > "$work/config.json"
python3 -I "$here/local-test-plan.py" "$slug" "$work"
# plan.sh sets: port, health, owned (space-separated "volume:uid:gid:mode")
# plan.sh sets: port, health, owned (space-separated "volume:uid:gid:mode"),
# tcp (space-separated "name:port" for tcp_ports)
. "$work/plan.sh"
echo "$slug: starting on http://127.0.0.1:$port"
@@ -55,5 +56,18 @@ if [ "$code" != 200 ]; then
compose logs --tail 40 || true
exit 1
fi
# each public TCP port must accept a connection; an "ssh" port must greet like an SSH server
for t in $tcp; do
name=${t%%:*}; tport=${t#*:}
banner=$(python3 -I -c 'import socket,sys
s=socket.create_connection(("127.0.0.1",int(sys.argv[1])),timeout=10); s.settimeout(10)
print(s.recv(64).decode("ascii","replace").strip())' "$tport" 2>/dev/null || true)
if [ "$name" = ssh ] && [ "${banner#SSH-}" = "$banner" ]; then
echo "$slug: tcp port $name (127.0.0.1:$tport) didn't answer like an SSH server: '$banner'"
compose logs --tail 40 || true
exit 1
fi
echo "$slug: tcp port $name answered on 127.0.0.1:$tport ($banner)"
done
passed=1
echo "$slug: ok ($url answered 200)"