Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Make OIDC Test require the same issuer identity as sign-in
pulse-triage[bot]ea6f38be77ee
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex da52fea6ba..884069535c 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -4946,7 +4946,14 @@ the authoritative analysis outcome.metadata URLs and OIDC issuer URLs must reject non-HTTP or userinfo-bearinginputs before any outbound request is attempted, and OIDC discovery mustappend `/.well-known/openid-configuration` beneath the configured issuer- base path instead of resetting to the origin root.+ base path instead of resetting to the origin root. OIDC Test must reject a+ missing discovery issuer or any byte-for-byte mismatch with the configured+ issuer, including trailing slashes and case, just as normal sign-in+ discovery does. Use bounded `missing_discovery_issuer` / `issuer_mismatch`+ failures without reflecting untrusted discovery values. Successful Test+ only establishes discovery and issuer equality, not client credentials or+ sign-in, and must say so. Testing must not change saved provider settings,+ secrets, admission restrictions or local administrator recovery.32. Keep SSO provider-detail payloads edit-complete and non-secret:`GET /api/security/sso/providers/{id}` may keep flat list/card fields forsummary compatibility, but it must also return the nested OIDC/SAML fields@@ -7222,6 +7229,13 @@ egress boundary. It is exported via `pkg/securityutil`, withsuch as `pulse-enterprise` can reuse the same DNS-rebinding-safe dial andredirect policy for operator-configured audit webhooks instead of reintroducingraw `http.Client` egress paths.+The admin OIDC Test verdict must match normal sign-in's nonempty exact issuer+comparison. `TestOIDCConnectionIssuerParity` couples matching, trailing-slash,+case, realm, authority and missing-issuer controls to `NewOIDCService`.+`TestContractSSOOIDCIssuerConsumer` exercises the authenticated route, canonical+collections, non-reflecting failures and unchanged provider/credential/admin+state. The existing Settings SSO result consumes these qualified outcomes;+metadata success alone is never sign-in acceptance.That same SSO boundary also owns manual SAML endpoint validation payloads.`internal/api/identity_sso_handlers.go`, `internal/api/saml_service.go`, and`internal/api/contract_test.go` must preserve both `idpSsoUrl` and optionaldiff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 30734add4c..af88125c40 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -28268,3 +28268,82 @@ func TestContractSSOEnvironmentBoundaryConsumer(t *testing.T) {}}}++// The real authenticated SSO test route must report issuer failures without+// changing a saved provider, its secret/restrictions, or local admin recovery.+func TestContractSSOOIDCIssuerConsumer(t *testing.T) {+ const token = "oidc-issuer-consumer-synthetic-token.12345678"+ record := newTokenRecord(t, token, []string{config.ScopeSettingsRead, config.ScopeSettingsWrite}, nil)+ r := NewRouter(newTestConfigWithTokens(t, record), nil, nil, nil, nil, "test")+ seedRestrictedSSOProvider(t, r)+ before, err := json.Marshal(r.currentSSOConfig())+ if err != nil {+ t.Fatal(err)+ }+ beforeFiles := ssoAdmissionFiles(t, r.config.DataPath)+ beforeAuthUser, beforeAuthPass := r.config.AuthUser, r.config.AuthPass+ var frames []map[string]interface{}+ var discovered atomic.Value+ discovered.Store("")+ server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {+ if req.Method != http.MethodGet || req.URL.Path != "/realms/pulse/.well-known/openid-configuration" {+ t.Errorf("unexpected diagnostic request: %s %s", req.Method, req.URL.Path)+ http.NotFound(w, req)+ return+ }+ w.Header().Set("Content-Type", "application/json")+ _ = json.NewEncoder(w).Encode(map[string]interface{}{+ "issuer": discovered.Load().(string), "token_endpoint": "https://idp.example.test/token",+ "authorization_endpoint": "https://idp.example.test/authorize", "jwks_uri": "https://idp.example.test/jwks",+ })+ }))+ defer server.Close()+ issuer := server.URL + "/realms/pulse"+ for _, tt := range []struct {+ name, reported, code string+ status int+ }{+ {"mismatch", issuer + "/other", "issuer_mismatch", http.StatusBadRequest},+ {"missing", "", "missing_discovery_issuer", http.StatusBadRequest},+ {"exact", issuer, "", http.StatusOK},+ } {+ discovered.Store(tt.reported)+ payload, _ := json.Marshal(SSOTestRequest{Type: "oidc", OIDC: &OIDCTestConfig{IssuerURL: issuer, ClientID: "synthetic-client"}})+ req := httptest.NewRequest(http.MethodPost, "/api/security/sso/providers/test", bytes.NewReader(payload))+ req.Header.Set("X-API-Token", token)+ req.Header.Set("Content-Type", "application/json")+ setTestIP(req)+ w := httptest.NewRecorder()+ r.Handler().ServeHTTP(w, req)+ if w.Code != tt.status {+ t.Fatalf("%s: status %d, want %d: %s", tt.name, w.Code, tt.status, w.Body.String())+ }+ var response SSOTestResponse+ if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {+ t.Fatal(err)+ }+ if response.Success != (tt.status == http.StatusOK) || response.Error != tt.code {+ t.Fatalf("%s: misleading result: %+v", tt.name, response)+ }+ if response.Success {+ if response.Details == nil || response.Details.Certificates == nil || response.Details.SupportedScopes == nil {+ t.Fatal("successful details must have canonical empty collections")+ }+ } else if response.Details != nil || tt.reported != "" && strings.Contains(w.Body.String(), tt.reported) {+ t.Fatal("failure must not echo untrusted issuer or validated details")+ }+ if strings.Contains(w.Body.String(), "fixture-secret") || strings.Contains(w.Body.String(), "synthetic-token") {+ t.Fatal("diagnostic exposed a saved credential")+ }+ frames = append(frames, map[string]interface{}{"name": tt.name, "request": string(payload), "status": w.Code, "body": w.Body.String()})+ after, err := json.Marshal(r.currentSSOConfig())+ if err != nil || string(before) != string(after) || !reflect.DeepEqual(beforeFiles, ssoAdmissionFiles(t, r.config.DataPath)) || r.config.AuthUser != beforeAuthUser || r.config.AuthPass != beforeAuthPass {+ t.Fatalf("%s: a diagnostic changed provider settings, files or local admin recovery: %v", tt.name, err)+ }+ }+ encoded, err := json.Marshal(frames)+ if err != nil {+ t.Fatal(err)+ }+ t.Logf("OIDC_CONSUMER_FRAMES %s", encoded)+}diff --git a/internal/api/identity_sso_handlers.go b/internal/api/identity_sso_handlers.goindex 81e8491fe9..2fb4d22967 100644--- a/internal/api/identity_sso_handlers.go+++ b/internal/api/identity_sso_handlers.go@@ -1113,12 +1113,22 @@ func (r *Router) testOIDCConnection(ctx context.Context, cfg *OIDCTestConfig) SS}}- // Validate issuer matches- if discovery.Issuer != cfg.IssuerURL && discovery.Issuer != strings.TrimRight(cfg.IssuerURL, "/") {- log.Warn().- Str("expected", cfg.IssuerURL).- Str("actual", discovery.Issuer).- Msg("OIDC issuer mismatch - this may cause token validation issues")+ // Normal sign-in uses oidc.NewProvider, which requires the discovery issuer+ // to equal the configured issuer byte-for-byte. Do not normalise this+ // identity comparison just because the fetch URL has been normalised.+ if discovery.Issuer == "" {+ return SSOTestResponse{+ Success: false,+ Message: "OIDC discovery did not return an issuer. Sign-in requires an exact issuer match.",+ Error: "missing_discovery_issuer",+ }+ }+ if discovery.Issuer != cfg.IssuerURL {+ return SSOTestResponse{+ Success: false,+ Message: "OIDC discovery issuer does not exactly match the Issuer URL. Check the URL, including any trailing slash.",+ Error: "issuer_mismatch",+ }}details := &SSOTestDetails{@@ -1132,7 +1142,7 @@ func (r *Router) testOIDCConnection(ctx context.Context, cfg *OIDCTestConfig) SSreturn SSOTestResponse{Success: true,- Message: "OIDC discovery successful",+ Message: "OIDC discovery succeeded with an exact issuer match. Client credentials and sign-in have not been tested.",Details: details,}}diff --git a/internal/api/sso_handlers_test.go b/internal/api/sso_handlers_test.goindex 02e2cbaf10..bca992e870 100644--- a/internal/api/sso_handlers_test.go+++ b/internal/api/sso_handlers_test.go@@ -6,6 +6,7 @@ import ("fmt""net/http""net/http/httptest"+ "strings""sync/atomic""testing")@@ -208,7 +209,7 @@ func TestHandleTestSSOProvider_OIDCSuccess(t *testing.T) {discoveryServer := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {if r.URL.Path == "/.well-known/openid-configuration" {w.Header().Set("Content-Type", "application/json")- w.Write([]byte(testOIDCDiscovery))+ fmt.Fprint(w, strings.Replace(testOIDCDiscovery, "https://idp.example.com", "http://"+r.Host, 1))} else {w.WriteHeader(http.StatusNotFound)}diff --git a/internal/api/sso_oidc_issuer_test.go b/internal/api/sso_oidc_issuer_test.gonew file mode 100644index 0000000000..a78e196632--- /dev/null+++ b/internal/api/sso_oidc_issuer_test.go@@ -0,0 +1,84 @@+package api++import (+ "encoding/json"+ "net/http"+ "strings"+ "sync/atomic"+ "testing"++ "github.com/rcourtman/pulse-go-rewrite/internal/config"+ "github.com/stretchr/testify/require"+)++// TestOIDCConnectionIssuerParity compares the diagnostic with the actual+// sign-in service, not a second implementation of the issuer comparison.+func TestOIDCConnectionIssuerParity(t *testing.T) {+ for _, tt := range []struct {+ name string+ configured string+ discovered string+ omit bool+ wantError string+ }{+ {name: "exact", configured: "/realms/pulse", discovered: "/realms/pulse"},+ {name: "exact trailing slash", configured: "/realms/pulse/", discovered: "/realms/pulse/"},+ {name: "configured trailing slash", configured: "/realms/pulse/", discovered: "/realms/pulse", wantError: "issuer_mismatch"},+ {name: "discovered trailing slash", configured: "/realms/pulse", discovered: "/realms/pulse/", wantError: "issuer_mismatch"},+ {name: "case mismatch", configured: "/realms/pulse", discovered: "/realms/Pulse", wantError: "issuer_mismatch"},+ {name: "different realm", configured: "/realms/pulse", discovered: "/realms/other", wantError: "issuer_mismatch"},+ {name: "different authority", configured: "/realms/pulse", discovered: "https://foreign.example.test/realms/pulse", wantError: "issuer_mismatch"},+ {name: "omitted issuer", configured: "/realms/pulse", omit: true, wantError: "missing_discovery_issuer"},+ {name: "empty issuer", configured: "/realms/pulse", wantError: "missing_discovery_issuer"},+ {name: "whitespace issuer", configured: "/realms/pulse", discovered: " ", wantError: "issuer_mismatch"},+ } {+ t.Run(tt.name, func(t *testing.T) {+ var requests atomic.Int32+ server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {+ requests.Add(1)+ require.Equal(t, http.MethodGet, req.Method)+ require.Equal(t, strings.TrimRight(tt.configured, "/")+"/.well-known/openid-configuration", req.URL.Path)+ base := "http://" + req.Host+ document := map[string]interface{}{+ "authorization_endpoint": base + "/authorize",+ "token_endpoint": base + "/token",+ "jwks_uri": base + "/jwks",+ }+ if !tt.omit {+ issuer := tt.discovered+ if strings.HasPrefix(issuer, "/") {+ issuer = base + issuer+ }+ document["issuer"] = issuer+ }+ w.Header().Set("Content-Type", "application/json")+ require.NoError(t, json.NewEncoder(w).Encode(document))+ }))+ defer server.Close()+ issuer := server.URL + tt.configured++ response := (&Router{}).testOIDCConnection(t.Context(), &OIDCTestConfig{IssuerURL: issuer})+ require.Equal(t, tt.wantError == "", response.Success)+ require.Equal(t, tt.wantError, response.Error)+ if tt.wantError == "" {+ require.Equal(t, issuer, response.Details.EntityID)+ require.Contains(t, response.Message, "Client credentials and sign-in have not been tested.")+ } else {+ require.Nil(t, response.Details, "untrusted discovery values must not be presented as validated details")+ require.NotContains(t, response.Message, server.URL)+ require.NotContains(t, response.Message, "foreign.example.test")+ }++ service, err := NewOIDCService(t.Context(), &config.OIDCConfig{+ Enabled: true, IssuerURL: issuer, ClientID: "synthetic-client",+ ClientSecret: "synthetic-not-tested", RedirectURL: "https://pulse.example.test/api/oidc/callback",+ Scopes: []string{"openid"},+ })+ if service != nil {+ defer service.stateStore.Stop()+ }+ require.Equal(t, response.Success, err == nil, "diagnostic and real sign-in discovery disagree: %v", err)+ require.Equal(t, int32(2), requests.Load(), "each discovery is one read-only fetch, without token or JWKS requests")+ })+ }+}