Skip to content

Fix catalog create secret cleanup#4974

Merged
dimas-b merged 3 commits into
apache:mainfrom
iting0321:fix-catalog-create-secret-cleanup
Jul 9, 2026
Merged

Fix catalog create secret cleanup#4974
dimas-b merged 3 commits into
apache:mainfrom
iting0321:fix-catalog-create-secret-cleanup

Conversation

@iting0321

@iting0321 iting0321 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Solve the TODO for // TODO: Proactive garbage-collection of any inline secrets that were written to the secrets manager, here and on any other unexpected exception as well.
Clean up inline external catalog secrets when catalog creation fails.
External catalog creation can write inline OAuth or bearer credentials to UserSecretsManager before the catalog entity is created in the metastore.
If catalog creation then fails, those stored secrets could be left behind without a catalog referencing them.

This change tracks the SecretReferences produced during catalog creation and deletes them if the catalog is not successfully created.

Checklist

  • 🛡️ Don't disclose security issues! (contact security@apache.org)
  • 🔗 Clearly explained why the changes are needed, or linked related issues: Fixes #
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (if needed)
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed)

Copilot AI review requested due to automatic review settings July 5, 2026 10:03
@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board Jul 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents leaked inline external-catalog credentials (OAuth client secret / bearer token) when external catalog creation fails after secrets have already been written to UserSecretsManager.

Changes:

  • Track SecretReferences created during external catalog creation and delete them on any catalog-creation failure path.
  • Ensure secret-cleanup failures are logged but do not mask the original catalog-creation failure.
  • Add unit tests covering cleanup on AlreadyExists and unexpected failure, and no cleanup on success.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java Adds failure-path secret reference cleanup via try/finally around external catalog creation and metastore create.
runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java Adds tests to verify secrets are deleted on failed create (and not deleted on success), including cleanup-failure resilience.

@iting0321
iting0321 force-pushed the fix-catalog-create-secret-cleanup branch from 940b4e9 to a6b2f39 Compare July 5, 2026 10:27
dimas-b
dimas-b previously approved these changes Jul 7, 2026
LOGGER
.atWarn()
.setCause(e)
.addKeyValue("secretReference", secretReference.urn())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Is it useful without being referenced in the message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your feedback! I just updated the message to reference the URN directly while keeping the structured field for filtering and correlation.

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Jul 7, 2026
dimas-b
dimas-b previously approved these changes Jul 8, 2026

@dimas-b dimas-b left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fix merge conflicts 😅

@iting0321
iting0321 force-pushed the fix-catalog-create-secret-cleanup branch from b595924 to c347960 Compare July 9, 2026 04:44
@dimas-b
dimas-b merged commit a8cce27 into apache:main Jul 9, 2026
25 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants