Skip to content

Update the secret sync - #68

Merged
kpouget merged 3 commits into
openshift-psap:mainfrom
kpouget:sync
Apr 28, 2026
Merged

Update the secret sync#68
kpouget merged 3 commits into
openshift-psap:mainfrom
kpouget:sync

Conversation

@kpouget

@kpouget kpouget commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator
  • set PSAP sync default values
  • Enhance vault sync with skip filter and destructive sync

Fixes: #53 #63

Summary by CodeRabbit

  • New Features
    • Added CLI defaults for Vault address, secret path, and namespace configuration.
    • Implemented skip functionality to exclude specific Vault entries from syncing.
    • Added destructive sync capability to remove managed Kubernetes Secrets no longer in Vault.
    • Enhanced dry-run mode to preview secret deletions before applying changes.

kpouget and others added 2 commits April 28, 2026 12:10
- Skip vaults containing 'fournos_skip_sync' key
- Add destructive sync to delete orphaned managed secrets
- Improve logging for skipped entries and deletions

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
@openshift-ci

openshift-ci Bot commented Apr 28, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign avasilevskii for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@kpouget has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 35 minutes and 55 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 075640d1-3efe-4f06-915a-18b251a313a4

📥 Commits

Reviewing files that changed from the base of the PR and between 683bf8a and 32e7ba1.

📒 Files selected for processing (1)
  • hacks/sync_vault_secrets.py
📝 Walkthrough

Walkthrough

The hacks/sync_vault_secrets.py script was enhanced to support CLI configuration defaults for Vault settings and target namespace. A destructive synchronization mechanism was implemented that lists currently managed Kubernetes Secrets (via labels), tracks which ones are processed from Vault, and deletes any managed Secrets not present in the Vault source unless in --dry-run mode. Vault entries containing the fournos_skip_sync key are now skipped during sync. Dry-run mode was improved to report would-be deletions.

Changes

Cohort / File(s) Summary
Vault Secrets Synchronization
hacks/sync_vault_secrets.py
Added CLI defaults for VAULT_ADDR, VAULT_SECRET_PATH, and namespace configuration. Implemented destructive-sync with managed Secret listing, tracking, and deletion. Added skip mechanism for Vault entries with fournos_skip_sync key. Enhanced dry-run mode to report processed and would-be-deleted Secrets.

Sequence Diagram

sequenceDiagram
    participant Script as Sync Script
    participant Vault as Vault Server
    participant K8s as Kubernetes API
    
    Script->>K8s: List managed Secrets (by label)
    K8s-->>Script: Return current managed Secrets
    
    Script->>Vault: Fetch all Vault entries
    Vault-->>Script: Return Vault secrets
    
    Script->>Script: Filter out skipped entries<br/>(fournos_skip_sync=true)
    Script->>Script: Track processed Secrets<br/>from Vault
    
    alt Dry-run Mode
        Script->>Script: Identify unprocessed Secrets<br/>to be deleted
        Script-->>Script: Report would-be deletions
    else Normal Mode
        Script->>K8s: Delete unprocessed<br/>managed Secrets
        K8s-->>Script: Deletion confirmed
    end
    
    Script-->>Script: Complete sync
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Poem

🐰 Through Vaults I hop and secrets sync with care,
Managed ones tracked true, old ones stripped bare,
Skip the marked, keep the rest so bright,
Dry-run first, then clean—a safer sync tonight! 🔐

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Update the secret sync' is vague and generic, using non-descriptive language that doesn't convey meaningful information about the specific changes. Consider a more descriptive title like 'Add skip filter and destructive sync to vault secrets' to clearly indicate the main features added.
Out of Scope Changes check ❓ Inconclusive The PR adds destructive sync mode and default configuration values, which extend beyond issue #53's scope; however, these appear to be related enhancements supporting the main sync functionality. Verify that the destructive sync and default configuration features align with issue #63 or are explicitly approved scope additions for this PR.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR implements the skip filter feature for issue #53 by allowing vaults containing 'fournos_skip_sync' key to be skipped during sync, matching the requested requirement.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@hacks/sync_vault_secrets.py`:
- Around line 183-193: The current destructive helpers swallow Kubernetes
ApiException errors which hides failures from the overall sync process; change
_list_managed_secrets and _delete_secret so they do not convert API errors into
silent successes: in _list_managed_secrets (the function that builds
label_selector using LABEL_MANAGED_BY, MANAGER_VALUE and LABEL_VAULT_ENTRY and
calls v1.list_namespaced_secret) stop returning an empty list on
ApiException—log the error and re-raise the exception (or let it propagate) so
sync() can detect failure; in _delete_secret ensure you only swallow
404/NotFound but for any other ApiException log and re-raise (do not suppress
non-404 failures) so the destructive pass reports errors to the caller.
- Around line 252-260: The preview mode never sees deletions because
existing_managed_secrets is only populated when dry_run is False; fix by always
loading the existing managed secrets for the destructive diff so --dry-run can
report deletions: call _list_managed_secrets(namespace) (or
_list_managed_secrets(v1, namespace)) unconditionally and ensure a v1 client is
created when needed (move or duplicate the v1 = _k8s_core_api() call so v1 is
available for listing even in dry_run), leaving actual mutation logic gated by
the dry_run flag.
- Around line 290-296: The skip branch currently continues before marking the
vault's secret as processed, so SKIP_SYNC_KEY vaults (checked via kv_data and
vault_name) still end up in existing_managed_secrets - processed_secrets and get
purged; fix by adding the corresponding secret identifier to processed_secrets
(e.g., processed_secrets.add(secret_name) or the appropriate key used elsewhere)
before the continue and then increment skipped_count as now so skipped vaults
are treated as processed and won't be deleted later.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ffbeacdd-2f01-49d6-981f-99f4c8208b8c

📥 Commits

Reviewing files that changed from the base of the PR and between 08736c2 and 683bf8a.

📒 Files selected for processing (1)
  • hacks/sync_vault_secrets.py

Comment thread hacks/sync_vault_secrets.py Outdated
Comment thread hacks/sync_vault_secrets.py Outdated
Comment thread hacks/sync_vault_secrets.py
@avasilevskii

Copy link
Copy Markdown

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2026
@kpouget
kpouget merged commit 87dddb7 into openshift-psap:main Apr 28, 2026
4 of 5 checks passed
@kpouget
kpouget deleted the sync branch April 28, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEATURE: allow skipping some vaults from the safe synchronization

2 participants