Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **`PEERS` names are resolved again while the relay runs, so peers behind a name join and leave without a restart; an entry without a port is an SRV name (`_moqt._udp.hubs.example.com`) (`internal/relay`).** A `PEERS` entry that is neither `host:port` nor a name without a port now stops the relay at startup, and a host that doesn't resolve is retried instead of being dialed by name.
- **The relay re-reads its certificates while it runs (`internal/relay`).** About once a minute it reads `CERT_FILE`/`KEY_FILE`, `PEER_CERT_FILE`/`PEER_KEY_FILE` and `CA_FILE` and compares them with what it holds; what changed is taken from the next TLS handshake on, so cert-manager, a Vault or step-ca agent, or any job that writes the files needs no restart. A public certificate is taken once it parses and matches its key; a peer certificate and the CA together, once they pass the startup checks (issued by the CA, the peering name, valid now). Anything else is logged, once per distinct error rather than at every read, and the certificates in use are kept; renewal tools should replace the files atomically (write, then rename). Sessions already established are untouched. The CA is now checked at each handshake on both sides: as the dialed relay (`GetConfigForClient`) and as the dialer (`VerifyConnection` against the current CA, with the same checks crypto/tls made). The relay's key-set and usage requests are signed with the renewed peer certificate (`reqsign.Signer.Rotate`), and `qumo dns` re-reads its `PEER_CERT_FILE`/`PEER_KEY_FILE` on the same one-minute cadence and signs its feed reads with a renewed pair (`internal/certreload`, shared by both). New metrics: `qumo_relay_cert_reloads_total{cert,result}` and `qumo_relay_cert_not_after_seconds{cert}`, and `qumo_dns_cert_reloads_total{cert,result}` and `qumo_dns_cert_not_after_seconds{cert}`; alert on the `not_after` gauges. A CA is rotated by putting the new one beside the old in `CA_FILE` first ([TLS & mTLS](docs/site/content/en/docs/deployment/tls.md#certificate-renewal)).

### Changed

- **Usage reporting is a package of its own, for every server to use (`internal/meter`).** What sends usage records (`usage.Record`) to `QUMO_USAGE_URL` is no longer the relay's: `meter.Reporter` takes a server's sessions (`Open`, `Report` with cumulative metrics, `Close`) and running totals per key (`Total`), and keeps them in memory, coalesces each session's usage, batches by 500, retries through an outage, signs the requests when given a signer and sends what is left at shutdown, as the relay did. The relay reports through it, with what it decides itself (a publisher by itself, viewers in one total per key) kept in `internal/auth`. The records the relay sends are unchanged.

### Fixed

- **A subscriber that stops one group keeps its subscription (`internal/relay`).** Egress took any failed write to a group stream for the subscriber leaving and ended its subscription, so a subscriber that stopped one group's stream (STOP_SENDING), as a player gives up a late group or one of a rendition it is leaving, lost the track. A failed write while the subscription is open now abandons that group alone.
Expand Down
22 changes: 0 additions & 22 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ package auth
import (
"errors"
"fmt"
"net"
"net/http"
"net/url"
)

// maxBody bounds how much of a reply's body is drained.
Expand Down Expand Up @@ -60,26 +58,6 @@ func RefusalStatus(err error) int {
return http.StatusServiceUnavailable
}

// checkURL accepts an https URL, or http only on a loopback host: the bearer
// token the relay sends to it must not cross a network in the clear.
func checkURL(rawURL string) error {
u, err := url.Parse(rawURL)
if err != nil {
return err
}
switch u.Scheme {
case "https":
case "http":
host := u.Hostname()
if ip := net.ParseIP(host); host != "localhost" && (ip == nil || !ip.IsLoopback()) {
return fmt.Errorf("http is allowed only for a loopback host, got %q", host)
}
default:
return fmt.Errorf("want an https URL, got scheme %q", u.Scheme)
}
return nil
}

// Request is one session event: what the relay asks its Authorize about at
// connect and revalidate, and reports to its End.
type Request struct {
Expand Down
24 changes: 0 additions & 24 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestCheckURL(t *testing.T) {
tests := map[string]struct {
url string
wantErrText string
}{
"https": {url: "https://keys.example.com/v1/set"},
"loopback http": {url: "http://127.0.0.1:4440/"},
"localhost http": {url: "http://localhost:4440/"},
"http off loopback": {url: "http://keys.example.com/", wantErrText: "loopback"},
"another scheme": {url: "ftp://keys.example.com/", wantErrText: "https"},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
err := checkURL(tt.url)

if tt.wantErrText != "" {
assert.ErrorContains(t, err, tt.wantErrText)
return
}
assert.NoError(t, err)
})
}
}

func TestRefusalStatus(t *testing.T) {
tests := map[string]struct {
err error
Expand Down
2 changes: 1 addition & 1 deletion internal/auth/keysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (u *urlKeySource) touchCache(now time.Time) {
}

func newURLKeySource(rawURL, bearer string, signer *reqsign.Signer) (*urlKeySource, error) {
if err := checkURL(rawURL); err != nil {
if err := reqsign.CheckURL(rawURL); err != nil {
return nil, err
}
return &urlKeySource{url: rawURL, token: bearer, signer: signer, client: reqsign.NoRedirectClient(keysFetchTimeout)}, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/auth/signed_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func TestVerifier_SignsItsRequests(t *testing.T) {

require.NoError(t, v.source.refresh(t.Context(), &store, time.Now()))
v.usage.open("s1", testUsageSession)
assert.Error(t, v.usage.flush(t.Context()))
require.NoError(t, v.usage.flush(t.Context()))
assert.Error(t, v.usage.meter.Flush(t.Context()))
require.NoError(t, v.usage.meter.Flush(t.Context()))

require.Len(t, keyReqs.all(), 1)
assertSigned(t, keyReqs.all()[0], "relay-token")
Expand Down
Loading
Loading