Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# An alert destination's endpoint, header values and credentials are encrypted at rest, masked in every response, and restored from the stored alert when the mask is sent back

- **Status:** Accepted
- **Revisions:** v1 2026-10-23 (initial); v2 2026-10-26 (bind stored OAuth2 test credentials to their token URL); v3 2026-10-27 (a stored secret does not follow a moved target; a destination keeps its served channel); v4 2026-10-27 (a PATCH that moves a target must itself write every secret, since a row stored in plaintext reads as entered); v5 2026-10-28 (a PATCH may not carry a stored value into a channel that does not name it a secret); v6 2026-10-29 (a receivers list is a target; a template send resolves masks as a test send does); v7 2026-11-03 (an id the alert does not store, or one the request repeats, is matched by position); v8 2026-11-03 (a destination may change channel while its stored secrets stay secret; user and team profile webhooks follow the same rules)
- **Revisions:** v1 2026-10-23 (initial); v2 2026-10-26 (bind stored OAuth2 test credentials to their token URL); v3 2026-10-27 (a stored secret does not follow a moved target; a destination keeps its served channel); v4 2026-10-27 (a PATCH that moves a target must itself write every secret, since a row stored in plaintext reads as entered); v5 2026-10-28 (a PATCH may not carry a stored value into a channel that does not name it a secret); v6 2026-10-29 (a receivers list is a target; a template send resolves masks as a test send does); v7 2026-11-03 (an id the alert does not store, or one the request repeats, is matched by position); v8 2026-11-03 (a destination may change channel while its stored secrets stay secret; user and team profile webhooks follow the same rules); v9 2026-11-03 (secrets are encrypted for the destination or profile webhook that holds it; the 2.1.0 data step follows ADR:2026-11-03-a-webhook-secret-opens-only-where-it-was-written)
- **Deciders:** Teddy Crepineau
- **Guard:** `DestinationSecretsTest`, `DestinationSecretGuardsTest`, `DestinationSecretGuardsTest#aDestinationMayChangeChannelWhileItsStoredSecretsStaySecret`, `EventSubscriptionResourceIT#test_destinationSecretsAreMaskedEncryptedAndRestored`, `EventSubscriptionResourceIT#test_patchCannotCarryAStoredSecretIntoAChannelThatDoesNotMaskIt`, `EventSubscriptionResourceIT#test_receiversCannotRedirectStoredCredentials`, `EventSubscriptionResourceIT#test_ownersDestinationMovesFromEmailToSlack`, `TemplateTestSendIT`, `ProfileWebhookSecretsTest`, `WebhookSecretStoresTest`, `ProfileWebhookSecretsIT`
- **Related:** ADR:2026-10-20-mcp-responses-mask-stored-credentials
- **Related:** ADR:2026-10-20-mcp-responses-mask-stored-credentials, ADR:2026-11-03-a-webhook-secret-opens-only-where-it-was-written

## Context

Expand Down Expand Up @@ -93,5 +93,8 @@ mask back, decrypt only at the point of use.
saved again. Search documents of users and teams drop their profile webhooks when they are
reindexed.
- The team page shows a profile webhook as the mask, team admins included, as the alert form does.
- (v9:2026-11-03) Each secret is encrypted for the destination or profile webhook that holds it, and
the 2.1.0 data step binds stored rows to their owner rather than encrypting them as they are,
as ADR:2026-11-03-a-webhook-secret-opens-only-where-it-was-written describes.
- A new channel with secrets implements `secretFields` and gets storage, masking and restoring
without touching the resource or repository.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# A webhook secret is encrypted for the destination or profile webhook that holds it, and opens only there

- **Status:** Accepted
- **Revisions:** v1 2026-11-03 (initial)
- **Deciders:** OpenMetadata maintainers
- **Guard:** `BoundCiphertextTest`, `DestinationSecretsTest#decrypted_refusesCiphertextNotWrittenForTheDestination`, `ProfileWebhookSecretsTest#deliveryLeavesOutAWebhookWhoseSecretWasNotWrittenForIt`, `StoredWebhookSecretsTest`, `WebhookRequestsTest#theSigningKeyIsUsedAsGiven`, `OAuth2TokenManagerIT#getAccessToken_sendsTheCredentialsAsGiven`, `WebhookSecretOwnershipIT`, `WebhookSecretsMigrationIT`
- **Related:** ADR:2026-10-23-alert-destination-secrets-are-encrypted-masked-and-restored, ADR:2026-10-30-owned-secret-keys-are-derived-from-owner-ids (owned vault keys, a different mechanism that shares `SecretOwner`)

## Context

