Skip to content

fix: exit an enterprise boot that has no kiro login or no governance rules - #23968

Merged
iamwhatever merged 1 commit into
mainfrom
fix/ee-boot-exit-on-failed-login
Oct 26, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/ee-boot-exit-on-failed-login

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An enterprise build with no kiro login, or whose governance rules fail to load, stops at boot with a clear error instead of running a locked gateway.

Refs #23697. That PR keeps a failed enterprise boot running with the gate CLOSED and serves the pinned login/health routes. The owner rejected this: a gateway that is running but locked is still a surface someone could get past. The accepted RFC docs/request-for-change/rfc-crew-enterprise-edition.md, section "Enterprise gate", says Crew stops:

| Start | Login and fetch rules. If either fails, exit |

and in the Migration plan, phase 2: "Exit: with no login, or with the governance fetch failing, an enterprise build exits".

Why it matters

Today an enterprise gateway with no login listens on its port and serves a set of routes. Every route that stays reachable is something an attacker can probe, and the allowlist has to stay correct forever. If the gateway exits before it binds, there is nothing to reach.

Not a goal

What changed (motivation → approach → change)

Product-shape decision: the accepted RFC above, section "Enterprise gate" and Migration plan phase 2. It is on main with status accepted since #23714.

Everything below applies only when kiro_crew.edition.is_enterprise() is true. An oss build skips every new branch.

  • New kiro_crew/enterprise_boot.py.
    • require_kiro_login() calls the new KiroPrerequisiteService.boot_login_status(). It runs only the setup gate's own --version and whoami steps (not a second login check). The spec and acp --help checks of a full probe are left for after the bind. The probe is left not done, so the post-bind warm-up and the login watch run the full one.
    • If there is no verified sign-in, the gateway prints what failed and how to fix it, then exits 1. Only a whoami that clearly answers "signed out" reads as no sign-in, which names kiro-cli login and the SSO command. A missing CLI names the install link, and a CLI that does not start names the reinstall. A sandbox refusal, a CLI that does not answer in time, or a whoami that times out or fails says the sign-in could not be checked, and gives that error.
    • refuse_policy_boot(exc) turns a PlatformCompositionError from boot_platform (the policy load) into the same kind of error and exit 1.
  • Login check before any service starts. GatewayOrchestrator.run calls require_kiro_login right after the sandbox warm-up (the probe runs kiro-cli inside the sandbox). That is before _init_services, before the MCP gateway sidecar starts, and before the HTTP bind. This is a bounded, fail-closed check that has to come before serving: --version has a 10 s limit and whoami has 30 s.
    • The verified service is passed to start_dashboard / start_api_server as kiro_prerequisite_service. If a caller passes no service, those two functions run the same check themselves, still before runner.setup() / site.start().
  • Policy check before any server binds. cli.main and run_gateway send a failed boot_platform to refuse_policy_boot. doctor still runs on a failed composition. That exception is unchanged.
  • The gate starts open. install_enterprise_gate now builds an open EnterpriseGate and raises if the service it is given has no login. A caller that skips the boot check therefore fails at boot instead of serving a locked app.
  • Runtime behaviour is unchanged. LoginWatch still closes the gate when the login is lost or expires while running, and the middleware, its allowlist and the dashboard's sign-in screen are untouched.
  • Docs: docs/system-specs/modules/platform-context.md § Enterprise gate.

Desktop (Electron):

  • Showing the error needs no change. The supervisor already writes the gateway child's stdout and stderr to its launch log (gateway-supervisor.js, childOut). When that child exits non-zero during boot, the supervisor opens its "gateway failed to start" window, which shows the tail of that log.
  • Waiting long enough. The pre-bind checks take up to 10 s (--version), 30 s (whoami) and 10 s (policy fetch). The app's 30 s Mac/Linux wait could expire on a signed-in user whose token refresh is slow.
    • packaging/build-desktop.sh now stages website/electron/EDITION from the same KIROCREW_BUILD_EDITION stamp the backend uses. It does this for an enterprise build only, and refuses any other value.
    • The file is packed into app.asar and read by the new website/electron/edition.js. No environment variable or config is read at run time.
    • gatewayWaitTimeoutMs gives an enterprise spawned local gateway its normal budget plus 50 s for the checks and 30 s of headroom (110 s on Mac/Linux, 200 s on Windows). A failed check still ends the wait at once, because the child exits.
    • An oss build stages nothing, and its budgets (30 s, 120 s on Windows local) are unchanged and pinned by tests.

