Phase 4: SSO scaffolding, RBAC enforcement, tenant-scoped dashboards, audit logging, K8s deployment
RBAC (api/internal/authz) is live on /query and /dashboards, backed by a new enterprise/ module (session issuance, audit logging, RBAC storage, OIDC/SAML protocol wiring) that core never imports -- only calls over HTTP. Found and fixed a real cross-tenant vulnerability in dashboards (no tenant_id filtering at all) while writing the threat model doc. Two things are explicitly NOT done, documented rather than hidden: tenant isolation for log data itself (/query still shares one ClickHouse connection and Tantivy index across every tenant -- RBAC controls who can query, not what a query can see), and human SSO login (protocol wiring exists, no HTTP handler calls it yet). See docs/security/threat-model.md and docs/phase-4-runbook.md. Also adds deploy/ (Go Operator + Helm chart, validated offline only -- no cluster was reachable in this environment).
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFromContextRoundTrip(t *testing.T) {
|
||||
id := TrustFromValidatedSession("acme-corp")
|
||||
ctx := WithContext(context.Background(), id)
|
||||
|
||||
got, ok := FromContext(ctx)
|
||||
if !ok {
|
||||
t.Fatalf("expected FromContext to find a tenant")
|
||||
}
|
||||
if got.String() != "acme-corp" {
|
||||
t.Fatalf("got %q, want %q", got.String(), "acme-corp")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromContextMissing(t *testing.T) {
|
||||
_, ok := FromContext(context.Background())
|
||||
if ok {
|
||||
t.Fatalf("expected no tenant in a bare context")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromContextDoesNotMatchUnrelatedStringKey(t *testing.T) {
|
||||
// The unexported contextKey type is what closes the "collision" gap
|
||||
// the design doc calls out -- a context.WithValue using a plain
|
||||
// string key must not be found by FromContext.
|
||||
ctx := context.WithValue(context.Background(), "tenant_id", "spoofed") //nolint:staticcheck
|
||||
_, ok := FromContext(ctx)
|
||||
if ok {
|
||||
t.Fatalf("FromContext must not find a value set under an unrelated key type")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user