Skip to content

feat(support): diagnose-install checks EKS Pod Identity for every ServiceAccount the release uses - #558

Merged
khaliqgant merged 2 commits into
mainfrom
aa/podid
Nov 26, 2026
Merged

khaliqgant merged 2 commits into
mainfrom
aa/podid

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What

scripts/support/diagnose-install.py checks EKS Pod Identity coverage whenever it runs with a cluster scope.

  1. Which ServiceAccounts need AWS. It reads the release's Deployments, StatefulSets, Jobs and CronJobs (app.kubernetes.io/instance=<release>). A ServiceAccount counts when its pods read S3 (LOCKER_BUCKET with no static LOCKER_ACCESS_KEY_ID) or sign OpenSearch requests (SEARCH_INDEX_OPENSEARCH_AUTH=sigv4). It checks the release as rendered, not a fixed list. From the templates, the EKS profiles render:

    ServiceAccount Workloads (0.7.54 / 0.7.81 render) Needs
    agent-relay-worker session-summary/status/metadata workers, worker-migrate Job S3 read/write
    agent-relay-session-ingest-api ingest edge S3 read/write
    agent-relay-search-indexer search indexer + bootstrap Job S3 read, OpenSearch write
    agent-relay-session-read read API S3 read, OpenSearch read
    agent-relay-alleyoop not rendered by values-eks-native.yaml; only legacy profiles S3 read/write
  2. Associations. It runs aws eks list-pod-identity-associations --cluster-name … --region … --namespace …. The cluster and region come from the EKS kube context: the cluster ARN, or the exec plugin's --cluster-name/--region and AWS_PROFILE. --eks-cluster and --aws-region override them. Each missing association is a FAIL whose next step is the exact aws eks create-pod-identity-association line. The role is the one a ServiceAccount with the same access already uses; if there is none, it's a placeholder naming the access. The next step also includes rollout restart for that ServiceAccount's Deployments. Associations no workload uses (here agent-relay-alleyoop) are listed for information.

  3. Stretch: role reach. For each association it runs aws iam simulate-principal-policy against the bucket (arn:aws:s3:::<bucket> and /*) and the OpenSearch domain parsed from SEARCH_INDEX_OPENSEARCH_URL. If the caller may not simulate, the result is UNKNOWN. The simulation covers identity policies only; the docs say so.

All AWS calls are reads. Without AWS credentials, each ServiceAccount is UNKNOWN with the list command to run. --no-aws and --no-iam-simulate skip the section. Raw AWS errors never reach the report, only fixed categories, which matches the script's existing rule.

Docs. docs/self-hosted-eks.md gets the ServiceAccount → access table and a pre-install MISSING check. docs/support/diagnose-install.md gets an EKS Pod Identity section.

Terraform. terraform/examples/aws-existing-cluster (used by the EKS guide) and terraform/examples/aws already associate worker, alleyoop and session-ingest-api with the sessions role, and modules/aws/search associates search-indexer and session-read. aws-environments covers the worker too. No change needed.

Output (rehearsal shape: no worker association)

This is a real run of main() with kubectl/aws stubbed to the rehearsal's state. I couldn't reach a real EKS account from here.

PASS podidentity.agent-relay-search-indexer [agent-relay-search-indexer]: Pod Identity association exists (role arn:aws:iam::123456789012:role/session-indexer); needs S3 read, OpenSearch write.
PASS podidentity.agent-relay-search-indexer.s3-r [agent-relay-search-indexer]: S3 read: the role's IAM policy allows it.
PASS podidentity.agent-relay-search-indexer.os-w [agent-relay-search-indexer]: OpenSearch write: the role's IAM policy allows it.
PASS podidentity.agent-relay-session-ingest-api [agent-relay-session-ingest-api]: Pod Identity association exists (role arn:aws:iam::123456789012:role/session-ingest-api); needs S3 read/write.
...
FAIL podidentity.agent-relay-worker [agent-relay-worker]: No Pod Identity association for ServiceAccount agent-relay-worker (used by agent-relay-worker-session-summary-worker, agent-relay-worker-migrate-6ae46510), which needs S3 read/write. Its pods get no AWS credentials.
  Next: aws eks create-pod-identity-association --cluster-name demo --region us-west-2 --namespace agent-relay --service-account agent-relay-worker --role-arn arn:aws:iam::123456789012:role/session-ingest-api  then restart its pods: kubectl -n agent-relay rollout restart deployment/agent-relay-worker-session-summary-worker
PASS podidentity.unused: Associations no workload of this release uses (harmless; remove if unwanted): agent-relay-alleyoop.

Tests

python3 -m unittest discover -s scripts/support/tests -p 'test_*.py': 45 passed (8 new). They cover the exact fix line and role reuse, the access levels, the simulated resource ARNs, deny → FAIL, AccessDenied on simulate → UNKNOWN, no credentials → UNKNOWN without the raw error, the placeholder role, static keys and non-S3 providers, the cluster from flags, ARN and exec args, and --no-aws.

Coordination

#553 also edits diagnose-install.py (cluster_checks ConfigMaps, values_checks rds-ca). This PR doesn't touch either function. The new code sits after database_checks, and its only hook is in main. The helm test status table (#554) is separate.

Site docs (table plus association check in the EKS guide) are in a separate agentrelay.com PR that doesn't depend on this one.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

diagnose-install.py now checks EKS Pod Identity coverage for every ServiceAccount the release's workloads run as, so a missing association is reported at install time instead of surfacing later as "no Locker credentials" pod errors.

Details

  • Finds the ServiceAccounts the release's Deployments, StatefulSets, Jobs, and CronJobs use for S3 (LOCKER_BUCKET without static keys), the S3 re-arm sweeper (INGEST_REARM_CREDENTIALS=podIdentity), or OpenSearch (SEARCH_INDEX_OPENSEARCH_AUTH=sigv4), with the access level each needs; only the access a workload actually uses is checked.
  • Lists the namespace's associations, reading the cluster, region, and AWS_PROFILE from the kube context (--aws-profile, --eks-cluster, and --aws-region override them); non-EKS contexts skip the section.
  • FAILs each missing association with the exact create-pod-identity-association line (reusing a role that already has the same access; never the ingest edge's role under direct uploads) plus the --context rollout restart for its Deployments; associations no workload uses are listed for information only.
  • Optionally runs iam simulate-principal-policy per role against the search module's S3/OpenSearch action sets, covering identity policies only; a blocked simulation or unreadable role is UNKNOWN.
  • All AWS calls are reads. Without credentials each ServiceAccount is UNKNOWN with the command to run; --no-aws and --no-iam-simulate skip the section.

Docs gain the ServiceAccount → access table, a pre-install association check, and a diagnose-install.md section. The Terraform examples already associate the worker; no Terraform change. 13 new tests.

Written for commit 9cd856f. Summary will update on new commits.

View guided diff Turn on auto-fix

…viceAccount the release uses

In a sandbox rehearsal the customer created roles for alleyoop, session-ingest-api,
the search indexer and session-read, but no association for agent-relay-worker.
That only surfaced later, as "no Locker credentials: set LOCKER_ACCESS_KEY_ID/
LOCKER_SECRET_ACCESS_KEY, or run with EKS Pod Identity" in the session-summary
worker.

With a cluster scope, diagnose-install.py now:
- finds the ServiceAccounts of the release's Deployments, StatefulSets, Jobs and
  CronJobs whose pods read S3 (LOCKER_BUCKET, no static key) or sign OpenSearch
  requests (SEARCH_INDEX_OPENSEARCH_AUTH=sigv4), with the access level each needs
  (worker, session-ingest-api, alleyoop: S3 read/write; search-indexer: S3 read +
  OpenSearch write; session-read: S3 read + OpenSearch read);
- lists the namespace's associations (aws eks list-pod-identity-associations,
  cluster and region from the EKS kube context, or --eks-cluster/--aws-region);
- FAILs each missing one with the exact create-pod-identity-association line,
  reusing the role of a ServiceAccount that needs the same access, and the
  rollout restart for its Deployments;
- for each association, asks iam simulate-principal-policy whether the role
  allows that S3/OpenSearch access; UNKNOWN when not permitted.
All AWS calls are reads; no AWS credentials means UNKNOWN with the command to
run. --no-aws and --no-iam-simulate skip them.

Docs: the ServiceAccount -> access table and a pre-install association check in
docs/self-hosted-eks.md; an EKS Pod Identity section in
docs/support/diagnose-install.md. The Terraform examples (aws-existing-cluster,
aws) already associate the worker; no Terraform change.

Tests: 8 new (32 in test_diagnose_install.py, 45 in scripts/support/tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e75612db-c253-4cbc-aed8-5be303deda33
Commits

Reviewing files that changed from the base of the PR and between 294412e and 9cd856f.

Files selected for processing: 4

  • docs/self-hosted-eks.md
  • docs/support/diagnose-install.md
  • scripts/support/diagnose-install.py
  • scripts/support/tests/test_diagnose_install.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 4 potential issues.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread scripts/support/diagnose-install.py Outdated
Comment on lines +612 to +613
if getattr(options, 'aws_profile', None) and 'AWS_PROFILE' not in env:
env['AWS_PROFILE'] = options.aws_profile

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.

🔴 Pod Identity checks the wrong account

When the kube context and shell specify different profiles, aws_json uses the shell profile. If both accounts have a same-named cluster in that region, the report uses the wrong cluster’s associations.

Learn more

The diagnostic reads workloads through the selected kube context, which sets the credential plugin’s AWS_PROFILE explicitly. eks_target extracts that profile but skips reading it altogether when both cluster flags are provided. The EKS API request identifies the cluster by only name and region, and pod_identity_checks accepts the returned associations without checking the cluster's account. This permits two valid reads against different clusters to end in a false diagnosis.

Example: The selected context uses profile customer for cluster relay in us-west-2, but the shell exports the profile sandbox. Both accounts have a relay cluster; only the sandbox worker has an association. The report passes the customer worker’s association check using sandbox data.

Recommended fix: Read the context profile independently of name and region overrides. Define AWS credential precedence that honors the selected context by default. When the context provides a cluster ARN, validate that the AWS association lookup is for that ARN before treating any result as evidence.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9cd856f. The AWS calls now use the AWS_PROFILE the kube context's exec plugin sets (or --aws-profile). It overrides the shell's profile and clears static key env vars, so the associations come from the same account as the workloads. It's discovered even when --eks-cluster/--aws-region are passed. Test: test_the_kube_contexts_profile_wins_over_the_shell.

Comment thread scripts/support/diagnose-install.py Outdated
report.add(name, 'FAIL', 'No Pod Identity association for ServiceAccount '+sa+' (used by '+workloads+'), which needs '
+_access_text(entry['access'])+'. Its pods get no AWS credentials.',
create_line(sa, suggested_role(entry))
+(' then restart its pods: kubectl -n '+options.namespace+' rollout restart '+deployments if deployments else ''))

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.

🟡 Recovery restarts the wrong cluster

When --context selects a non-current cluster, rollout restart still targets the current context. The diagnosed pods stay unchanged, and matching deployments in the current cluster restart instead.

Learn more

The documented invocation accepts a specific Kubernetes context without changing the current one. The workload lookup correctly uses that context. The generated recovery command omits it, so kubectl resolves the same namespace and Deployment names using whichever context is current when the command runs.

Example: Run the diagnostic with --context staging while production is current. After adding the association to staging, run the proposed restart. If both clusters have the named Deployment, production rolls it out while staging retains the original pods.

Recommended fix: Include the diagnostic’s explicit context in the suggested restart and shell-quote its arguments, ideally rendering the AWS and Kubernetes commands on separate lines.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9cd856f: the restart line is now kubectl --context <selected context, shlex-quoted> -n <ns> rollout restart deployment/....

Comment thread scripts/support/diagnose-install.py Outdated
Comment on lines +808 to +810
for other, other_entry in sorted(accounts.items()):
if other in roles and other_entry['access'] == entry['access']:
return roles[other]

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.

🟡 Direct-upload repair suggests an incompatible role

When direct ingest lacks an association, suggested_role can recommend the worker role based on generic S3 access. The upload inbox policy denies that role access, so direct uploads remain unprocessed.

Learn more

The direct-upload setup requires a dedicated ingest consumer ServiceAccount and explicitly denies legacy roles access to its upload inbox. Its Helm values render the same locker variables used by ordinary ingest. The discovery fallback therefore assigns the ingest consumer s3-rw, the same level as the worker, even though their roles are not interchangeable. The upload inbox policy denies access to roles not on the consumer allowlist.

Example: The worker has an association but agent-relay-ingest-edge does not. Applying the suggested association gives the ingest edge the worker role; it still cannot read inbox objects.

Recommended fix: Restrict role reuse to explicitly interchangeable workload identities. For a direct-upload consumer, identify the dedicated consumer role from an authoritative source or print a placeholder that names that role.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, fixed in 9cd856f. A role is only suggested from the reference Terraform's shared sessions role (worker, alleyoop, session-ingest-api). With HISTORY_UPLOAD_DIRECT on, the ingest edge neither donates nor receives a shared role, and its fix line asks for its own upload-consumer role. Test: test_direct_uploads_never_share_the_ingest_role.

Comment thread scripts/support/diagnose-install.py Outdated
Comment on lines +822 to +823
if role and not getattr(options, 'no_iam_simulate', False):
simulate_access(options, role, entry, region, report, name)

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.

🟡 Denied role lookup hides IAM gaps

When AWS denies the association description, pod_identity_checks reports the association as present but silently omits its IAM checks. The report never marks that access as UNKNOWN.

Learn more

AWS lists associations without role ARNs, so the script separately describes each association. Role discovery swallows describe errors, and the check loop then treats the missing ARN like an opt-out from policy simulation. The association PASS remains valid, but report status aggregation cannot distinguish unverified permissions from an omitted check.

Example: Allow eks:ListPodIdentityAssociations and iam:SimulatePrincipalPolicy for an operator, but deny eks:DescribePodIdentityAssociation. Each association passes and no IAM row explains that the role could not be resolved.

Recommended fix: Retain the sanitized describe error for each association. When simulation is requested and no role is available, emit UNKNOWN for its access levels and point to the describe permission.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9cd856f: if describe-pod-identity-association fails, the association stays PASS and each needed access level is UNKNOWN with the fixed category (for example aws-access-denied). Test: test_unreadable_role_makes_its_access_unknown.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge, with a remaining non-blocking accuracy issue in the sweeper's IAM checks.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with a remaining non-blocking accuracy issue in the sweeper's IAM checks.

FindingsFix All in CodexFindings

  1. P2 Sweeper credentials are not checked ▶
Fix with agent prompt
### Issue 1
scripts/support/diagnose-install.py:701-711
Discovery misses the chart's `rearmSweeper` CronJob. In Pod Identity mode it requires its own association, but uses `INGEST_REARM_BUCKET` and `INGEST_REARM_CREDENTIALS`, so neither detection branch includes it. A missing association stays unchecked, and an existing one can be called unused.

Recognize this workload's environment settings and its separate access needs.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds EKS Pod Identity checks for the release's AWS-using ServiceAccounts.

  • The install diagnostic checks EKS associations for ServiceAccounts its workloads use.
  • The diagnostic checks whether associated roles allow the access workloads need.

Reviews (2) · Last reviewed commit: "fix(support): Pod Identity checks use th..." · Reviewed by Greptile

Comment thread scripts/support/diagnose-install.py Resolved
Comment thread scripts/support/diagnose-install.py Resolved
Comment thread scripts/support/diagnose-install.py Resolved
Comment thread scripts/support/diagnose-install.py Resolved
Comment thread scripts/support/diagnose-install.py Resolved
Comment on lines +690 to +695
if env.get('LOCKER_BUCKET') and 'LOCKER_ACCESS_KEY_ID' not in env and (env.get('LOCKER_PROVIDER') or 's3') == 's3':
needs.add('s3')
if (env.get('SEARCH_INDEX_OPENSEARCH_AUTH') or '').lower() == 'sigv4':
needs.add('os')
if not needs or not re.fullmatch(NAME_RE, sa):
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Sweeper credentials are not checked

Discovery misses the chart's rearmSweeper CronJob. In Pod Identity mode it requires its own association, but uses INGEST_REARM_BUCKET and INGEST_REARM_CREDENTIALS, so neither detection branch includes it. A missing association stays unchecked, and an existing one can be called unused.

Recognize this workload's environment settings and its separate access needs.

Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/support/diagnose-install.py
Line: 690-695

Comment:
**Sweeper credentials are not checked**

Discovery misses the chart's `rearmSweeper` CronJob. In Pod Identity mode it requires its own association, but uses `INGEST_REARM_BUCKET` and `INGEST_REARM_CREDENTIALS`, so neither detection branch includes it. A missing association stays unchecked, and an existing one can be called unused.

Recognize this workload's environment settings and its separate access needs.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex Fix in Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9cd856f: INGEST_REARM_CREDENTIALS=podIdentity with INGEST_REARM_BUCKET is detected as its own access level, s3-sweep (ListBucketVersions, GetObject, DeleteObjectVersion), on the sweeper's own ServiceAccount. It doesn't suggest a restart, since it's a CronJob.

Comment thread scripts/support/diagnose-install.py Resolved
…the search module's actions

Review findings on #558:
- AWS calls use the AWS_PROFILE the kube context authenticates with (or
  --aws-profile), not the shell's, so they read the same account as the
  workloads; suggested commands carry --profile.
- Suggested restarts carry --context.
- Role suggestions come only from the reference Terraform's shared sessions role
  (worker, alleyoop, session-ingest-api); with direct uploads the ingest edge
  is the upload consumer and never shares or donates a role.
- An association whose role can't be described now gets UNKNOWN access checks
  instead of silently none.
- OpenSearch simulation uses modules/aws/search's reader and indexer action sets.
- Non-EKS contexts (GKE, kind) skip the section instead of reporting UNKNOWN;
  no S3/OpenSearch workloads add no check.
- The S3 re-arm sweeper (INGEST_REARM_CREDENTIALS=podIdentity) is detected,
  with its own version list/delete access.
- Only the access a workload uses is checked (no OpenSearch for a read API on
  PostgreSQL search).

Tests: 5 new (50 in scripts/support/tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@khaliqgant
khaliqgant merged commit 8675c5f into main Nov 26, 2026
11 checks passed
@khaliqgant
khaliqgant deleted the aa/podid branch November 26, 2026 22:55
khaliqgant added a commit that referenced this pull request Nov 26, 2026
…luster when they can't run here

In the EKS rehearsal the operator couldn't reach RDS (split VPN) and
--scope database returned 10 UNKNOWN (network / credential-not-available).

--in-cluster runs the database section from a short-lived Job in the release
namespace, and the diagnostic now does that by itself when every local database
attempt ends in network, dns, timeout, tls, tool-missing or no credentials and
the cluster answers (--scope database probes the cluster only then;
--no-in-cluster opts out).

The Job mounts only the ten credential keys of the release's own Secrets and
the rds-ca ConfigMap, runs the pinned PostgreSQL client image rds-setup.sh and
configure-rds.sh use (PSQL_IMAGE or --psql-image for a mirror), and runs the
same catalog SQL as the same logins with sslmode=verify-full, in READ ONLY
transactions. No ServiceAccount token, read-only root, no capabilities,
backoffLimit 0, a deadline and a TTL. Its log carries only the credential
values with passwords replaced (so the local URL checks run unchanged), each
query's JSON and fixed error categories (one ERROR_RULES table, used by the
local path and the probe). The latest object's key is left out. The diagnostic
reads the log, always deletes the Job, and replays the results through the
unchanged database_checks. The operator needs create/get/delete on Jobs and
get on Pods and their logs; no Secret reads.

Tests: 8 new unit tests (32 in test_diagnose_install.py). New opt-in
scripts/support/tests/diagnose-in-cluster-postgres-test.sh runs it for real:
an RDS-shaped PostgreSQL 17 with TLS, rds-setup.sh pre for the logins and
Secret files, the Job as a container with the pinned image on a network the
host can't resolve.

Review fixes folded in (#559 threads): the probe parses each credential first and logs only URL parts (no password or other Secret fields, JSON::PP for wrapped values, bracketed IPv6); --in-cluster gates on auth can-i create jobs, not a Secret read; CA is rds-ca else cloud-sql-ca or --ca-configmap; no fallback over explicitly selected files or a credential FAIL; credentialSource in-cluster-job; create timeouts still cleaned up and failed deletes reported; --psql-image must be digest-pinned; network is unreachable maps to network; a URL fragment stays a failure. Rebased onto #558 (Pod Identity).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
khaliqgant added a commit that referenced this pull request Nov 26, 2026
…luster when they can't run here (#559)

* feat(support): diagnose-install runs the database checks inside the cluster when they can't run here

In the EKS rehearsal the operator couldn't reach RDS (split VPN) and
--scope database returned 10 UNKNOWN (network / credential-not-available).

--in-cluster runs the database section from a short-lived Job in the release
namespace, and the diagnostic now does that by itself when every local database
attempt ends in network, dns, timeout, tls, tool-missing or no credentials and
the cluster answers (--scope database probes the cluster only then;
--no-in-cluster opts out).

The Job mounts only the ten credential keys of the release's own Secrets and
the rds-ca ConfigMap, runs the pinned PostgreSQL client image rds-setup.sh and
configure-rds.sh use (PSQL_IMAGE or --psql-image for a mirror), and runs the
same catalog SQL as the same logins with sslmode=verify-full, in READ ONLY
transactions. No ServiceAccount token, read-only root, no capabilities,
backoffLimit 0, a deadline and a TTL. Its log carries only the credential
values with passwords replaced (so the local URL checks run unchanged), each
query's JSON and fixed error categories (one ERROR_RULES table, used by the
local path and the probe). The latest object's key is left out. The diagnostic
reads the log, always deletes the Job, and replays the results through the
unchanged database_checks. The operator needs create/get/delete on Jobs and
get on Pods and their logs; no Secret reads.

Tests: 8 new unit tests (32 in test_diagnose_install.py). New opt-in
scripts/support/tests/diagnose-in-cluster-postgres-test.sh runs it for real:
an RDS-shaped PostgreSQL 17 with TLS, rds-setup.sh pre for the logins and
Secret files, the Job as a container with the pinned image on a network the
host can't resolve.

Review fixes folded in (#559 threads): the probe parses each credential first and logs only URL parts (no password or other Secret fields, JSON::PP for wrapped values, bracketed IPv6); --in-cluster gates on auth can-i create jobs, not a Secret read; CA is rds-ca else cloud-sql-ca or --ca-configmap; no fallback over explicitly selected files or a credential FAIL; credentialSource in-cluster-job; create timeouts still cleaned up and failed deletes reported; --psql-image must be digest-pinned; network is unreachable maps to network; a URL fragment stays a failure. Rebased onto #558 (Pod Identity).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(support): the in-cluster probe never logs query values it doesn't allow; empty passwords stay malformed

Review findings on #559: only sslmode, sslrootcert, connect_timeout and
application_name pass through to the log; any other query parameter (e.g.
sslpassword=) becomes a fixed unsupported=1 marker, so the local check
rejects it without the value. The probe records whether the password was
empty, and the rebuilt URL keeps it empty so parse_credential still rejects
it. The Docker test adds an sslpassword= URL (refused, value never logged)
and checks that --no-in-cluster writes a local report and creates no Job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(support): decode query parameter names before the in-cluster allowlist

Review finding on #559: ssl%6dode=verify-full is valid for parse_qsl but was
withheld as unsupported. Names are now percent-decoded (and + as space, as
parse_qsl does) before the allowlist; unsupported values are still withheld.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
khaliqgant added a commit that referenced this pull request Nov 26, 2026
…tall path

Rebuilt on main after #555/#557/#558/#559 (OCI chart install, find_cluster,
in-cluster database checks). Earlier review rounds on #556 are folded in.

Why configure-rds.sh and not a new install.sh: it already owns the master
login, rds-setup.sh pre/post with the HoopDb layout, the release pins, the
chart (now the published OCI chart, #557), helm, the migration wait and
first sign-in. It now does the rest of the install too, so hand-filling
Secrets 01-05 is the bring-your-own option, and databaseGuard checks it.

- Secrets: the application keys are generated only when neither the cluster
  nor the credential files hold them, and never replaced (an empty openssl
  result stops the run). The ingest introspect-secret is copied, the five
  Secrets are written in the shapes the guard checks, and the script says
  what to back up.
- values.yaml: the rds-ca sha256 is pinned. The HoopDb layout
  (worker.migrations.hoopdb, rdsLayout, searchIndexer.bootstrap),
  relay-control.bootstrap.adminEmail and databaseGuard.statusTest.rbac.create
  are written into the operator's values file instead of a hidden -f overlay
  and --set flags, so a later plain helm upgrade keeps them (the rehearsal's
  rds_profile_unproven at revision 4). Block YAML is edited in place;
  comments, anchors and flow mappings are untouched. If the file can't be
  edited, the script falls back to the overlay with a loud warning.
- helm: works with the OCI chart and a checkout. On refusal the script
  points at AR_DB_LOGIN and the db-guard hook log, then stops.
- Jobs: wait_job returns at Complete or Failed (reset, migration, search
  bootstrap), instead of sitting out kubectl wait's timeout on a failed Job.
  A search bootstrap that failed before rds-setup.sh post is shown with its
  cause, deleted, and re-run through helm.
- --reset-databases checks that the master owns all three databases before
  dropping any. On a dedicated-owner install it refuses with "Nothing was
  dropped"; it used to drop two databases and then fail.
- Step 8: helm test, then the diagnostic next to the script when there is
  one. The run ends with one line (HEALTHY, UNHEALTHY or INCOMPLETE) and
  numbered Next steps. First sign-in waits for the relay-control rollout
  and retries the port-forward.
- diagnose-install.py: find_cluster() retries the probe (8s, 15s, 30s).
  Skipped workload checks end in "RESULT: INCOMPLETE: workload checks
  skipped" (exit 3), never a clean summary; otherwise RESULT is FAIL,
  PARTIAL or PASS.
- RELEASE_VERSION=checkout uses this checkout's chart and scripts (not with
  an OCI chart).
- Docs: scripts/selfhost/README.md (OCI-first), examples/aws README and the
  Secret 01-05 comments, docs/self-hosted-rds-manual-setup.md and
  docs/self-hosted-eks.md. Registry: opt.agent-relay.database-guard.

Tests: configure-rds-chart-test.sh 9/9. Its openssl mock now returns hex,
its kubectl mock answers Job status, and step 5 asserts that the layout is
in values.yaml with no hidden overlay. scripts/support tests 63/63.
configure-rds-e2e (kind + RDS-shaped PG17 with TLS, the rehearsal's
Secrets): the hand-filled install is refused up front, and the guided run
creates the logins, completes the migrations, mints the key and ends with
the verdict. A plain upgrade keeps rdsLayout. A fully healthy run needs S3
and OpenSearch, which the harness doesn't have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
khaliqgant added a commit that referenced this pull request Nov 27, 2026
…tall path (#556)

Rebuilt on main after #555/#557/#558/#559 (OCI chart install, find_cluster,
in-cluster database checks). Earlier review rounds on #556 are folded in.

Why configure-rds.sh and not a new install.sh: it already owns the master
login, rds-setup.sh pre/post with the HoopDb layout, the release pins, the
chart (now the published OCI chart, #557), helm, the migration wait and
first sign-in. It now does the rest of the install too, so hand-filling
Secrets 01-05 is the bring-your-own option, and databaseGuard checks it.

- Secrets: the application keys are generated only when neither the cluster
  nor the credential files hold them, and never replaced (an empty openssl
  result stops the run). The ingest introspect-secret is copied, the five
  Secrets are written in the shapes the guard checks, and the script says
  what to back up.
- values.yaml: the rds-ca sha256 is pinned. The HoopDb layout
  (worker.migrations.hoopdb, rdsLayout, searchIndexer.bootstrap),
  relay-control.bootstrap.adminEmail and databaseGuard.statusTest.rbac.create
  are written into the operator's values file instead of a hidden -f overlay
  and --set flags, so a later plain helm upgrade keeps them (the rehearsal's
  rds_profile_unproven at revision 4). Block YAML is edited in place;
  comments, anchors and flow mappings are untouched. If the file can't be
  edited, the script falls back to the overlay with a loud warning.
- helm: works with the OCI chart and a checkout. On refusal the script
  points at AR_DB_LOGIN and the db-guard hook log, then stops.
- Jobs: wait_job returns at Complete or Failed (reset, migration, search
  bootstrap), instead of sitting out kubectl wait's timeout on a failed Job.
  A search bootstrap that failed before rds-setup.sh post is shown with its
  cause, deleted, and re-run through helm.
- --reset-databases checks that the master owns all three databases before
  dropping any. On a dedicated-owner install it refuses with "Nothing was
  dropped"; it used to drop two databases and then fail.
- Step 8: helm test, then the diagnostic next to the script when there is
  one. The run ends with one line (HEALTHY, UNHEALTHY or INCOMPLETE) and
  numbered Next steps. First sign-in waits for the relay-control rollout
  and retries the port-forward.
- diagnose-install.py: find_cluster() retries the probe (8s, 15s, 30s).
  Skipped workload checks end in "RESULT: INCOMPLETE: workload checks
  skipped" (exit 3), never a clean summary; otherwise RESULT is FAIL,
  PARTIAL or PASS.
- RELEASE_VERSION=checkout uses this checkout's chart and scripts (not with
  an OCI chart).
- Docs: scripts/selfhost/README.md (OCI-first), examples/aws README and the
  Secret 01-05 comments, docs/self-hosted-rds-manual-setup.md and
  docs/self-hosted-eks.md. Registry: opt.agent-relay.database-guard.

Tests: configure-rds-chart-test.sh 9/9. Its openssl mock now returns hex,
its kubectl mock answers Job status, and step 5 asserts that the layout is
in values.yaml with no hidden overlay. scripts/support tests 63/63.
configure-rds-e2e (kind + RDS-shaped PG17 with TLS, the rehearsal's
Secrets): the hand-filled install is refused up front, and the guided run
creates the logins, completes the migrations, mints the key and ends with
the verdict. A plain upgrade keeps rdsLayout. A fully healthy run needs S3
and OpenSearch, which the harness doesn't have.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
khaliqgant added a commit that referenced this pull request Nov 27, 2026
…ne run: Pod Identity preflight, in-cluster search readiness, one final table

Khaliq's bar: from Automation Anywhere's broken state to fully green in one
run, with no manual follow-ups.

A. Pod Identity preflight, before anything destructive (including
   --reset-databases), reusing #558's checks in diagnose-install.py:
   - `diagnose-install.py --only pod-identity` checks every ServiceAccount the
     release's workloads use for S3 or OpenSearch (worker,
     session-ingest-api, session-read, search-indexer, alleyoop where
     rendered).
   - A missing association stops configure-rds.sh with the exact
     `aws eks create-pod-identity-association ...` line and the access the
     role needs; nothing has been changed at that point.
   - Opt-in POD_IDENTITY_ROLES="sa=roleArn,..." (diagnose
     --create-pod-identity) creates the missing ones and restarts their
     Deployments. A failed create (no eks:CreatePodIdentityAssociation or
     iam:PassRole) is a FAIL with the manual line.
   - No AWS credentials, or not EKS: reported UNKNOWN with the manual
     command, and the run goes on unless POD_IDENTITY_STRICT=1.
   - The check runs again after helm, for fresh installs.

B. Search readiness, from inside the cluster (`--only search`, and part of a
   full run):
   - The search bootstrap Job: its status and recorded cause, with the fix.
     The cause is the guard's termination message from #554;
     permission-denied causes point to rds-setup.sh post.
   - One signed GET /_cluster/health as the search indexer's ServiceAccount,
     in the release's services image, using its own Pod Identity credential
     source and SigV4 signer. It runs through #559's run_in_cluster, now
     generic over the Job builder and parser. Classified as:
     - unreachable (DNS/network/security group);
     - no AWS credentials;
     - 403 from fine-grained access control, with the exact
       relayhistory_indexer role and rolesmapping PUT bodies (the role ARN
       with and without its IAM path) from install step 7;
     - 403 from the domain access policy;
     - 401 (signing region).

C. The final verdict reflects workloads: after the rollouts, the full
   diagnostic (--scope all) and helm test become one table (migrations,
   Secrets, database logins + CA, Pod Identity, S3, search bootstrap,
   OpenSearch auth, workloads, values, helm test). configure-rds.sh exits 0
   only when every row passes, and keeps the report as
   STATE_DIR/last-install-diagnostic.json. Works with HELM_CHART=oci://...
   (#557) and the site: block (#560).

The diagnostic is resolved once: the copy next to the script, else the
release tag's, else the old pin. Its --only sections are feature-detected,
so an older release's copy skips them with a note.

Tests:
- configure-rds-chart-test.sh: 15/15, 6 new. A missing association stops
  before any Secrets Manager write, rds-setup.sh or helm. POD_IDENTITY_ROLES
  creates it and the run continues. No credentials goes on, and stops under
  POD_IDENTITY_STRICT. FGAC 403 gives a FAIL row with the rolesmapping body
  and a non-zero exit; unreachable gives a FAIL row; success gives PASS
  rows.
- diagnose tests: 62, 8 new (create; failed create; FGAC 403 with both ARN
  forms; FGAC via assumed role; domain-policy 403;
  unreachable/no-credentials/success; bootstrap cause; probe parser).
- The bun probe ran for real in the pinned services image: without
  credentials it reports no-credentials. With a fake credentials endpoint
  it signs and fetches: an unknown domain gives ENOTFOUND (classified
  unreachable) and a live host gives its HTTP status.
- bash -n on bash 3.2 and 5, shellcheck clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
khaliqgant added a commit that referenced this pull request Nov 27, 2026
…ne run (Pod Identity preflight, in-cluster search readiness, slow-auth probe, one final table) (#561)

* fix(support): the cluster probe gets at least 30s, and slow exec-plugin credentials aren't called unreachable

Root cause, from the coordinator: find_cluster() ran its probe with
probe=True, which capped kubectl at min(--timeout, 8)s. With kubeconfig auth
through `aws eks get-token` and a slow credential_process, one `kubectl get
secret` takes ~14s (measured: real 0m13.876s). The probe always timed out and
every workload and Pod Identity check was skipped, while the in-cluster
database Job, which uses the full timeout, still worked.

- Each probe attempt gets max(--timeout, 30)s, with one retry after 5s. The
  probe never runs below --timeout.
- When every attempt times out and the kubeconfig user authenticates
  through an exec plugin (kubectl config view --minify), the note says so:
  "This kubeconfig authenticates through an exec plugin (aws), so this is
  most likely slow credentials ..., not an unreachable cluster. Refresh the
  credentials or rerun with --timeout 90." Otherwise it still says "not
  reachable", with the time taken.
- Unchanged: skipped workload checks end in RESULT: INCOMPLETE, exit 3.

Tests (real subprocesses with a fake kubectl on PATH): a kubectl that takes
12s per call is found reachable with no "not reachable" note. A timeout with
an aws exec plugin says slow credentials. --timeout 90 is honoured. The
retry-then-INCOMPLETE test now asserts 2 attempts at 30s. Diagnose tests:
52/52. docs/support/diagnose-install.md covers exit 3, the RESULT line and
slow credentials.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(selfhost): configure-rds.sh takes a broken install to green in one run: Pod Identity preflight, in-cluster search readiness, one final table

Khaliq's bar: from Automation Anywhere's broken state to fully green in one
run, with no manual follow-ups.

A. Pod Identity preflight, before anything destructive (including
   --reset-databases), reusing #558's checks in diagnose-install.py:
   - `diagnose-install.py --only pod-identity` checks every ServiceAccount the
     release's workloads use for S3 or OpenSearch (worker,
     session-ingest-api, session-read, search-indexer, alleyoop where
     rendered).
   - A missing association stops configure-rds.sh with the exact
     `aws eks create-pod-identity-association ...` line and the access the
     role needs; nothing has been changed at that point.
   - Opt-in POD_IDENTITY_ROLES="sa=roleArn,..." (diagnose
     --create-pod-identity) creates the missing ones and restarts their
     Deployments. A failed create (no eks:CreatePodIdentityAssociation or
     iam:PassRole) is a FAIL with the manual line.
   - No AWS credentials, or not EKS: reported UNKNOWN with the manual
     command, and the run goes on unless POD_IDENTITY_STRICT=1.
   - The check runs again after helm, for fresh installs.

B. Search readiness, from inside the cluster (`--only search`, and part of a
   full run):
   - The search bootstrap Job: its status and recorded cause, with the fix.
     The cause is the guard's termination message from #554;
     permission-denied causes point to rds-setup.sh post.
   - One signed GET /_cluster/health as the search indexer's ServiceAccount,
     in the release's services image, using its own Pod Identity credential
     source and SigV4 signer. It runs through #559's run_in_cluster, now
     generic over the Job builder and parser. Classified as:
     - unreachable (DNS/network/security group);
     - no AWS credentials;
     - 403 from fine-grained access control, with the exact
       relayhistory_indexer role and rolesmapping PUT bodies (the role ARN
       with and without its IAM path) from install step 7;
     - 403 from the domain access policy;
     - 401 (signing region).

C. The final verdict reflects workloads: after the rollouts, the full
   diagnostic (--scope all) and helm test become one table (migrations,
   Secrets, database logins + CA, Pod Identity, S3, search bootstrap,
   OpenSearch auth, workloads, values, helm test). configure-rds.sh exits 0
   only when every row passes, and keeps the report as
   STATE_DIR/last-install-diagnostic.json. Works with HELM_CHART=oci://...
   (#557) and the site: block (#560).

The diagnostic is resolved once: the copy next to the script, else the
release tag's, else the old pin. Its --only sections are feature-detected,
so an older release's copy skips them with a note.

Tests:
- configure-rds-chart-test.sh: 15/15, 6 new. A missing association stops
  before any Secrets Manager write, rds-setup.sh or helm. POD_IDENTITY_ROLES
  creates it and the run continues. No credentials goes on, and stops under
  POD_IDENTITY_STRICT. FGAC 403 gives a FAIL row with the rolesmapping body
  and a non-zero exit; unreachable gives a FAIL row; success gives PASS
  rows.
- diagnose tests: 62, 8 new (create; failed create; FGAC 403 with both ARN
  forms; FGAC via assumed role; domain-policy 403;
  unreachable/no-credentials/success; bootstrap cause; probe parser).
- The bun probe ran for real in the pinned services image: without
  credentials it reports no-credentials. With a fake credentials endpoint
  it signs and fetches: an unknown domain gives ENOTFOUND (classified
  unreachable) and a live host gives its HTTP status.
- bash -n on bash 3.2 and 5, shellcheck clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(selfhost): review fixes for the one-run installer (#561)

From Greptile, Devin and CodeRabbit on #561, and Devin on agentrelay.com#344:

diagnose-install.py
- find_cluster keeps every attempt's error. It gives the slow-credentials
  message only when every attempt timed out, and also names a stalled VPN
  connection as the other cause.
- The --only sections probe the namespace's default ServiceAccount, not
  agent-relay-secrets, and count NotFound/Forbidden as an answer. A fresh
  install (no Secret yet) or a narrow Role no longer reads as "cluster
  unreachable". kubectl's (NotFound) now has its own category.
- The search probe Job carries the indexer's imagePullSecrets, so a private
  image pulls.

configure-rds.sh
- The final table counts cast./control./hoop. database checks and adds an
  "other checks" row for anything unmapped. A non-zero diagnostic exit adds
  a diagnostic row when nothing else failed, so a failed or partial
  diagnostic never becomes HEALTHY.
- The Pod Identity stop says which stage it is ("Nothing has been changed
  yet" only before any change) and lists the associations created in this
  run. It restarts their pods before stopping.
- A failed rollout restart prints the exact command and stays pending; the
  final table has a failing "pod restarts" row until it's done.
- POD_IDENTITY_STRICT=1 also stops when the release's diagnostic has no
  --only sections.
- The post-helm Pod Identity check runs after both the automatic and the
  manual helm paths.
- A fresh install creates the namespace when the cluster answers NotFound,
  instead of stopping before rds-setup.sh pre could create it.

Tests: configure-rds-chart-test.sh 17/17 (new: the namespace is created on a
fresh install; a partial POD_IDENTITY_ROLES restarts what it created, then
stops naming it). Diagnose tests: the earlier error stays visible on a mixed
failure; --only counts NotFound as an answer and never reads the Secret; the
probe carries pull secrets. shellcheck and bash -n (3.2 and 5) are clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(selfhost): keep pending Pod Identity restarts across runs; don't claim nothing changed after creating associations

CodeRabbit on #561:
- A failed rollout restart is written to STATE_DIR/pending-pod-identity-restarts and
  retried on the next run (the diagnostic won't report CREATED again for an existing
  association); the file is removed once every restart succeeds, and the final table
  keeps a failing 'pod restarts' row until then.
- The stop after a partial POD_IDENTITY_ROLES says 'Only Pod Identity associations have
  been created so far: <sa>' instead of 'Nothing has been changed yet'.

configure-rds-chart-test.sh 18/18 (new: a pending restart from an earlier run is retried
and cleared).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant