Repository navigation
feat(config): refuse a wildcard advertise_addr, and an operator guide for clustering (#152) - #418
Merged
Merged
Conversation
… for clustering (#152) Nothing validated the `cluster:` block before this. `Validate` checked storage, cache, network, monitoring and mount, then returned — so every value below was accepted and discovered, if at all, as a runtime symptom on a different host. The defect worth naming is one #152 does not mention, found by probing rather than by reading the issue. `listen_addr` defaults to `0.0.0.0:8080` and `advertise_addr` is the next key in the file, so copying the value down is the obvious operator move, and it is the worst one available. `advertise_addr` is what peers are told to dial, and a peer that dials a wildcard reaches its own loopback: measured with net.DialUDP, `0.0.0.0:8080` resolves to `remote=127.0.0.1:8080` and `[::]:8080` to `remote=[::1]:8080`, and the dial *succeeds*. Gossip is one-way UDP, so no send fails and no reply is expected — a three-node cluster becomes three clusters of one, each mounting, serving reads and reporting healthy, and each able to serve an object a peer has already overwritten. That is an integrity outcome with no error anywhere, so it fails closed. Also refused: a negative `replication_factor` (applyConfigDefaults only substitutes for 0, so a negative value survives, SelectNodes returns nothing for any count <= 0, and every write fails with "no target nodes selected" — naming neither the key nor the value), a non-host:port address, a non-numeric port, and port 0 on `advertise_addr`. Port 0 stays legal on `listen_addr`, because the asymmetry is real and measured: ListenUDP on 127.0.0.1:0 binds and the kernel assigns a port, while DialUDP to 127.0.0.1:0 fails with "can't assign requested address". This is why validateGossipAddr is separate from validateListenAddr rather than reusing it — the latter's port-0 advice is right for a monitoring endpoint and wrong here. Reusing it first broke two real adapter tests that set `cluster.listen_addr: 127.0.0.1:0` deliberately; the check was wrong, not the tests. Two settings are warnings on --dry-run instead, because each is correct in one deployment and wrong in another: an empty `seed_nodes` is how the first node of a new cluster is configured, and a loopback `advertise_addr` is what NewDefault sets and what the shipped Compose file uses. Refusing either breaks a real deployment; ignoring either ships a silent partition. Warnings go to stderr and the exit code stays 0, so a config-management tool can still bring up a first node. The section reports the cluster secret by source and never by value — a dry run is the kind of output that gets pasted into an issue, and which of OBJECTFS_CLUSTER_SECRET or `secret_file` is in use is the hardest thing to establish from outside, since the environment leaves no trace in the file. Three of the six documentation sections #152 asked for could not be written, and are not faked. `cluster.persistent_log`, `cluster.data_dir` and `peer_fetch_timeout` have zero occurrences in the tree, so the in-memory-to-persistent-log upgrade procedure describes nothing; the consistency-modes section is replaced by CAS-against-S3, because ConsistencyEventual/Session/Strong were removed in 0.12.0 and survive only as a comment recording it. The issue's own proposed check — `enabled && advertise_addr == ""` — can never fire, verified by calling Validate: NewDefault sets the field and applyConfigDefaults sets it again. docs/admin-guide/distributed.md lists what is absent under limitations instead, and corrects two more of the issue's numbers: the gossip port is 8080, not 7946, and the cache-sizing formula must not multiply by `replication_factor`, because the cluster makes no copies and S3 holds the single one. internal/config/docs_distributed_test.go gates the page, because the four existing documentation gates cannot see what it gets wrong: a default written as prose in a table cell is invisible to the YAML gate, the symbol gate and the link gate alike. It pins the defaults against NewDefault, checks every ClusterConfig yaml tag has a table row, checks each documented environment variable against getEnvMappings — #146's defect exactly, four variables documented and unread — and asserts the three absent keys are still absent, which inverts the usual staleness direction: that claim goes stale when someone does the work, at which point the page tells an operator a shipped feature is unavailable. Verified by mutation, since a predicted failure signature has been wrong before: 10 mutations of the two source files and 6 of the documentation gates, all caught, every file restored. The row check needed tightening after one miss — deleting the `secret_file` row passed, because the key is also named in the prose three paragraphs down, so it now requires a table row rather than a mention. go build ./..., gofmt, go vet, golangci-lint (0 issues), go test -race ./... all clean, and the coverage gate passes under CI's own conditions: 35 packages at or above their floor.
…ement TestClusterAddrsAllowPortZeroOnlyWhereItBinds asserted that net.DialUDP to "127.0.0.1:0" fails, on the strength of a measurement made on darwin, where it returns "can't assign requested address". It passed locally and failed in CI at validate_cluster_test.go:215 with the message it was written to print: "dialing 127.0.0.1:0 succeeded ... that rule should be reconsidered rather than kept on faith". Measured on Linux rather than reasoned about: the dial succeeds, reports remote=127.0.0.1:0, and a subsequent Write returns n=12 with a nil error. The datagram goes nowhere. So the rule stands and its justification was half wrong. The platforms differ only in where the failure appears, and Linux — the platform CI runs and most deployments use — is the worse of the two: darwin refuses at the dial, while Linux accepts the address, accepts the send, and drops the datagram with nothing reported at either end. That is exactly the silent-partition shape this validation exists for, so an advertised port 0 is refused on every platform and the error message now describes both behaviours instead of the one I happened to measure. The dial probe is removed rather than made conditional. Its purpose was to keep the rule honest if the platform changed, but a probe that behaves differently per platform asserts something about the runner instead of about the rule. What remains asserted is the half that is observable on both: the listening side binds and the kernel assigns a real port, so port 0 has to stay legal on cluster.listen_addr — which internal/distributed's testConfig sets and ClusterManager.GossipAddr exists to report back. The unobservable half is argued in the doc comment and in the refusal's own message, because a test cannot assert "the send silently goes nowhere" without a receiver to prove the absence against, and a negative over UDP is a timeout rather than a fact. Verified on both platforms this time: ./internal/config/ and ./cmd/objectfs/ pass on darwin and pass in a linux/amd64 container. gofmt clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #152.
What this refuses, and why that list is short
Nothing validated the
cluster:block before this.Validatechecked storage, cache, network,monitoring and mount, then returned — so every value below was accepted and discovered, if at all,
as a runtime symptom on a different host.
The defect worth reading is one #152 does not mention.
listen_addrdefaults to0.0.0.0:8080and
advertise_addris the next key in the file, so copying the value down is the obvious operatormove — and it is the worst one available.
advertise_addris what peers are told to dial, and a peerthat dials a wildcard reaches its own loopback. Measured with
net.DialUDP, replicatinggossip.go'ssendMessage:0.0.0.0:8080remote=127.0.0.1:8080:8080remote=127.0.0.1:8080[::]:8080remote=[::1]:8080The dial succeeds. Since gossip is one-way UDP, no send fails and no reply is expected, so a
three-node cluster silently becomes three clusters of one — each mounting, serving reads and
reporting healthy, and each able to serve an object a peer has already overwritten. An integrity
outcome with no error anywhere, so it fails closed.
Also refused, each with a diagnostic naming the key and the value:
replication_factor—applyConfigDefaultsonly substitutes for0, so a negativevalue survives;
min(rf, len(alive))stays negative,LoadBalancer.SelectNodesreturns[]forany count
<= 0(probed with -1, 0, 1, 3, 99), andexecuteOnceturns that intono target nodes selected— naming neither the key nor the value.advertise_addr.Port 0 stays legal on
listen_addr, because the asymmetry is real and measured:ListenUDPon127.0.0.1:0binds and the kernel assigns a port (49314 observed), whileDialUDPto127.0.0.1:0fails with
can't assign requested address. That is whyvalidateGossipAddris separate fromvalidateListenAddrrather than reusing it — the latter's port-0 advice is right for a monitoringendpoint and wrong here. Reusing it first broke two real
internal/adaptertests that setcluster.listen_addr: 127.0.0.1:0on purpose; the check was wrong, not the tests, andClusterManager.GossipAddrexists precisely to report the kernel-assigned port back.What warns instead of failing
Two settings are legal in one deployment and wrong in another, so they are
--dry-runwarnings:seed_nodes: []advertise_addrRefusing either breaks a real deployment — the second is what
NewDefaultsets and what the shippedCompose file uses. Ignoring either ships a silent partition. Warnings go to stderr and the exit
code stays 0, so a config-management tool can still bring up a first node.
The section reports the cluster secret by source, never by value (
from OBJECTFS_CLUSTER_SECRET,from <path>, ornot configured — the cluster will refuse to start). A dry run gets pasted intoissues, and which of the two sources is in use is the hardest thing to establish from outside, since
the environment leaves no trace in the file.
Three of the six documented sections could not be written
Stated here rather than faked, and repeated in the page's limitations section:
cluster.persistent_log,cluster.data_dirandpeer_fetch_timeouthave zero occurrences inthe tree, so the in-memory-to-persistent-log upgrade procedure describes nothing, and two of the
issue's validation rows have no field to validate.
ConsistencyEventual/Session/ Strongwere removed in 0.12.0 and survive only as a comment recording it.enabled && advertise_addr == ""— can never fire, verifiedby calling
Validate:NewDefaultsets the field andapplyConfigDefaultssets it again.Two more of the issue's numbers are corrected in the page: the gossip port is 8080, not 7946
(7946 is memberlist's default and appears in some test fixtures, but is the default nowhere in the
code — an operator who opens only 7946 gets the silent-partition failure by following the docs), and
the cache-sizing formula must not multiply by
replication_factor, because the cluster makes nocopies. S3 holds the single one; the factor is a selection width.
The documentation gate
internal/config/docs_distributed_test.goexists because the four existing documentation gatescannot see what this page gets wrong: a default written as prose in a table cell is invisible to
the YAML gate, the symbol gate and the link gate alike. It pins the defaults against
NewDefault,requires a table row for every
ClusterConfigyaml tag, checks each documented environment variableagainst
getEnvMappings()— #146's defect exactly, four variables documented and unread — andasserts the three absent keys are still absent. That last one inverts the usual staleness
direction: the claim goes stale when someone does the work, at which point the page is telling an
operator a shipped feature is unavailable, so the test says to write the section rather than delete
the check.
Verification
Mutation-verified, since a predicted failure signature has been wrong here before. 10 mutations of
the two source files (wildcard refusal deleted, negative RF allowed, the
validateClusterConfigcall removed, port 0 allowed on advertise, the enabled guard removed; seed warning suppressed,
loopback warning suppressed,
emitClusterDryRuncall removed, the section printed when the clusteris off, secret material printed) and 6 of the documentation gates — all caught, every file
restored clean.
One mutation initially missed: deleting the
secret_filetable row passed, because the key isalso named in the prose three paragraphs down. The check now requires a row rather than a mention,
and the reason is in the test's comment.
go build ./...,gofmt -l .,go vet ./...— cleangolangci-lint run— 0 issuesgo test -race ./...— passCGO_ENABLED=1 go test -covermode=atomicover the wholetree) — 35 packages at or above their floor
--dry-run: prints the block plus both warnings at exit 0 for a loopback/no-seeds/no-secret config, prints the block with no warnings for a good three-node config, and prints
nothing for
deploy/docker/node-config.yaml