Every Fernet ciphertext the server writes uses the same keys and the same `fernet:` format,
whatever it protects, so a stored value does not say which secret it is or where it belongs.
Webhook secrets are used at one place only, the destination or profile webhook that holds them,
so they can have keys of their own and open only there.

## Decision

- `BoundCiphertext` encrypts a secret for an owner (`SecretOwner`) and a field, the JSON pointer of
the value inside the owner's configuration. Each owner and field has its own Fernet key, derived
with HKDF-SHA256 (RFC 5869) from each configured Fernet key, so key rotation works as before. The
value is written as `fernet:bound:<token>`, which every existing check still reads as ciphertext.
- A value opens only for the owner and field it was written for. Plain `Fernet` ciphertext does not
open, and `Fernet.decrypt` does not open a bound value.
- The owner of an alert destination's secrets is the destination (`alertdestination` and its id).
The owner of a profile webhook's secrets is the user or team and the webhook's slot (`user` or
`team`, its id, `webhook`, the slot).
- `ConfigSecrets` is the only place webhook secrets are encrypted or decrypted, at the fields
`WebhookSecrets.fieldsIn` names. A stored value that does not open is refused with a 400 that
names the field to enter again: a test send answers 400, a real send records the destination as
not usable with that reason, and a profile webhook whose value does not open is left out of the
send while the profile's other webhooks still send.
`WebhookRequests` and `OAuth2TokenManager` use the configuration they are given and decrypt
nothing.
- The 2.1.0 data step (`WebhookSecretsMigration`) binds what is stored. Its rules are frozen in
`StoredWebhookSecrets`, beside it: the secret fields, the channels that hold them, the owner
shapes and the key derivation. It calls no live alerting or secrets code, only the Fernet token
format, BouncyCastle and the configured Fernet keys, so it writes what 2.1 writes whatever later
releases change. A row it cannot read stops the step with an error that names the row.
- plaintext is encrypted for its owner;
- ciphertext at the fields releases before 2.1 stored encrypted, an alert destination's bearer
signing key and OAuth2 client id and secret, is encrypted for its owner again, unless the same
ciphertext is stored anywhere else (`StoredCiphertextCopies`: another field or alert, any
other table with a `json` column, or a version of an entity of those tables). Fernet
encryption is randomized, so a value the server wrote for one field is stored at that field
only, and in the versions of the alert that holds it. Only a frozen list of large tables that
cannot hold a secret is left out: data assets, event and execution logs, relationships, stored
documents and time series. A table the list does not name, such as one a distribution adds, is read, so a
store nobody listed is never missed. Versions are found by their entity's id, through the
primary key of the versions table, so the cost does not follow the number of data assets or
events;
- any other ciphertext stays as stored. It opens for no owner, so the destination stays enabled
and reports the field to enter again, and a profile webhook is left out of the send, until the
value is entered again.

Versions, change descriptions and the stored change events of alerts, users and teams keep the
mask, since nothing sends from them. Running the step again changes nothing. It runs after the 2.1.0
destination id step, because each destination's id owns its secrets.

## Consequences

- Upgrading to 2.1.0 keeps signing keys and OAuth2 credentials working. A value the step does not
carry over is reported on its destination, in its recent events and by a test send, as a field to
enter again. Releases before 2.1 stored endpoints, header values and profile webhooks in plain
text, so only a server that ran a pre-release build after
ADR:2026-10-23-alert-destination-secrets-are-encrypted-masked-and-restored has endpoints and
header values saved there in that time to enter again.
- A value is carried over when nothing else stored holds the same ciphertext any more: its other
copy belonged to an entity that was hard-deleted, or was replaced, re-encrypted included, without
a version keeping it. Such a value cannot be told apart from one the server wrote.
- Destination ids must stay unique and stable, because they own their secrets. A destination given
a new id has its secrets entered again.
- Webhooks are the first secrets bound to their owner. The intended end state is one shared secret
codec that binds every stored secret this way, with the owner from `SecretOwner` and the field
from a stable field id rather than its JSON pointer; `ConfigSecrets` and the field list in
`WebhookSecrets` then fold into it. Until then, renaming a webhook secret field needs a data step
that binds its values again.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openmetadata.schema.entity.events.authentication.WebhookOAuth2Config;
import org.openmetadata.service.fernet.Fernet;
import org.openmetadata.service.util.OAuth2TokenManager;
import org.openmetadata.service.util.OAuth2TokenManager.OAuth2TokenException;

Expand All @@ -29,6 +30,7 @@ class OAuth2TokenManagerIT {
private static int serverPort;

private static final Map<String, ClientBehavior> clientBehaviors = new ConcurrentHashMap<>();
private static final Map<String, String> secretsReceived = new ConcurrentHashMap<>();

private final OAuth2TokenManager tokenManager = OAuth2TokenManager.getInstance();

Expand Down Expand Up @@ -67,6 +69,7 @@ static void startServer() throws IOException {
String body =
new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
String clientId = extractFormParam(body, "client_id");
secretsReceived.put(clientId, extractFormParam(body, "client_secret"));

ClientBehavior behavior = clientBehaviors.get(clientId);
if (behavior == null) {
Expand Down Expand Up @@ -197,6 +200,19 @@ void getAccessToken_differentConfigs_separateCacheEntries() {
assertEquals(1, clientBehaviors.get(clientIdB).requestCount().get());
}

// The credentials reach the token manager as their destination decrypted them, so whatever
// they read, ciphertext included, is sent as it reads.
@Test
void getAccessToken_sendsTheCredentialsAsGiven() {
String clientId = uniqueClientId();
clientBehaviors.put(clientId, ClientBehavior.ok("as-given", 3600));
String ciphertext = Fernet.getInstance().encrypt("a value held elsewhere");

tokenManager.getAccessToken(buildConfig(clientId).withClientSecret(ciphertext));

assertEquals(ciphertext, secretsReceived.get(clientId));
}

private static String uniqueClientId() {
return "test-client-" + UUID.randomUUID();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@
import org.openmetadata.sdk.network.HttpMethod;
import org.openmetadata.sdk.network.RequestOptions;
import org.openmetadata.service.Entity;
import org.openmetadata.service.alerting.channel.DestinationSecrets;
import org.openmetadata.service.fernet.Fernet;
import org.openmetadata.service.resources.events.subscription.EventSubscriptionMapper;
import org.openmetadata.service.resources.events.subscription.EventSubscriptionResource;
import org.openmetadata.service.secrets.BoundCiphertext;
import org.openmetadata.service.secrets.masker.PasswordEntityMasker;

/**
Expand Down Expand Up @@ -2257,9 +2259,9 @@ void test_destinationSecretsAreMaskedEncryptedAndRestored(TestNamespace ns) thro
String id = created.getId().toString();
assertSecretsMasked(created.getDestinations().getFirst());
Map<String, Object> storedConfig = storedConfig(created.getId());
assertEquals(endpoint, decrypted(storedConfig.get("endpoint")));
assertEquals(headerValue, decrypted(headersOf(storedConfig).get("Authorization")));
assertEquals(secretKey, decrypted(authTypeOf(storedConfig).get("secretKey")));
assertEquals(endpoint, opened(created.getId(), "/endpoint"));
assertEquals(headerValue, opened(created.getId(), "/headers/Authorization"));
assertEquals(secretKey, opened(created.getId(), "/authType/secretKey"));

String path = "/v1/events/subscriptions/" + id;
List<String> reads =
Expand Down Expand Up @@ -2299,10 +2301,9 @@ void test_destinationSecretsAreMaskedEncryptedAndRestored(TestNamespace ns) thro
withNewEndpoint.getDestinations().getFirst().withConfig(fresh);
EventSubscription moved = patchEntity(id, withNewEndpoint);
assertSecretsMasked(moved.getDestinations().getFirst());
assertEquals(otherEndpoint, decrypted(storedConfig(created.getId()).get("endpoint")));
assertEquals(
headerValue, decrypted(headersOf(storedConfig(created.getId())).get("Authorization")));
assertEquals(secretKey, decrypted(authTypeOf(storedConfig(created.getId())).get("secretKey")));
assertEquals(otherEndpoint, opened(created.getId(), "/endpoint"));
assertEquals(headerValue, opened(created.getId(), "/headers/Authorization"));
assertEquals(secretKey, opened(created.getId(), "/authType/secretKey"));
assertNoSecretOrCiphertext(
rawGet(SdkClients.adminClient(), path + "/versions"),
List.of(otherEndpoint, headerValue, secretKey));
Expand Down Expand Up @@ -2355,8 +2356,7 @@ void test_putInsertedDestinationKeepsDistinctIds(TestNamespace ns) {
2,
updated.getDestinations().stream().map(SubscriptionDestination::getId).distinct().count());
assertEquals(retained.getId(), updated.getDestinations().get(1).getId());
assertEquals(
"http://localhost:8585/inserted", decrypted(storedConfig(created.getId()).get("endpoint")));
assertEquals("http://localhost:8585/inserted", opened(created.getId(), "/endpoint"));
}

@Test
Expand Down Expand Up @@ -2387,9 +2387,7 @@ void test_unrelatedPatchCopyWithLegacyNumericHeader(TestNamespace ns) throws Exc
EventSubscription updated = getEntity(created.getId().toString());
assertEquals(created.getName(), updated.getDisplayName());
assertEquals(numericSecret, updated.getBatchSize());
assertEquals(
String.valueOf(numericSecret),
decrypted(headersOf(storedConfig(created.getId())).get("Authorization")));
assertEquals(String.valueOf(numericSecret), opened(created.getId(), "/headers/Authorization"));
}

@Test
Expand All @@ -2398,7 +2396,7 @@ void test_putNewDestinationSecretsAreEncryptedAndGuarded(TestNamespace ns) {
EventSubscription created =
putSubscription(secretRequest(ns, "new_put_secrets", endpoint, "header-token", null));
assertSecretsMasked(created.getDestinations().getFirst());
assertEquals(endpoint, decrypted(storedConfig(created.getId()).get("endpoint")));
assertEquals(endpoint, opened(created.getId(), "/endpoint"));
assertRefused(
() ->
putSubscription(
Expand All @@ -2424,9 +2422,8 @@ void test_batchCreateDestinationSecretsAreEncrypted(TestNamespace ns) {
secretRequest(ns, "batch_secrets", endpoint, "batch-header", null), "admin");
AlertFixtures.repository().prepareInternal(entity, false);
AlertFixtures.repository().createManyEntitiesForImport(List.of(entity));
assertEquals(endpoint, decrypted(storedConfig(entity.getId()).get("endpoint")));
assertEquals(
"batch-header", decrypted(headersOf(storedConfig(entity.getId())).get("Authorization")));
assertEquals(endpoint, opened(entity.getId(), "/endpoint"));
assertEquals("batch-header", opened(entity.getId(), "/headers/Authorization"));
assertSecretsMasked(getEntity(entity.getId().toString()).getDestinations().getFirst());
}

Expand Down Expand Up @@ -2529,9 +2526,7 @@ void test_destinationSecretsTheServerAloneWrites_400(TestNamespace ns) throws Ex
.executeForString(
HttpMethod.PATCH, "/v1/events/subscriptions/" + created.getId(), copyOut));
assertEquals(
endpoint,
decrypted(storedConfig(created.getId()).get("endpoint")),
"a refused request changes nothing");
endpoint, opened(created.getId(), "/endpoint"), "a refused request changes nothing");
}

/**
Expand Down Expand Up @@ -2562,7 +2557,7 @@ void test_patchCannotCarryAStoredSecretIntoAChannelThatDoesNotMaskIt(TestNamespa
Object storedEndpoint = storedConfig(created.getId()).get("endpoint");
assertEquals(
endpoint,
legacy ? storedEndpoint : decrypted(storedEndpoint),
legacy ? storedEndpoint : opened(created.getId(), "/endpoint"),
"a refused request changes nothing");
assertSecretsMasked(getEntity(created.getId().toString()).getDestinations().getFirst());
}
Expand Down Expand Up @@ -2684,8 +2679,7 @@ void test_receiversCannotRedirectStoredCredentials(TestNamespace ns) throws Exce
assertEquals(
List.of(receiver.url("/other-receiver")),
configOf(moved.getDestinations().getFirst()).get("receivers"));
assertEquals(
headerValue, decrypted(headersOf(storedConfig(created.getId())).get("Authorization")));
assertEquals(headerValue, opened(created.getId(), "/headers/Authorization"));
assertTrue(receiver.received().isEmpty(), "the alert never runs, disabled as it is");
}
}
Expand All @@ -2702,9 +2696,7 @@ void test_patchKeepsTheServedChannel_400(TestNamespace ns) {

assertRefused(() -> patchEntity(created.getId().toString(), withAnotherChannel));
assertEquals(
endpoint,
decrypted(storedConfig(created.getId()).get("endpoint")),
"the refused request changes nothing");
endpoint, opened(created.getId(), "/endpoint"), "the refused request changes nothing");
}

/**
Expand Down Expand Up @@ -2958,9 +2950,14 @@ private static Map<String, Object> storedConfig(UUID alertId) {
return configOf(AlertFixtures.stored(alertId).getDestinations().getFirst());
}

private static String decrypted(Object ciphertext) {
assertTrue(Fernet.isTokenized((String) ciphertext), "stored in the clear: " + ciphertext);
return Fernet.getInstance().decrypt((String) ciphertext);
/** The value the alert's first destination stores at {@code field}, opened for it. */
private static String opened(UUID alertId, String field) {
SubscriptionDestination stored = AlertFixtures.stored(alertId).getDestinations().getFirst();
String value = JsonUtils.valueToTree(stored.getConfig()).at(field).asText();
assertTrue(BoundCiphertext.isBound(value), "not bound to its destination: " + value);
return JsonUtils.valueToTree(DestinationSecrets.decrypted(stored).getConfig())
.at(field)
.asText();
}

private static String headerOf(RecordingReceiver.Received received, String name) {
Expand Down
Loading
Loading