Repository navigation
feat(secrets): store owned credentials under keys derived from their owner's id - #36706
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
| } | ||
|
|
||
| private String storeValue(SecretOwner owner, List<String> fieldPath, String value) { | ||
| return secretsManager.storeOwnedValue(fieldPath.getLast(), secretId(owner, fieldPath), value); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…ead of recovering a deleted secret
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, andSecretsManagerUpdateExtension, so a distribution can update the credentials it stores itself duringmigrateandmigrate-secrets. Callers move toOwnedSecretsin follow-up changes. Nothing in this repository calls it yet, and existing keys, references and callers are unchanged.Type of change:
High-level design:
SecretOwner: code literals followed by the owner's ids, for exampleSecretOwner.builder("pipeline").id(pipelineId).build(). Segments are restricted to[a-z0-9]+.OwnedSecrets(fromSecretsManager.ownedSecrets()):encrypt(value, owner, path, keptReferences)stores each plaintext credential under the owner's key, replaces it with itssecret: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 amongkeptReferences.secret:reference into the managed namespace is kept when it lies in the owner's namespace or is inkeptReferences; otherwise the call returns 400 naming the field. References outside the managed namespace are left as they are.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.<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.PasswordFieldWalkervisits the same@PasswordFieldfields as the existing encrypt walk and gives each field's path to a visitor.SecretsManagerUpdateExtension(SPI,META-INF/services):SecretsManagerUpdateService.updateEntitiesruns 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.Compatibility: additive. Readers resolve the exact name after
secret:, so both key layouts work side by side.Tests:
Use cases covered
rekeycopies the secret, keeps the source, reports missing and unreadable secrets, and changes nothing on a second run.deleteremoves only the owner's secrets, and a refused delete does not fail the caller.Unit tests
OwnedSecretsTest(28),PasswordFieldWalkerTest(2) andSecretsManagerUpdateExtensionTest(5), with the in-memory secrets manager as the vault; one name-comparison test each inAzureKVSecretsManagerTest,AWSSecretsManagerTestandAWSSSMSecretsManagerTest, and two soft-delete tests inAzureKVSecretsManagerTestwith a mocked Key Vault client.org.openmetadata.service.secretspass locally.make java_affectedselects: 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
Summary by Gitar
SecretsManagerUpdateExtensionSPI, run bySecretsManagerUpdateServiceduring migrate commandsmaxSecretIdLengthandcanonicalSecretNameoverrides for AWS SSM, GCP, and KubernetesstoreOwnedValueandfindSecretValuetoExternalSecretsManagerThis will update automatically on new commits.