Skip to content

Fixes #36586: Defer external service secret writes - #36587

Merged
pmbrull merged 3 commits into
mainfrom
pmbrull/defer-service-secret-writes
Nov 1, 2026
Merged

pmbrull merged 3 commits into
mainfrom
pmbrull/defer-service-secret-writes

Conversation

@pmbrull

@pmbrull pmbrull commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Describe your changes

Fixes #36586

Keep service connection preparation free of external vault mutations. Preparation validates and locally encrypts credentials; the storage hooks persist external secrets after authorization. This covers single writes, version-checked updates, and batch inserts and updates.

Existing secret keys and references remain unchanged. Collision handling is separate follow-up work; no migration is required.

Type of change

  • Bug fix

High-level design

SecretsManager.prepareServiceConnectionConfig protects prepared and approval-staged credentials with local Fernet encryption, preserving existing ciphertext. ServiceEntityRepository performs external persistence through store, storeMany, and updateMany so every storage path remains encrypted.

Explicit plaintext credentials submitted to an external manager count as a replacement and record a connection update, even if their value is unchanged. Reference round trips and identical database-backed credentials remain no-ops. This avoids adding vault read permissions or a secret-equality oracle.

Decision: ADR:2026-10-29-service-connection-secrets-are-written-only-during-storage.

Tests

Use cases covered

  • A denied service PUT cannot replace or clear existing vault credentials.
  • Preparation encrypts flat, nested, and array credentials locally without touching the vault.
  • Single, optimistic, and batch storage paths persist encrypted credentials; connectionless services remain supported.
  • Approval revisions retain encrypted proposed values and leave published credentials untouched.
  • External plaintext replacements, reference round trips, and database-backed no-ops follow the behavior above.

Unit tests

The selected run passed 166 tests across 19 unit classes, including all 18 ServiceEntitySecretsTest cases. The initial regression run against unchanged main reproduced premature overwrite and deletion during preparation.

The command is make java_affected_run with --keep-going and additional unit classes ServiceConnectionPatchTest, ExternalSecretsManagerUnitTest, SecretsManagerLifecycleTest, and DBSecretsManagerTest, to cover patch guards and both encryption modes. A separate JaCoCo 0.8.13 run passed 59 focused tests and covered all 27 added executable source lines (20/20 in ServiceEntityRepository and 7/7 in SecretsManager). Whole-class line coverage in that focused run was 37/158 (23.4%) and 218/366 (59.6%), respectively; these are not full-suite coverage figures.

Backend integration tests

All seven SecretsManagerNullSecretIT tests passed, including the new HTTP authorization, approval, and credential replacement regressions. The broader run completed with 3,744 passing integration tests, one workflow-redeployment failure, and 467 skips. The selected TODO-only McpServiceResourceIT has no runnable class and produces no report; that planner cleanup is tracked separately in PR #36553. The failing method, WorkflowRedeploySignalIT#suspendedWorkflowRedeployedTakesNoSignal, passed when rerun alone on both unchanged main at 7843a02 and the PR head (one test passed in each MySQL/Elasticsearch run). The original broader-run failure remains recorded below; it did not reproduce in either isolated rerun. The PR remains draft.

Local Java test run: FAILED

  • Commit: abd608fdeb6b (base origin/main)
  • Finished: 2026-10-29 17:51 UTC · 17.0 min
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (19 classes) 19 166 0 0 1.3 passed
integration mysql-elasticsearch · parallel 49 4074 1 467 5.3 FAILED
integration mysql-elasticsearch · isolated 2 138 0 0 10.4 passed

Failed: WorkflowRedeploySignalIT#suspendedWorkflowRedeployedTakesNoSignal(TestNamespace)

Selected but produced no report: McpServiceResourceIT (mysql-elasticsearch · parallel)

  • Impacted, not run locally: 1 class (listed in the details)

Ingestion integration tests

Not applicable — no Python ingestion changes.

Playwright and manual testing

No UI changes. make playwright_affected was attempted but dependency expansion could not run because local @playwright/test is unavailable. No Playwright or manual UI tests were run; the service paths are exercised over HTTP by the integration tests.

UI screen recording

Not applicable — backend-only change.

