Repository navigation
feat: authenticate gossip messages, and refuse to start without a secret (#206) - #270
Merged
Merged
Conversation
…without a secret (#206) The gossip protocol runs over UDP and verified nothing about who sent a datagram. Any host that could reach the port could add itself to the cluster, announce that a node was dead, or announce that it held the current copy of a cached object — which is a path to a reading process being served bytes chosen by whoever sent the last announcement. Every message is now wrapped in an envelope carrying an HMAC-SHA256 over the exact bytes of the inner message. Two properties of the ordering are load-bearing and are not incidental: The MAC is verified before the payload is parsed, so a datagram from an unauthenticated source never reaches the JSON decoding of any message type, let alone a handler. And freshness is checked after the MAC, because the nonce cache must not be writable by an unauthenticated sender — otherwise flooding it with random message IDs would evict the real entries and re-open the replay window. The MAC covers a json.RawMessage of what arrived, never a re-marshal. Re-marshaling to verify would make the check depend on Go's map ordering and number formatting agreeing byte-for-byte with the sender's, which is true today between identical builds and a silent cluster-wide authentication failure the first time it is not. A MAC authenticates the sender but not the moment, so messages carry a timestamp and ID checked against a 30-second window with a nonce cache: a captured "node N owns key K" cannot be replayed later to undo the state that replaced it. A window plus a nonce cache rather than a per-node sequence, because a sequence has to survive restarts to be monotonic — which reintroduces the fsync-before-ack obligation that per-key conditional writes exist to avoid. Authentication is wired at the two chokepoints, sendMessage and handleIncomingMessage, which are the only places that write to and read from the socket. So a new message type cannot be introduced unauthenticated by forgetting a step; there is no step to forget. Fail closed: with no secret configured, NewClusterManager returns an error naming both OBJECTFS_CLUSTER_SECRET and cluster.secret_file rather than starting unauthenticated. Running without authentication is the failure nobody notices. That behavior broke five existing tests when it landed, which is the evidence that it cannot be bypassed — they are updated to supply a secret, and the multi-node test supplies one secret for the whole cluster rather than one per node, since three different secrets would produce three clusters of one, which is the failure that test exists to distinguish from a working cluster. The secret comes from the environment or a file, never a YAML field: packaging installs the shipped configuration world-readable, so a secret there would be published to every user on the node. A file readable by anyone but its owner is refused, as is one shorter than 32 bytes, and both errors say how to generate a good one. examples/config.yaml says why there is no secret_file key in it rather than adding an inert one. Rejections are counted separately for a bad MAC, a replay, and an unknown envelope version, each with its own operator hint, because the three send someone to three different places: a cluster of one with a rising unauthenticated count is a wrong secret, while the same cluster with a rising wrong-version count is a half-finished upgrade. An unenveloped message decodes as version 0 and is therefore reported as version skew, not as a bad secret — which is correct, since a peer sending one is running a build from before this change. Verified by mutation, per the rule that a predicted failure signature is not a verified one. Five mutations, each caught: a MAC comparison that always succeeds, a skipped freshness check, a missing secret that falls back to a default, a removed permissions check, and — the one that matters most — a bypass at the chokepoint that falls through to the bare message when authentication fails. The package documentation states what this does not do: payloads are not encrypted, and because every member holds the same key, a compromised node can impersonate any other. Its two cluster-setup examples also no longer set an Enabled field and a FailureTimeout field that do not exist on the type, or call NewCoordinator with two of its three arguments. Note that tests/distributed_test.go, which is behind -tags=distributed, has a pre-existing failure unrelated to this change: TestConcurrentOperations reports "Failed 10 out of 10" and then "Successful: 10, Failed: 0" in the same run, because a failed operation is counted as a success. Filed as #269. No CI job compiles that tag, which is #240.
golangci-lint's gosec honors only //nolint; the standalone gosec whose SARIF feeds GitHub code scanning honors only #nosec, and it wants #nosec in the trailing comment rather than after a //nolint on the same line. So a finding suppressed one way passes the lint job and fails the security check — which is what happened here: lint reported 0 issues while code scanning gated the pull request on G304. Both sites are deliberate and neither is fixable by changing the code. auth.go reads a file at an operator-supplied path, which is the whole function. The test writes a 0644 secret file because that is the insecure file the loader must refuse; satisfying G306 there would delete the test. Matches the existing convention in internal/fuse/unmount_path.go and internal/awsrates/offerfile/cmd/genrates/main.go, whose comments already document this trap. It is #264.
5 tasks
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 #206.
The gossip protocol runs over UDP and verified nothing about who sent a datagram. Any host that could
reach the port could add itself to the cluster, announce that a node was dead, or announce that it
held the current copy of a cached object — which is a path to a reading process being served bytes
chosen by whoever sent the last announcement.
Every message is now wrapped in an envelope carrying an HMAC-SHA256 over the exact bytes of the inner
message.
The design, in the parts that are load-bearing
Authentication happens at two chokepoints.
sendMessageandhandleIncomingMessageare the onlyplaces that write to and read from the socket, so authentication is wired there rather than per
message type. A new message type cannot be introduced unauthenticated by forgetting a step, because
there is no step to forget.
The MAC is verified before the payload is parsed. A datagram from an unauthenticated source never
reaches the JSON decoding of any message type, let alone a handler.
Freshness is checked after the MAC. The nonce cache must not be writable by an unauthenticated
sender — otherwise flooding it with random message IDs would evict the real entries and re-open the
replay window.
The MAC covers a
json.RawMessageof what arrived, never a re-marshal. Re-marshaling to verifywould make the check depend on Go's map ordering and number formatting agreeing byte-for-byte with
the sender's. That is true today between identical builds, and a silent cluster-wide authentication
failure the first time it is not.
Replay protection is a window plus a nonce cache, not a sequence number. A MAC authenticates the
sender but not the moment, so a captured "node N owns key K" would otherwise stay valid forever and
could be replayed to undo the state that replaced it. A per-node monotonic sequence would have to
survive restarts to be monotonic, which reintroduces the fsync-before-ack obligation that per-key
conditional writes exist to avoid; a 30-second window bounds the cache with no persistent state, and
a restart is indistinguishable from a normal message.
It fails closed. With no secret configured,
NewClusterManagerreturns an error naming bothOBJECTFS_CLUSTER_SECRETandcluster.secret_filerather than starting unauthenticated. Runningwithout authentication is the failure nobody notices. This broke five existing tests when it landed,
which is the evidence that it cannot be bypassed — and the multi-node test now supplies one secret
for the whole cluster rather than one per node, since three different secrets would produce three
clusters of one, the exact failure that test exists to distinguish from a working cluster.
The secret is never a YAML field. Packaging installs the shipped configuration world-readable, so
a secret there would be published to every user on the node. Environment or file only; a file
readable by anyone but its owner is refused, as is one shorter than 32 bytes, and both errors say how
to generate a good one.
examples/config.yamlexplains why there is nosecret_filekey in itrather than adding one that nothing reads.
Rejections are counted three ways, not one. A bad MAC, a replay, and an unknown envelope version
each get their own counter and their own operator hint, because they send someone to three different
places: a cluster of one with a rising unauthenticated count is a wrong secret; the same cluster with
a rising wrong-version count is a half-finished upgrade. An unenveloped message decodes as version 0
and is therefore reported as version skew rather than a bad secret — correct, since a peer sending
one is running a build from before this change.
What it does not do
Stated in the package documentation rather than left to be assumed: payloads are not encrypted (they
are membership metadata and cache keys), and because every member holds the same key, a compromised
node can impersonate any other. Per-node keys are a different threat model.
Verification
Mutation-verified, per the rule that a predicted failure signature is not a verified one. Five
mutations, each caught by the tests:
TestUnauthenticatedJoinIsRejected,TestTamperedPayloadIsRejectedTestClusterRefusesToStartWithoutASecretTestLoadClusterSecret,TestSecretFilePermissionsTestUnauthenticatedJoinIsRejectedThe last one is the one that matters most: an authenticator that verifies correctly while a handler
runs anyway would pass every test that only checks the verifier's return value. So the join tests
assert on observable cluster state — "the intruder is not in the nodes map" — and not only on errors.
Gates:
go build,go vet,gofmt -lclean, full suite green under-race, coverage gate 34packages at or above floor (
internal/distributed70.0%),golangci-lint --new-from-merge-base0 issues.
One thing found along the way, not fixed here
tests/distributed_test.gois behind-tags=distributedand has a pre-existing failure that thisbranch did not introduce (confirmed by stashing):
TestConcurrentOperationsprintsFailed 10 out of 10 concurrent operationsand thenSuccessful: 10, Failed: 0in the same run,because a failed operation is counted as a success. Filed as #269. That no CI job compiles this tag
is #240, and this is what it would have caught.