Skip to content

Add: secret_rotation_stale_env_credentials_astronomy_shop problem - #851

Merged
Saadmrp1038 merged 8 commits into
SREGym:mainfrom
Ipetr14:feature/secret_rotation_stale_env_credentials_astronomy_shop
Jun 12, 2026
Merged

Saadmrp1038 merged 8 commits into
SREGym:mainfrom
Ipetr14:feature/secret_rotation_stale_env_credentials_astronomy_shop

Conversation

@Ipetr14

@Ipetr14 Ipetr14 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #822

Problem

This PR adds secret_rotation_stale_env_credentials_astronomy_shop issue. The problem targets deployment/product-catalog in namespace astronomy-shop. Injection rotates the PostgreSQL password and updates the Secret-backed DB_CONNECTION_STRING, but the already-running product-catalog pod keeps the old environment value loaded at container startup. The Secret and PostgreSQL backend use the new credential; the active product-catalog process still uses the old one.

Real-world failure story

This models a mechanism of some real issues: credential/configuration material is updated, but a long-running process does not use the new value until it is restarted. A close mechanism appears in Laravel Horizon issue #213, where database credentials changed in .env were not picked up until the processes were manually restarted:

https://github.com/laravel/horizon/issues/213

In our case, mechanism causes one of the pods to use wrong credentials to access the database. This may cause outages of various services of the application like in this case (the mechanism of the issue is different, but similar consequnces):

https://blog.cloudflare.com/cloudflare-incident-march-21-2025/

Fault injection

The injection first restores the original, correct state of the application:

  1. Restore PostgreSQL user otelu to the original password otelp.
  2. Set product-catalog back to a literal baseline DB_CONNECTION_STRING.
  3. Delete secret/product-catalog-db-conn if it exists.
  4. Restart deployment/product-catalog.

Then it injects the fault:

Step Action Result
1 Create secret/product-catalog-db-conn with the original connection string. The Secret initially matches the old PostgreSQL password.
2 Patch deployment/product-catalog so DB_CONNECTION_STRING comes from the Secret. New pods read DB credentials through valueFrom.secretKeyRef.
3 Restart product-catalog and record the current pod UID. The active pod has the old connection string in its process env.
4 Rotate PostgreSQL from otelp to otelp_7k9m2q4x. PostgreSQL now accepts only the new password.
5 Update secret/product-catalog-db-conn with the new connection string. The Kubernetes Secret contains new password.
6 Terminate existing PostgreSQL sessions for otelu. product-catalog must reconnect.
7 Wait until the expected stale credential state is confirmed. Secret/PostgreSQL are new; running product-catalog env is old.

Expected active fault state:

Secret:          postgres://otelu:otelp_7k9m2q4x@postgresql/otel?sslmode=disable
PostgreSQL:      accepts otelp_7k9m2q4x, rejects otelp
product-catalog: still uses postgres://otelu:otelp@postgresql/otel?sslmode=disable

Observable symptoms

Symptom Command Expected evidence
Pods health looks normal kubectl get pods -A product-catalog and the other app pods are Running.
product-catalog is configured to read DB credentials from the Secret. kubectl get deploy product-catalog -n astronomy-shop -o yaml | grep -A8 -B4 DB_CONNECTION_STRING DB_CONNECTION_STRING uses valueFrom.secretKeyRef.name: product-catalog-db-conn.
The Secret contains the rotated DB credential. kubectl get secret product-catalog-db-conn -n astronomy-shop -o jsonpath='{.data.DB_CONNECTION_STRING}' | base64 -d; echo postgres://otelu:otelp_7k9m2q4x@postgresql/otel?sslmode=disable
The running product-catalog process still has the stale credential. kubectl debug -n astronomy-shop -it "$(kubectl get pod -n astronomy-shop -l app.kubernetes.io/name=product-catalog -o jsonpath='{.items[0].metadata.name}')" --image=busybox:1.36 --target=product-catalog --profile=sysadmin -- sh -c 'tr "\0" "\n" < /proc/1/environ | grep "^DB_CONNECTION_STRING="' DB_CONNECTION_STRING=postgres://otelu:otelp@postgresql/otel?sslmode=disable
PostgreSQL rejects the stale password. kubectl exec -n astronomy-shop deploy/postgresql -- sh -lc 'PGPASSWORD=otelp psql -h postgresql -U otelu -d otel -c "select 1"' Authentication fails.
PostgreSQL accepts the rotated password. kubectl exec -n astronomy-shop deploy/postgresql -- sh -lc 'PGPASSWORD=otelp_7k9m2q4x psql -h postgresql -U otelu -d otel -c "select 1"' Query succeeds.