Checklist

  • Linked issue and regression coverage are included.
  • Spotless and git diff --check pass; the Java impact map owns the changed code and tests.
  • Decision record validation passes.
  • Self-review of abd608fdeb6b8c636ce1d51fb75bd4cdef8ab9f0 against REVIEW.md: no unresolved Important findings. Preparation retains local encryption for approval staging; external replacement behavior is documented and tested.
  • Resolve the workflow test failure and the missing-report planner issue before requesting review.

Keep preparation free of vault mutations so rejected authorization cannot change credentials. Encrypt through single, versioned, and batch storage paths.
Keep prepared and approval-staged credentials encrypted locally. Persist external secrets only when storage runs, preserving existing ciphertext during preparation.
@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Oct 29, 2026
Comment on lines +209 to +223
@Override
protected void store(T service, boolean update, Double expectedVersion) {
encryptConnection(service);
super.store(service, update, expectedVersion);
}

@Override
protected void storeMany(List<T> services) {
services.forEach(this::encryptConnection);
super.storeMany(services);
}

@Override
protected void updateMany(List<T> services) {
services.forEach(this::encryptConnection);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Performance: Vault network writes now run inside the open DB transaction

Before this change, external secrets were written in prepare(), before any database transaction had started. They are now written from store, storeMany and updateMany. Those methods run inside a database transaction: store(T, boolean) is @Transaction, and the bulk paths run inside flushInOneTransaction(...). As a result, every upsertSecret/deleteSecret call to AWS, Azure or GCP happens while the transaction holds its JDBC connection and row locks. That is one remote call for each password field. In a bulk create or update of N services, the transaction stays open for N × fields vault round trips. Under load this can use up the connection pool and lengthen lock waits.

One fix is to work out the encrypted references inside the transaction (storeValue with store=false already returns the secret: reference) and do the vault upserts/deletes in a post-commit hook. Running them after authorization but before the transaction opens would also work. Either way, the stored JSON and the vault would still agree.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 closed / 1 findings

🔴 High risk · Deferring external service-secret writes from preparation to single and batch storage hooks could overwrite or lose credentials if a path mishandles them.

Defers external service connection secret writes out of preparation and into the storage hooks (store, storeMany, updateMany), so unauthorized PUTs can no longer replace or clear vault credentials while preparation keeps local Fernet encryption. Approved with suggestions: external vault upserts and deletes now run inside the open DB transaction, adding one remote call per password field and holding connections and row locks longer during bulk operations. Consider working out encrypted references inside the transaction and performing vault writes in a post-commit hook.

💡 Performance: Vault network writes now run inside the open DB transaction

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java:209-223

Before this change, external secrets were written in prepare(), before any database transaction had started. They are now written from store, storeMany and updateMany. Those methods run inside a database transaction: store(T, boolean) is @Transaction, and the bulk paths run inside flushInOneTransaction(...). As a result, every upsertSecret/deleteSecret call to AWS, Azure or GCP happens while the transaction holds its JDBC connection and row locks. That is one remote call for each password field. In a bulk create or update of N services, the transaction stays open for N × fields vault round trips. Under load this can use up the connection pool and lengthen lock waits.

One fix is to work out the encrypted references inside the transaction (storeValue with store=false already returns the secret: reference) and do the vault upserts/deletes in a post-commit hook. Running them after authorization but before the transaction opens would also work. Either way, the stored JSON and the vault would still agree.

🤖 Prompt for agents
Code Review: Defers external service connection secret writes out of preparation and into the storage hooks (`store`, `storeMany`, `updateMany`), so unauthorized PUTs can no longer replace or clear vault credentials while preparation keeps local Fernet encryption. Approved with suggestions: external vault upserts and deletes now run inside the open DB transaction, adding one remote call per password field and holding connections and row locks longer during bulk operations. Consider working out encrypted references inside the transaction and performing vault writes in a post-commit hook.

1. 💡 Performance: Vault network writes now run inside the open DB transaction
   Files: openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java:209-223

   Before this change, external secrets were written in `prepare()`, before any database transaction had started. They are now written from `store`, `storeMany` and `updateMany`. Those methods run inside a database transaction: `store(T, boolean)` is `@Transaction`, and the bulk paths run inside `flushInOneTransaction(...)`. As a result, every `upsertSecret`/`deleteSecret` call to AWS, Azure or GCP happens while the transaction holds its JDBC connection and row locks. That is one remote call for each password field. In a bulk create or update of N services, the transaction stays open for N × fields vault round trips. Under load this can use up the connection pool and lengthen lock waits.
   
   One fix is to work out the encrypted references inside the transaction (`storeValue` with `store=false` already returns the `secret:` reference) and do the vault upserts/deletes in a post-commit hook. Running them after authorization but before the transaction opens would also work. Either way, the stored JSON and the vault would still agree.

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

@pmbrull

pmbrull commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Local Java test run: FAILED — details

  • Commit: abd608fdeb6b (base origin/main)
  • The summary is in the PR description.

Failed: WorkflowRedeploySignalIT#suspendedWorkflowRedeployedTakesNoSignal(TestNamespace)

Selected but produced no report: McpServiceResourceIT (mysql-elasticsearch · parallel)

Tests run locally

  • unit · openmetadata-service (19 classes): AWSSSMSecretsManagerLocalStackTest (5 passed), AWSSSMSecretsManagerTest (15 passed), AWSSecretsManagerLocalStackTest (6 passed), AWSSecretsManagerTest (16 passed), AzureKVSecretsManagerTest (2 passed), BotTokenCacheTest (1 passed), CreateIngestionPipelineImplTest (11 passed), DBSecretsManagerTest (6 passed), DataContractPipelineTokenRefreshTest (6 passed), ExternalSecretsManagerUnitTest (21 passed), GCPSecretsManagerTest (14 passed), IngestionPipelineSecretsTest (3 passed), KubernetesSecretsManagerTest (21 passed), NestedSecretConverterCoverageTest (1 passed), OpenMetadataConnectionBuilderTest (5 passed), SecretsManagerLifecycleTest (11 passed), ServiceConnectionPatchTest (3 passed), ServiceEntitySecretsTest (18 passed), WorkflowResourceDecryptTest (1 passed)
  • integration · mysql-elasticsearch · parallel: 49 classes, 3607 tests executed (listed below)
  • integration · mysql-elasticsearch · isolated: UserMetricsResourceIT (7 passed), WorkflowDefinitionResourceIT (131 passed)

Per-class counts come from the test reports, which can credit a test to the wrong class when classes run concurrently, and keep only the last run of a nested class that several test classes inherit. The summary's step totals are Maven's own counts.

integration · mysql-elasticsearch · parallel: 50 classes

APIServiceResourceIT (26 passed, 5 skipped), AppMarketPlaceResourceIT (14 passed, 1 skipped), AppOperationPermissionsIT (74 passed, 5 skipped), AppRunInterruptionIT (6 passed), AppTriggerConflictIT (2 passed), BaseEntityIT$ListEntityHistoryByTimestampPaginationTest (110 passed, 3 skipped), BotImpersonationIT (48 passed, 2 skipped), BotResourceIT (57 passed, 5 skipped), ConfigResourceIT (15 passed), DashboardServiceResourceIT (3 passed, 1 skipped), DatabaseServiceResourceIT (58 passed, 11 skipped), DatabaseSmokeIT (49 passed, 7 skipped), DriveServiceResourceIT (3 passed, 1 skipped), GlossaryTermResourceIT (235 passed, 15 skipped), IngestionPipelineAgentTypeIT (61 passed, 10 skipped), IngestionPipelineLogStreamIT (226 passed, 37 skipped), IngestionPipelineLogStreamingResourceIT (122 passed, 16 skipped), IngestionPipelineOwnerInheritanceIT (179 passed, 30 skipped), IngestionPipelineProgressStreamIT (6 passed), IngestionPipelineResourceIT (189 passed, 13 skipped), IngestionPipelineSortIT (22 passed, 4 skipped), LLMServiceResourceIT (106 passed, 15 skipped), MessagingServiceResourceIT (116 passed, 16 skipped), MetadataServiceResourceIT (27 passed, 7 skipped), MlModelServiceResourceIT (425 passed, 64 skipped), MlModelServiceSearchAliasIT (184 passed, 26 skipped), OrphanIngestionPipelineCleanupIT (9 passed), PipelineServiceResourceIT (61 passed, 18 skipped), RunIngestionPipelineForEntityIT (35 passed, 6 skipped), SearchServiceResourceIT (87 passed, 15 skipped), SecretsManagerNullSecretIT (7 passed), SecurityServiceResourceIT (6 passed, 1 skipped), SeedDataPresenceIT (28 passed, 5 skipped), ServiceAttributePolicyIT (40 passed, 5 skipped), ServiceLineagePipelineRoutingMigrationIT (8 passed), ServiceLineageRefcountIT (64 passed, 14 skipped), ServicesOverviewResourceIT (64 passed, 8 skipped), StorageServiceResourceIT (178 passed, 26 skipped), TableResourceIT (9 passed), TestConnectionDefinitionResourceIT (12 passed, 2 skipped), UserDefaultTeamAssignmentIT (1 passed), UserImportPrivilegeEscalationIT (29 passed, 6 skipped), UserPreferencesIT (21 passed, 1 skipped), UserResourceIT (76 passed), UserTeamAssignmentPrivilegeIT (7 passed), WorkflowRedeploySignalIT (1 passed, 1 failed), WorkflowResourceIT (31 passed, 4 skipped), WorkflowSignalDeliveryIT (4 passed, 2 skipped), WorkflowTaskAssigneesIT (28 passed, 5 skipped), WorkflowTriggerPermissionsIT (30 passed, 4 skipped)

Why these tests
  • added by author: Service secret preparation and storage must preserve patch guards and both managed and database encryption ← DBSecretsManagerTest, ExternalSecretsManagerUnitTest, SecretsManagerLifecycleTest, ServiceConnectionPatchTest
  • area secrets ← openmetadata-service/src/main/java/org/openmetadata/service/secrets/SecretsManager.java
  • area services ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java
  • called from entity App ← openmetadata-service/src/main/java/org/openmetadata/service/secrets/SecretsManager.java
  • called from entity IngestionPipeline ← openmetadata-service/src/main/java/org/openmetadata/service/secrets/SecretsManager.java
  • called from entity SecurityService ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServiceEntityRepository.java
  • called from entity User ← openmetadata-service/src/main/java/org/openmetadata/service/secrets/SecretsManager.java
  • called from entity Workflow ← openmetadata-service/src/main/java/org/openmetadata/service/secrets/SecretsManager.java
  • changed test ← openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/SecretsManagerNullSecretIT.java, openmetadata-service/src/test/java/org/openmetadata/service/secrets/ServiceEntitySecretsTest.java
  • smoke ← code other than a test class changed
Impacted, not run locally (1)
  • ServiceDeleteSearchCleanupScaleIT → nightly: openmetadata-nightly k8s-java-it (scale-it)
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=AWSSSMSecretsManagerLocalStackTest,AWSSSMSecretsManagerTest,AWSSecretsManagerLocalStackTest,AWSSecretsManagerTest,AzureKVSecretsManagerTest,BotTokenCacheTest,CreateIngestionPipelineImplTest,DBSecretsManagerTest,DataContractPipelineTokenRefreshTest,ExternalSecretsManagerUnitTest,GCPSecretsManagerTest,IngestionPipelineSecretsTest,KubernetesSecretsManagerTest,NestedSecretConverterCoverageTest,OpenMetadataConnectionBuilderTest,SecretsManagerLifecycleTest,ServiceConnectionPatchTest,ServiceEntitySecretsTest,WorkflowResourceDecryptTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<50 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=UserMetricsResourceIT,WorkflowDefinitionResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

@pmbrull
pmbrull marked this pull request as ready for review October 30, 2026 07:07
@pmbrull
pmbrull requested a review from a team as a code owner October 30, 2026 07:07
@pmbrull
pmbrull requested a review from TeddyCr October 30, 2026 07:07
@pmbrull
pmbrull added this pull request to the merge queue Oct 30, 2026
@pmbrull pmbrull added the To release Will cherry-pick this PR into the release branch label Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-31T10:18:11Z)

Blocked the queue: integration-tests-mysql-elasticsearch

@pmbrull
pmbrull added this pull request to the merge queue Oct 31, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-11-01T00:59:17Z)

Blocked the queue: integration-tests-mysql-elasticsearch

@pmbrull
pmbrull added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 715ed84 Nov 1, 2026
178 checks passed
@pmbrull
pmbrull deleted the pmbrull/defer-service-secret-writes branch November 1, 2026 09:09
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.1 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

gh-bot-collate Bot commented Nov 1, 2026

Copy link
Copy Markdown

🤖 Backport to 2.1 opened as #36777 (clean cherry-pick). It merges itself once the checks pass.

@gh-bot-collate

gh-bot-collate Bot commented Nov 1, 2026

Copy link
Copy Markdown

🤖 Backport to 2.0 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persist service connection secrets after authorization

2 participants