Repository navigation
fix(config): reject site names that cannot be hostnames - #208
xiaozou-second wants to merge 3 commits into
Conversation
A folder whose name makes no hostname (a non-Latin name such as 我的项目, a
name made only of punctuation, or one longer than 63 characters) was linked
with an empty site name. Config.Domain then produced the domain ".test", and
the Caddy adapter rejects it ("subject does not qualify for certificate"), so
the next daemon start never brought the web server up and every site became
unreachable; while the daemon was running it was only a status warning.
Validate site names as DNS labels with the same hostLabel rule UpsertProxy
already uses:
- Config.Upsert returns an error instead of storing an unusable name, so the
Add Site endpoint cannot store one either;
- flock link reports that the folder name cannot become a site name and asks
for one (flock link <name>);
- Config.AllSites skips a parked subfolder whose name makes no site name.
flock link my-project keeps working, and a folder name that can be made into
a hostname (My_App) still becomes one (my-app). docs/sites.md says how to name
a folder the default does not fit.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
This pull request claims issue #207. |
ValidSiteName enforces the 1-63 character DNS-label limit through hostLabel, but the rejection messages only named the allowed characters. A 64-character name made of a-z, 0-9 and hyphens was rejected with a sentence that described exactly that name as allowed. State the whole rule, and assert the length limit in the tests.
The Add Site endpoint the apps call passes the picked folder's name to
Config.Upsert. That guard now rejects a name that cannot be a hostname, but
the handler returned the internal message ("\"\" is not a valid site name ...),
which is the only feedback the apps show and names an empty string instead of
the folder. Validate the derived or explicit name in the handler and answer
with the folder and the CLI remedy; the Upsert guard stays as the last line of
defence.
Fixes #207
What and why
A site's name is its hostname:
<name>.<tld>.flock linkderived that name from the folder name, so a folder whose name cannot become a hostname (我的项目,Проект, a name made only of punctuation, or a name longer than 63 characters) was stored as a site with an empty name.Config.Domainthen produced the domain.test, which the Caddy adapter rejects withsubject does not qualify for certificate: '.test'. While the daemon was already running this was only aflock statuswarning; on the next daemon start the web server did not start, so every site was unreachable. The Add Site endpoint that the apps call passesconfig.SiteNameto the sameConfig.Upsert, so it could store the same broken name.This change validates site names as DNS labels with the same
hostLabelruleUpsertProxyalready uses:internal/config/config.go: newValidSiteName;Config.Upsertreturns an error instead of storing an unusable name;Config.AllSitesskips a parked subfolder whose name makes no site name.internal/cli/sites.go:flock linkreports that the folder name cannot become a site name and asks for one (flock link <name>) instead of storing an empty one.internal/api/configapi.go: Add Site validates the derived or explicit name and answers with the folder and the same remedy, instead of the internalUpsertmessage that names an empty string. TheUpsertguard stays as the last line of defence.docs/sites.md: one sentence on naming a folder that the default does not fit.The site-name errors state the whole rule (1-63 characters of a-z, 0-9 and inner hyphens), because
hostLabelalso enforces the length: a 64-character name made of allowed characters is rejected for its length.A folder name that can be made into a hostname still is (
My_App→my-app), andflock link my-projectis unchanged. For a config that is already broken by an older version,cd <folder> && flock unlinkremoves the nameless entry; thenflock link <name>links the folder properly.How I tested it
mainat 346231b: a daemon with a workingokapp.test(HTTP 404 from its web server);flock linkinside我的项目exited 0 and stored an empty site;flock statuswarned about.test; after a daemon restart nothing listened on the web port (HTTP 000).flock unlinkplus a restart broughtokapp.testback (HTTP 404).go test ./internal/config -run 'TestUpsertRejectsUnusableSiteNames|TestAllSitesSkipsParkedFoldersWithoutASiteName'go test ./internal/cli -run 'TestLinkNeedsANameWhenTheFolderMakesNoSiteName|TestLinkRejectsNamesThatAreNotHostnames|TestLinkStoresValidSiteNames'go test ./internal/api -run TestSiteAndParkedEndpoints(on 346231b Add Site returns 200 and stores the empty name)go build ./...,go veton every non-tool package,go test -race ./...(all packages) andgo run ./tools/docslintpass on Linux;GOOS=windowsandGOOS=darwinvet pass for the changed packages.flock linkinside我的项目exits non-zero, explains the folder name cannot become a site name and stores nothing;flock link my-projectlinks it andokapp.teststill answers after a daemon restart; parking a parent folder that contains我的项目lists only the usable subfolders;POST /v1/sitesfor that folder returns HTTP 400"我的项目" can't be made into a site name — pass one: flock link <name>and stores nothing.{"name":"","path":"…/我的项目"}) recovers withflock unlinkin the folder (unlinked) followed byflock link my-project; verified with binaries built from 346231b and from this branch.Only Linux was available locally; the change is Go-only and CI covers macOS, Windows, Linux amd64 and Linux arm64.
Checklist
docs/, or no docs change is neededlang/README.md(a new key when the meaning changes), or there are noneSummary by CodeRabbit