test: Okta SSO e2e (kind + live Okta + Playwright); local OIDC for any issuer; fix local-up databaseGuard

Merged
KH
3d ago
+1029-17

What

1. ci/agent-relay/okta-e2e/kind.sh: the customer Okta path on kind

This runs the published okta-setup.sh, verified against SHA256SUMS, or OKTA_SETUP=<path> for an unreleased copy.

  • mock: runs against mock_okta.py, a stateful stand-in for the Okta API.

    • It refuses before any Okta call when the Secret is missing, or when kubectl can read the Secret but not patch it (server dry run).
    • It writes one key, oidc-client-secret, with a merge patch. Every other key stays byte-for-byte the same, including keys that exist only in the cluster.
    • It never prints the token or the client secret, and the backup copy is 0600.
    • A second run refuses and writes nothing.
    • The guide's console merge patch and its "turn it off" JSON-patch remove run verbatim.
  • chart: helm template relay-control with the exact values the script prints. It also renders with them removed (turn it off), and with oidcClientSecret left behind, which is refused.

  • live (OKTA_LIVE_ORG + OKTA_TOKEN_CMD): a throwaway group, then the real script against a real org. It checks:

    • the app's settings and group assignment;
    • that the Secret holds the app's active client secret (compared, never printed);
    • that issuer discovery matches;
    • that authorize accepts only the registered redirect (200 vs 400).

    It deletes the app and group afterwards, also on failure.

2. ci/agent-relay/okta-e2e/browser.sh + browser_signin.py: real sign-in with Playwright

  • It creates a throwaway group, three users, and an app shaped like okta-setup.sh's, under a unique label. It adds a password-only authentication policy, because the org default needs two factors.
  • It points the local stack at that app with make local-oidc, checks login-config, and drives Continue with Okta in Chromium:
    • member (in the group, allowed domain) joins the local organization with role member; the owner-only usage endpoint returns 403;
    • outsider (not in the group): Okta refuses with "User is not assigned to the client application";
    • otherdom (in the group, another email domain): Okta returns a code, and Control refuses with "Accounts from other-example.com can't sign in here".
  • It deletes every Okta object it created and restores the stack's previous OIDC setting.

3. local_stack.py: local OIDC for any issuer

The stored client may now name an https issuer and a display_name. Google stays the default, with its client-ID check unchanged. make local-oidc is an alias of make local-google-oidc. There's a new unit case for an Okta issuer.

4. local_stack.py: fix make local-up on main

Since the render-time databaseGuard (#552), the first agent-relay upgrade failed. The worker's migrations.hoopdb still pointed at kind-pipeline from values-kind-core, a Secret this recipe never creates. It now points at local-pipeline-owner/url, the HoopDb owner login the recipe already uses.

Evidence (linuyc, amd64 Linux)

  • kind.sh with the live phase against integrator-6407170: 22/22, using agentrelay.com#356's script. The same harness reproduces #356's newline bug at f025b5c.
  • A fresh make local-up (LOCAL_RELAYCAST_BACKEND=postgres) completes. test_local_stack: 40/40.
  • browser.sh: 9/9.
  • After all runs, the Okta org is back to its baseline (7 apps, 6 access policies, 1 user, no okta-e2e objects), and login-config shows oidc: null again.

Secrets: the token goes from OKTA_TOKEN_CMD into a 0600 curl config. The client secret and passwords live in 0600 files or stdin. None is printed or put on argv.

Related: agentrelay.com#356 (okta-setup merge patch), #641 (install step 10 regenerates keys).

🤖 Generated with Claude Code


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


Summary by cubic

Adds end-to-end coverage for the self-hosted Okta SSO path: a kind-based harness that runs the published okta-setup.sh against a mock Okta API and optionally a live org, plus a Playwright-driven browser sign-in test against the local stack. Also lets the local stack use any OIDC issuer instead of only Google, and fixes make local-up, which failed at the first agent-relay helm upgrade since the render-time databaseGuard was added.

Testing

  • The mock phase proves the script refuses before any Okta call when the Secret is missing or kubectl can't patch it, writes one key with a merge patch while keeping cluster-only keys byte-for-byte, never prints the token or secret, and refuses a second run.
  • It also runs the guide's console merge patch and its JSON-patch "turn it off" remove, but only when they match the reviewed guide-blocks.sha256 exactly; a changed guide fails with a diff. It renders the chart with the printed values, with them removed, and with oidcClientSecret left behind (refused).
  • The harness reuses or deletes only a cluster it created itself; any other existing cluster is refused before anything changes.
  • The live phase (with OKTA_LIVE_ORG and OKTA_TOKEN_CMD) verifies app settings, group assignment, that the stored secret equals the app's active client secret, issuer discovery, and that authorize accepts only the registered redirect.
  • browser.sh creates a throwaway group, three users, and an OIDC app with a password-only policy, points the local stack at it, and signs in with Playwright: the member joins as member, the outsider is refused by Okta, and the other-domain user is refused by Control.
  • Before the browser cases, the harness waits for each Deployment to roll out and for the Okta button on /login.
  • Chromium pins only the local Kind cert keys for TLS, so Okta keeps full certificate checks; a failed cleanup or OIDC restore fails the run, and cleanup warnings print the failing step and the run ID for manual recovery.
  • All Okta objects are deleted and the stack's previous OIDC setting restored, also on failure; secrets flow through 0600 files or stdin.

Local OIDC and the make local-up fix

  • The stored OIDC client may now name an https issuer and display_name; Google stays the default with its client-ID check unchanged, and make local-oidc aliases make local-google-oidc.
  • The worker's migrations.hoopdb now uses local-pipeline-owner/url, the HoopDb owner login the recipe already uses, instead of the never-created kind-pipeline Secret, so databaseGuard no longer blocks the upgrade.