Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/release-qa-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ jobs:
run: |
./dist-bin/release-gate run-suite \
--name suite/server-race --report-dir "${GATE_REPORT_DIR}" \
-- go test -tags server -race ./internal/serveredition/...
-- go test -tags server -race ./internal/serveredition/... ./internal/oauth/...

- name: Upload report fragment
if: always()
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,16 @@ jobs:
- name: Build server edition
run: go build -tags server ./cmd/mcpproxy

# internal/oauth is where the redaction rules live, and half of them are
# build-tagged: serverfields_serveredition.go holds the mask decisions for
# the `auth_broker` block, whose fields do not exist in the personal
# edition. Its canaries — the walk over config.ServerConfig that fails
# when a text-carrying leaf has no decision — therefore only compile under
# `-tags server`. Without this package in the list they never ran, and the
# guarantee the #1161 fix rests on (a field added to the tagged block is
# masked because the walk reaches it) was unenforced in CI.
- name: Test server edition packages
run: go test -race -tags server ./internal/serveredition/... ./internal/config/...
run: go test -race -tags server ./internal/serveredition/... ./internal/config/... ./internal/oauth/...

build:
name: Build
Expand Down
16 changes: 13 additions & 3 deletions internal/oauth/serverconfigfields.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,20 @@ func RedactedServerConfigViews(servers []*config.ServerConfig, r Redaction) []ma
return out
}

// RedactServerConfigSecrets returns a masked COPY of sc under the LIVE policy,
// RedactServerConfigSecrets returns a masked COPY of sc under the given policy,
// for a door that must hand back a *config.ServerConfig rather than a map (the
// server edition's ServerResponse embeds one).
//
// The policy is a PARAMETER because the choice is the caller's and it is not
// obvious. Pass LiveRedaction on a surface whose reader owns the credential and
// may edit it — MaskValue's `••••<last2> (<N> chars)` says which token is
// configured and the write-path unmaskers recognise it. Pass AuditRedaction
// wherever the reader is NOT the owner: for a server edition shared server the
// affordance buys that reader nothing (shared servers are read-only to users)
// while publishing the admin credential's exact length and trailing bytes to
// every tenant of the deployment — a durable fingerprint and a correlation
// handle, which is the case AuditMaskValue was written for.
//
// The input is never mutated and the result shares no map, slice or pointer
// with it: the masked view is decoded into a FRESH struct. That matters because
// the caller's config is typically the LIVE one — `h.sharedServers` is the
Expand All @@ -96,11 +106,11 @@ func RedactedServerConfigViews(servers []*config.ServerConfig, r Redaction) []ma
// unredacted credential is this issue.
//
// Returns nil for a nil config.
func RedactServerConfigSecrets(sc *config.ServerConfig) *config.ServerConfig {
func RedactServerConfigSecrets(sc *config.ServerConfig, r Redaction) *config.ServerConfig {
if sc == nil {
return nil
}
view := RedactedServerConfigView(sc, LiveRedaction)
view := RedactedServerConfigView(sc, r)
encoded, err := json.Marshal(view)
if err != nil {
return &config.ServerConfig{Name: sc.Name}
Expand Down
12 changes: 6 additions & 6 deletions internal/oauth/serverconfigfields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestRedactServerConfigSecrets_MasksEverySecretBearingLeaf(t *testing.T) {
sc := &config.ServerConfig{}
fillTextLeaves(reflect.ValueOf(sc).Elem(), ghpToken)

masked := RedactServerConfigSecrets(sc)
masked := RedactServerConfigSecrets(sc, LiveRedaction)
require.NotNil(t, masked)

for _, path := range findTokenPaths(t, masked, ghpToken) {
Expand All @@ -42,7 +42,7 @@ func TestRedactServerConfigSecrets_MasksEverySecretBearingLeaf(t *testing.T) {
func TestRedactServerConfigSecrets_MasksTheNamedShapes(t *testing.T) {
sc := secretBearingServerConfig()

masked := RedactServerConfigSecrets(sc)
masked := RedactServerConfigSecrets(sc, LiveRedaction)
require.NotNil(t, masked)

assert.NotContains(t, masked.Headers["Authorization"], "hdrsecretvalue")
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestRedactServerConfigSecrets_LeavesTheInputUntouched(t *testing.T) {
sc := secretBearingServerConfig()
pristine := secretBearingServerConfig()

masked := RedactServerConfigSecrets(sc)
masked := RedactServerConfigSecrets(sc, LiveRedaction)
require.NotNil(t, masked)

assert.Equal(t, pristine, sc, "redacting a read payload mutated the config it was built from")
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestRedactServerConfigSecrets_PreservesNonSecretFields(t *testing.T) {
SourceRegistryProvenance: "official",
}

masked := RedactServerConfigSecrets(sc)
masked := RedactServerConfigSecrets(sc, LiveRedaction)
require.NotNil(t, masked)

assert.Equal(t, sc.Name, masked.Name)
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestRedactServerConfigSecrets_PreservesNonSecretFields(t *testing.T) {
}

func TestRedactServerConfigSecrets_NilIsNil(t *testing.T) {
assert.Nil(t, RedactServerConfigSecrets(nil))
assert.Nil(t, RedactServerConfigSecrets(nil, LiveRedaction))
assert.Nil(t, RedactedServerConfigView(nil, LiveRedaction))
}

Expand All @@ -162,7 +162,7 @@ func TestRedactServerConfigSecrets_AgreesWithTheMapView(t *testing.T) {
sc := secretBearingServerConfig()

view := RedactedServerConfigView(sc, LiveRedaction)
typed := RedactServerConfigSecrets(sc)
typed := RedactServerConfigSecrets(sc, LiveRedaction)
require.NotNil(t, typed)

assert.Equal(t, view, NormalizeForRedaction(typed),
Expand Down
21 changes: 19 additions & 2 deletions internal/serveredition/api/credential_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,28 @@ func (h *CredentialHandlers) lookupServer(w http.ResponseWriter, r *http.Request
return srv, true
}

// brokerEntitled reports whether a per-user credential surface may act on this
// upstream at all.
//
// `Shared` is the ENTITLEMENT check (issue #1161 follow-up), not a formality:
// setup.go hands these handlers `deps.Config.Servers` — the admin's WHOLE
// server list — under the name `sharedServers`. Selecting on `AuthBroker != nil`
// alone therefore reached admin upstreams the admin deliberately did not share,
// disclosing their existence and broker mode through the list, and letting any
// authenticated user drive the connect flow against the admin's registered
// OAuth client for a server they were never granted.
//
// Every credential surface selects through this one predicate so a new one
// cannot reintroduce the gap by copying the old two-thirds of the condition.
func brokerEntitled(s *config.ServerConfig) bool {
return s != nil && s.Shared && s.AuthBroker != nil
}

// brokerServerList returns the shared servers that carry an auth_broker block.
func (h *CredentialHandlers) brokerServerList() []*config.ServerConfig {
out := make([]*config.ServerConfig, 0, len(h.brokerServers))
for _, s := range h.brokerServers {
if s != nil && s.AuthBroker != nil {
if brokerEntitled(s) {
out = append(out, s)
}
}
Expand All @@ -337,7 +354,7 @@ func (h *CredentialHandlers) brokerServerList() []*config.ServerConfig {
// brokerServerByName finds a brokered upstream by case-insensitive name.
func (h *CredentialHandlers) brokerServerByName(name string) *config.ServerConfig {
for _, s := range h.brokerServers {
if s != nil && s.AuthBroker != nil && strings.EqualFold(s.Name, name) {
if brokerEntitled(s) && strings.EqualFold(s.Name, name) {
return s
}
}
Expand Down
Loading
Loading