Skip to content

feat(secrets): store owned credentials under keys derived from their owner's id - #36706

Merged
manerow merged 9 commits into
mainfrom
secrets/owner-scoped-keys
Nov 4, 2026
Merged

manerow merged 9 commits into
mainfrom
secrets/owner-scoped-keys

Conversation

@manerow

@manerow manerow commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

No linked issue: a self-contained addition to the secrets manager API.

I added OwnedSecrets, a way to store a credential in an external secrets manager under a key derived from its owner's id, and SecretsManagerUpdateExtension, so a distribution can update the credentials it stores itself during migrate and migrate-secrets. Callers move to OwnedSecrets in follow-up changes. Nothing in this repository calls it yet, and existing keys, references and callers are unchanged.

Type of change:

  • Improvement

High-level design:

  • SecretOwner: code literals followed by the owner's ids, for example SecretOwner.builder("pipeline").id(pipelineId).build(). Segments are restricted to [a-z0-9]+.
  • OwnedSecrets (from SecretsManager.ownedSecrets()):
    • encrypt(value, owner, path, keptReferences) stores each plaintext credential under the owner's key, replaces it with its secret: reference, and keeps every field Fernet-encrypted. A field whose value does not change keeps its ciphertext. A field keeps one key for its whole life: a new value is written to the key the field already holds, found among keptReferences.
    • A secret: reference into the managed namespace is kept when it lies in the owner's namespace or is in keptReferences; otherwise the call returns 400 naming the field. References outside the managed namespace are left as they are.
    • Names are compared the way the provider resolves them (canonicalSecretName): case-insensitively on Azure Key Vault, and by the name inside an ARN on AWS Secrets Manager and SSM.
    • rekey(value, owner, path) copies a secret from another key of the managed namespace to the owner's key and reports fields whose secret is missing or unreadable. It never deletes the source.
    • references, delete(references, owner) (the owner's namespace only; a failed delete is logged), isManaged, isOwnedBy, exists.
  • Key layout: <prefix>/<cluster>/<owner segments>/<field key>. Ids are lowercase base32. The field key is the first 64 bits of the SHA-256 of the field's RFC 6901 path inside the owner, also base32. Each provider reports its maximum key length (maxSecretIdLength()); a longer key fails before anything is written.
  • A key that is not free: a field holding no key yet gets its own field key, unless another field of the value still refers to it (a list element keyed by its position taking a removed element's place) or the provider keeps the name for a deleted secret (Azure Key Vault soft delete, 409). Then it gets a fresh key: the field key plus a random suffix, which later saves keep updating. Deleted secrets are never recovered, so no extra permission is needed.
  • PasswordFieldWalker visits the same @PasswordField fields as the existing encrypt walk and gives each field's path to a visitor.
  • SecretsManagerUpdateExtension (SPI, META-INF/services): SecretsManagerUpdateService.updateEntities runs every registered extension after its own entities. An extension that throws, or a registration that cannot be loaded, does not stop the others; the update then fails and names them.
  • Decision records: ADR:2026-10-30-owned-secret-keys-are-derived-from-owner-ids and ADR:2026-10-30-distributions-update-their-own-credentials-through-an-extension.

Compatibility: additive. Readers resolve the exact name after secret:, so both key layouts work side by side.

Tests:

Use cases covered

  • Two owners saving the same field get separate secrets; saving again writes the same key.
  • Two parts of one owner, a nested credential and array elements each get their own key.
  • A list element that takes a removed element's position does not overwrite the secret a remaining element still reads, and keeps its own key on later saves.
  • A reference outside the owner's namespace that the owner does not hold is rejected; one it holds, or one outside the managed namespace, is kept.
  • A cleared field stores nothing; an unchanged field keeps its ciphertext.
  • rekey copies the secret, keeps the source, reports missing and unreadable secrets, and changes nothing on a second run.
  • delete removes only the owner's secrets, and a refused delete does not fail the caller.
  • Keys fit each provider's character set and length; a key that is too long fails before any write.
  • The database secrets manager keeps the credential in the field.
  • Each provider compares names the way it resolves them.
  • A field whose key a deleted secret still holds gets a fresh key and keeps updating it; nothing is recovered. Only a 409 counts as a held name on Azure Key Vault.
  • Every secrets update extension runs; one that fails or cannot be loaded fails the update without stopping the others.

Unit tests

  • OwnedSecretsTest (28), PasswordFieldWalkerTest (2) and SecretsManagerUpdateExtensionTest (5), with the in-memory secrets manager as the vault; one name-comparison test each in AzureKVSecretsManagerTest, AWSSecretsManagerTest and AWSSSMSecretsManagerTest, and two soft-delete tests in AzureKVSecretsManagerTest with a mocked Key Vault client.
  • All 301 tests under org.openmetadata.service.secrets pass locally.
  • The unit classes make java_affected selects: 167 tests in 17 classes pass. The two LocalStack classes did not run locally because Docker was unresponsive; PR CI runs them.

Backend integration tests

Not run locally. The change adds API and changes no existing caller.

Ingestion integration tests

Not applicable.

Playwright and manual testing

Not applicable: backend only.

Checklist

  • Spotless and the decision-record check pass; the impact map is complete.

Summary by Gitar

  • Secrets update extension:
    • Added SecretsManagerUpdateExtension SPI, run by SecretsManagerUpdateService during migrate commands
    • Extensions run independently, and any failure is reported as a failed update
  • Provider support:
    • Added maxSecretIdLength and canonicalSecretName overrides for AWS SSM, GCP, and Kubernetes
    • Added storeOwnedValue and findSecretValue to ExternalSecretsManager

This will update automatically on new commits.

@manerow
manerow requested a review from a team as a code owner October 30, 2026 13:59
@manerow
manerow requested a review from sonika-shah October 30, 2026 13:59
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 30, 2026
@open-metadata open-metadata deleted a comment from gitar-bot Bot Oct 30, 2026
@open-metadata open-metadata deleted a comment from gitar-bot Bot Oct 30, 2026
@open-metadata open-metadata deleted a comment from gitar-bot Bot Oct 30, 2026
}

private String storeValue(SecretOwner owner, List<String> fieldPath, String value) {
return secretsManager.storeOwnedValue(fieldPath.getLast(), secretId(owner, fieldPath), value);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a list element has no unique name, its field key comes from its position. If an earlier element is removed (or the list is reordered), a surviving element keeps its existing reference, e.g. to the key for position 1, while a new plaintext value that now sits at position 1 is written to that same key. The surviving element then silently resolves to the new value, and retire removes the old position-0 key.

As far as I can see no current caller has such a list, but since this is a generic API: could encryptField refuse (or choose a different key) when the target key is already referenced by another field in the same write? A test that saves a list, removes the first element and adds a new one would cover it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in f2ba90f. Before a write, OwnedSecrets now collects the keys that the value's other fields still point at. If a new value's key is one of them, the value gets a fresh key under the same owner instead. The surviving element keeps its secret, and retire only removes the key nothing points at anymore. Test: anElementTakingARemovedElementsPlaceKeepsTheSurvivorsSecret.

}

@Override
protected int maxSecretIdLength() {

@yan-3005 yan-3005 Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure Key Vault soft-deletes secrets by default, and deleteSecretInternal does not purge, so a deleted secret name cannot be set again until the vault's retention period ends. Since owned keys are fixed per owner and field, storing a key that was deleted earlier becomes a normal path for callers of this API.

Could we handle that in this PR, e.g. recover the deleted secret before setting it, and add a delete-then-store test for Azure?

@manerow manerow Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed in e268243, though without recovering the deleted secret. When Key Vault still holds a field's key after a delete (409), the field now gets a fresh key: its field key plus a random suffix. Later saves keep updating that key. This way a credential the user cleared stays deleted, together with its old versions, and no recover permission is needed. The same rule covers Sonika's case: a field gets a fresh key whenever its own key is not free. Tests: aFieldWhoseKeyADeletedSecretHoldsGetsAFreshKeyAndKeepsIt and anOwnedFieldWhoseNameADeletedSecretHoldsGetsAFreshKey.

@open-metadata open-metadata deleted a comment from gitar-bot Bot Nov 4, 2026
@open-metadata open-metadata deleted a comment from gitar-bot Bot Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants