From 56fdac751c072253657a1539d4c61528940d77c6 Mon Sep 17 00:00:00 2001 From: Bolin Chen Date: Fri, 6 Nov 2026 09:58:50 +0000 Subject: [PATCH] refactor: drop the unreachable control-secret derive fallback control_secret_id built a secret name from the configured prefix and the record's tag when a matched MicroVM crew record carried no control_secret_ref. Every record is created by the launch with that reference set, and the field and its writer landed together, so no live record reaches the branch. Return "" for a record with no reference, the same "cannot authenticate" answer a row that owns no record already gets, and drop the path template and the tests that pinned its shape. Closes #24735 --- src/kiro_crew/dashboard/handlers_crew_turn.py | 30 ++-------- test/test_crew_turn_proxy.py | 55 +++---------------- 2 files changed, 13 insertions(+), 72 deletions(-) diff --git a/src/kiro_crew/dashboard/handlers_crew_turn.py b/src/kiro_crew/dashboard/handlers_crew_turn.py index 9bb8689e19e0..2e31c429f58c 100644 --- a/src/kiro_crew/dashboard/handlers_crew_turn.py +++ b/src/kiro_crew/dashboard/handlers_crew_turn.py @@ -65,14 +65,6 @@ #: test rather than copied by eye. CONTROL_SECRET_HEADER = "X-SMC-Control-Secret" -#: The shape a per-crew control secret's name has, as the lane writes it: the -#: path the lane's own launch spec builds (``MicroVmLaunchSpec.control_secret_name``) -#: from the crew's launch tag, so the hub derives the name itself instead of -#: being told a path by the caller. Used only to DERIVE an id when the lane -#: recorded none; the recorded reference is always preferred, because it is what -#: the launch actually minted. -_SECRET_PATH = "{prefix}/{crew}/CONTROL_SECRET" - #: The one lane this route serves. #: @@ -103,27 +95,15 @@ def control_secret_id(inst: Any) -> str: Fargate lane's own label (``Kiro Crew Cloud ()``) is not a valid secret name at all. - Derives the name from the operator's configured prefix -- not the hardcoded - default, so a moved prefix is honoured -- only when the record was already - matched and simply carries no reference, where the tag used is the RECORD's - own. A row that owns no record gets ``""``, which the caller reports as a - crew it cannot authenticate to rather than guessing a name for it. + The recorded reference is the only source: ``MicroVmLaunchEngine.provision`` + writes it into the record it creates. A row that owns no record, or a record + that carries no reference, gets ``""``, which the caller reports as a crew it + cannot authenticate to rather than guessing a name for it. """ - try: - from kiro_crew.cloud.config import CloudConfig - except Exception: # noqa: BLE001 - no lane, no reference - return "" record = _record_for(inst) if record is None: return "" - if record.control_secret_ref: - return record.control_secret_ref - # No reference stored, but the row IS this record's: the tag is the record's - # own, not a label the caller supplied, so deriving a path from it names this - # crew's secret and no other. - config = CloudConfig.load().microvm_config() - prefix = config.secret_path_prefix if config else "kirocrew/crew" - return _SECRET_PATH.format(prefix=prefix, crew=record.tag) + return record.control_secret_ref def _record_for(inst: Any) -> Any: diff --git a/test/test_crew_turn_proxy.py b/test/test_crew_turn_proxy.py index 54b64e865e53..0913e362c1e7 100644 --- a/test/test_crew_turn_proxy.py +++ b/test/test_crew_turn_proxy.py @@ -67,32 +67,6 @@ def test_the_far_ends_own_turn_url_wins_over_a_composed_one(): assert mod._turn_target(status, "microvm") == "http://127.0.0.1:19999/v1/chat/completions" -def test_the_secret_path_is_the_one_the_deploy_wrote(): - """Derived from the crew's launch tag, never supplied by the caller. - - A caller-supplied secret path would let any request name a secret for the - gateway to read with the owner's credentials and send to an endpoint of the - caller's choosing -- which is a read-any-secret primitive wearing a chat - route's clothes. - """ - assert ( - mod._SECRET_PATH.format(prefix="kirocrew/crew", crew="l2crew") - == "kirocrew/crew/l2crew/CONTROL_SECRET" - ) - from kiro_crew.cloud.microvm.engine import MicroVmLaunchSpec - - spec = MicroVmLaunchSpec( - image_identifier="arn:aws:lambda:us-east-1:1:microvm-image:x", - image_version="1.0", - kms_key_id="", - ) - # The lane's launcher and this route must name the SAME secret, or the hub - # authenticates with a value the guest never read. - assert spec.control_secret_name("l2crew") == mod._SECRET_PATH.format( - prefix="kirocrew/crew", crew="l2crew" - ) - - def test_the_control_header_matches_the_containers_own_constant(): """One definition, asserted rather than copied by eye. @@ -332,8 +306,7 @@ async def test_a_turn_against_a_really_registered_row_is_not_refused_for_its_sec class TestTheSecretIsNamedByTheLaneNotTheDisplayName: """A crew's display name is a label, and labels are not secret names. - ``Kiro Crew Cloud ()`` is not a valid Secrets Manager name, and a hardcoded - path would ignore a moved ``microvm.secret_path_prefix``. + ``Kiro Crew Cloud ()`` is not a valid Secrets Manager name. """ def test_a_recorded_reference_is_preferred(self, tmp_path, monkeypatch): @@ -394,13 +367,6 @@ class Inst: assert control_secret_id(Inst()) == "" - def test_the_path_shape_takes_the_configured_prefix(self): - """A hardcoded prefix ignores an operator who moved theirs.""" - from kiro_crew.dashboard.handlers_crew_turn import _SECRET_PATH - - assert "{prefix}" in _SECRET_PATH - assert _SECRET_PATH.startswith("{prefix}") - class TestTheCrewIsAddressedByItsOwnNameNotTheLaunchTag: """``model`` names the crew, and the launch tag is not that name. @@ -914,8 +880,7 @@ def _must_not_run(*a, **k): class TestControlSecretIdLanePrecedence: - """``control_secret_id`` prefers this crew's recorded reference, then a derive - FROM THAT RECORD'S OWN TAG -- never from a label the row supplied. + """``control_secret_id`` answers with this crew's recorded reference or nothing. A row with no record resolves to nothing: ``instances.json`` is not write-protected, so deriving from the row's label would let a relabelled row name any crew's secret. @@ -950,11 +915,9 @@ def test_a_record_for_another_instance_is_not_borrowed(self, tmp_path, monkeypat assert "someone-else" not in got, "another instance's reference was borrowed" assert got == "", "a secret path was derived from the row's own label" - def test_the_derive_still_runs_for_a_matched_record_without_a_reference( - self, tmp_path, monkeypatch - ): - """The surviving half of the precedence: identity matched, no reference - stored, so the path is derived -- from the RECORD's tag.""" + def test_a_matched_record_without_a_reference_resolves_nothing(self, tmp_path, monkeypatch): + """Identity matched, no reference stored: no name is guessed for the + secret, so the route answers ``crew_secret_unavailable``.""" from types import SimpleNamespace from kiro_crew.cloud.microvm.record import CrewRecord, CrewStore @@ -964,17 +927,15 @@ def test_the_derive_still_runs_for_a_matched_record_without_a_reference( monkeypatch.setattr("kiro_crew.cloud.microvm.record.CrewStore", lambda *a, **k: store) inst = SimpleNamespace( - name="Kiro Crew Cloud (anything-else)", + name="Kiro Crew Cloud (l2crew)", provisioner_id="microvm", - id="anything-else", + id="l2crew", connection_method="ssm", ssm_target=_REAL_NODE, aws_profile="", aws_region="", ) - got = mod.control_secret_id(inst) - assert got.endswith("/l2crew/CONTROL_SECRET"), "the record's own tag was not used" - assert "anything-else" not in got, "the row's label reached the secret name" + assert mod.control_secret_id(inst) == "" class _ExplodingStream(_CapturingStream):