Order of the two checks: today the policy loads in boot_platform, before the login probe. RFC open question 1 (how the login identity is presented to the governance service) is still undecided, so the fetch does not use the login yet. Either failure exits before the bind.

Backwards compatibility

Compatible: an oss build runs no new code. In an enterprise build the only change is that a boot with no login or no rules exits instead of serving a locked gateway, which is what the accepted RFC requires.

Reader: src/kiro_crew/dashboard/enterprise_gate_middleware.py:install_enterprise_gate -- release -- both gateway entrypoints pass it the boot-verified service; test_gate_starts_open_after_the_boot_check, test_gate_refuses_to_install_without_a_login
Reader: src/kiro_crew/enterprise_gate.py:EnterpriseGate -- release -- the default (closed for login) is unchanged for direct callers; the gateway passes closed_for=(); test/test_enterprise_gate.py
Reader: website/src/components/KiroPrerequisiteGate.tsx:KiroPrerequisiteGate -- crew page -- still reads enterprise_login_required, now set only after a login is lost while running; test_closed_gate_status_asks_an_established_install_to_sign_in

Tests

Proof: not provable -- other: prove.py is INCONCLUSIVE because reverting the production hunks removes the new enterprise_boot module, so the tests fail at collection (head 785c4e8)

test/test_enterprise_boot.py. No fixed sleeps.

  • No login: require_kiro_login exits 1 with the sign-in command. A missing CLI, a CLI that does not start, a sandbox refusal, a version-probe timeout, a probe error and a probe that raises each exit 1 with their own message, and none of them says "no sign-in".
  • Real service with a fake process runner: the boot probe runs exactly --version and whoami, and a later snapshot() still runs acp --help. A timed-out whoami latches a probe_error, and a clearly signed-out whoami latches none.
  • Gateway with no login: GatewayOrchestrator.run exits 1 before _init_services, _init_mcp_gateway, _init_dashboard and _init_api_server, and no TCP socket listens (a socket.listen spy).
  • start_api_server handed no service, with no login: exits 1, TCPSite.start is never awaited, and no TCP socket listens.
  • Failed policy fetch: run_gateway and cli.main gateway each exit 1 with the error before the orchestrator or _gateway runs, and no TCP socket listens.
  • oss: require_kiro_login constructs nothing and returns None. GatewayOrchestrator.run goes on to _init_services with no probe. refuse_policy_boot returns, so the caller re-raises as before.
  • Desktop (website/electron/test/edition.test.js): no baked file, or anything but enterprise, reads as oss. Oss budgets are unchanged on all platforms. An enterprise local gateway gets +80 s, and an enterprise connection tab keeps 30 s. Both wait callers pass the baked edition. The file is packed, and build-desktop.sh stages it only for enterprise.
  • Gate: it installs open after the boot check and refuses to install with no login. The existing test/test_enterprise_gate.py runtime tests now install the gate after a login and then expire it, which models a mid-run expiry.

Local gates: black, isort, flake8, mypy (3630 files), comment-history and brand all pass. 2,100+ related tests pass. test_cli_main_entry.py::TestMcpBuiltinDispatch::test_mcp_builtin_dispatches_to_module also fails locally on unmodified origin/main, so this change did not cause it.

Manual verification

Ran a real enterprise-stamped gateway (EDITION patched to enterprise, isolated HOME, --test-mode --port auto) on a host with no usable sandbox. It printed "Kiro Crew cannot start: the Kiro sign-in could not be checked (unshare(CLONE_NEWUSER) failed with errno 1 (EPERM))" with its fix, exited 1, and no TCP socket listened.

Related Issues

Refs #23697

Sibling sweep

Siblings: none -- the two boot entrypoints (start_dashboard, start_api_server) both changed here, and they are the only places install_enterprise_gate is called

Pattern harvest

Not generalizable: the defect is one design choice (keep a failed enterprise boot serving), reversed by an owner decision, not a coding pattern

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 25, 2026 07:36
@iamwhatever
iamwhatever force-pushed the fix/ee-boot-exit-on-failed-login branch from 9f49a98 to 8b3574a Compare October 25, 2026 07:37
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 785c4e8b81e066bc487d0ae3c09182d352ccf030 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing blocks: the diff adds no dashboard control and changes no existing one. The only new user-facing output is the stderr boot-refusal text, and each message says what failed and gives the next step.

Notes

  • enterprise_boot.py:64: "the organisation's governance rules or enterprise platform could not be loaded" leaves the user to guess which of the two failed, so they don't know what to check. Split it into two messages, or drop "or enterprise platform".

[UX-REVIEWED] 785c4e8

Description read

[DESCRIPTION-READ] e8cc69350234ece094c0d3f5704ef128468515ca2b5e3d289d059e22006a6083

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 785c4e8b81e066bc487d0ae3c09182d352ccf030 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change does what the accepted RFC says ("If either fails, exit"), every check runs before any port is bound, and an oss build runs none of the new code.

Notes

  • A whoami that times out or fails for a passing network reason now stops an enterprise boot outright. Write down whether the desktop supervisor retries a boot that exits with status 1, or only shows its failure window, so a slow token refresh doesn't look like a permanent failure.
  • The boot check (--version/whoami only) and the later full probe both write _status. Keep that single latch as the one place that decides, and don't let callers start reading the boot-time ready=False as meaning something.

[DESIGN-REVIEWED] 785c4e8

Description read

[DESCRIPTION-READ] 2ebfc28ab5325eb56699201933a9262082411bcdce4c895252418983c95653c4

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 785c4e8b81e066bc487d0ae3c09182d352ccf030 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The fallback login check inside start_dashboard and start_api_server never runs in production, and install_enterprise_gate's new raise already covers the case it guards.

Notes

  • Item 6 — one consumer, generalized: the hunk if kiro_prerequisite_service is None: kiro_prerequisite_service = await require_kiro_login(...) is in both entrypoints. Their only callers are at service_boot.py:636 and :685. Both are reached only from run() (:893, :896), and run() has already set _boot_kiro_service or exited. In oss the fallback returns None, so no build ever uses it. A caller that skipped the boot check would also hit install_enterprise_gate's new raise RuntimeError, which is a second guard for the same case. Subtraction: delete the inner require_kiro_login call in server.py and api_entrypoint.py, along with test_api_server_without_a_login_exits_before_the_bind. Keep the raise in install_enterprise_gate as the one guard.

What this change ships

Inventory (8 items) — 7 justified

Intent: an enterprise build with no kiro login, or whose governance rules fail to load, exits at boot with a clear error instead of running a locked gateway. FIX (the accepted RFC covers it: "Start | Login and fetch rules. If either fails, exit").

  1. An enterprise gateway with no kiro login exits 1 before any service starts or binds, naming the fix — justified
  2. A failed governance policy load exits 1 with the error, in cli.main and run_gateway — justified
  3. The boot probe runs only --version and whoami, and the full probe runs after the bind — justified
  4. The enterprise gate starts open instead of closed — justified
  5. install_enterprise_gate refuses a service with no login — justified
  6. start_dashboard and start_api_server re-run the login check when handed no service — one consumer, generalized; never reached in production
  7. The enterprise desktop app waits 80 s longer for its local gateway — justified
  8. build-desktop.sh stages an EDITION file, which edition.js reads — justified

[FIRST-PRINCIPLES-REVIEWED] 785c4e8

Description read

[DESCRIPTION-READ] ba681ba444a72509a7404b577138ed4efae7b2d3ff20fdb09382ddbf92fd92ab

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 785c4e8b81e066bc487d0ae3c09182d352ccf030 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 785c4e8

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 785c4e8b81e066bc487d0ae3c09182d352ccf030 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 785c4e8b81e066bc487d0ae3c09182d352ccf030 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 785c4e8

Verdict parsed from the review's SHA-scoped output markers for commit 785c4e8b81e066bc487d0ae3c09182d352ccf030.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 785c4e8b81e066bc487d0ae3c09182d352ccf030 false-positive: <reason, 20 to 500 characters>

@iamwhatever
iamwhatever force-pushed the fix/ee-boot-exit-on-failed-login branch from 8b3574a to e164a41 Compare October 25, 2026 08:22
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 25, 2026
@iamwhatever
iamwhatever force-pushed the fix/ee-boot-exit-on-failed-login branch from e164a41 to 947ed61 Compare October 25, 2026 11:42
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 25, 2026
…rules

An enterprise build now checks the kiro login (the setup gate's own
--version and whoami steps) before any gateway service starts, and exits 1
with what failed and the fix when it fails. A governance policy load that
fails in boot_platform exits the same way. Both run before the HTTP server
binds, so a failed boot serves nothing.

The enterprise gate now starts open on the verified login and refuses to
install on a service with no login. A login lost while running still
closes it and the middleware is unchanged.

The desktop build bakes EDITION from the same KIROCREW_BUILD_EDITION stamp
(enterprise only), and an enterprise app waits 80s longer for its local
gateway so those checks can finish. An oss app is unchanged.

Design: docs/request-for-change/rfc-crew-enterprise-edition.md,
"Enterprise gate".
@iamwhatever
iamwhatever force-pushed the fix/ee-boot-exit-on-failed-login branch from 947ed61 to 785c4e8 Compare October 25, 2026 12:33
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 25, 2026

@cruisercohen cruisercohen 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.

Reviewed 785c4e8b81 merged onto current main 09816d215f. This is a comment, not an approval: it changes the enterprise gate's boot behaviour, which is governance and security scope.

What changed in the enterprise gate: it now starts OPEN (EnterpriseGate(closed_for=())) instead of closed until a probe. It can only start open after a login was verified before the bind:

  • Every boot runs the check. start_dashboard and start_api_server both run require_kiro_login before the bind unless they are handed a service. The Slack gateway path hands in the service its own pre-start require_kiro_login produced.
  • The check fails closed. It exits on every non-signed-in status, and on a probe that raises.
  • No test-mode bypass. assume_ready cannot mark an enterprise service ready: self._assume_ready = assume_ready and not is_enterprise() is unchanged from main.
  • A skipped check fails at boot. install_enterprise_gate raises when its login source is not authenticated, so a caller that skipped the check fails at boot rather than opening the gate.
  • The runtime half is unchanged. A login lost while the gateway runs still closes the gate; the middleware change is the starting state only.

The electron EDITION file only lengthens the local gateway's wait budget. It decides nothing about access.

Tests:

  • test_enterprise_boot.py plus test_kiro_prerequisite_service.py: 55 of 60 pass.
  • The other 5 are the gateway, api-server and CLI exit-before-bind tests. They need an optional dependency my environment lacks, so I could not run them. Neither could test_enterprise_gate.py, which holds the install-time guard. CI's backend shards are green on this head.
  • Electron edition.test.js and gateway-wait.test.js pass 51/51.

Fail-open mutations (each turned the suite red; worktree restored clean after each):

  • The boot check returning the service while signed out.
  • The check swallowing a probe exception.
  • The login-only latch reporting authenticated regardless of whoami.
  • The policy refusal returning instead of exiting.

@iamwhatever
iamwhatever enabled auto-merge (squash) October 26, 2026 02:01

@buluoray buluoray 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.

Approve @ 785c4e8b81e066bc487d0ae3c09182d352ccf030.

Matches the accepted RFC ("Start | Login and fetch rules. If either fails, exit"; phase 2 exit criterion).

oss unchanged: require_kiro_login and refuse_policy_boot return before doing anything when not enterprise. start_dashboard / start_api_server then build the service exactly as before, and cli.main / run_gateway re-raise the same exceptions. The desktop wait only grows for watchSpawn && edition === "enterprise", and a missing or odd EDITION file reads as oss. Mutating the edition early-return turns test_oss_checks_nothing and test_oss_gateway_boots_on_without_a_login_check red.

Enterprise fails closed: any exception or non-authenticated status exits 1 before _init_services and before any bind. The login-only latch uses the same authenticated=whoami.ok as the full probe, and --test-mode still cannot assume readiness. install_enterprise_gate refuses an unauthenticated service, so a skipped check still stops at boot.

No conflict with merged work: #23686's cold-cache/failed-fetch abort raises PlatformCompositionError in boot_platform, which is exactly what refuse_policy_boot turns into a clean exit. #23689 is composition data only. For #23697 only the starting state changes; the allowlist, middleware, LoginWatch and gateway_locked are untouched, and the route-pinning tests pass.

Tests: 166 backend tests pass (including the exit-before-bind gateway / API / CLI tests), and 176 Electron tests pass. 11 of 12 single mutants go red on a named test.

Non-blocking:

  • One survivor: dropping start_dashboard's own check when handed no service. It still stops via the install guard, but with a traceback, and no test covers the dashboard path. A twin of test_api_server_without_a_login_exits_before_the_bind would pin it.
  • platform-context.md says the boot check is a login_verified(max_age_secs=0) probe; the code calls boot_login_status().
  • The policy-refusal hint "and that you are signed in to Kiro" points at the login, but the fetch does not use it yet.
  • Not run in a packaged enterprise desktop build.

@iamwhatever
iamwhatever merged commit a42f83b into main Oct 26, 2026
164 of 172 checks passed
@iamwhatever
iamwhatever deleted the fix/ee-boot-exit-on-failed-login branch October 26, 2026 02:23
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 26, 2026
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.

3 participants