From 298cc4efd61b0549c1557b215558b48b61cd4427 Mon Sep 17 00:00:00 2001 From: Andrew S Erwin Date: Mon, 16 Nov 2026 21:38:28 -0600 Subject: [PATCH] Fix Nextcloud DAV connections on Core: public-IP pin + username-composed prefills MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs made the suggested Nextcloud shares fail on Core: 1. Reachability: nextcloud.$DOMAIN is split-horizon DNS — inside the core network it answers the Nextcloud container's private IP, where nothing listens on 443 (traefik holds TLS on the public address), and netguard refuses private dials anyway. Verified from the core network: the private route refuses connections; the public route answers PROPFIND with 401 (correct credentials-required). The installer's rendered compose now pins nextcloud.$DOMAIN to EXTERNALIP via extra_hosts on the APP service — the exact house pattern the web service already uses for authelia. DNS inside the app container resolves the public address, the dial goes through traefik like any external client, and netguard stays fully strict (no guard relaxation, no trusted-host change). update.sh re-renders compose from the shipped lib, so running cores pick this up on upgrade. 2. Wrong endpoint: Nextcloud's DAV roots are per-user (/remote.php/dav/files//, /calendars//), but the WebDAV and CalDAV suggestion prefills handed over the bare /files/ and /calendars/ homes — one level above any valid endpoint. Both now compose the viewer's username into the URL (the URL shown is the URL saved), matching the CardDAV prefill. Dry-rendered the updated compose template and validated it with docker compose config. Regressions updated to assert the composed per-user URLs are what gets POSTed (20/20 PASS incl. the mobile suite); real-stack e2e all PASS; lint/SSR-lint/build clean. API.md and the local AGENTS invariant document the pin and the composition. --- API.md | 5 ++++- deploy/federated/lib-superbrain.sh | 8 ++++++++ scripts/regressions.mjs | 11 ++++++----- web/components/caldav-settings.tsx | 7 ++++++- web/components/webdav-settings.tsx | 7 ++++++- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/API.md b/API.md index aec5536..07e5749 100644 --- a/API.md +++ b/API.md @@ -119,7 +119,10 @@ share every ~30 minutes under a global advisory lease; `WebDavConnection` + `WebDavItem` (migration 020) store credentials and the path↔bookmark ledger. On Core the deployment's `NEXTCLOUD_URL` makes the list carry a one-click suggestion (`https:///remote.php/dav/files/`) — DATA, not a code -fork on TIER. +fork on TIER. The UI composes the viewer's username into the per-user DAV +root (`/files//`), and the Core app container pins the Nextcloud +hostname to the deployment's public IP (compose `extra_hosts`): the +split-horizon private answer has no 443 listener and netguard stays strict. | Method | Path | Returns / behavior | |---|---|---| diff --git a/deploy/federated/lib-superbrain.sh b/deploy/federated/lib-superbrain.sh index fbfd133..2757e18 100644 --- a/deploy/federated/lib-superbrain.sh +++ b/deploy/federated/lib-superbrain.sh @@ -69,6 +69,14 @@ services: migrate: {condition: service_completed_successfully} env_file: - ./.env + # Split-horizon DNS: nextcloud.$DOMAIN resolves to a private container IP + # inside the core network, where nothing listens on 443 (traefik holds + # TLS on the public address) and netguard refuses private dials anyway. + # Pin the public IP - the same house pattern the web service uses for + # authelia - so the WebDAV/CalDAV/CardDAV connectors reach the deployment's + # Nextcloud over the public, netguard-clean route. No guard relaxation. + extra_hosts: + - "nextcloud.$DOMAIN:$EXTERNALIP" healthcheck: test: [CMD, /superbrain, --healthcheck] interval: 3s diff --git a/scripts/regressions.mjs b/scripts/regressions.mjs index c7e3b25..7ad9d6b 100644 --- a/scripts/regressions.mjs +++ b/scripts/regressions.mjs @@ -681,7 +681,8 @@ try { console.log('PASS: sidebar persists drag reordering') // Settings → WebDAV: masked list rows render; the deployment suggestion - // (NEXTCLOUD_URL) prefills the connect form with the viewer's username; + // (NEXTCLOUD_URL) prefills the connect form with the username composed into + // the per-user DAV root; // save POSTs the form; Sync/Test surface the server's verbatim results. await page.goto(`${base}/settings`) await page.getByRole('tab', { name: 'WebDAV' }).click() @@ -690,13 +691,13 @@ try { await page.getByText('Nextcloud files detected on this server').waitFor() await page.getByRole('button', { name: 'Use', exact: true }).click() const suggestUrl = page.getByPlaceholder('https://cloud.example.com/remote.php/dav/files/username/Documents') - assert.equal(await suggestUrl.inputValue(), 'https://cloud.federatedcomputer.ai/remote.php/dav/files/') + assert.equal(await suggestUrl.inputValue(), 'https://cloud.federatedcomputer.ai/remote.php/dav/files/fixture/') assert.equal(await page.getByPlaceholder('erwin').inputValue(), 'fixture') // session email local-part await page.getByPlaceholder('erwin').fill('erwin') await page.getByPlaceholder('Account or app password').fill('app-secret') await page.locator('[role="dialog"]').getByRole('button', { name: 'Connect share' }).click() await eventually(() => webdavConnections.length === 2, 'WebDAV connect POST did not reach the API') - assert.equal(lastWebdavCreate.url, 'https://cloud.federatedcomputer.ai/remote.php/dav/files/') + assert.equal(lastWebdavCreate.url, 'https://cloud.federatedcomputer.ai/remote.php/dav/files/fixture/') assert.equal(lastWebdavCreate.username, 'erwin') assert.equal(lastWebdavCreate.password, 'app-secret') await page.getByRole('button', { name: 'Sync House docs' }).click() @@ -716,13 +717,13 @@ try { await page.getByText('Nextcloud calendars detected on this server').waitFor() await page.getByRole('button', { name: 'Use', exact: true }).click() const calSuggestUrl = page.getByPlaceholder('https://cloud.example.com/remote.php/dav/calendars/username') - assert.equal(await calSuggestUrl.inputValue(), 'https://cloud.federatedcomputer.ai/remote.php/dav/calendars/') + assert.equal(await calSuggestUrl.inputValue(), 'https://cloud.federatedcomputer.ai/remote.php/dav/calendars/fixture/') assert.equal(await page.getByPlaceholder('erwin').inputValue(), 'fixture') await page.getByPlaceholder('erwin').fill('erwin') await page.getByPlaceholder('Account or app password').fill('cal-app-secret') await page.locator('[role="dialog"]').getByRole('button', { name: 'Connect calendar' }).click() await eventually(() => caldavConnections.length === 2, 'CalDAV connect POST did not reach the API') - assert.equal(lastCaldavCreate.url, 'https://cloud.federatedcomputer.ai/remote.php/dav/calendars/') + assert.equal(lastCaldavCreate.url, 'https://cloud.federatedcomputer.ai/remote.php/dav/calendars/fixture/') assert.equal(lastCaldavCreate.username, 'erwin') assert.equal(lastCaldavCreate.password, 'cal-app-secret') await page.getByRole('button', { name: 'Sync My calendars' }).click() diff --git a/web/components/caldav-settings.tsx b/web/components/caldav-settings.tsx index 6354a49..c38c6fb 100644 --- a/web/components/caldav-settings.tsx +++ b/web/components/caldav-settings.tsx @@ -74,7 +74,12 @@ export function CalDavSettings() { const openCreate = () => setForm({ ...emptyForm }) const openSuggestion = (s: Suggestion) => { const email = session?.user?.email ?? '' - setForm({ ...emptyForm, name: s.name, url: s.url, username: email ? email.split('@')[0] : '' }) + const username = email ? email.split('@')[0] : '' + // Nextcloud's DAV roots are per-user (/files//, + // /calendars//): compose the username into the URL so the + // prefill is a working endpoint, not a 404 one level up. The URL shown + // is the URL saved; the person can still edit both fields. + setForm({ ...emptyForm, name: s.name, username, url: username ? s.url + username + '/' : s.url }) } const openEdit = (c: CalDavConnection) => setForm({ id: c.id, version: c.version, name: c.name, url: c.url, username: c.username, diff --git a/web/components/webdav-settings.tsx b/web/components/webdav-settings.tsx index da6e5ae..19ce692 100644 --- a/web/components/webdav-settings.tsx +++ b/web/components/webdav-settings.tsx @@ -72,7 +72,12 @@ export function WebdavSettings() { const openCreate = () => setForm({ ...emptyForm }) const openSuggestion = (s: Suggestion) => { const email = session?.user?.email ?? '' - setForm({ ...emptyForm, name: s.name, url: s.url, username: email ? email.split('@')[0] : '' }) + const username = email ? email.split('@')[0] : '' + // Nextcloud's DAV roots are per-user (/files//, + // /calendars//): compose the username into the URL so the + // prefill is a working endpoint, not a 404 one level up. The URL shown + // is the URL saved; the person can still edit both fields. + setForm({ ...emptyForm, name: s.name, username, url: username ? s.url + username + '/' : s.url }) } const openEdit = (c: WebdavConnection) => setForm({ id: c.id, version: c.version, name: c.name, url: c.url, username: c.username,