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,9 +1,9 @@
# 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)
- **Revisions:** v1 2026-11-03 (initial) · v2 2026-11-06 (a value waiting to be entered again stops no edit)
- **Deciders:** OpenMetadata maintainers
- **Guard:** `BoundCiphertextTest`, `DestinationSecretsTest#decrypted_refusesCiphertextNotWrittenForTheDestination`, `ProfileWebhookSecretsTest#deliveryLeavesOutAWebhookWhoseSecretWasNotWrittenForIt`, `StoredWebhookSecretsTest`, `WebhookRequestsTest#theSigningKeyIsUsedAsGiven`, `OAuth2TokenManagerIT#getAccessToken_sendsTheCredentialsAsGiven`, `WebhookSecretOwnershipIT`, `WebhookSecretsMigrationIT`
- **Guard:** `BoundCiphertextTest`, `DestinationSecretsTest#decrypted_refusesCiphertextNotWrittenForTheDestination`, `ProfileWebhookSecretsTest#deliveryLeavesOutAWebhookWhoseSecretWasNotWrittenForIt`, `StoredWebhookSecretsTest`, `DestinationValidationTest#aStoredValueThatDoesNotOpenStopsNoEdit`, `AlertLimitsTest#receiversAreCountedWhenASecretDoesNotOpen`, `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
Expand Down Expand Up @@ -74,3 +74,11 @@ so they can have keys of their own and open only there.
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.

## Amendment (v2, 2026-11-06)

Only sending opens a stored secret. Saving an alert also reads its stored destinations, to compare
them and to count their receivers, and neither needs a secret, so a value that does not open stops
neither: an alert holding one can be edited and switched off, and the value can be entered again,
which is the only way to repair it. A destination changed while it still holds such a value is
refused with a 400 that names the field, and the same value is still never sent.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,40 @@ void theUpgradeStepCarriesOverEarlierCredentialsAndLeavesTheRestToEnterAgain(Tes
}
}

/** Only an edit can repair these values, so the alert has to stay editable until they are. */
@Test
void aValueLeftToEnterAgainStopsNoEditAndDeliversOnceEntered(TestNamespace ns) throws Exception {
try (RecordingReceiver receiver = new RecordingReceiver()) {
receiver.answer("/token", "{\"access_token\":\"the-token\",\"expires_in\":3600}");
String clientSecret = ns.prefix("client-secret-entered-again");
String header = ns.prefix("header-entered-again");
EventSubscription alert = legacyAlert(ns, "entered_again", receiver, "held-elsewhere");
TestSuiteBootstrap.getJdbi()
.useHandle(
handle -> WebhookSecretsMigration.bindAlertDestinationSecrets(handle, dialect()));

HttpResponse<String> renamed =
patchAlert(alert.getId(), replace("/description", "edited after the upgrade"));
HttpResponse<String> entered =
patchAlert(
alert.getId(),
replace("/destinations/2/config/authType/clientSecret", clientSecret),
replace("/destinations/3/config/headers/X-Legacy", header));
FixtureEvents.insert(FixtureEvents.tableEvents());
DirectTick.run(AlertFixtures.stored(alert.getId()));

assertEquals(200, renamed.statusCode(), renamed.body());
assertEquals(200, entered.statusCode(), entered.body());
List<RecordingReceiver.Received> sends = receiver.received();
assertTrue(sendsTo(sends, "/token").stream().anyMatch(send -> carries(send, clientSecret)));
assertFalse(sendsTo(sends, "/hook-stored-twice").isEmpty(), sends.toString());
assertTrue(
sendsTo(sends, "/hook-header").stream()
.anyMatch(send -> header.equals(headerOf(send, "X-Legacy"))),
sends.toString());
}
}

/**
* An alert stored as a release before 2.1 could store it: a signing key and an OAuth2 client
* secret the server encrypted for it, an OAuth2 client secret whose ciphertext a database service
Expand Down Expand Up @@ -322,6 +356,25 @@ private static List<SubscriptionDestination> readAsAdmin(UUID id) throws Excepti
return JsonUtils.readValue(body, EventSubscription.class).getDestinations();
}

private static Map<String, String> replace(String path, String value) {
return Map.of("op", "replace", "path", path, "value", value);
}

@SafeVarargs
private static HttpResponse<String> patchAlert(UUID id, Map<String, String>... operations)
throws Exception {
HttpRequest request =
HttpRequest.newBuilder()
.uri(URI.create(SdkClients.getServerUrl() + "/v1/events/subscriptions/" + id))
.header("Authorization", "Bearer " + SdkClients.getAdminToken())
.header("Content-Type", "application/json-patch+json")
.method(
"PATCH",
HttpRequest.BodyPublishers.ofString(JsonUtils.pojoToJson(List.of(operations))))
.build();
return HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
}

private static HttpResponse<String> postTestDestination(
List<SubscriptionDestination> destinations) throws Exception {
HttpRequest request =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public SubscriptionAction receiversOf(SubscriptionDestination destination) {
*/
void validate(SubscriptionDestination destination);

/** The configured receivers, or null for a channel that has none. */
/**
* The configured receivers as stored, or null for a channel that has none. Its secrets stay as
* stored, so a caller that sends with it decrypts the destination first.
*/
SubscriptionAction receiversOf(SubscriptionDestination destination);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.ws.rs.BadRequestException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -100,6 +101,18 @@ public static SubscriptionDestination decrypted(SubscriptionDestination destinat
return copy;
}

/**
* The destination as it reads when judging what it says rather than sending it: decrypted, or as
* stored when a secret does not open, so a value waiting to be entered again stops no edit.
*/
public static SubscriptionDestination decryptedOrAsStored(SubscriptionDestination destination) {
try {
return decrypted(destination);
} catch (BadRequestException e) {
return destination;
}
}

/**
* Who a destination's secrets belong to: the destination itself, by its id, which the server
* keeps for its whole life. A destination without an id has nothing stored for it, so it gets an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static void validate(SubscriptionDestination destination) {
// secret sent again, is the same configuration.
private static JsonNode whatAUserConfigures(SubscriptionDestination destination) {
ObjectNode content =
(ObjectNode) JsonUtils.valueToTree(DestinationSecrets.decrypted(destination));
(ObjectNode) JsonUtils.valueToTree(DestinationSecrets.decryptedOrAsStored(destination));
content.remove(NOT_PART_OF_WHAT_A_USER_CONFIGURES);
return withoutEmptyValues(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static void validateConfigured(Webhook webhook) {

@Override
public Webhook receiversOf(SubscriptionDestination destination) {
return stored(destination);
return DestinationConfig.stored(destination, Webhook.class);
}

/** As it can be sent to: the configuration with its secrets decrypted. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.openmetadata.service.alerting.channel.Channel;
import org.openmetadata.service.alerting.channel.DeliveryMemory;
import org.openmetadata.service.alerting.channel.Destination;
import org.openmetadata.service.alerting.channel.DestinationSecrets;
import org.openmetadata.service.alerting.channel.IsolatedSends;
import org.openmetadata.service.alerting.channel.SendStatus;
import org.openmetadata.service.alerting.content.EventContent;
Expand Down Expand Up @@ -202,7 +203,7 @@ private SubscriptionAction receiversOf(SubscriptionDestination destination) {
if (config instanceof SubscriptionAction action) {
receivers = action;
} else if (config != null) {
receivers = channel.configRules().receiversOf(destination);
receivers = channel.configRules().receiversOf(DestinationSecrets.decrypted(destination));
}
return receivers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
import java.net.URI;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openmetadata.schema.alert.type.EmailAlertConfig;
import org.openmetadata.schema.entity.events.EventSubscription;
import org.openmetadata.schema.entity.events.SubscriptionDestination;
import org.openmetadata.schema.type.Webhook;
import org.openmetadata.service.fernet.Fernet;

/** Every save is held within the bounds, and an alert stored past them stays editable. */
class AlertLimitsTest {
Expand All @@ -27,6 +31,17 @@ class AlertLimitsTest {
private static final String MAIN = "main";
private static final String MOVED = "moved";
private static final String COPY = "copy";
private static final String TEST_FERNET_KEY = "GhtAEzEb5WD6bTLvwa24JA6ePHxfVLDjb8X4hMShmVY=";

@BeforeEach
void setUp() {
Fernet.getInstance().setFernetKey(TEST_FERNET_KEY);
}

@AfterEach
void tearDown() {
Fernet.getInstance().setFernetKey((String) null);
}

@Test
void anAlertMayGrowUpToEachLimit() {
Expand All @@ -52,6 +67,19 @@ void aSaveThatGrowsPastALimitIsRefused() {
stored, alert(destinations(1), AlertLimits.MAX_BATCH_SIZE + 1)));
}

@Test
void receiversAreCountedWhenASecretDoesNotOpen() {
UUID id = UUID.randomUUID();
EventSubscription stored = holdingACiphertextEndpoint(id, PAST_THE_LIMIT);
EventSubscription kept = holdingACiphertextEndpoint(id, PAST_THE_LIMIT);
EventSubscription grown = holdingACiphertextEndpoint(id, PAST_THE_LIMIT + 1);

assertDoesNotThrow(() -> AlertLimits.requireWithin(stored, kept));
BadRequestException refused =
assertThrows(BadRequestException.class, () -> AlertLimits.requireWithin(stored, grown));
assertTrue(refused.getMessage().contains("receivers"), refused.getMessage());
}

@Test
void aBatchSizeBelowOneIsRefused() {
EventSubscription stored = alert(destinations(1), ORDINARY_BATCH);
Expand Down Expand Up @@ -191,6 +219,18 @@ private static void sendAgain(EventSubscription stored, SubscriptionDestination
AlertLimits.requireWithin(stored, alert(List.of(destination), ORDINARY_BATCH));
}

private static EventSubscription holdingACiphertextEndpoint(UUID id, int receivers) {
SubscriptionDestination destination =
webhookTo(id, Set.of(), MAIN)
.withConfig(
Map.of(
"endpoint",
Fernet.getInstance().encrypt("https://hooks.example.com/old"),
"receivers",
receivers(receivers)));
return alert(List.of(destination), ORDINARY_BATCH);
}

private static Set<String> receivers(int count) {
return IntStream.range(0, count)
.mapToObj(index -> "https://hooks.example.com/receiver/" + index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ void decrypted_refusesCiphertextNotWrittenForTheDestination() {
}
}

@Test
void decryptedOrAsStored_opensWhatItCanAndKeepsWhatItCannot() {
SubscriptionDestination stored = oauth2Destination();
Map<String, Object> plainAuth = new LinkedHashMap<>(authTypeOf(stored));
DestinationSecrets.encrypt(List.of(stored));
SubscriptionDestination notWrittenForIt =
buildOAuth2Destination("client", Fernet.getInstance().encrypt("a value held elsewhere"));

assertEquals(plainAuth, authTypeOf(DestinationSecrets.decryptedOrAsStored(stored)));
assertEquals(
authTypeOf(notWrittenForIt),
authTypeOf(DestinationSecrets.decryptedOrAsStored(notWrittenForIt)));
}

@Test
void mask_hidesEverySecretOfTheAlertAndItsHistory_onACopy() {
SubscriptionDestination stored = incomingWebhook(SubscriptionType.WEBHOOK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,31 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openmetadata.schema.entity.events.EventSubscription;
import org.openmetadata.schema.entity.events.SubscriptionDestination;
import org.openmetadata.schema.entity.events.SubscriptionDestination.SubscriptionCategory;
import org.openmetadata.schema.entity.events.SubscriptionDestination.SubscriptionType;
import org.openmetadata.schema.type.Webhook;
import org.openmetadata.schema.utils.JsonUtils;
import org.openmetadata.service.fernet.Fernet;

class DestinationValidationTest {
private static final String USABLE = "https://hooks.example.com/ok";
private static final String NOT_A_WEBHOOK = "ftp://saved-long-ago.example.com";
private static final String TEST_FERNET_KEY = "GhtAEzEb5WD6bTLvwa24JA6ePHxfVLDjb8X4hMShmVY=";

@BeforeEach
void setUp() {
Fernet.getInstance().setFernetKey(TEST_FERNET_KEY);
}

@AfterEach
void tearDown() {
Fernet.getInstance().setFernetKey((String) null);
}

@Test
void everyDestinationOfANewAlertIsChecked() {
Expand All @@ -44,6 +58,38 @@ void everyDestinationOfANewAlertIsChecked() {
assertTrue(refused.getMessage().contains("Invalid webhook endpoint URL"));
}

@Test
void aStoredValueThatDoesNotOpenStopsNoEdit() {
EventSubscription stored = alertWith(signedWith(Fernet.getInstance().encrypt("old key")));
EventSubscription renamed = copyOf(stored).withDisplayName("Renamed");

assertDoesNotThrow(() -> DestinationValidation.ofWhatChanged(stored, renamed));
}

@Test
void aStoredValueThatDoesNotOpenCanBeEnteredAgain() {
SubscriptionDestination holdingIt = signedWith(Fernet.getInstance().encrypt("old key"));
EventSubscription stored = alertWith(holdingIt);
SubscriptionDestination entered = signedWith("new key").withId(holdingIt.getId());
EventSubscription updated =
copyOf(stored).withDestinations(DestinationSecrets.encrypt(List.of(entered)));

assertDoesNotThrow(() -> DestinationValidation.ofWhatChanged(stored, updated));
}

@Test
void aChangedDestinationStillHoldingAValueThatDoesNotOpenIsRefused() {
EventSubscription stored = alertWith(signedWith(Fernet.getInstance().encrypt("old key")));
EventSubscription changed = copyOf(stored);
changed.getDestinations().getFirst().withTimeout(99);

BadRequestException refused =
assertThrows(
BadRequestException.class, () -> DestinationValidation.ofWhatChanged(stored, changed));

assertTrue(refused.getMessage().contains("must be entered again"), refused.getMessage());
}

@Test
void unchangedDestinationIsNotCheckedAgain() {
EventSubscription stored = alertWith(webhook(NOT_A_WEBHOOK));
Expand Down Expand Up @@ -202,6 +248,13 @@ private static SubscriptionDestination webhookConfigured(Map<String, Object> con
return webhook(NOT_A_WEBHOOK).withConfig(config);
}

private static SubscriptionDestination signedWith(String signingKey) {
return webhook(USABLE)
.withConfig(
Map.of(
"endpoint", USABLE, "authType", Map.of("type", "bearer", "secretKey", signingKey)));
}

private static SubscriptionDestination webhook(String endpoint) {
return new SubscriptionDestination()
.withId(UUID.randomUUID())
Expand Down
Loading