From 0ef903e1d44478474a651654240676bc1b700eaf Mon Sep 17 00:00:00 2001 From: blurbery <271863866+blurbery@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:53:55 +1100 Subject: [PATCH 01/11] fix(plugins): reuse saved secrets in staged tests only with saved settings A plugin connection test filled every blank secret field from the stored entry, even when the staged entry pointed the plugin at a different server. An admin could change LDAP `urls` or the OIDC `issuer_url`, leave the secret blank, and the test would send the saved bind password or client secret to the new destination. A staged test now reuses a stored secret only while every other field of that entry matches the stored entry, comparing JSON values, treating blank fields as absent and absent fields as their declared defaults. When any other setting changes, only the secrets the admin typed reach the plugin; a required secret left out then fails validation. Saves are unchanged. Closes #2796 --- contracts/api/v2/openapi.json | 4 +- docs/admin-api.md | 7 +- docs/auth-api.md | 2 +- internal/apiv2/admin_plugin_configuration.go | 6 +- internal/apiv2/external_sign_in.go | 2 +- internal/plugins/service_admin_config.go | 80 +++++++-- internal/plugins/service_auth_connection.go | 3 +- internal/plugins/service_connection.go | 168 ++++++++++++++++++- internal/plugins/service_connection_test.go | 162 +++++++++++++++++- web/src/api/v2/schema.ts | 4 +- 10 files changed, 404 insertions(+), 34 deletions(-) diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index 84b4caf961..ad9e4ec758 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -16793,7 +16793,7 @@ }, "value": { "additionalProperties": true, - "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret", + "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while every other field of the entry matches the stored entry", "type": "object", "x-silo-extension-bag": "plugin-json-value" } @@ -109421,7 +109421,7 @@ }, "/api/v2/admin/plugins/installations/{id}/auth-binding/test": { "post": { - "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", + "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while every other field of that entry matches the stored entry; otherwise the test runs with the secret entered, or none. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", "operationId": "testAdminPluginAuthBinding", "parameters": [ { diff --git a/docs/admin-api.md b/docs/admin-api.md index 64d1c6ca6c..57fa4c6d41 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -3501,7 +3501,12 @@ are kept. Manifest-declared secret fields left blank keep their stored value, an removed only when named in `clear_secrets`. The frozen v1 `PUT .../config` shares the clearing rule as a bridge bug fix: before it, an emptied field kept its stored value. The connection test (`.../config/test` and the auth connection test) merges a staged entry the -same way without storing it. The server validates the merged entry against the +same way without storing it, with one difference: a blank secret reuses the stored secret +only while every other field of the entry, after clears and with absent fields read as +their declared defaults, matches the stored entry. A staged entry that changes a server +URL, issuer, CA or any other setting is tested with the secrets the administrator typed, +or without them, so a test never sends a saved credential to a destination it was not +saved for. The server validates the merged entry against the plugin's schema and returns 422 with the plugin's own message on failure, then persists under a compare-and-swap on the stored revision and stops the running plugin so it rebinds. Success is 204. Repeating the same request converges on one stored entry, so the row is diff --git a/docs/auth-api.md b/docs/auth-api.md index ab28b5ae70..48a6c07a95 100644 --- a/docs/auth-api.md +++ b/docs/auth-api.md @@ -706,7 +706,7 @@ linking rule whether or not `network_sign_in` is served. | `POST /admin/users/{id}/identities` (`createAdminUserIdentity`) | acting admin | Links by `installation_id` and the exact `external_subject`. Turns local password sign-in off unless the account is break-glass or the installation is a network identity provider. | | `DELETE /admin/users/{id}/identities/{identity_id}` (`deleteAdminUserIdentity`) | acting admin | May leave the account without a sign-in method; setting a password with `updateAdminUser` turns its local password sign-in back on. | | `PUT /admin/users/{id}` (`updateAdminUser`) | acting admin | `break_glass` sets or clears the flag: admin accounts only, and only the server Owner may change it (403 `permission_denied`). The Owner has it by default (set at first-run setup and on every ownership move) and may clear it on its own account. A `password` also turns the account's local password sign-in back on, so an admin other than the Owner may not set its own while its local sign-in is off (403 `permission_denied`; the v1 route answers `owner_protected`). Demoting, disabling or clearing the last usable break-glass admin while local sign-in is off is 409 `break_glass_required`; so is deleting it (`deleteAdminUser`) or turning `auth.local_password_login` off without one (`updateAdminSettings`, `updateAdminSetting`). | -| `POST /admin/plugins/installations/{id}/auth-binding/test` (`testAdminPluginAuthBinding`) | acting admin | Sends staged `config` entries (blank secrets keep the stored value) to the plugin's `TestConnection`; answers `ok`, the plugin's `steps` and `callback_url`, the redirect URI to register at an OAuth provider (empty without a public URL). A plugin without a connection test, or a disabled installation, is 409. Not retried automatically. | +| `POST /admin/plugins/installations/{id}/auth-binding/test` (`testAdminPluginAuthBinding`) | acting admin | Sends staged `config` entries (blank secrets keep the stored value only while the rest of that entry matches what is stored) to the plugin's `TestConnection`; answers `ok`, the plugin's `steps` and `callback_url`, the redirect URI to register at an OAuth provider (empty without a public URL). A plugin without a connection test, or a disabled installation, is 409. Not retried automatically. | | `PUT /admin/plugins/installations/{id}/auth-binding` (`updateAdminPluginAuthBinding`) | acting admin | Applies without a restart (`X-Silo-Restart-Required: false`). `auto_provision` defaults to true. Enabling a second binding of the same kind is 409 `provider_already_enabled`; one network identity binding may be enabled beside the one OIDC or LDAP binding. | | `GET /admin/plugins/installations` (`listAdminPluginInstallations`) | acting admin | Each OAuth auth binding carries `callback_url` (the v2 callback to register at the provider) and `post_logout_redirect_url` (`/login`, to register for provider logout), both on `server.public_url`; empty without a public URL and for a password provider. The other operations that answer an installation carry them too. | diff --git a/internal/apiv2/admin_plugin_configuration.go b/internal/apiv2/admin_plugin_configuration.go index 8b6568db33..b14dbfa0e3 100644 --- a/internal/apiv2/admin_plugin_configuration.go +++ b/internal/apiv2/admin_plugin_configuration.go @@ -26,10 +26,12 @@ type AdminPluginConfigurationService interface { // value. A declared non-secret top-level field sent as null or a blank string // is removed, so the plugin's default applies; undeclared fields are never // cleared that way. Manifest-declared secret fields left blank keep their -// stored value; a secret is removed only when named in clear_secrets. +// stored value; a secret is removed only when named in clear_secrets. A +// connection test keeps a stored secret only while the rest of the entry +// matches what was saved with it. type AdminPluginConfigWrite struct { Key string `json:"key" minLength:"1" maxLength:"256" doc:"The manifest global_config_schema key"` - Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret"` + Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while every other field of the entry matches the stored entry"` ClearSecrets []string `json:"clear_secrets,omitempty" maxItems:"64" doc:"Secret fields to remove; each must be a manifest-declared secret of this key"` } type AdminPluginConfigInput struct { diff --git a/internal/apiv2/external_sign_in.go b/internal/apiv2/external_sign_in.go index 28360657ce..9efaa2ef9d 100644 --- a/internal/apiv2/external_sign_in.go +++ b/internal/apiv2/external_sign_in.go @@ -562,7 +562,7 @@ func registerExternalSignIn(reg *Registry) { test := Operation{Operation: humaOp(http.MethodPost, Prefix+"/admin/plugins/installations/{id}/auth-binding/test", "testAdminPluginAuthBinding", "admin-plugins", "Test an auth plugin's connection with staged, unsaved settings."), Class: ClassActingAdmin, DemoRestricted: true, ServiceBacked: true, RetrySafety: RetrySafetyNonRetryable} - test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." + test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while every other field of that entry matches the stored entry; otherwise the test runs with the secret entered, or none. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." test.Errors = []int{http.StatusNotFound, http.StatusConflict} Register(reg, test, func(ctx context.Context, in *AdminPluginAuthBindingTestInput) (*AuthConnectionTestOutput, error) { if reg.deps.ExternalSignIn == nil || !reg.deps.ExternalSignIn.ConnectionTestAvailable() { diff --git a/internal/plugins/service_admin_config.go b/internal/plugins/service_admin_config.go index 62410d3c5a..adf4a4ef73 100644 --- a/internal/plugins/service_admin_config.go +++ b/internal/plugins/service_admin_config.go @@ -144,15 +144,21 @@ func validatedSecretClearSet( return clearSet, nil } +// preserveStoredSecrets merges a staged entry over the stored one the way a +// save would and also returns the stored entry it merged over (nil when none +// is saved). The stored map is the store's own value and must not be changed. func (s *Service) preserveStoredSecrets( ctx context.Context, installationID int, key string, value map[string]any, secretPaths [][]string, -) (map[string]any, error) { - merged, _, err := s.mergeStoredConfig(ctx, installationID, key, value, secretPaths) - return merged, err +) (merged, stored map[string]any, err error) { + stored, _, err = s.storedGlobalConfigEntry(ctx, installationID, key, len(secretPaths) > 0) + if err != nil { + return nil, nil, err + } + return mergeConfigOverStored(stored, value, secretPaths), stored, nil } func (s *Service) mergeStoredConfig( @@ -161,31 +167,50 @@ func (s *Service) mergeStoredConfig( key string, value map[string]any, secretPaths [][]string, +) (map[string]any, *time.Time, error) { + existing, expectedUpdatedAt, err := s.storedGlobalConfigEntry(ctx, installationID, key, len(secretPaths) > 0) + if err != nil { + return nil, nil, err + } + return mergeConfigOverStored(existing, value, secretPaths), expectedUpdatedAt, nil +} + +// storedGlobalConfigEntry loads one saved entry and its version. Without a +// config store there is nothing saved, which is an error only when the +// caller needs stored secrets. +func (s *Service) storedGlobalConfigEntry( + ctx context.Context, + installationID int, + key string, + needsStore bool, ) (map[string]any, *time.Time, error) { if s.configs == nil { - if len(secretPaths) > 0 { + if needsStore { return nil, nil, fmt.Errorf("plugin config store not configured") } - merged := make(map[string]any, len(value)) - for field, incoming := range value { - merged[field] = cloneConfigValue(incoming) - } - return merged, nil, nil + return nil, nil, nil } configs, err := s.configs.ListGlobalConfigs(ctx, installationID) if err != nil { return nil, nil, fmt.Errorf("load existing plugin config: %w", err) } - var existing map[string]any - var expectedUpdatedAt *time.Time for _, config := range configs { if config != nil && config.Key == key { - existing = config.Value updatedAt := config.UpdatedAt - expectedUpdatedAt = &updatedAt - break + return config.Value, &updatedAt, nil } } + return nil, nil, nil +} + +// mergeConfigOverStored overlays a submitted entry on the stored one. A +// secret the submission leaves blank keeps its stored value, including +// secrets nested inside submitted objects. +func mergeConfigOverStored( + existing map[string]any, + value map[string]any, + secretPaths [][]string, +) map[string]any { merged := make(map[string]any, len(existing)+len(value)) for field, saved := range existing { merged[field] = cloneConfigValue(saved) @@ -194,7 +219,7 @@ func (s *Service) mergeStoredConfig( merged[field] = cloneConfigValue(incoming) } if len(secretPaths) == 0 { - return merged, expectedUpdatedAt, nil + return merged } pathsByField := make(map[string][][]string) for _, path := range secretPaths { @@ -223,7 +248,7 @@ func (s *Service) mergeStoredConfig( merged[field] = cloneConfigValue(saved) } } - return merged, expectedUpdatedAt, nil + return merged } // applyGlobalConfigClears finishes a merged config entry and validates it: @@ -237,10 +262,33 @@ func applyGlobalConfigClears( value map[string]any, clearSet map[string]struct{}, ) error { + removeGlobalConfigClears(manifest, key, merged, value, clearSet) + return validateMergedGlobalConfig(manifest, key, merged, value) +} + +// removeGlobalConfigClears removes the secrets in clearSet and the fields the +// admin cleared from a merged entry. +func removeGlobalConfigClears( + manifest *pluginv1.PluginManifest, + key string, + merged map[string]any, + value map[string]any, + clearSet map[string]struct{}, +) { for field := range clearSet { delete(merged, field) } dropClearedConfigFields(manifest, key, merged, value) +} + +// validateMergedGlobalConfig checks a finished entry's declared projection +// against the schema. +func validateMergedGlobalConfig( + manifest *pluginv1.PluginManifest, + key string, + merged map[string]any, + value map[string]any, +) error { projection := globalConfigValidationProjection(manifest, key, merged, value) return ValidateGlobalConfigValue(manifest, key, projection) } diff --git a/internal/plugins/service_auth_connection.go b/internal/plugins/service_auth_connection.go index 4d8f3606f3..870020c9f8 100644 --- a/internal/plugins/service_auth_connection.go +++ b/internal/plugins/service_auth_connection.go @@ -17,7 +17,8 @@ import ( var ErrAuthConnectionTestUnsupported = errors.New("auth provider has no connection test") // StagedConfig is one global configuration entry as the operator has it on -// screen, not yet saved. Blank secret fields fall back to the stored secret; +// screen, not yet saved. Blank secret fields fall back to the stored secret +// only while the entry's other fields match the stored entry; // ClearSecrets drops stored secrets from the test. type StagedConfig struct { Key string diff --git a/internal/plugins/service_connection.go b/internal/plugins/service_connection.go index 05763cb930..c4fc1c953d 100644 --- a/internal/plugins/service_connection.go +++ b/internal/plugins/service_connection.go @@ -2,9 +2,11 @@ package plugins import ( "context" + "encoding/json" "errors" "fmt" "log/slog" + "reflect" "sort" "strings" "time" @@ -176,6 +178,12 @@ func (s *Service) TestGlobalConfigWithClears( // a save would, without saving it: blank secret fields keep the stored // secret, clearSecrets drops stored ones, emptied declared fields are // cleared, and the result must validate. +// +// A stored secret is reused only while the rest of the entry matches what +// was saved with it. Once the staged entry changes any other setting (a +// server URL, issuer, CA or anything else), only the secrets the admin typed +// reach the plugin, so a test cannot send a saved credential to a destination +// it was never saved for (issue #2796). // invalid wraps a rejected entry in the caller's error type. func (s *Service) prepareStagedGlobalConfig( ctx context.Context, @@ -193,16 +201,172 @@ func (s *Service) prepareStagedGlobalConfig( if err != nil { return nil, invalid(err) } - merged, err := s.preserveStoredSecrets(ctx, installationID, key, value, GlobalConfigSecretPaths(manifest, key)) + secretPaths := GlobalConfigSecretPaths(manifest, key) + merged, stored, err := s.preserveStoredSecrets(ctx, installationID, key, value, secretPaths) if err != nil { return nil, err } - if err := applyGlobalConfigClears(manifest, key, merged, value, clearSet); err != nil { + removeGlobalConfigClears(manifest, key, merged, value, clearSet) + if len(secretPaths) > 0 && stagedConfigChangesSettings(manifest, key, merged, stored, secretPaths) { + keepOnlySubmittedSecrets(merged, value, secretPaths) + } + if err := validateMergedGlobalConfig(manifest, key, merged, value); err != nil { return nil, invalid(err) } return merged, nil } +// stagedConfigChangesSettings reports whether a staged entry differs from the +// stored one anywhere outside its secrets. Both sides are compared as JSON +// values, a blank or null top-level field counts as absent, and an absent +// field counts as its declared default, so re-sending the saved settings +// (with the defaults the admin form fills in) is not a change. +func stagedConfigChangesSettings( + manifest *pluginv1.PluginManifest, + key string, + staged map[string]any, + stored map[string]any, + secretPaths [][]string, +) bool { + defaults := globalConfigFieldDefaults(manifest, key) + stagedSettings, stagedOK := settingsForComparison(staged, secretPaths, defaults) + storedSettings, storedOK := settingsForComparison(stored, secretPaths, defaults) + // An entry that cannot be compared counts as changed. + return !stagedOK || !storedOK || !reflect.DeepEqual(stagedSettings, storedSettings) +} + +func settingsForComparison( + value map[string]any, + secretPaths [][]string, + defaults map[string]any, +) (map[string]any, bool) { + encoded, err := json.Marshal(value) + if err != nil { + return nil, false + } + var normalized map[string]any + if err := json.Unmarshal(encoded, &normalized); err != nil { + return nil, false + } + if normalized == nil { + normalized = map[string]any{} + } + for _, path := range secretPaths { + deleteConfigPath(normalized, path) + } + for field, fieldValue := range normalized { + if isClearedConfigValue(fieldValue) { + delete(normalized, field) + } + } + for field, fallback := range defaults { + if _, present := normalized[field]; !present { + normalized[field] = fallback + } + } + return normalized, true +} + +// globalConfigFieldDefaults returns the scalar defaults the admin form shows +// for top-level fields: an admin form field's default_value, else the JSON +// schema property's default. Values are JSON-normalized. +func globalConfigFieldDefaults(manifest *pluginv1.PluginManifest, key string) map[string]any { + defaults := map[string]any{} + schema := globalConfigSchema(manifest, key) + if schema == nil { + return defaults + } + var document any + if json.Unmarshal([]byte(schema.GetJsonSchema()), &document) == nil { + properties := make(map[string][]any) + collectTopLevelSchemaProperties(document, document, make(map[string]bool), properties) + for field, candidates := range properties { + for _, candidate := range candidates { + property, _ := candidate.(map[string]any) + switch fallback := property["default"].(type) { + case string, float64, bool: + defaults[field] = fallback + } + } + } + } + for _, field := range schema.GetAdminForm().GetFields() { + fieldKey := strings.TrimSpace(field.GetKey()) + if fieldKey == "" || field.GetDefaultValue() == nil { + continue + } + switch fallback := field.GetDefaultValue().AsInterface().(type) { + case string, float64, bool: + defaults[fieldKey] = fallback + } + } + for field, fallback := range defaults { + if isClearedConfigValue(fallback) { + delete(defaults, field) + } + } + return defaults +} + +// keepOnlySubmittedSecrets replaces every secret in merged with the value the +// admin submitted at the same path, removing it when the submission left it +// blank or out. Stored secrets merged in by a blank field are dropped. +func keepOnlySubmittedSecrets(merged map[string]any, submitted map[string]any, secretPaths [][]string) { + for _, path := range secretPaths { + typed, present := configPathValue(submitted, path) + if !present || isClearedConfigValue(typed) { + deleteConfigPath(merged, path) + continue + } + setConfigPath(merged, path, cloneConfigValue(typed)) + } +} + +func configPathValue(value map[string]any, path []string) (any, bool) { + if len(path) == 0 { + return nil, false + } + current := value + for _, segment := range path[:len(path)-1] { + next, ok := current[segment].(map[string]any) + if !ok { + return nil, false + } + current = next + } + found, ok := current[path[len(path)-1]] + return found, ok +} + +func deleteConfigPath(value map[string]any, path []string) { + if len(path) == 0 { + return + } + current := value + for _, segment := range path[:len(path)-1] { + next, ok := current[segment].(map[string]any) + if !ok { + return + } + current = next + } + delete(current, path[len(path)-1]) +} + +// setConfigPath sets a secret at path. The submitted value had objects along +// the path, and merged copies them, so the parents exist. +func setConfigPath(value map[string]any, path []string, secret any) { + current := value + for _, segment := range path[:len(path)-1] { + next, ok := current[segment].(map[string]any) + if !ok { + return + } + current = next + } + current[path[len(path)-1]] = secret +} + // storedGlobalConfigs returns copies of an installation's saved global // config entries by key. func (s *Service) storedGlobalConfigs(ctx context.Context, installationID int) (map[string]map[string]any, error) { diff --git a/internal/plugins/service_connection_test.go b/internal/plugins/service_connection_test.go index b56d9999c3..7e9add7f70 100644 --- a/internal/plugins/service_connection_test.go +++ b/internal/plugins/service_connection_test.go @@ -59,7 +59,7 @@ func TestPreserveStoredSecretsMergesNestedObjectsWithoutMutatingInputs(t *testin }} service := &Service{configs: store} - merged, err := service.preserveStoredSecrets( + merged, _, err := service.preserveStoredSecrets( context.Background(), 7, "account", @@ -94,7 +94,7 @@ func TestPreserveStoredSecretsMergesNestedObjectsWithoutMutatingInputs(t *testin t.Fatalf("incoming input mutated: got %#v want %#v", incomingConnection, wantIncoming) } - replacement, err := service.preserveStoredSecrets( + replacement, _, err := service.preserveStoredSecrets( context.Background(), 7, "account", @@ -292,10 +292,14 @@ func TestSetGlobalConfigClearsEmptiedNonSecretFields(t *testing.T) { "client_secret": "stored-secret", "plugin_owned": "retained", } - for name, got := range map[string]map[string]any{"saved": store.puts[0].value, "staged": staged} { - if !reflect.DeepEqual(got, want) { - t.Fatalf("%s config = %#v, want %#v", name, got, want) - } + if !reflect.DeepEqual(store.puts[0].value, want) { + t.Fatalf("saved config = %#v, want %#v", store.puts[0].value, want) + } + // The staged entry changed settings, so the test runs without the + // saved secret (TestStagedConfigReusesSecretsOnlyWithSavedSettings). + delete(want, "client_secret") + if !reflect.DeepEqual(staged, want) { + t.Fatalf("staged config = %#v, want %#v", staged, want) } // Clearing an undeclared field is not a clear: it is validated (and @@ -307,6 +311,152 @@ func TestSetGlobalConfigClearsEmptiedNonSecretFields(t *testing.T) { } } +// TestStagedConfigReusesSecretsOnlyWithSavedSettings: a connection test +// fills a blank secret from the stored entry only while every other setting +// matches what was saved, so a staged destination never receives a saved +// credential (issue #2796). +func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { + const savedPassword = "saved-bind-password" + stored := map[string]any{ + "urls": "ldaps://directory.example.invalid", + "bind_dn": "cn=silo,dc=example,dc=invalid", + "bind_password": savedPassword, + "ca_pem": "", + "connect_timeout": float64(10), + "plugin_owned": "retained", + "service": map[string]any{ + "endpoint": "https://api.example.invalid", + "token": "saved-token", + }, + } + unchanged := func(edit func(map[string]any)) map[string]any { + value := map[string]any{ + "urls": "ldaps://directory.example.invalid", + "bind_dn": "cn=silo,dc=example,dc=invalid", + "ca_pem": "", + "connect_timeout": 10, + "service": map[string]any{"endpoint": "https://api.example.invalid"}, + } + if edit != nil { + edit(value) + } + return value + } + for _, tc := range []struct { + name string + submitted map[string]any + clearSecrets []string + requireToken bool + wantPassword any // nil: absent + wantToken any + wantErr bool + }{ + { + name: "saved settings with the secret left out", + submitted: unchanged(nil), + wantPassword: savedPassword, + wantToken: "saved-token", + }, + { + name: "saved settings with a blank secret and the form default", + submitted: unchanged(func(v map[string]any) { v["bind_password"] = ""; v["start_tls"] = false }), + wantPassword: savedPassword, + wantToken: "saved-token", + }, + { + name: "changed server", + submitted: unchanged(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid:389" }), + }, + { + name: "changed server with a blank secret", + submitted: unchanged(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid"; v["bind_password"] = " " }), + }, + { + name: "changed CA", + submitted: unchanged(func(v map[string]any) { v["ca_pem"] = "-----BEGIN CERTIFICATE-----" }), + }, + { + name: "default replaced by another value", + submitted: unchanged(func(v map[string]any) { v["start_tls"] = true }), + }, + { + name: "changed nested endpoint", + submitted: unchanged(func(v map[string]any) { v["service"] = map[string]any{"endpoint": "https://elsewhere.example.invalid"} }), + }, + { + name: "changed server with typed secrets", + submitted: unchanged(func(v map[string]any) { + v["urls"] = "ldap://elsewhere.example.invalid" + v["bind_password"] = "typed-password" + v["service"] = map[string]any{"endpoint": "https://api.example.invalid", "token": "typed-token"} + }), + wantPassword: "typed-password", + wantToken: "typed-token", + }, + { + name: "saved settings with a cleared secret", + submitted: unchanged(nil), + clearSecrets: []string{"bind_password"}, + wantToken: "saved-token", + }, + { + name: "changed server with a required secret left out", + submitted: unchanged(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid" }), + requireToken: true, + wantErr: true, + }, + } { + t.Run(tc.name, func(t *testing.T) { + manifest := connectionTestManifest(t, "silo.auth.ldap", "0.1.0") + required := "" + if tc.requireToken { + required = `,"required":["token"]` + } + manifest.GlobalConfigSchema[0].JsonSchema = `{ + "type":"object", + "properties":{ + "urls":{"type":"string"}, + "bind_dn":{"type":"string"}, + "bind_password":{"type":"string","writeOnly":true}, + "ca_pem":{"type":"string"}, + "start_tls":{"type":"boolean","default":false}, + "connect_timeout":{"type":"number"}, + "service":{ + "type":"object", + "properties":{ + "endpoint":{"type":"string"}, + "token":{"type":"string","writeOnly":true} + }` + required + ` + } + } + }` + manifest.GlobalConfigSchema[0].AdminForm = nil + service, _ := connectionConfigService(t, manifest, cloneConfigValue(stored).(map[string]any)) + + staged, err := service.prepareStagedGlobalConfig(t.Context(), 7, manifest, "connection", tc.submitted, tc.clearSecrets, func(err error) error { return err }) + if tc.wantErr { + if err == nil { + t.Fatalf("staged = %#v, want a validation error", staged) + } + return + } + if err != nil { + t.Fatal(err) + } + if got, present := staged["bind_password"]; (tc.wantPassword == nil && present) || (tc.wantPassword != nil && got != tc.wantPassword) { + t.Fatalf("bind_password = %#v (present %v), want %#v", got, present, tc.wantPassword) + } + serviceValue, _ := staged["service"].(map[string]any) + if got, present := serviceValue["token"]; (tc.wantToken == nil && present) || (tc.wantToken != nil && got != tc.wantToken) { + t.Fatalf("service.token = %#v (present %v), want %#v", got, present, tc.wantToken) + } + if staged["plugin_owned"] != "retained" { + t.Fatalf("plugin-owned field = %#v, want it kept", staged["plugin_owned"]) + } + }) + } +} + func TestSetGlobalConfigPreservesOmittedPluginOwnedFields(t *testing.T) { manifest := connectionTestManifest(t, "silo.metadb", "0.0.36") manifest.GlobalConfigSchema[0].JsonSchema = `{ diff --git a/web/src/api/v2/schema.ts b/web/src/api/v2/schema.ts index b02b7b7da4..d551d45a18 100644 --- a/web/src/api/v2/schema.ts +++ b/web/src/api/v2/schema.ts @@ -3918,7 +3918,7 @@ export interface paths { put?: never; /** * Test an auth plugin's connection with staged, unsaved settings. - * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. + * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while every other field of that entry matches the stored entry; otherwise the test runs with the secret entered, or none. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. */ post: operations["testAdminPluginAuthBinding"]; delete?: never; @@ -19873,7 +19873,7 @@ export interface components { clear_secrets?: string[]; /** @description The manifest global_config_schema key */ key: string; - /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret */ + /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while every other field of the entry matches the stored entry */ value: { [key: string]: unknown; }; From c76803c3d0a2de3b173c5dc29992ffb256a0d980 Mon Sep 17 00:00:00 2001 From: blurbery <271863866+blurbery@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:57:58 +1100 Subject: [PATCH 02/11] fix(plugins): compare whole secret objects before reusing their secrets A secret path that names a whole object (a map of servers with keys inside, or a shape the path walker cannot address) was stripped from both sides of the comparison, so a changed URL inside it did not count as a change and the saved keys reached the new URL. Such objects are now compared whole. --- internal/plugins/service_connection.go | 10 ++++- internal/plugins/service_connection_test.go | 41 ++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/internal/plugins/service_connection.go b/internal/plugins/service_connection.go index c4fc1c953d..de01de88bd 100644 --- a/internal/plugins/service_connection.go +++ b/internal/plugins/service_connection.go @@ -217,7 +217,7 @@ func (s *Service) prepareStagedGlobalConfig( } // stagedConfigChangesSettings reports whether a staged entry differs from the -// stored one anywhere outside its secrets. Both sides are compared as JSON +// stored one anywhere outside its secret values. Both sides are compared as JSON // values, a blank or null top-level field counts as absent, and an absent // field counts as its declared default, so re-sending the saved settings // (with the defaults the admin form fills in) is not a change. @@ -252,6 +252,14 @@ func settingsForComparison( normalized = map[string]any{} } for _, path := range secretPaths { + // A secret path can name a whole object or list (a map of servers + // with secrets inside, or a shape the path walker cannot address). + // Its other values may be destinations, so it is compared whole. + secret, _ := configPathValue(normalized, path) + switch secret.(type) { + case map[string]any, []any: + continue + } deleteConfigPath(normalized, path) } for field, fieldValue := range normalized { diff --git a/internal/plugins/service_connection_test.go b/internal/plugins/service_connection_test.go index 7e9add7f70..c4aa946ac4 100644 --- a/internal/plugins/service_connection_test.go +++ b/internal/plugins/service_connection_test.go @@ -328,6 +328,9 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { "endpoint": "https://api.example.invalid", "token": "saved-token", }, + "servers": map[string]any{ + "main": map[string]any{"url": "https://api.example.invalid", "key": "saved-server-key"}, + }, } unchanged := func(edit func(map[string]any)) map[string]any { value := map[string]any{ @@ -349,7 +352,10 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { requireToken bool wantPassword any // nil: absent wantToken any - wantErr bool + // wantServerKey is servers.main.key; the zero value means it was + // not checked, because the row leaves servers out. + wantServerKey any + wantErr bool }{ { name: "saved settings with the secret left out", @@ -399,6 +405,22 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { clearSecrets: []string{"bind_password"}, wantToken: "saved-token", }, + { + name: "same URL inside an object of secrets", + submitted: unchanged(func(v map[string]any) { + v["servers"] = map[string]any{"main": map[string]any{"url": "https://api.example.invalid", "key": ""}} + }), + wantPassword: savedPassword, + wantToken: "saved-token", + wantServerKey: "saved-server-key", + }, + { + name: "changed URL inside an object of secrets", + submitted: unchanged(func(v map[string]any) { + v["servers"] = map[string]any{"main": map[string]any{"url": "https://elsewhere.example.invalid", "key": ""}} + }), + wantServerKey: nil, + }, { name: "changed server with a required secret left out", submitted: unchanged(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid" }), @@ -427,6 +449,16 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { "endpoint":{"type":"string"}, "token":{"type":"string","writeOnly":true} }` + required + ` + }, + "servers":{ + "type":"object", + "additionalProperties":{ + "type":"object", + "properties":{ + "url":{"type":"string"}, + "key":{"type":"string","writeOnly":true} + } + } } } }` @@ -450,6 +482,13 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { if got, present := serviceValue["token"]; (tc.wantToken == nil && present) || (tc.wantToken != nil && got != tc.wantToken) { t.Fatalf("service.token = %#v (present %v), want %#v", got, present, tc.wantToken) } + if _, sent := tc.submitted["servers"]; sent { + servers, _ := staged["servers"].(map[string]any) + main, _ := servers["main"].(map[string]any) + if got := main["key"]; got != tc.wantServerKey && !(tc.wantServerKey == nil && got == "") { + t.Fatalf("servers.main.key = %#v, want %#v", got, tc.wantServerKey) + } + } if staged["plugin_owned"] != "retained" { t.Fatalf("plugin-owned field = %#v, want it kept", staged["plugin_owned"]) } From 68bd5439e83d4814ee2e29dcea21b6380511ed17 Mon Sep 17 00:00:00 2001 From: blurbery <271863866+blurbery@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:18:37 +1100 Subject: [PATCH 03/11] fix(plugins): treat typed secrets and removed defaults as changed settings An independent review of the staged-test rule found three gaps: - A typed secret was never a change, so a typed secret that is itself a destination (a proxy or webhook URL) received the entry's other stored secrets. Any typed secret now counts as a change. It is not compared with the stored value, which would let a caller probe stored secrets. - Undeclared stored fields (plugin-written state, fields an older manifest declared) went to changed settings. They are now left out, as admin reads already leave them out. - Removing a stored value that equals its declared default compared equal, though the plugin then receives no value. A field the stored entry lacks still matches its declared default, which the admin form sends. --- contracts/api/v2/openapi.json | 4 +- docs/admin-api.md | 11 +-- docs/auth-api.md | 2 +- internal/apiv2/admin_plugin_configuration.go | 6 +- internal/apiv2/external_sign_in.go | 2 +- internal/plugins/service_auth_connection.go | 2 +- internal/plugins/service_connection.go | 85 ++++++++++++++------ internal/plugins/service_connection_test.go | 31 +++++-- web/src/api/v2/schema.ts | 4 +- 9 files changed, 104 insertions(+), 43 deletions(-) diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index ad9e4ec758..32d08acc7c 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -16793,7 +16793,7 @@ }, "value": { "additionalProperties": true, - "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while every other field of the entry matches the stored entry", + "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered", "type": "object", "x-silo-extension-bag": "plugin-json-value" } @@ -109421,7 +109421,7 @@ }, "/api/v2/admin/plugins/installations/{id}/auth-binding/test": { "post": { - "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while every other field of that entry matches the stored entry; otherwise the test runs with the secret entered, or none. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", + "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise the test runs with only the secrets entered. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", "operationId": "testAdminPluginAuthBinding", "parameters": [ { diff --git a/docs/admin-api.md b/docs/admin-api.md index 57fa4c6d41..da7bf199b0 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -3502,11 +3502,12 @@ removed only when named in `clear_secrets`. The frozen v1 `PUT .../config` share clearing rule as a bridge bug fix: before it, an emptied field kept its stored value. The connection test (`.../config/test` and the auth connection test) merges a staged entry the same way without storing it, with one difference: a blank secret reuses the stored secret -only while every other field of the entry, after clears and with absent fields read as -their declared defaults, matches the stored entry. A staged entry that changes a server -URL, issuer, CA or any other setting is tested with the secrets the administrator typed, -or without them, so a test never sends a saved credential to a destination it was not -saved for. The server validates the merged entry against the +only while the entry is otherwise unchanged. Unchanged means no secret is typed and every +other field, after clears, matches the stored entry; a field the stored entry lacks +matches its declared default. A staged entry that changes a server URL, issuer, CA or any +other setting, or types a secret, is tested with only the secrets the administrator typed +and without undeclared stored fields, so a test never sends a saved credential to a +destination it was not saved for. The server validates the merged entry against the plugin's schema and returns 422 with the plugin's own message on failure, then persists under a compare-and-swap on the stored revision and stops the running plugin so it rebinds. Success is 204. Repeating the same request converges on one stored entry, so the row is diff --git a/docs/auth-api.md b/docs/auth-api.md index 48a6c07a95..da8529c3d5 100644 --- a/docs/auth-api.md +++ b/docs/auth-api.md @@ -706,7 +706,7 @@ linking rule whether or not `network_sign_in` is served. | `POST /admin/users/{id}/identities` (`createAdminUserIdentity`) | acting admin | Links by `installation_id` and the exact `external_subject`. Turns local password sign-in off unless the account is break-glass or the installation is a network identity provider. | | `DELETE /admin/users/{id}/identities/{identity_id}` (`deleteAdminUserIdentity`) | acting admin | May leave the account without a sign-in method; setting a password with `updateAdminUser` turns its local password sign-in back on. | | `PUT /admin/users/{id}` (`updateAdminUser`) | acting admin | `break_glass` sets or clears the flag: admin accounts only, and only the server Owner may change it (403 `permission_denied`). The Owner has it by default (set at first-run setup and on every ownership move) and may clear it on its own account. A `password` also turns the account's local password sign-in back on, so an admin other than the Owner may not set its own while its local sign-in is off (403 `permission_denied`; the v1 route answers `owner_protected`). Demoting, disabling or clearing the last usable break-glass admin while local sign-in is off is 409 `break_glass_required`; so is deleting it (`deleteAdminUser`) or turning `auth.local_password_login` off without one (`updateAdminSettings`, `updateAdminSetting`). | -| `POST /admin/plugins/installations/{id}/auth-binding/test` (`testAdminPluginAuthBinding`) | acting admin | Sends staged `config` entries (blank secrets keep the stored value only while the rest of that entry matches what is stored) to the plugin's `TestConnection`; answers `ok`, the plugin's `steps` and `callback_url`, the redirect URI to register at an OAuth provider (empty without a public URL). A plugin without a connection test, or a disabled installation, is 409. Not retried automatically. | +| `POST /admin/plugins/installations/{id}/auth-binding/test` (`testAdminPluginAuthBinding`) | acting admin | Sends staged `config` entries (blank secrets keep the stored value only while the rest of that entry is unchanged and no secret in it is typed) to the plugin's `TestConnection`; answers `ok`, the plugin's `steps` and `callback_url`, the redirect URI to register at an OAuth provider (empty without a public URL). A plugin without a connection test, or a disabled installation, is 409. Not retried automatically. | | `PUT /admin/plugins/installations/{id}/auth-binding` (`updateAdminPluginAuthBinding`) | acting admin | Applies without a restart (`X-Silo-Restart-Required: false`). `auto_provision` defaults to true. Enabling a second binding of the same kind is 409 `provider_already_enabled`; one network identity binding may be enabled beside the one OIDC or LDAP binding. | | `GET /admin/plugins/installations` (`listAdminPluginInstallations`) | acting admin | Each OAuth auth binding carries `callback_url` (the v2 callback to register at the provider) and `post_logout_redirect_url` (`/login`, to register for provider logout), both on `server.public_url`; empty without a public URL and for a password provider. The other operations that answer an installation carry them too. | diff --git a/internal/apiv2/admin_plugin_configuration.go b/internal/apiv2/admin_plugin_configuration.go index b14dbfa0e3..5f89dfb1fc 100644 --- a/internal/apiv2/admin_plugin_configuration.go +++ b/internal/apiv2/admin_plugin_configuration.go @@ -27,11 +27,11 @@ type AdminPluginConfigurationService interface { // is removed, so the plugin's default applies; undeclared fields are never // cleared that way. Manifest-declared secret fields left blank keep their // stored value; a secret is removed only when named in clear_secrets. A -// connection test keeps a stored secret only while the rest of the entry -// matches what was saved with it. +// connection test keeps a stored secret only while the rest of the entry is +// unchanged and no secret in it is entered. type AdminPluginConfigWrite struct { Key string `json:"key" minLength:"1" maxLength:"256" doc:"The manifest global_config_schema key"` - Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while every other field of the entry matches the stored entry"` + Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered"` ClearSecrets []string `json:"clear_secrets,omitempty" maxItems:"64" doc:"Secret fields to remove; each must be a manifest-declared secret of this key"` } type AdminPluginConfigInput struct { diff --git a/internal/apiv2/external_sign_in.go b/internal/apiv2/external_sign_in.go index 9efaa2ef9d..dff13ecf16 100644 --- a/internal/apiv2/external_sign_in.go +++ b/internal/apiv2/external_sign_in.go @@ -562,7 +562,7 @@ func registerExternalSignIn(reg *Registry) { test := Operation{Operation: humaOp(http.MethodPost, Prefix+"/admin/plugins/installations/{id}/auth-binding/test", "testAdminPluginAuthBinding", "admin-plugins", "Test an auth plugin's connection with staged, unsaved settings."), Class: ClassActingAdmin, DemoRestricted: true, ServiceBacked: true, RetrySafety: RetrySafetyNonRetryable} - test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while every other field of that entry matches the stored entry; otherwise the test runs with the secret entered, or none. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." + test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise the test runs with only the secrets entered. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." test.Errors = []int{http.StatusNotFound, http.StatusConflict} Register(reg, test, func(ctx context.Context, in *AdminPluginAuthBindingTestInput) (*AuthConnectionTestOutput, error) { if reg.deps.ExternalSignIn == nil || !reg.deps.ExternalSignIn.ConnectionTestAvailable() { diff --git a/internal/plugins/service_auth_connection.go b/internal/plugins/service_auth_connection.go index 870020c9f8..5d3a421b07 100644 --- a/internal/plugins/service_auth_connection.go +++ b/internal/plugins/service_auth_connection.go @@ -18,7 +18,7 @@ var ErrAuthConnectionTestUnsupported = errors.New("auth provider has no connecti // StagedConfig is one global configuration entry as the operator has it on // screen, not yet saved. Blank secret fields fall back to the stored secret -// only while the entry's other fields match the stored entry; +// only while the rest of the entry is unchanged and no secret is typed; // ClearSecrets drops stored secrets from the test. type StagedConfig struct { Key string diff --git a/internal/plugins/service_connection.go b/internal/plugins/service_connection.go index de01de88bd..ab47c97bf9 100644 --- a/internal/plugins/service_connection.go +++ b/internal/plugins/service_connection.go @@ -180,10 +180,11 @@ func (s *Service) TestGlobalConfigWithClears( // cleared, and the result must validate. // // A stored secret is reused only while the rest of the entry matches what -// was saved with it. Once the staged entry changes any other setting (a -// server URL, issuer, CA or anything else), only the secrets the admin typed -// reach the plugin, so a test cannot send a saved credential to a destination -// it was never saved for (issue #2796). +// was saved with it and no secret is typed. Once the staged entry changes +// any setting (a server URL, issuer, CA or anything else), only the secrets +// the admin typed and the fields the schema declares reach the plugin, so a +// test cannot send a saved credential to a destination it was never saved +// for (issue #2796). // invalid wraps a rejected entry in the caller's error type. func (s *Service) prepareStagedGlobalConfig( ctx context.Context, @@ -207,8 +208,9 @@ func (s *Service) prepareStagedGlobalConfig( return nil, err } removeGlobalConfigClears(manifest, key, merged, value, clearSet) - if len(secretPaths) > 0 && stagedConfigChangesSettings(manifest, key, merged, stored, secretPaths) { + if len(secretPaths) > 0 && stagedConfigChangesSettings(manifest, key, merged, stored, value, secretPaths) { keepOnlySubmittedSecrets(merged, value, secretPaths) + dropStoredUndeclaredFields(manifest, key, merged, value) } if err := validateMergedGlobalConfig(manifest, key, merged, value); err != nil { return nil, invalid(err) @@ -217,29 +219,48 @@ func (s *Service) prepareStagedGlobalConfig( } // stagedConfigChangesSettings reports whether a staged entry differs from the -// stored one anywhere outside its secret values. Both sides are compared as JSON -// values, a blank or null top-level field counts as absent, and an absent -// field counts as its declared default, so re-sending the saved settings -// (with the defaults the admin form fills in) is not a change. +// stored one in anything a stored secret could be sent with. Both sides are +// compared as JSON values without their secret values, and a blank or null +// top-level field counts as absent. A field the stored entry lacks matches a +// staged field holding its declared default, which the admin form fills in; +// removing a stored value is still a change. A secret the admin typed is a +// change too: it can be a destination itself (a proxy or webhook URL), and +// comparing it with the stored value would let a caller guess at secrets. func stagedConfigChangesSettings( manifest *pluginv1.PluginManifest, key string, staged map[string]any, stored map[string]any, + submitted map[string]any, secretPaths [][]string, ) bool { - defaults := globalConfigFieldDefaults(manifest, key) - stagedSettings, stagedOK := settingsForComparison(staged, secretPaths, defaults) - storedSettings, storedOK := settingsForComparison(stored, secretPaths, defaults) - // An entry that cannot be compared counts as changed. - return !stagedOK || !storedOK || !reflect.DeepEqual(stagedSettings, storedSettings) + for _, path := range secretPaths { + typed, present := configPathValue(submitted, path) + if !present || isClearedConfigValue(typed) { + continue + } + switch typed.(type) { + case map[string]any, []any: + // A secret object or list is compared whole below. + default: + return true + } + } + stagedSettings, stagedOK := settingsForComparison(staged, secretPaths) + storedSettings, storedOK := settingsForComparison(stored, secretPaths) + if !stagedOK || !storedOK { + // An entry that cannot be compared counts as changed. + return true + } + for field, fallback := range globalConfigFieldDefaults(manifest, key) { + if _, inStored := storedSettings[field]; !inStored && reflect.DeepEqual(stagedSettings[field], fallback) { + delete(stagedSettings, field) + } + } + return !reflect.DeepEqual(stagedSettings, storedSettings) } -func settingsForComparison( - value map[string]any, - secretPaths [][]string, - defaults map[string]any, -) (map[string]any, bool) { +func settingsForComparison(value map[string]any, secretPaths [][]string) (map[string]any, bool) { encoded, err := json.Marshal(value) if err != nil { return nil, false @@ -267,12 +288,30 @@ func settingsForComparison( delete(normalized, field) } } - for field, fallback := range defaults { - if _, present := normalized[field]; !present { - normalized[field] = fallback + return normalized, true +} + +// dropStoredUndeclaredFields removes stored top-level fields the schema does +// not declare and the admin did not submit. Plugin-written state and fields +// left over from an older manifest can hold credentials the admin API never +// shows, so they do not go to changed settings either. +func dropStoredUndeclaredFields( + manifest *pluginv1.PluginManifest, + key string, + merged map[string]any, + submitted map[string]any, +) { + public, secrets := GlobalConfigFieldSets(manifest, key) + declared := secretFieldSet(append(append([]string(nil), public...), secrets...)) + for field := range merged { + if _, isDeclared := declared[field]; isDeclared { + continue } + if _, sent := submitted[field]; sent { + continue + } + delete(merged, field) } - return normalized, true } // globalConfigFieldDefaults returns the scalar defaults the admin form shows diff --git a/internal/plugins/service_connection_test.go b/internal/plugins/service_connection_test.go index c4aa946ac4..81244a6f99 100644 --- a/internal/plugins/service_connection_test.go +++ b/internal/plugins/service_connection_test.go @@ -296,8 +296,10 @@ func TestSetGlobalConfigClearsEmptiedNonSecretFields(t *testing.T) { t.Fatalf("saved config = %#v, want %#v", store.puts[0].value, want) } // The staged entry changed settings, so the test runs without the - // saved secret (TestStagedConfigReusesSecretsOnlyWithSavedSettings). + // saved secret or undeclared stored fields + // (TestStagedConfigReusesSecretsOnlyWithSavedSettings). delete(want, "client_secret") + delete(want, "plugin_owned") if !reflect.DeepEqual(staged, want) { t.Fatalf("staged config = %#v, want %#v", staged, want) } @@ -322,6 +324,7 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { "bind_dn": "cn=silo,dc=example,dc=invalid", "bind_password": savedPassword, "ca_pem": "", + "start_tls": false, "connect_timeout": float64(10), "plugin_owned": "retained", "service": map[string]any{ @@ -356,19 +359,34 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { // not checked, because the row leaves servers out. wantServerKey any wantErr bool + // sameSettings rows keep undeclared stored fields. + sameSettings bool }{ { name: "saved settings with the secret left out", + sameSettings: true, submitted: unchanged(nil), wantPassword: savedPassword, wantToken: "saved-token", }, { name: "saved settings with a blank secret and the form default", - submitted: unchanged(func(v map[string]any) { v["bind_password"] = ""; v["start_tls"] = false }), + sameSettings: true, + submitted: unchanged(func(v map[string]any) { v["bind_password"] = ""; v["page_size"] = 100 }), wantPassword: savedPassword, wantToken: "saved-token", }, + { + name: "stored value removed in favour of its default", + submitted: unchanged(func(v map[string]any) { v["start_tls"] = nil }), + }, + { + name: "one secret typed, another left out", + submitted: unchanged(func(v map[string]any) { v["bind_password"] = "typed-password" }), + // The typed secret may itself be a destination, so the + // other stored secrets stay behind. + wantPassword: "typed-password", + }, { name: "changed server", submitted: unchanged(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid:389" }), @@ -401,12 +419,14 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { }, { name: "saved settings with a cleared secret", + sameSettings: true, submitted: unchanged(nil), clearSecrets: []string{"bind_password"}, wantToken: "saved-token", }, { - name: "same URL inside an object of secrets", + name: "same URL inside an object of secrets", + sameSettings: true, submitted: unchanged(func(v map[string]any) { v["servers"] = map[string]any{"main": map[string]any{"url": "https://api.example.invalid", "key": ""}} }), @@ -442,6 +462,7 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { "bind_password":{"type":"string","writeOnly":true}, "ca_pem":{"type":"string"}, "start_tls":{"type":"boolean","default":false}, + "page_size":{"type":"number","default":100}, "connect_timeout":{"type":"number"}, "service":{ "type":"object", @@ -489,8 +510,8 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { t.Fatalf("servers.main.key = %#v, want %#v", got, tc.wantServerKey) } } - if staged["plugin_owned"] != "retained" { - t.Fatalf("plugin-owned field = %#v, want it kept", staged["plugin_owned"]) + if got, present := staged["plugin_owned"]; present != tc.sameSettings { + t.Fatalf("undeclared stored field = %#v (present %v), want present %v", got, present, tc.sameSettings) } }) } diff --git a/web/src/api/v2/schema.ts b/web/src/api/v2/schema.ts index d551d45a18..09d44ccfbf 100644 --- a/web/src/api/v2/schema.ts +++ b/web/src/api/v2/schema.ts @@ -3918,7 +3918,7 @@ export interface paths { put?: never; /** * Test an auth plugin's connection with staged, unsaved settings. - * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while every other field of that entry matches the stored entry; otherwise the test runs with the secret entered, or none. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. + * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise the test runs with only the secrets entered. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. */ post: operations["testAdminPluginAuthBinding"]; delete?: never; @@ -19873,7 +19873,7 @@ export interface components { clear_secrets?: string[]; /** @description The manifest global_config_schema key */ key: string; - /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while every other field of the entry matches the stored entry */ + /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered */ value: { [key: string]: unknown; }; From 2a61a4666d0f6367551430ebfa0bdf4fcec4e85d Mon Sep 17 00:00:00 2001 From: blurbery <271863866+blurbery@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:24:11 +1100 Subject: [PATCH 04/11] fix(plugins): let clear_secrets win in changed connection tests A changed staged entry that both typed a secret and named it in clear_secrets restored the typed secret after the clear removed it. Cleared secrets now stay out of the test, as they stay out of a save. Also split the staged-secret table test to fit the function length limit, and say in the API and admin docs that the rule is per entry. --- contracts/api/v2/openapi.json | 4 +- docs/admin-api.md | 4 +- internal/apiv2/external_sign_in.go | 4 +- internal/plugins/service_connection.go | 15 +- internal/plugins/service_connection_test.go | 337 +++++++++++--------- web/src/api/v2/schema.ts | 4 +- 6 files changed, 203 insertions(+), 165 deletions(-) diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index 32d08acc7c..81d094f57e 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -16439,7 +16439,7 @@ "type": "string" }, "config": { - "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret; clear_secrets drops it from the test", + "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used; clear_secrets drops it from the test", "items": { "$ref": "#/components/schemas/AdminPluginConfigWrite" }, @@ -109421,7 +109421,7 @@ }, "/api/v2/admin/plugins/installations/{id}/auth-binding/test": { "post": { - "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise the test runs with only the secrets entered. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", + "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", "operationId": "testAdminPluginAuthBinding", "parameters": [ { diff --git a/docs/admin-api.md b/docs/admin-api.md index da7bf199b0..5fbe333c92 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -3507,7 +3507,9 @@ other field, after clears, matches the stored entry; a field the stored entry la matches its declared default. A staged entry that changes a server URL, issuer, CA or any other setting, or types a secret, is tested with only the secrets the administrator typed and without undeclared stored fields, so a test never sends a saved credential to a -destination it was not saved for. The server validates the merged entry against the +destination it was not saved for. The rule is per entry: the other stored entries go to the +plugin unchanged, so a plugin that keeps a credential in one entry and its destination in +another is not covered. The server validates the merged entry against the plugin's schema and returns 422 with the plugin's own message on failure, then persists under a compare-and-swap on the stored revision and stops the running plugin so it rebinds. Success is 204. Repeating the same request converges on one stored entry, so the row is diff --git a/internal/apiv2/external_sign_in.go b/internal/apiv2/external_sign_in.go index dff13ecf16..18fd9ebb00 100644 --- a/internal/apiv2/external_sign_in.go +++ b/internal/apiv2/external_sign_in.go @@ -190,7 +190,7 @@ type AdminPluginAuthBindingTestInput struct { RawBody []byte Body struct { CapabilityID string `json:"capability_id,omitempty" maxLength:"256" doc:"auth_provider.v1 capability to test; empty tests the plugin's first one"` - Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret; clear_secrets drops it from the test"` + Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used; clear_secrets drops it from the test"` } } @@ -562,7 +562,7 @@ func registerExternalSignIn(reg *Registry) { test := Operation{Operation: humaOp(http.MethodPost, Prefix+"/admin/plugins/installations/{id}/auth-binding/test", "testAdminPluginAuthBinding", "admin-plugins", "Test an auth plugin's connection with staged, unsaved settings."), Class: ClassActingAdmin, DemoRestricted: true, ServiceBacked: true, RetrySafety: RetrySafetyNonRetryable} - test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise the test runs with only the secrets entered. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." + test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." test.Errors = []int{http.StatusNotFound, http.StatusConflict} Register(reg, test, func(ctx context.Context, in *AdminPluginAuthBindingTestInput) (*AuthConnectionTestOutput, error) { if reg.deps.ExternalSignIn == nil || !reg.deps.ExternalSignIn.ConnectionTestAvailable() { diff --git a/internal/plugins/service_connection.go b/internal/plugins/service_connection.go index ab47c97bf9..69f7b8de80 100644 --- a/internal/plugins/service_connection.go +++ b/internal/plugins/service_connection.go @@ -209,7 +209,7 @@ func (s *Service) prepareStagedGlobalConfig( } removeGlobalConfigClears(manifest, key, merged, value, clearSet) if len(secretPaths) > 0 && stagedConfigChangesSettings(manifest, key, merged, stored, value, secretPaths) { - keepOnlySubmittedSecrets(merged, value, secretPaths) + keepOnlySubmittedSecrets(merged, value, secretPaths, clearSet) dropStoredUndeclaredFields(manifest, key, merged, value) } if err := validateMergedGlobalConfig(manifest, key, merged, value); err != nil { @@ -357,11 +357,18 @@ func globalConfigFieldDefaults(manifest *pluginv1.PluginManifest, key string) ma // keepOnlySubmittedSecrets replaces every secret in merged with the value the // admin submitted at the same path, removing it when the submission left it -// blank or out. Stored secrets merged in by a blank field are dropped. -func keepOnlySubmittedSecrets(merged map[string]any, submitted map[string]any, secretPaths [][]string) { +// blank or out, or named its field in clearSet. Stored secrets merged in by a +// blank field are dropped. +func keepOnlySubmittedSecrets( + merged map[string]any, + submitted map[string]any, + secretPaths [][]string, + clearSet map[string]struct{}, +) { for _, path := range secretPaths { + _, cleared := clearSet[path[0]] typed, present := configPathValue(submitted, path) - if !present || isClearedConfigValue(typed) { + if cleared || !present || isClearedConfigValue(typed) { deleteConfigPath(merged, path) continue } diff --git a/internal/plugins/service_connection_test.go b/internal/plugins/service_connection_test.go index 81244a6f99..2bb41657ae 100644 --- a/internal/plugins/service_connection_test.go +++ b/internal/plugins/service_connection_test.go @@ -313,16 +313,30 @@ func TestSetGlobalConfigClearsEmptiedNonSecretFields(t *testing.T) { } } -// TestStagedConfigReusesSecretsOnlyWithSavedSettings: a connection test -// fills a blank secret from the stored entry only while every other setting -// matches what was saved, so a staged destination never receives a saved -// credential (issue #2796). -func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { - const savedPassword = "saved-bind-password" - stored := map[string]any{ +// stagedSavedPassword is the stored bind_password in +// TestStagedConfigReusesSecretsOnlyWithSavedSettings. +const stagedSavedPassword = "saved-bind-password" + +type stagedSecretCase struct { + name string + submitted map[string]any + clearSecrets []string + requireToken bool + wantPassword any // nil: absent + wantToken any + // wantServerKey is servers.main.key; the zero value means it was + // not checked, because the row leaves servers out. + wantServerKey any + wantErr bool + // sameSettings rows keep undeclared stored fields. + sameSettings bool +} + +func stagedSecretStored() map[string]any { + return map[string]any{ "urls": "ldaps://directory.example.invalid", "bind_dn": "cn=silo,dc=example,dc=invalid", - "bind_password": savedPassword, + "bind_password": stagedSavedPassword, "ca_pem": "", "start_tls": false, "connect_timeout": float64(10), @@ -335,156 +349,167 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { "main": map[string]any{"url": "https://api.example.invalid", "key": "saved-server-key"}, }, } - unchanged := func(edit func(map[string]any)) map[string]any { - value := map[string]any{ - "urls": "ldaps://directory.example.invalid", - "bind_dn": "cn=silo,dc=example,dc=invalid", - "ca_pem": "", - "connect_timeout": 10, - "service": map[string]any{"endpoint": "https://api.example.invalid"}, - } - if edit != nil { - edit(value) - } - return value +} + +// stagedSecretSubmission is the stored entry as the admin form sends it back, +// secrets left out, after edit. +func stagedSecretSubmission(edit func(map[string]any)) map[string]any { + value := map[string]any{ + "urls": "ldaps://directory.example.invalid", + "bind_dn": "cn=silo,dc=example,dc=invalid", + "ca_pem": "", + "connect_timeout": 10, + "service": map[string]any{"endpoint": "https://api.example.invalid"}, } - for _, tc := range []struct { - name string - submitted map[string]any - clearSecrets []string - requireToken bool - wantPassword any // nil: absent - wantToken any - // wantServerKey is servers.main.key; the zero value means it was - // not checked, because the row leaves servers out. - wantServerKey any - wantErr bool - // sameSettings rows keep undeclared stored fields. - sameSettings bool - }{ - { - name: "saved settings with the secret left out", - sameSettings: true, - submitted: unchanged(nil), - wantPassword: savedPassword, - wantToken: "saved-token", - }, - { - name: "saved settings with a blank secret and the form default", - sameSettings: true, - submitted: unchanged(func(v map[string]any) { v["bind_password"] = ""; v["page_size"] = 100 }), - wantPassword: savedPassword, - wantToken: "saved-token", - }, - { - name: "stored value removed in favour of its default", - submitted: unchanged(func(v map[string]any) { v["start_tls"] = nil }), - }, - { - name: "one secret typed, another left out", - submitted: unchanged(func(v map[string]any) { v["bind_password"] = "typed-password" }), - // The typed secret may itself be a destination, so the - // other stored secrets stay behind. - wantPassword: "typed-password", - }, - { - name: "changed server", - submitted: unchanged(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid:389" }), - }, - { - name: "changed server with a blank secret", - submitted: unchanged(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid"; v["bind_password"] = " " }), - }, - { - name: "changed CA", - submitted: unchanged(func(v map[string]any) { v["ca_pem"] = "-----BEGIN CERTIFICATE-----" }), - }, - { - name: "default replaced by another value", - submitted: unchanged(func(v map[string]any) { v["start_tls"] = true }), - }, - { - name: "changed nested endpoint", - submitted: unchanged(func(v map[string]any) { v["service"] = map[string]any{"endpoint": "https://elsewhere.example.invalid"} }), - }, - { - name: "changed server with typed secrets", - submitted: unchanged(func(v map[string]any) { - v["urls"] = "ldap://elsewhere.example.invalid" - v["bind_password"] = "typed-password" - v["service"] = map[string]any{"endpoint": "https://api.example.invalid", "token": "typed-token"} - }), - wantPassword: "typed-password", - wantToken: "typed-token", - }, - { - name: "saved settings with a cleared secret", - sameSettings: true, - submitted: unchanged(nil), - clearSecrets: []string{"bind_password"}, - wantToken: "saved-token", - }, - { - name: "same URL inside an object of secrets", - sameSettings: true, - submitted: unchanged(func(v map[string]any) { - v["servers"] = map[string]any{"main": map[string]any{"url": "https://api.example.invalid", "key": ""}} - }), - wantPassword: savedPassword, - wantToken: "saved-token", - wantServerKey: "saved-server-key", - }, - { - name: "changed URL inside an object of secrets", - submitted: unchanged(func(v map[string]any) { - v["servers"] = map[string]any{"main": map[string]any{"url": "https://elsewhere.example.invalid", "key": ""}} - }), - wantServerKey: nil, - }, - { - name: "changed server with a required secret left out", - submitted: unchanged(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid" }), - requireToken: true, - wantErr: true, - }, - } { - t.Run(tc.name, func(t *testing.T) { - manifest := connectionTestManifest(t, "silo.auth.ldap", "0.1.0") - required := "" - if tc.requireToken { - required = `,"required":["token"]` - } - manifest.GlobalConfigSchema[0].JsonSchema = `{ + if edit != nil { + edit(value) + } + return value +} + +func stagedSecretSchema(requireToken bool) string { + required := "" + if requireToken { + required = `,"required":["token"]` + } + return `{ + "type":"object", + "properties":{ + "urls":{"type":"string"}, + "bind_dn":{"type":"string"}, + "bind_password":{"type":"string","writeOnly":true}, + "ca_pem":{"type":"string"}, + "start_tls":{"type":"boolean","default":false}, + "page_size":{"type":"number","default":100}, + "connect_timeout":{"type":"number"}, + "service":{ "type":"object", "properties":{ - "urls":{"type":"string"}, - "bind_dn":{"type":"string"}, - "bind_password":{"type":"string","writeOnly":true}, - "ca_pem":{"type":"string"}, - "start_tls":{"type":"boolean","default":false}, - "page_size":{"type":"number","default":100}, - "connect_timeout":{"type":"number"}, - "service":{ - "type":"object", - "properties":{ - "endpoint":{"type":"string"}, - "token":{"type":"string","writeOnly":true} - }` + required + ` - }, - "servers":{ - "type":"object", - "additionalProperties":{ - "type":"object", - "properties":{ - "url":{"type":"string"}, - "key":{"type":"string","writeOnly":true} - } - } + "endpoint":{"type":"string"}, + "token":{"type":"string","writeOnly":true} + }` + required + ` + }, + "servers":{ + "type":"object", + "additionalProperties":{ + "type":"object", + "properties":{ + "url":{"type":"string"}, + "key":{"type":"string","writeOnly":true} } } - }` + } + } + }` +} + +var stagedSecretCases = []stagedSecretCase{ + { + name: "saved settings with the secret left out", + sameSettings: true, + submitted: stagedSecretSubmission(nil), + wantPassword: stagedSavedPassword, + wantToken: "saved-token", + }, + { + name: "saved settings with a blank secret and the form default", + sameSettings: true, + submitted: stagedSecretSubmission(func(v map[string]any) { v["bind_password"] = ""; v["page_size"] = 100 }), + wantPassword: stagedSavedPassword, + wantToken: "saved-token", + }, + { + name: "stored value removed for its default", + submitted: stagedSecretSubmission(func(v map[string]any) { v["start_tls"] = nil }), + }, + { + name: "one secret typed, another left out", + submitted: stagedSecretSubmission(func(v map[string]any) { v["bind_password"] = "typed-password" }), + // The typed secret may itself be a destination, so the + // other stored secrets stay behind. + wantPassword: "typed-password", + }, + { + name: "changed server", + submitted: stagedSecretSubmission(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid:389" }), + }, + { + name: "changed server with a blank secret", + submitted: stagedSecretSubmission(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid"; v["bind_password"] = " " }), + }, + { + name: "changed CA", + submitted: stagedSecretSubmission(func(v map[string]any) { v["ca_pem"] = "-----BEGIN CERTIFICATE-----" }), + }, + { + name: "default replaced by another value", + submitted: stagedSecretSubmission(func(v map[string]any) { v["start_tls"] = true }), + }, + { + name: "changed nested endpoint", + submitted: stagedSecretSubmission(func(v map[string]any) { v["service"] = map[string]any{"endpoint": "https://elsewhere.example.invalid"} }), + }, + { + name: "changed server with typed secrets", + submitted: stagedSecretSubmission(func(v map[string]any) { + v["urls"] = "ldap://elsewhere.example.invalid" + v["bind_password"] = "typed-password" + v["service"] = map[string]any{"endpoint": "https://api.example.invalid", "token": "typed-token"} + }), + wantPassword: "typed-password", + wantToken: "typed-token", + }, + { + name: "saved settings with a cleared secret", + sameSettings: true, + submitted: stagedSecretSubmission(nil), + clearSecrets: []string{"bind_password"}, + wantToken: "saved-token", + }, + { + name: "same URL inside an object of secrets", + sameSettings: true, + submitted: stagedSecretSubmission(func(v map[string]any) { + v["servers"] = map[string]any{"main": map[string]any{"url": "https://api.example.invalid", "key": ""}} + }), + wantPassword: stagedSavedPassword, + wantToken: "saved-token", + wantServerKey: "saved-server-key", + }, + { + name: "changed URL inside an object of secrets", + submitted: stagedSecretSubmission(func(v map[string]any) { + v["servers"] = map[string]any{"main": map[string]any{"url": "https://elsewhere.example.invalid", "key": ""}} + }), + wantServerKey: nil, + }, + { + name: "changed server with a secret both typed and cleared", + submitted: stagedSecretSubmission(func(v map[string]any) { + v["urls"] = "ldap://elsewhere.example.invalid" + v["bind_password"] = "typed-password" + }), + clearSecrets: []string{"bind_password"}, + }, + { + name: "changed server with a required secret left out", + submitted: stagedSecretSubmission(func(v map[string]any) { v["urls"] = "ldap://elsewhere.example.invalid" }), + requireToken: true, + wantErr: true, + }, +} + +// TestStagedConfigReusesSecretsOnlyWithSavedSettings: a connection test +// fills a blank secret from the stored entry only while every other setting +// matches what was saved, so a staged destination never receives a saved +// credential (issue #2796). +func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { + for _, tc := range stagedSecretCases { + t.Run(tc.name, func(t *testing.T) { + manifest := connectionTestManifest(t, "silo.auth.ldap", "0.1.0") + manifest.GlobalConfigSchema[0].JsonSchema = stagedSecretSchema(tc.requireToken) manifest.GlobalConfigSchema[0].AdminForm = nil - service, _ := connectionConfigService(t, manifest, cloneConfigValue(stored).(map[string]any)) + service, _ := connectionConfigService(t, manifest, stagedSecretStored()) staged, err := service.prepareStagedGlobalConfig(t.Context(), 7, manifest, "connection", tc.submitted, tc.clearSecrets, func(err error) error { return err }) if tc.wantErr { @@ -506,8 +531,12 @@ func TestStagedConfigReusesSecretsOnlyWithSavedSettings(t *testing.T) { if _, sent := tc.submitted["servers"]; sent { servers, _ := staged["servers"].(map[string]any) main, _ := servers["main"].(map[string]any) - if got := main["key"]; got != tc.wantServerKey && !(tc.wantServerKey == nil && got == "") { - t.Fatalf("servers.main.key = %#v, want %#v", got, tc.wantServerKey) + got := main["key"] + if tc.wantServerKey == nil && got == "" { + got = nil // a blank key is no key + } + if got != tc.wantServerKey { + t.Fatalf("servers.main.key = %#v, want %#v", main["key"], tc.wantServerKey) } } if got, present := staged["plugin_owned"]; present != tc.sameSettings { diff --git a/web/src/api/v2/schema.ts b/web/src/api/v2/schema.ts index 09d44ccfbf..090031480a 100644 --- a/web/src/api/v2/schema.ts +++ b/web/src/api/v2/schema.ts @@ -3918,7 +3918,7 @@ export interface paths { put?: never; /** * Test an auth plugin's connection with staged, unsaved settings. - * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise the test runs with only the secrets entered. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. + * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. */ post: operations["testAdminPluginAuthBinding"]; delete?: never; @@ -19761,7 +19761,7 @@ export interface components { AdminPluginAuthBindingTestInputBody: { /** @description auth_provider.v1 capability to test; empty tests the plugin's first one */ capability_id?: string; - /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret; clear_secrets drops it from the test */ + /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used; clear_secrets drops it from the test */ config?: components["schemas"]["AdminPluginConfigWrite"][]; }; AdminPluginAuthBindingWrite: { From 7ddba9070435206a63cb5b778150819fa541c454 Mon Sep 17 00:00:00 2001 From: blurbery <271863866+blurbery@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:34:53 +1100 Subject: [PATCH 05/11] docs(apiv2): say a changed test entry leaves out undeclared stored fields --- contracts/api/v2/openapi.json | 4 ++-- internal/apiv2/admin_plugin_configuration.go | 2 +- internal/apiv2/external_sign_in.go | 2 +- web/src/api/v2/schema.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index 81d094f57e..6c7d4bec7c 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -16439,7 +16439,7 @@ "type": "string" }, "config": { - "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used; clear_secrets drops it from the test", + "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test", "items": { "$ref": "#/components/schemas/AdminPluginConfigWrite" }, @@ -16793,7 +16793,7 @@ }, "value": { "additionalProperties": true, - "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered", + "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered; otherwise it also leaves out stored fields the schema does not declare", "type": "object", "x-silo-extension-bag": "plugin-json-value" } diff --git a/internal/apiv2/admin_plugin_configuration.go b/internal/apiv2/admin_plugin_configuration.go index 5f89dfb1fc..cb0e5550ea 100644 --- a/internal/apiv2/admin_plugin_configuration.go +++ b/internal/apiv2/admin_plugin_configuration.go @@ -31,7 +31,7 @@ type AdminPluginConfigurationService interface { // unchanged and no secret in it is entered. type AdminPluginConfigWrite struct { Key string `json:"key" minLength:"1" maxLength:"256" doc:"The manifest global_config_schema key"` - Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered"` + Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered; otherwise it also leaves out stored fields the schema does not declare"` ClearSecrets []string `json:"clear_secrets,omitempty" maxItems:"64" doc:"Secret fields to remove; each must be a manifest-declared secret of this key"` } type AdminPluginConfigInput struct { diff --git a/internal/apiv2/external_sign_in.go b/internal/apiv2/external_sign_in.go index 18fd9ebb00..ff9f7ff3ab 100644 --- a/internal/apiv2/external_sign_in.go +++ b/internal/apiv2/external_sign_in.go @@ -190,7 +190,7 @@ type AdminPluginAuthBindingTestInput struct { RawBody []byte Body struct { CapabilityID string `json:"capability_id,omitempty" maxLength:"256" doc:"auth_provider.v1 capability to test; empty tests the plugin's first one"` - Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used; clear_secrets drops it from the test"` + Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test"` } } diff --git a/web/src/api/v2/schema.ts b/web/src/api/v2/schema.ts index 090031480a..a58baab7cf 100644 --- a/web/src/api/v2/schema.ts +++ b/web/src/api/v2/schema.ts @@ -19761,7 +19761,7 @@ export interface components { AdminPluginAuthBindingTestInputBody: { /** @description auth_provider.v1 capability to test; empty tests the plugin's first one */ capability_id?: string; - /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used; clear_secrets drops it from the test */ + /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test */ config?: components["schemas"]["AdminPluginConfigWrite"][]; }; AdminPluginAuthBindingWrite: { @@ -19873,7 +19873,7 @@ export interface components { clear_secrets?: string[]; /** @description The manifest global_config_schema key */ key: string; - /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered */ + /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered; otherwise it also leaves out stored fields the schema does not declare */ value: { [key: string]: unknown; }; From 15932b874041302b4d873d7c8ad0749b3da7313e Mon Sep 17 00:00:00 2001 From: blurbery <271863866+blurbery@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:36:41 +1100 Subject: [PATCH 06/11] docs(admin-api): limit the staged-test guarantee to the changed entry --- docs/admin-api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/admin-api.md b/docs/admin-api.md index 5fbe333c92..84ed52ff14 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -3506,8 +3506,8 @@ only while the entry is otherwise unchanged. Unchanged means no secret is typed other field, after clears, matches the stored entry; a field the stored entry lacks matches its declared default. A staged entry that changes a server URL, issuer, CA or any other setting, or types a secret, is tested with only the secrets the administrator typed -and without undeclared stored fields, so a test never sends a saved credential to a -destination it was not saved for. The rule is per entry: the other stored entries go to the +and without undeclared stored fields, so a destination changed in an entry never receives +that entry's saved credentials. The rule is per entry: the other stored entries go to the plugin unchanged, so a plugin that keeps a credential in one entry and its destination in another is not covered. The server validates the merged entry against the plugin's schema and returns 422 with the plugin's own message on failure, then persists From 08d03dcf78b61af0ebf28ec83a4c7cab0ffde87f Mon Sep 17 00:00:00 2001 From: blurbery <271863866+blurbery@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:51:52 +1100 Subject: [PATCH 07/11] docs(apiv2): explain how a submitted secret object counts as entered --- contracts/api/v2/openapi.json | 6 +++--- docs/admin-api.md | 4 +++- internal/apiv2/admin_plugin_configuration.go | 2 +- internal/apiv2/external_sign_in.go | 4 ++-- web/src/api/v2/schema.ts | 6 +++--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index 6c7d4bec7c..8a148e7fc0 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -16439,7 +16439,7 @@ "type": "string" }, "config": { - "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test", + "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test", "items": { "$ref": "#/components/schemas/AdminPluginConfigWrite" }, @@ -16793,7 +16793,7 @@ }, "value": { "additionalProperties": true, - "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered; otherwise it also leaves out stored fields the schema does not declare", + "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise it also leaves out stored fields the schema does not declare", "type": "object", "x-silo-extension-bag": "plugin-json-value" } @@ -109421,7 +109421,7 @@ }, "/api/v2/admin/plugins/installations/{id}/auth-binding/test": { "post": { - "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", + "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", "operationId": "testAdminPluginAuthBinding", "parameters": [ { diff --git a/docs/admin-api.md b/docs/admin-api.md index 84ed52ff14..2146e5950c 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -3504,7 +3504,9 @@ connection test (`.../config/test` and the auth connection test) merges a staged same way without storing it, with one difference: a blank secret reuses the stored secret only while the entry is otherwise unchanged. Unchanged means no secret is typed and every other field, after clears, matches the stored entry; a field the stored entry lacks -matches its declared default. A staged entry that changes a server URL, issuer, CA or any +matches its declared default. A secret object or list (such as a map of servers with keys +inside) is compared whole, blank secrets filled from the stored one, so it counts as typed +only when it differs from what is stored. A staged entry that changes a server URL, issuer, CA or any other setting, or types a secret, is tested with only the secrets the administrator typed and without undeclared stored fields, so a destination changed in an entry never receives that entry's saved credentials. The rule is per entry: the other stored entries go to the diff --git a/internal/apiv2/admin_plugin_configuration.go b/internal/apiv2/admin_plugin_configuration.go index cb0e5550ea..1ca0b224f9 100644 --- a/internal/apiv2/admin_plugin_configuration.go +++ b/internal/apiv2/admin_plugin_configuration.go @@ -31,7 +31,7 @@ type AdminPluginConfigurationService interface { // unchanged and no secret in it is entered. type AdminPluginConfigWrite struct { Key string `json:"key" minLength:"1" maxLength:"256" doc:"The manifest global_config_schema key"` - Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered; otherwise it also leaves out stored fields the schema does not declare"` + Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise it also leaves out stored fields the schema does not declare"` ClearSecrets []string `json:"clear_secrets,omitempty" maxItems:"64" doc:"Secret fields to remove; each must be a manifest-declared secret of this key"` } type AdminPluginConfigInput struct { diff --git a/internal/apiv2/external_sign_in.go b/internal/apiv2/external_sign_in.go index ff9f7ff3ab..48fa17bd38 100644 --- a/internal/apiv2/external_sign_in.go +++ b/internal/apiv2/external_sign_in.go @@ -190,7 +190,7 @@ type AdminPluginAuthBindingTestInput struct { RawBody []byte Body struct { CapabilityID string `json:"capability_id,omitempty" maxLength:"256" doc:"auth_provider.v1 capability to test; empty tests the plugin's first one"` - Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test"` + Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test"` } } @@ -562,7 +562,7 @@ func registerExternalSignIn(reg *Registry) { test := Operation{Operation: humaOp(http.MethodPost, Prefix+"/admin/plugins/installations/{id}/auth-binding/test", "testAdminPluginAuthBinding", "admin-plugins", "Test an auth plugin's connection with staged, unsaved settings."), Class: ClassActingAdmin, DemoRestricted: true, ServiceBacked: true, RetrySafety: RetrySafetyNonRetryable} - test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." + test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." test.Errors = []int{http.StatusNotFound, http.StatusConflict} Register(reg, test, func(ctx context.Context, in *AdminPluginAuthBindingTestInput) (*AuthConnectionTestOutput, error) { if reg.deps.ExternalSignIn == nil || !reg.deps.ExternalSignIn.ConnectionTestAvailable() { diff --git a/web/src/api/v2/schema.ts b/web/src/api/v2/schema.ts index a58baab7cf..bf78ad3f1f 100644 --- a/web/src/api/v2/schema.ts +++ b/web/src/api/v2/schema.ts @@ -3918,7 +3918,7 @@ export interface paths { put?: never; /** * Test an auth plugin's connection with staged, unsaved settings. - * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered; otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. + * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. */ post: operations["testAdminPluginAuthBinding"]; delete?: never; @@ -19761,7 +19761,7 @@ export interface components { AdminPluginAuthBindingTestInputBody: { /** @description auth_provider.v1 capability to test; empty tests the plugin's first one */ capability_id?: string; - /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered, otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test */ + /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test */ config?: components["schemas"]["AdminPluginConfigWrite"][]; }; AdminPluginAuthBindingWrite: { @@ -19873,7 +19873,7 @@ export interface components { clear_secrets?: string[]; /** @description The manifest global_config_schema key */ key: string; - /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered; otherwise it also leaves out stored fields the schema does not declare */ + /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise it also leaves out stored fields the schema does not declare */ value: { [key: string]: unknown; }; From 7a323ad4fcebb625332046d877339340020cd6a5 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:30:20 -0500 Subject: [PATCH 08/11] fix(plugins): count a submitted secret object as entered in connection tests A connection test compared a submitted secret object or list with the stored one, contents included, and reused the entry's other stored secrets when they matched. The result could confirm a guessed stored key. Any non-blank secret value that is sent now counts as entered, the same as a typed scalar secret, and secret paths always stay out of the comparison. The admin API never returns an object that holds secrets, so the web form cannot send one back and testing saved settings is unaffected. Co-Authored-By: Claude Opus 5.5 --- contracts/api/v2/openapi.json | 6 +++--- docs/admin-api.md | 3 +-- internal/apiv2/admin_plugin_configuration.go | 2 +- internal/apiv2/external_sign_in.go | 4 ++-- internal/plugins/service_connection.go | 22 ++++++-------------- internal/plugins/service_connection_test.go | 16 ++++++++++---- web/src/api/v2/schema.ts | 6 +++--- 7 files changed, 28 insertions(+), 31 deletions(-) diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index 3d316ce4d3..892b88b439 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -16469,7 +16469,7 @@ "type": "string" }, "config": { - "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test", + "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test", "items": { "$ref": "#/components/schemas/AdminPluginConfigWrite" }, @@ -16823,7 +16823,7 @@ }, "value": { "additionalProperties": true, - "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise it also leaves out stored fields the schema does not declare", + "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored fields the schema does not declare", "type": "object", "x-silo-extension-bag": "plugin-json-value" } @@ -109719,7 +109719,7 @@ }, "/api/v2/admin/plugins/installations/{id}/auth-binding/test": { "post": { - "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", + "description": "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically.", "operationId": "testAdminPluginAuthBinding", "parameters": [ { diff --git a/docs/admin-api.md b/docs/admin-api.md index 84812e7500..14d45801a5 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -3507,8 +3507,7 @@ same way without storing it, with one difference: a blank secret reuses the stor only while the entry is otherwise unchanged. Unchanged means no secret is typed and every other field, after clears, matches the stored entry; a field the stored entry lacks matches its declared default. A secret object or list (such as a map of servers with keys -inside) is compared whole, blank secrets filled from the stored one, so it counts as typed -only when it differs from what is stored. A staged entry that changes a server URL, issuer, CA or any +inside) counts as typed whenever it is sent, because its contents are secret. A staged entry that changes a server URL, issuer, CA or any other setting, or types a secret, is tested with only the secrets the administrator typed and without undeclared stored fields, so a destination changed in an entry never receives that entry's saved credentials. The rule is per entry: the other stored entries go to the diff --git a/internal/apiv2/admin_plugin_configuration.go b/internal/apiv2/admin_plugin_configuration.go index 1ca0b224f9..632b038722 100644 --- a/internal/apiv2/admin_plugin_configuration.go +++ b/internal/apiv2/admin_plugin_configuration.go @@ -31,7 +31,7 @@ type AdminPluginConfigurationService interface { // unchanged and no secret in it is entered. type AdminPluginConfigWrite struct { Key string `json:"key" minLength:"1" maxLength:"256" doc:"The manifest global_config_schema key"` - Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise it also leaves out stored fields the schema does not declare"` + Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored fields the schema does not declare"` ClearSecrets []string `json:"clear_secrets,omitempty" maxItems:"64" doc:"Secret fields to remove; each must be a manifest-declared secret of this key"` } type AdminPluginConfigInput struct { diff --git a/internal/apiv2/external_sign_in.go b/internal/apiv2/external_sign_in.go index 9f237e62eb..c64975f625 100644 --- a/internal/apiv2/external_sign_in.go +++ b/internal/apiv2/external_sign_in.go @@ -195,7 +195,7 @@ type AdminPluginAuthBindingTestInput struct { RawBody []byte Body struct { CapabilityID string `json:"capability_id,omitempty" maxLength:"256" doc:"auth_provider.v1 capability to test; empty tests the plugin's first one"` - Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test"` + Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test"` } } @@ -593,7 +593,7 @@ func registerExternalSignIn(reg *Registry) { test := Operation{Operation: humaOp(http.MethodPost, Prefix+"/admin/plugins/installations/{id}/auth-binding/test", "testAdminPluginAuthBinding", "admin-plugins", "Test an auth plugin's connection with staged, unsaved settings."), Class: ClassActingAdmin, DemoRestricted: true, ServiceBacked: true, RetrySafety: RetrySafetyNonRetryable} - test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." + test.Description = "The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically." test.Errors = []int{http.StatusNotFound, http.StatusConflict} Register(reg, test, func(ctx context.Context, in *AdminPluginAuthBindingTestInput) (*AuthConnectionTestOutput, error) { if reg.deps.ExternalSignIn == nil || !reg.deps.ExternalSignIn.ConnectionTestAvailable() { diff --git a/internal/plugins/service_connection.go b/internal/plugins/service_connection.go index 69f7b8de80..baa5657a8a 100644 --- a/internal/plugins/service_connection.go +++ b/internal/plugins/service_connection.go @@ -185,6 +185,7 @@ func (s *Service) TestGlobalConfigWithClears( // the admin typed and the fields the schema declares reach the plugin, so a // test cannot send a saved credential to a destination it was never saved // for (issue #2796). +// // invalid wraps a rejected entry in the caller's error type. func (s *Service) prepareStagedGlobalConfig( ctx context.Context, @@ -235,14 +236,9 @@ func stagedConfigChangesSettings( secretPaths [][]string, ) bool { for _, path := range secretPaths { - typed, present := configPathValue(submitted, path) - if !present || isClearedConfigValue(typed) { - continue - } - switch typed.(type) { - case map[string]any, []any: - // A secret object or list is compared whole below. - default: + // A secret object or list counts as typed too: its contents are + // secret, so comparing them would answer the same guesses. + if typed, present := configPathValue(submitted, path); present && !isClearedConfigValue(typed) { return true } } @@ -273,14 +269,8 @@ func settingsForComparison(value map[string]any, secretPaths [][]string) (map[st normalized = map[string]any{} } for _, path := range secretPaths { - // A secret path can name a whole object or list (a map of servers - // with secrets inside, or a shape the path walker cannot address). - // Its other values may be destinations, so it is compared whole. - secret, _ := configPathValue(normalized, path) - switch secret.(type) { - case map[string]any, []any: - continue - } + // A submitted secret already counts as a change, so a secret here + // is the stored one on both sides and is left out. deleteConfigPath(normalized, path) } for field, fieldValue := range normalized { diff --git a/internal/plugins/service_connection_test.go b/internal/plugins/service_connection_test.go index 2bb41657ae..9b0c011470 100644 --- a/internal/plugins/service_connection_test.go +++ b/internal/plugins/service_connection_test.go @@ -467,13 +467,21 @@ var stagedSecretCases = []stagedSecretCase{ wantToken: "saved-token", }, { - name: "same URL inside an object of secrets", - sameSettings: true, + // The admin API never shows an object of secrets, so sending one + // is typing it, even with the stored URL and a blank key. + name: "same URL inside an object of secrets", submitted: stagedSecretSubmission(func(v map[string]any) { v["servers"] = map[string]any{"main": map[string]any{"url": "https://api.example.invalid", "key": ""}} }), - wantPassword: stagedSavedPassword, - wantToken: "saved-token", + wantServerKey: nil, + }, + { + // Matching the stored key must not bring back the other stored + // secrets, or the result would confirm the guess. + name: "stored key guessed inside an object of secrets", + submitted: stagedSecretSubmission(func(v map[string]any) { + v["servers"] = map[string]any{"main": map[string]any{"url": "https://api.example.invalid", "key": "saved-server-key"}} + }), wantServerKey: "saved-server-key", }, { diff --git a/web/src/api/v2/schema.ts b/web/src/api/v2/schema.ts index c57b6eafe4..e2b7347f4a 100644 --- a/web/src/api/v2/schema.ts +++ b/web/src/api/v2/schema.ts @@ -3921,7 +3921,7 @@ export interface paths { put?: never; /** * Test an auth plugin's connection with staged, unsaved settings. - * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. + * @description The running plugin tests the staged configuration (merged over the stored entries it does not replace) and persists nothing. A blank secret field reuses the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise that entry is tested with only the secrets entered. The rule is per entry: stored entries not named here keep their secrets. A failed check is a 200 result with ok false. A plugin without a connection test, or a disabled installation, is 409. The check reaches the provider and is bounded by a server timeout; never retry an uncertain result automatically. */ post: operations["testAdminPluginAuthBinding"]; delete?: never; @@ -19891,7 +19891,7 @@ export interface components { AdminPluginAuthBindingTestInputBody: { /** @description auth_provider.v1 capability to test; empty tests the plugin's first one */ capability_id?: string; - /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test */ + /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test */ config?: components["schemas"]["AdminPluginConfigWrite"][]; }; AdminPluginAuthBindingWrite: { @@ -20003,7 +20003,7 @@ export interface components { clear_secrets?: string[]; /** @description The manifest global_config_schema key */ key: string; - /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list counts as entered only when it differs from the stored one); otherwise it also leaves out stored fields the schema does not declare */ + /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored fields the schema does not declare */ value: { [key: string]: unknown; }; From 9293b0a1226a7b8c16a0f10050bedd2759772706 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:43:03 -0500 Subject: [PATCH 09/11] docs(apiv2): say a changed test drops only top-level undeclared fields dropStoredUndeclaredFields removes stored top-level fields the schema does not declare. An undeclared key stored inside a declared object is kept, as before this change, so the descriptions and docs/admin-api.md now say top-level. Co-Authored-By: Claude Opus 5.5 --- contracts/api/v2/openapi.json | 4 ++-- docs/admin-api.md | 5 +++-- internal/apiv2/admin_plugin_configuration.go | 2 +- internal/apiv2/external_sign_in.go | 2 +- web/src/api/v2/schema.ts | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index 892b88b439..9f4791dffb 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -16469,7 +16469,7 @@ "type": "string" }, "config": { - "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test", + "description": "Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored top-level fields the schema does not declare are left out of that entry; clear_secrets drops it from the test", "items": { "$ref": "#/components/schemas/AdminPluginConfigWrite" }, @@ -16823,7 +16823,7 @@ }, "value": { "additionalProperties": true, - "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored fields the schema does not declare", + "description": "The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored top-level fields the schema does not declare", "type": "object", "x-silo-extension-bag": "plugin-json-value" } diff --git a/docs/admin-api.md b/docs/admin-api.md index 14d45801a5..74c63df781 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -3509,8 +3509,9 @@ other field, after clears, matches the stored entry; a field the stored entry la matches its declared default. A secret object or list (such as a map of servers with keys inside) counts as typed whenever it is sent, because its contents are secret. A staged entry that changes a server URL, issuer, CA or any other setting, or types a secret, is tested with only the secrets the administrator typed -and without undeclared stored fields, so a destination changed in an entry never receives -that entry's saved credentials. The rule is per entry: the other stored entries go to the +and without undeclared stored top-level fields, so a destination changed in an entry never +receives the saved secrets that entry declares. An undeclared key stored inside a declared +object is kept. The rule is per entry: the other stored entries go to the plugin unchanged, so a plugin that keeps a credential in one entry and its destination in another is not covered. The server validates the merged entry against the plugin's schema and returns 422 with the plugin's own message on failure, then persists diff --git a/internal/apiv2/admin_plugin_configuration.go b/internal/apiv2/admin_plugin_configuration.go index 632b038722..01e0b567e2 100644 --- a/internal/apiv2/admin_plugin_configuration.go +++ b/internal/apiv2/admin_plugin_configuration.go @@ -31,7 +31,7 @@ type AdminPluginConfigurationService interface { // unchanged and no secret in it is entered. type AdminPluginConfigWrite struct { Key string `json:"key" minLength:"1" maxLength:"256" doc:"The manifest global_config_schema key"` - Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored fields the schema does not declare"` + Value PluginJSONValue `json:"value" doc:"The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored top-level fields the schema does not declare"` ClearSecrets []string `json:"clear_secrets,omitempty" maxItems:"64" doc:"Secret fields to remove; each must be a manifest-declared secret of this key"` } type AdminPluginConfigInput struct { diff --git a/internal/apiv2/external_sign_in.go b/internal/apiv2/external_sign_in.go index c64975f625..5451dd9240 100644 --- a/internal/apiv2/external_sign_in.go +++ b/internal/apiv2/external_sign_in.go @@ -195,7 +195,7 @@ type AdminPluginAuthBindingTestInput struct { RawBody []byte Body struct { CapabilityID string `json:"capability_id,omitempty" maxLength:"256" doc:"auth_provider.v1 capability to test; empty tests the plugin's first one"` - Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test"` + Config []AdminPluginConfigWrite `json:"config,omitempty" maxItems:"64" doc:"Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored top-level fields the schema does not declare are left out of that entry; clear_secrets drops it from the test"` } } diff --git a/web/src/api/v2/schema.ts b/web/src/api/v2/schema.ts index e2b7347f4a..1fd13503f1 100644 --- a/web/src/api/v2/schema.ts +++ b/web/src/api/v2/schema.ts @@ -19891,7 +19891,7 @@ export interface components { AdminPluginAuthBindingTestInputBody: { /** @description auth_provider.v1 capability to test; empty tests the plugin's first one */ capability_id?: string; - /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored fields the schema does not declare are left out of that entry; clear_secrets drops it from the test */ + /** @description Staged global configuration entries, unsaved, merged as updateAdminPluginInstallationConfig would merge them. Entries and fields not named here use the stored values; a declared non-secret field sent as null or a blank string is cleared so the plugin default applies; blank secret fields use the stored secret only while the rest of that entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered), otherwise only the secrets entered are used and stored top-level fields the schema does not declare are left out of that entry; clear_secrets drops it from the test */ config?: components["schemas"]["AdminPluginConfigWrite"][]; }; AdminPluginAuthBindingWrite: { @@ -20003,7 +20003,7 @@ export interface components { clear_secrets?: string[]; /** @description The manifest global_config_schema key */ key: string; - /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored fields the schema does not declare */ + /** @description The entry's fields, merged over the stored entry. A declared non-secret top-level field sent as null or a blank string is removed so the plugin default applies; blank secret fields preserve the stored secret. A connection test reuses a stored secret only while the rest of the entry is unchanged and no secret in it is entered (a secret object or list sent in it counts as entered); otherwise it also leaves out stored top-level fields the schema does not declare */ value: { [key: string]: unknown; }; From a935c178a61829a79ea2296ee0b6fd17a6ec0261 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:55:43 -0500 Subject: [PATCH 10/11] docs(admin-api): note that entries without a declared secret merge as a save prepareStagedGlobalConfig filters a changed entry only when its schema declares a secret. An entry without one keeps its undeclared stored fields in a connection test, as it did before; the paragraph now says so. Co-Authored-By: Claude Opus 5.5 --- docs/admin-api.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/admin-api.md b/docs/admin-api.md index 74c63df781..f67ce1d2b4 100644 --- a/docs/admin-api.md +++ b/docs/admin-api.md @@ -3511,7 +3511,8 @@ inside) counts as typed whenever it is sent, because its contents are secret. A other setting, or types a secret, is tested with only the secrets the administrator typed and without undeclared stored top-level fields, so a destination changed in an entry never receives the saved secrets that entry declares. An undeclared key stored inside a declared -object is kept. The rule is per entry: the other stored entries go to the +object is kept, and an entry whose schema declares no secret is merged as a save would +merge it, undeclared stored fields included. The rule is per entry: the other stored entries go to the plugin unchanged, so a plugin that keeps a credential in one entry and its destination in another is not covered. The server validates the merged entry against the plugin's schema and returns 422 with the plugin's own message on failure, then persists From 87895a253cb647ac9d16a92814251c6a139f6eec Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Sat, 14 Nov 2026 16:19:37 -0500 Subject: [PATCH 11/11] chore(apiv2): drop the merged updateDownloadSubscription approvals #3535 is on main, so its six breaking-change approvals no longer match a change between this branch and its base, and the contract gate fails on them as stale. Co-Authored-By: Claude Opus 5.5 --- contracts/api/v2/breaking-approvals.json | 45 +----------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/contracts/api/v2/breaking-approvals.json b/contracts/api/v2/breaking-approvals.json index ec7f34fc05..08ac789b35 100644 --- a/contracts/api/v2/breaking-approvals.json +++ b/contracts/api/v2/breaking-approvals.json @@ -1,46 +1,3 @@ { - "approvals": [ - { - "operation_id": "updateDownloadSubscription", - "change_id": "request-property-became-not-nullable", - "fingerprint": "758bc212b081efa8d4532211cf311e027e493fb36971a7b6c9dcf912f025a11e", - "reason": "The handler already refuses null on every monitor patch field and docs/downloads-api.md says null is rejected; only the document claimed it was accepted. silo-apple omits nil fields, and silo-android and web do not call this operation.", - "approved_in": "#3535" - }, - { - "operation_id": "updateDownloadSubscription", - "change_id": "request-property-became-not-nullable", - "fingerprint": "a3a523da084f36d085bff481d94cebadd34aef3beb97b83d36fd24f79e813acc", - "reason": "The handler already refuses null on every monitor patch field and docs/downloads-api.md says null is rejected; only the document claimed it was accepted. silo-apple omits nil fields, and silo-android and web do not call this operation.", - "approved_in": "#3535" - }, - { - "operation_id": "updateDownloadSubscription", - "change_id": "request-property-became-not-nullable", - "fingerprint": "d2fbcd692e1d26043b7f191350163753c9df6e86b9007a46204dbad0dd024922", - "reason": "The handler already refuses null on every monitor patch field and docs/downloads-api.md says null is rejected; only the document claimed it was accepted. silo-apple omits nil fields, and silo-android and web do not call this operation.", - "approved_in": "#3535" - }, - { - "operation_id": "updateDownloadSubscription", - "change_id": "request-property-became-not-nullable", - "fingerprint": "6ab3919a77cf889c326d06ea05fbc49ce68490490a6cd850466928e6cb136c0e", - "reason": "The handler already refuses null on every monitor patch field and docs/downloads-api.md says null is rejected; only the document claimed it was accepted. silo-apple omits nil fields, and silo-android and web do not call this operation.", - "approved_in": "#3535" - }, - { - "operation_id": "updateDownloadSubscription", - "change_id": "request-property-became-not-nullable", - "fingerprint": "db3bc0b9bc885edf79e8d775113459c401e27e0999625f46c949fbaf1f097240", - "reason": "The handler already refuses null on every monitor patch field and docs/downloads-api.md says null is rejected; only the document claimed it was accepted. silo-apple omits nil fields, and silo-android and web do not call this operation.", - "approved_in": "#3535" - }, - { - "operation_id": "updateDownloadSubscription", - "change_id": "request-property-became-not-nullable", - "fingerprint": "ac753659fe85643f58ede9067603f9a00b4af6c911480a374c7471eb54b7f7a8", - "reason": "The handler already refuses null on every monitor patch field and docs/downloads-api.md says null is rejected; only the document claimed it was accepted. silo-apple omits nil fields, and silo-android and web do not call this operation.", - "approved_in": "#3535" - } - ] + "approvals": [] }