Expected mitigation

Valid mitigation would be to restart the product-catalog pod so it would pick the correct credentials from env Secert:

kubectl rollout restart deployment/product-catalog -n astronomy-shop
kubectl rollout status deployment/product-catalog -n astronomy-shop --timeout=180s

Mitigation oracle

The oracle checks:

Check Required passing state
deployment/product-catalog exists Deployment can be read and parsed.
Product-catalog pods are healthy Current pods are Running.
Deployment still references the Secret DB_CONNECTION_STRING uses product-catalog-db-conn.
Secret value is rotated Secret contains otelp_7k9m2q4x.
Running product-catalog env is rotated Effective runtime connection string contains otelp_7k9m2q4x.
PostgreSQL accepts product-catalog password Password parsed from product-catalog env succeeds.
PostgreSQL rejects old password otelp no longer authenticates.
PostgreSQL accepts new password otelp_7k9m2q4x authenticates.

Recovery

recover_fault() restores the original application state:

  1. Restore PostgreSQL user otelu to password otelp.
  2. Set deployment/product-catalog back to the literal original connection string.
  3. Delete secret/product-catalog-db-conn.
  4. Restart deployment/product-catalog.
  5. Clear the stored stale pod UID.

This returns the app to its original, correct state.

Testing and validation

Implementation of the issue passed automatic validation. Submission during the mitigation stage without any fixes fails, and passes with the implemented solution during mitigation stage. All expected symptoms present after the fault injection.

Agent run results

I ran one Stratus attempt with gpt-5 on my local deployment. It completely failed the diagnosis (0.0/100.0) and mitigation blaming the telemetry issues and trying to fix them. The nuance is that for some reasons my local deployment actually has telemetry issues in the astronomy-shop that show up when I check the logs of deployment/product_catalog (for multiple other problems that use astronomy-shop as well), so this noise is affecting the work of the agent. For this reason, I am not sure how agent would actually score on this problem without this additional noise.

Code changes

File Change
sregym/conductor/problems/secret_rotation_stale_env_credentials.py Adds the problem class, injection, recovery, and diagnosis oracle wiring.
sregym/conductor/oracles/secret_rotation_stale_env_mitigation.py Adds a mitigation oracle to check if the issue was fixed
sregym/conductor/problems/registry.py Registers secret_rotation_stale_env_credentials_astronomy_shop.

/validate-problem secret_rotation_stale_env_credentials_astronomy_shop

@Ipetr14 Ipetr14 changed the title New issue for benchmark: secret_rotation_stale_env_credentials_astronomy_shop Add: secret_rotation_stale_env_credentials_astronomy_shop Jun 2, 2026
@Ipetr14 Ipetr14 changed the title Add: secret_rotation_stale_env_credentials_astronomy_shop Add: secret_rotation_stale_env_credentials_astronomy_shop problem Jun 2, 2026
@Saadmrp1038
Saadmrp1038 self-requested a review June 3, 2026 15:47
@Saadmrp1038 Saadmrp1038 added the problem Adding a new problem to the benchmark label Jun 5, 2026

@Saadmrp1038 Saadmrp1038 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Ipetr14 Thanks for the effort!

I had some concerns:

  1. The postgresql-init ConfigMap contains CREATE USER otelu WITH PASSWORD 'otelp'; in plain text. An agent can read this, compare it to the Secret, and diagnose the issue as a simple password mismatch without ever reasoning about stale process environments or runtime vs. declared state.

  2. PostgreSQL has no persistent storage in this deployment. If the PostgreSQL pod restarts, init.sql re-runs and resets the password to otelp. The rotation is non-durable. The forward-fix (restart product-catalog to pick up otelp_7k9m2q4x) breaks as soon as PostgreSQL restarts because PG will only accept otelp again.

  3. The oracle does not verify that the rotated password (otelp_7k9m2q4x) still works in PostgreSQL after mitigation. An agent can ALTER USER otelu WITH PASSWORD 'otelp', update the Secret to match, restart the pod, and pass the oracle. This is dangerous because otelu is shared infrastructure (accounting also uses it), and modifying database credentials risks cascading failures. The oracle should reject any mitigation that changes the PostgreSQL password.

Ipetr14 added 2 commits June 6, 2026 13:02
  - Remove old password from postgresql-init ConfigMap
  - Keep PostgreSQL password rotation durable after pod restart
  - Reject mitigations that revert otelu to the old password
  - Remove old password leaks from unrelated pods
@Ipetr14

Ipetr14 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review! I have made some updates to address all three concerns:

  • Now during the injection the ConfigMap is changed so init.sql declares otelu with the rotated password to remove the shortcut
  • This change of ConfigMap also makes the rotation durable, and if the PostgreSQL pod is restarted the new password remains the correct one
  • The oracle now checks that after the submission of mitigation the PostgreSQL accepts the rotated password and not the old one

During testing I also noticed that pods accounting and product-reviews have old credentials after the rotation during the injection, so to fix this issue and avoid leaking the old password to the agent through these pods, during the injection the credentials of these pods are also rotated.

@Ipetr14
Ipetr14 requested a review from Saadmrp1038 June 8, 2026 18:56

@Saadmrp1038 Saadmrp1038 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Ipetr14 The changes look good. There's still one issue with how recover_fault works. I commented the details below.

Comment thread sregym/conductor/problems/registry.py Resolved
@Ipetr14

Ipetr14 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the clarification on how recovery_fault() should work. I updated it so it leaves the rotated credentials in place and restarts the product_catalog pod so it would have rotated credentials as well. I ran problem validation, and now after fault recovery oracle passes. I also fixed the ordering of imports in registry.py.

@Ipetr14
Ipetr14 requested a review from Saadmrp1038 June 12, 2026 07:18
@Saadmrp1038

Copy link
Copy Markdown
Collaborator

@Ipetr14 Thanks for addressing my comments! Works correctly now.

I did a few runs and the results are interesting. My initial hypothesis from the RFC kind of holds:

Even if the diagnosis is totally wrong, there's a high likelihood the agent would randomly mitigate the problem by restarting the faulty deployment.

In the third run, the diagnosis score was quite low and the mitigation attempt was also not quite accurate, but the restart did fix the fault.

Run Diagnosis Score Diagnosis Success Mitigation Success Diagnosis Summary Mitigation Summary
1 — Timed out — Found auth failure and credential mismatch but got distracted investigating unrelated issues, never submitted —
2 89/100 ✅ ✅ Correctly identified that the pod has stale credentials from before the Secret rotation, and env vars don't auto-refresh in running pods Restarted product-catalog deployment
3 34/100 ❌ ✅ Submitted that PG password was never updated to match the Secret (opposite of what actually happened) Set PG password to otelp_7k9m2q4x (already the current value) then restarted product-catalog. Passed because the restart picked up the correct Secret value, and the ALTER USER didn't change anything since PG already had that password.

Congrats on the first PR merged here 🎉

@Saadmrp1038
Saadmrp1038 merged commit 61f50c4 into SREGym:main Jun 12, 2026
5 of 6 checks passed
vsmart-06 pushed a commit to vsmart-06/SREGym that referenced this pull request Jul 12, 2026
…EGym#851)

* Add secret rotation stale env credentials problem

* Simplify secret rotation mitigation oracle checks

* Require rotated PostgreSQL in oracle

* Fix stale DB credential rotation shortcuts

  - Remove old password from postgresql-init ConfigMap
  - Keep PostgreSQL password rotation durable after pod restart
  - Reject mitigations that revert otelu to the old password
  - Remove old password leaks from unrelated pods

* Fix fault recovery to satisfy the oracle

* Fix problem registry import ordering

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Saadmrp1038 added a commit that referenced this pull request Jul 22, 2026
* Updated default mitigation oracle

* Stop timeout for 0 replicas

* TBC in CloudLab

* Pushing all attempts at the problem

* Enable idempotence

* Add mutating_webhook_resource_limits problem (#847)

* Add mutating_webhook_resource_limits problem

* Add mutating_webhook_resource_limits to Problem List

* mutating_webhook_resource_limits problem docstring fix

Removed incorrect information about mitigation options.

* Additions to mutating_webhook_limits_resource_limits problem

 - Memory limit/request patching before activating the webhook
 - Decoy pods for increased complexity

* More additions to mutating_webhook problem

 - Make decoys realisticly named
 - Similar minor changes

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Derive the default problem namespace from the application (#876)

* add the the probem redundency

* base.

* the fixed and dynamic app name are fixed. hte namespace are also fixed.

* unessessry formating is reverted.

* unessessry formating is reverted.

* formating correction.

* formating correction.

* formating correction.

* add fault injection decorator markers to test_problem_bsae.py

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Confluent kafka attempt

* Custom image attempt

* Threaded producer and added consumer

* Syntax error

* Added some imports

* fix edge cases

* run ruff check adn format

* New OOM attempt

* Force crash on OOM

* Add file_descriptor_exhaustion problem (#832)

* add file_descriptor_exhaustion problem

* Modify fault injection and recovery methods

* Fix fault recovery

* Change fault injection method
Add fault injection by flooding connections

* Update fault injection method and add custom oracle

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Finalizer deadlock controller clean (#873)

* finalizzer code is reaoslve dadlock benchmark.

* yaml file corrected.

* reverting hte comments back to their place.

* read only rbac

* controller log is generalized and avoiding any sregym related name exposing.

* applied ruff linter formatter accordingly.

* replace metadata naming and includding all the oprations on mitigation side.

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add: secret_rotation_stale_env_credentials_astronomy_shop problem (#851)

* Add secret rotation stale env credentials problem

* Simplify secret rotation mitigation oracle checks

* Require rotated PostgreSQL in oracle

* Fix stale DB credential rotation shortcuts

  - Remove old password from postgresql-init ConfigMap
  - Keep PostgreSQL password rotation durable after pod restart
  - Reject mitigations that revert otelu to the old password
  - Remove old password leaks from unrelated pods

* Fix fault recovery to satisfy the oracle

* Fix problem registry import ordering

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add cumulative_admission_webhook_timeout_hotel_reservation problem (#886)

* Add cumulative_admission_webhook_timeout_hotel_reservation problem

* Pin webhook backends to worker nodes via nodeAffinity

* Make webhook backends realistic admission services

Replace the dummy webhook backends with HTTPS admission servers that terminate TLS using Secret-mounted certificates, validate AdmissionReview

requests, and return proper admission responses. Certificates are signed by the same CA referenced in each webhook's `caBundle`, with SANs

covering the backend Service DNS names.

The admission logic enforces a trusted image registry allowlist and a

per-container CPU limit. All Hotel Reservation workloads satisfy these

policies, so the webhooks remain transparent during normal operation and

recovery.

Also:
* Vary webhook `timeoutSeconds` (12, 8, 11, 9) to make the cumulative
  timeout less obvious.

* Rename the CA CN from `sregym-webhook-ca` to
  `compliance-webhook-ca`.

* Remove a duplicate `rule.from_` check in the oracle.

* Fix create-or-replace handling for webhooks, NetworkPolicies,
  Deployments, and Services so re-injection updates existing resources
  instead of failing or silently skipping changes.

* Model the fault as a missing apiserver NetworkPolicy allow

* Model the fault as a missing apiserver allow with a near-miss policy

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add psa_restricted_blocks_recreation problem (#891)

Labelling a namespace pod-security.kubernetes.io/enforce=restricted leaves
running pods untouched but makes the apiserver reject recreated pods that run
as root / set no seccomp profile, so a deployment silently goes
under-replicated. Unlike the existing webhook problems, the policy is enforced
by the apiserver via a namespace label, not a webhook config.

* Add copilot cli agent (#893)

* add copilot cli agent

* remove -s flag

* Fix MCP retry error handling and CRLF parsing in CI (#896)

* fix(mcp): broaden MCP retry exceptions and return error instead of raising

* fix(ci): strip CRLF from PR description before parsing problem ID

* Fix kind cluster detection (#897)

* Fix custom kind cluster detection

* Handle failed kind detection output

* fix edge cases

* run ruff check adn format

* Shell state persistence (#903)

* Include shell persistence

* Include shell persistence

* Isolate problem IDs from agent runtime artifacts

* update SREGym-applications (18620ed) (#910)

* Add Calico route-reflector label drift problem (#828)

* Add Calico route-reflector label drift problem

* Address Calico route-reflector review comments

* Harden Calico cleanup ownership tracking

* Fix Codex agent install verification

* Tighten Codex platform package detection

* Restore kubelet eviction reset cleanup

* Neutralize Calico ownership metadata

---------

Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Fail alert oracle on Prometheus query errors (#912)

* Decouple failure configmaps from mongo pods in `hotel-reservation` (#899)

* decouple failure configmaps from mongo pods

* remove empty failure configmaps creation

* Support local LLM endpoints for Stratus and OpenCode (#917)

* Support local LLM endpoints for Stratus

* Prefer env vars for local LLM endpoints

* Support local LLM endpoints for OpenCode

* Route local endpoints into agent containers

* Normalize OpenCode local judge models

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Preflight check the judge model (#924)

* Add support for uniform agent trajectory (ATIF format) (#918)

* add support for ATIF trajectory conversion and normalization, add claudecode adapter

* fix: make _finish_problem idempotent

* isolate .codex mount in container runner

* better temp dir cleanup

* add codex adapter

* add opencode adapter

* add copilot adapter

* add stratus adapter

* fix antropic caching for stratus

* add gemini adapter

* store normalized ATIF trajectories in SQLite indexed by problem type

* edge tests

* bump litellm, tikoken

* update docker lib versions

* Add node_clock_drift Problem  (#894)

* adding clock drift problem

* fixing race condition causing sidecar log delay

* fixing recover_fault to reverse time sync removal applied, improve cleanup

* global cleanup added + fixed restoration for node_clock_drift problem

* fixing mitigation oracle to ensure correct node checked

* adding problem to non emulated cluster problems list

* extending wait

* indentation error fix

* fixing time restoration in global cleanup

* adding in check to make sure it picks worker node

* adding another control plane filter, fixing clock step-back in global recovery

* increase sidecar rollout timeout, make podnames/labels generic, idempotancy check

* formatting fixes

* format fix

* fix

* fix ruff check/format issues

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Minimum viable python version

* Changed diagnosis oracle

* Cleaned up fault recovery

* Edit tasklist.yml

* Removed old Java artifacts

* Updated mitigation oracle to be more robust

* Added polling

* Fail Kafka producer leak injection on timeout

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Co-authored-by: Kerem Akcalioglu <[email protected]>
Co-authored-by: ermias mulugeta <[email protected]>
Co-authored-by: Tejas Shukla <[email protected]>
Co-authored-by: Petr Myagkov <[email protected]>
Co-authored-by: Omar Faruqe Riyad <[email protected]>
Co-authored-by: Mohammad Tamimul Ehsan <[email protected]>
Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Om Kumar <[email protected]>
Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Tanzim Hossain Romel <[email protected]>
Co-authored-by: haani-maybe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

problem Adding a new problem to the benchmark

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Problem RFC] Stale Secret Environment Variable After Database Credential Rotation

2 participants