Skip to content

fix(alerts): encrypt webhook secrets for the destination or profile webhook that holds them - #36939

Merged
manerow merged 14 commits into
mainfrom
fix/webhook-secrets-bound-to-owner
Nov 6, 2026
Merged

manerow merged 14 commits into
mainfrom
fix/webhook-secrets-bound-to-owner

Conversation

@manerow

@manerow manerow commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Webhook secrets (the endpoint, header values, the signing key, and the OAuth2 client id and secret) now have encryption keys of their own: each one is encrypted for the alert destination, or the user or team profile webhook, that holds it, and it can only be decrypted there.

  • BoundCiphertext (new, in secrets) derives one key per owner and field from the configured Fernet keys (HKDF-SHA256, BouncyCastle). Key rotation works as before. Values are stored as fernet:bound:<token>, so existing checks still treat them as ciphertext. The owner is a SecretOwner (PR feat(secrets): store owned credentials under keys derived from their owner's id #36706): the destination id for an alert destination, and the user or team id plus the slot for a profile webhook.
  • ConfigSecrets is the only place webhook secrets are encrypted or decrypted. A stored value that does not decrypt for its owner is refused with "The value at '' must be entered again": a test send answers 400, a real send records the destination as not usable with that reason (its status and recent events show it), and a profile webhook is left out of the send while its other webhooks still send.
  • WebhookRequests and OAuth2TokenManager no longer decrypt anything; they use the configuration they are given.
  • A new alert's destinations get the ids they keep before their secrets are encrypted, since each destination's id owns its secrets.
  • The 2.1.0 data step (WebhookSecretsMigration, which PR fix(alerts): handle profile webhooks like alert destinations #36722 leaves to this PR) encrypts stored plaintext for its owner. The values earlier releases stored encrypted (an alert destination's signing key and OAuth2 client id and secret) are encrypted for their destination again, unless the same value is also stored somewhere else (StoredCiphertextCopies). That check reads every table with a json column except a frozen list of large ones that cannot hold a secret (data assets, event logs, relationships, stored documents, time series), so a store nobody listed, such as one a distribution adds, is still read. It finds versions by entity id through the primary key, so its cost does not follow the number of data assets or events. Any other stored value stays as it is and is reported as above until it is entered again. No destination is disabled and no profile webhook is removed. Versions, change descriptions and stored change events keep the mask. Running the step again changes nothing. The step's rules are frozen beside it in StoredWebhookSecrets, so it calls no live alerting or secrets code, and a row it cannot read stops it with an error that names the row.
  • Decision record: docs/decisions/2026-11-03-a-webhook-secret-opens-only-where-it-was-written.md, plus a v8 note on the 2026-10-23 destination secrets record.

Order: Destination ids own their secrets, so this data step runs after the 2.1.0 destination id step from PR #36791 (IngestionPipelineMigrationEntryPointTest checks the order).

Upgrade note: Signing keys and OAuth2 credentials keep working after upgrading to 2.1.0. A webhook value that is not carried over is reported, on its alert destination and by a test send, as a field to enter again; the destination stays enabled.

Type of change:

  • Bug fix

Tests:

  • Unit: BoundCiphertextTest (including the RFC 5869 test vectors), StoredWebhookSecretsTest, DestinationSecretsTest, ProfileWebhookSecretsTest, WebhookRequestsTest. Every alerting, secrets, migration and fernet unit test passes. The new decrypt, signing and token request checks fail without this change and pass with it.
  • Integration (Postgres): WebhookSecretOwnershipIT (new, runs the upgrade step end to end), WebhookSecretsMigrationIT, ProfileWebhookSecretsIT, EventSubscriptionResourceIT, OAuth2TokenManagerIT, DispatchScenariosIT, TemplateTestSendIT pass.

UI screen recording:

Not applicable: no UI change.

Checklist:

@manerow
manerow requested review from a team as code owners November 3, 2026 11:23
@github-actions

github-actions Bot commented Nov 3, 2026

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 Nov 3, 2026
@manerow
manerow changed the base branch from main to fix/profile-webhooks-like-destinations November 3, 2026 11:26
@manerow
manerow marked this pull request as draft November 3, 2026 11:27
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 81%
80.94% (136966/169206) 67.84% (49152/72446) 70.9% (27679/39034)

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

Base automatically changed from fix/profile-webhooks-like-destinations to main November 4, 2026 11:55
@manerow
manerow force-pushed the fix/webhook-secrets-bound-to-owner branch from 96ca28e to 2d0b44b Compare November 4, 2026 20:21
@manerow
manerow marked this pull request as ready for review November 4, 2026 20:21
@gitar-bot

gitar-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · Owner-bound webhook-secret encryption and the 2.1 migration alter credential access; migration errors could make stored secrets unusable and interrupt alert delivery.

Encrypts webhook secrets per owner so each alert destination or profile webhook holds keys only it can decrypt, with a 2.1.0 data step that re-encrypts stored values where possible. Two issues were resolved this session: the copy check now covers Fernet stores whose table names lack _entity, and execution logs are skipped so the check scales with runs. No open issues found.

✅ 2 closed
✅ Security: Copy check skips Fernet stores whose table name lacks _entity

📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/StoredCiphertextCopies.java:47 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/StoredCiphertextCopies.java:139-153 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/channel/DestinationSecrets.java:257-260
StoredCiphertextCopies is what keeps the upgrade step from carrying over and decrypting a token that was copied in from another secret. isOtherStore only scans tables ending in _entity, plus openmetadata_settings and user_session. App configurations are Fernet-encrypted on write (AppRepository.prepare → ApplicationHandler.appWithEncryptedAppConfiguration) and stored in installed_apps and apps_marketplace. Neither name ends in _entity, so neither table is scanned.

Suppose a pre-2.1 destination's authType/clientSecret or clientId holds a token copied from an app's configuration. storedElsewhere returns false, bindStoredAlert decrypts the token and re-encrypts it for the destination, and the next send posts the app's secret to whatever tokenUrl that destination names. This is the exact case the ADR and the class javadoc say is excluded ("any other stored entity, version or setting"). Other json tables outside the allowlist, such as change_event, doc_store and apps_data_store, are skipped the same way.

Fix: scan every table that has a json column except the alert table, and stop matching on name suffix. Missing a store lets a secret leak, while scanning an extra table only costs migration time.

✅ Performance: Execution logs are left off SKIPPED, so the copy check scales with runs

📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/StoredCiphertextCopies.java:52-66 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/StoredCiphertextCopies.java:155-166 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/StoredCiphertextCopies.java:226-230 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/StoredCiphertextCopies.java:254-256 📄 docs/decisions/2026-11-03-a-webhook-secret-opens-only-where-it-was-written.md:45-50
The new deny list leaves out mcp_execution_entity (whose DDL comment calls it 'MCP Execution logs'), agent_execution_entity, change_lifecycle_event and change_revision. These are logs with one row per run or event, and each has a json column. All four reach storesToRead, so the check does a full json::text LIKE '%fernet:%' scan of each one. The two *_execution_entity tables also match isVersioned because their names end in _entity and they have an id column. For those, readVersions runs SELECT id FROM across the whole table, holds every id in memory, and then makes one entity_extension lookup per 500 ids. On a deployment with a lot of MCP or agent activity, the 2.1.0 step's cost and memory therefore grow with the number of executions. The class Javadoc and the updated ADR both say this should not happen ('the cost does not follow the number of data assets or events'). Fix: add these log tables to SKIPPED, or at least keep the execution tables out of the versions lookup.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

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.

2 participants