Skip to content

Keep the proxy up without HaRP and move the shared key into a file - #9

Merged
oleksandr-nc merged 3 commits into
mainfrom
dev-setup/harp-key-file-and-proxy-upstream
Sep 14, 2026
Merged

oleksandr-nc merged 3 commits into
mainfrom
dev-setup/harp-key-file-and-proxy-upstream

Conversation

@oleksandr-nc

Copy link
Copy Markdown
Collaborator

Two things found while re-running the dev-setup runbook end to end (NC 36 dev, AppAPI 36.0.0-dev.0, HaRP 0.4.5, docker-dev d0d1016).

Proxy snippet. With a literal proxy_pass http://appapi-harp:8780/exapps/, nginx resolves the name at startup and refuses to start when the container is absent: [emerg] host not found in upstream "appapi-harp". Every URL of every instance then refuses the connection, status.php included, while Nextcloud's logs look fine. Any proxy restart while HaRP is stopped triggers it (host reboot, up -d after a down). set $harp_upstream ...; proxy_pass $harp_upstream; resolves per request through the resolver 127.0.0.11 nginx-proxy already generates; HaRP being down then degrades to a 502 on /exapps/ only, and recovery needs no proxy restart. Tested both ways.

Shared key. Moved from HP_SHARED_KEY in the override to an untracked data/harp.key mounted as HP_SHARED_KEY_FILE; Stage 6 reads the same file, so the two cannot drift, and docker compose config no longer prints it. The "unregister first to change values" note did not work for a key change: daemon:unregister refuses while the daemon holds ExApps and the ExApps cannot be removed through HaRP any more. Documented the order that does work.

tests/verify.py: new proxy_survives_harp_absence check (nginx -t plus the snippet must use a variable), and harp_info reads the key file instead of skipping. All nextcloud-dev-setup and harp-operations checks pass here.

A literal proxy_pass hostname stops nginx from starting whenever the appapi-harp container is absent, which takes every instance down; resolve it per request instead. The shared key now lives in an untracked data/harp.key mounted as HP_SHARED_KEY_FILE, with the rotation order that actually works. verify.py gains a proxy check and reads the key file.

Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
@oleksandr-nc

Copy link
Copy Markdown
Collaborator Author

will rebase this PR after we merge this one: #6

…n the triage script

A live rotation showed that docker compose up -d does not pick up a changed key file and that restart crash-loops HaRP (its generated FRP configs keep the old token); only a recreate works. The key one-liner needs LC_ALL=C on macOS. harp-triage.sh now reads HP_SHARED_KEY_FILE, and the harness accepts any proxy_pass that carries a variable.

Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
@oleksandr-nc
oleksandr-nc marked this pull request as ready for review September 11, 2026 09:34

@kyteinsky kyteinsky left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!
yeah this is one nasty issue
sorry I should've documented that in the harp readme instead of implicitly using the IP. Would you mind adding a note there too, or I can add it later?

- The HaRP shared key must be byte-identical between the compose override (`HP_SHARED_KEY`) and the
`daemon:register --harp_shared_key` value; a mismatch is the number one install failure.
files (`.env`, `docker-compose.override.yml`, `data/nginx/vhost.d/`, `data/harp.key`).
- The HaRP shared key lives in one untracked file, `data/harp.key`: HaRP mounts it as `HP_SHARED_KEY_FILE` and

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better to put this in data/ssl/ so it's also ignored by .gitignore

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data/ssl/ is mounted into the proxy container as its certs dir (docker-compose.yml line 12), so the key would be readable from inside nginx. I would rather keep it out of any mounted dir and pay the one exclude line.

and the ExApps cannot be removed the normal way because that goes through HaRP. The order that works:

```bash
./scripts/occ.sh nextcloud -- app_api:app:unregister <appid> --force --silent # per ExApp; drops the row without asking HaRP

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ex-app container might still be there if this unregister does not go through with harp
manual removal by container name nc_app_<appid> could be done

or the exapps should be removed before the key is rotated.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, unregistering the ExApps before the key changes is the cleaner order. Rewrote the section that way; the --force path is now the recovery case and names docker rm -f nc_app_<appid>.


```bash
(umask 077; LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 32 > data/harp.key) # any ASCII string works; LC_ALL=C keeps BSD tr (macOS) happy
echo data/harp.key >> .git/info/exclude

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah it's ignored here, might be still better to use already ignored dir data/ssl/

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as above, data/ssl/ is the proxy's certs mount.

Unregistering them while the old key still works lets HaRP remove the containers; the forced path becomes the recovery case and names the container to remove by hand.

Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
@oleksandr-nc

Copy link
Copy Markdown
Collaborator Author

Sure, note for the HaRP README is here: nextcloud/HaRP#121

@oleksandr-nc
oleksandr-nc merged commit 0532f54 into main Sep 14, 2026
4 checks passed
@oleksandr-nc
oleksandr-nc deleted the dev-setup/harp-key-file-and-proxy-upstream branch September 14, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants