An investigation needs Prometheus's own metrics, and Prometheus publishes an MCP server, so the connectors module now runs MCP servers as published instead of wrapping them: a stdio binary in its own user and network namespace with an egress allow-list, or an HTTP endpoint dialled through declared egress. Acceptance names the transport, the tools it permits, and the credential slots that resolve into the server's environment (stdio) or Authorization header (HTTP). Each permitted tool is declared as a lookup, or as an action with its effect; a tool the server lists but the acceptance doesn't name is never offered, and a declared tool the server doesn't list fails the start rather than going silently missing. Declared tools reach agents beside connector lookups through the same declaration and the same call path, with the server's own input schema, under a name no connector can take: an accepted name runs one package. A server that fails to start, exits or stops answering is reported by readiness and reconnected with backoff. Tool calls carry a deadline, results are capped, and an error result fails its call with the server's own text rather than the run. The investigate prompt now asks for a time-until-full figure from `predict_linear` through the metrics server instead of an estimate from raw points. The old core MCP path stays for now: the legacy gateway and task containers still read config.Tools.MCPServers, so it goes with them.
90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
package connectors
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestCredentialSlotsReachOnlyTheirOwnServer guards 2.5's boundary at the MCP
|
|
// server: a slot resolves into that server's environment or its Authorization
|
|
// header and nothing else, a kind that isn't an HTTP auth scheme is refused
|
|
// rather than handed over unshaped, and a second server's slot never appears in
|
|
// the first one's.
|
|
func TestCredentialSlotsReachOnlyTheirOwnServer(t *testing.T) {
|
|
bearer := map[string]string{"token": "s3cret"}
|
|
basic := map[string]string{"username": "archie", "password": "hunter2"}
|
|
tests := []struct {
|
|
name string
|
|
slot string
|
|
kind string
|
|
fields map[string]string
|
|
http bool
|
|
want []string
|
|
header string
|
|
refused bool
|
|
}{
|
|
{
|
|
name: "a bearer token in a stdio server's environment", slot: "metrics", kind: kindBearer,
|
|
fields: bearer, want: []string{"METRICS_TOKEN=s3cret"},
|
|
},
|
|
{
|
|
name: "a basic credential in a stdio server's environment", slot: "metrics", kind: kindBasic,
|
|
fields: basic, want: []string{"METRICS_USERNAME=archie", "METRICS_PASSWORD=hunter2"},
|
|
},
|
|
{
|
|
name: "a bearer token as a header", slot: "metrics", kind: kindBearer, fields: bearer, http: true,
|
|
header: "Bearer s3cret",
|
|
},
|
|
{
|
|
name: "a basic credential as a header", slot: "metrics", kind: kindBasic, fields: basic, http: true,
|
|
header: "Basic " + base64.StdEncoding.EncodeToString([]byte("archie:hunter2")),
|
|
},
|
|
{
|
|
name: "a slot named with a dot still makes a usable variable", slot: "prom.mcp", kind: kindBearer,
|
|
fields: bearer, want: []string{"PROM_MCP_TOKEN=s3cret"},
|
|
},
|
|
{
|
|
name: "a machine credential is refused rather than handed over unshaped", slot: "metrics", kind: "machine",
|
|
fields: map[string]string{"username": "archie", "private_key": "key"}, refused: true,
|
|
},
|
|
{
|
|
name: "an age identity is refused too", slot: "metrics", kind: "age",
|
|
fields: map[string]string{"identity": "AGE-SECRET-KEY-1"}, refused: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.http {
|
|
header, err := mcpAuthorization(tt.kind, tt.fields)
|
|
if refused := err != nil; refused != tt.refused {
|
|
t.Fatalf("refused = %v, want %v (%v)", refused, tt.refused, err)
|
|
}
|
|
if tt.refused {
|
|
return
|
|
}
|
|
if header != tt.header {
|
|
t.Fatalf("authorization = %q, want %q", header, tt.header)
|
|
}
|
|
return
|
|
}
|
|
env, err := mcpEnv(tt.slot, tt.kind, tt.fields)
|
|
if refused := err != nil; refused != tt.refused {
|
|
t.Fatalf("refused = %v, want %v (%v)", refused, tt.refused, err)
|
|
}
|
|
if tt.refused {
|
|
return
|
|
}
|
|
if !slices.Equal(env, tt.want) {
|
|
t.Fatalf("environment = %v, want %v", env, tt.want)
|
|
}
|
|
for _, line := range env {
|
|
if strings.Contains(line, "AGE-SECRET-KEY") || strings.Contains(line, "private_key") {
|
|
t.Fatalf("credential %q leaked into the server's environment", line)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|