-
Notifications
You must be signed in to change notification settings - Fork 33
[PLTF-2701] Restart openhands on secret config changes (checksum + CI guard) #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36af37b
Restart openhands pod when any secret config value changes
ak684 bc33939
CI: fail if a secret config field is missing from secretsChecksum
ak684 a83ff8b
Address review feedback on the secret checksum
ak684 24dfc03
Bump openhands chart to 0.7.24 and drop the push:main guard trigger
ak684 3b1ed1e
Add bitbucket_data_center_bot_token to secretsChecksum
ak684 c8d8473
Merge remote-tracking branch 'origin/main' into alona/secret-restart-…
ak684 7af203a
Apply secret checksum to integration + mcp deployments; restore push:…
ak684 84b66ce
Merge branch 'main' into alona/secret-restart-checksum
ak684 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: Check secret checksum | ||
|
|
||
| # Fails when a password-type config field is not part of secretsChecksum, so a | ||
| # new secret can't be added without wiring it into the pod-restart checksum. | ||
| # Runs on PRs and on push to main (like the chart-version checks) so drift is | ||
| # surfaced after merge. Note: this only blocks a merge if it is also added to | ||
| # the branch's required status checks (ideally strict / require up to date). | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "replicated/config.yaml" | ||
| - "replicated/openhands.yaml" | ||
| - "scripts/check_secret_checksum.py" | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "replicated/config.yaml" | ||
| - "replicated/openhands.yaml" | ||
| - "scripts/check_secret_checksum.py" | ||
|
|
||
| jobs: | ||
| check-secret-checksum: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.x" | ||
| - run: pip install --quiet pyyaml | ||
| - name: Every password config field must be in secretsChecksum | ||
| run: python3 scripts/check_secret_checksum.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/usr/bin/env python3 | ||
| """Fail if a password-type KOTS config field is missing from secretsChecksum. | ||
|
|
||
| Background: secret-backed env vars on the openhands deployment (sourced via | ||
| secretKeyRef) are read only at pod start, and Kubernetes does not restart a pod | ||
| when a referenced Secret changes. The openhands pod template carries a | ||
| checksum/config-secrets annotation whose value (secretsChecksum in | ||
| replicated/openhands.yaml) is a KOTS-rendered sha256 of every secret config | ||
| value. When a secret changes, the hash changes, the pod template changes, and | ||
| the pod rolls so the new secret is picked up. | ||
|
|
||
| That only works if every secret (password) field in config.yaml is part of the | ||
| hash. If someone adds a new password field but forgets to add it to the hash, | ||
| changing it in the admin console silently has no effect until a manual restart. | ||
| This check keeps the two in sync, the same way the chart-version check keeps | ||
| chart changes and version bumps in sync. | ||
|
|
||
| NOTE: this check only blocks a merge if it is configured as a required status | ||
| check on the protected branch (ideally strict / require-up-to-date). Otherwise | ||
| it is advisory. It also runs on push to main so drift is surfaced immediately. | ||
| """ | ||
|
|
||
| import pathlib | ||
| import re | ||
| import sys | ||
|
|
||
| import yaml | ||
|
|
||
| ROOT = pathlib.Path(__file__).resolve().parents[1] | ||
|
|
||
| # 1. Password (secret) field names declared in config.yaml, parsed structurally | ||
| # so reformatting the YAML can't make the check silently miss a field. | ||
| config = yaml.safe_load((ROOT / "replicated" / "config.yaml").read_text()) | ||
| password_fields = [] | ||
|
|
||
|
|
||
| def collect(items): | ||
| for item in items or []: | ||
| if isinstance(item, dict): | ||
| if item.get("type") == "password" and "name" in item: | ||
| password_fields.append(item["name"]) | ||
| collect(item.get("items")) | ||
|
|
||
|
|
||
| for group in config.get("spec", {}).get("groups", []): | ||
| collect(group.get("items")) | ||
|
|
||
| # 2. ConfigOption names referenced inside the secretsChecksum value. | ||
| checksum_expr = "" | ||
| for doc in yaml.safe_load_all((ROOT / "replicated" / "openhands.yaml").read_text()): | ||
| if isinstance(doc, dict): | ||
| value = (doc.get("spec", {}).get("values", {}) or {}).get("secretsChecksum") | ||
| if value: | ||
| checksum_expr = value | ||
| break | ||
| covered = set(re.findall(r'ConfigOption\s+"([^"]+)"', checksum_expr)) | ||
|
|
||
| # 3. Every secret field must be covered by the checksum. | ||
| missing = [f for f in password_fields if f not in covered] | ||
| if missing: | ||
| print( | ||
| "ERROR: these password config fields are not included in secretsChecksum " | ||
| "(replicated/openhands.yaml):" | ||
| ) | ||
| for field in missing: | ||
| print(f" - {field}") | ||
| print( | ||
| "\nAdd each one to the secretsChecksum sha256 so changing it in the admin " | ||
| "console restarts the openhands pod. See scripts/check_secret_checksum.py." | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| print(f"OK: all {len(password_fields)} password config fields are covered by secretsChecksum.") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: The comment explains the mechanism well, but consider adding a note about the restart scope: 'Changing any secret in the KOTS config restarts the openhands pod, even if that secret only affects other components (e.g., LiteLLM keys).' This helps operators understand the blast radius when rotating credentials.