From ac738e6d0753c8d7cfa1b6c0a970ae8399b67bb0 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 26 Sep 2026 03:17:49 +1000 Subject: [PATCH] feat(container): end the install phase between install and startup hooks StartKit calls InstallDone after the install hooks, before files and startup hooks, so the caller moves the egress session to its runtime policy exactly where the Kit spec ends the install phase. --- internal/container/kit.go | 7 +++++++ internal/container/kit_test.go | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/internal/container/kit.go b/internal/container/kit.go index 53499d6bc..e78dad5d3 100644 --- a/internal/container/kit.go +++ b/internal/container/kit.go @@ -32,6 +32,10 @@ type KitSpec struct { Binds []string Labels map[string]string Launch kit.Launch + // InstallDone runs after the install hooks and before anything else, so + // the caller can end the install phase: the egress session moves to its + // runtime policy and install-phase credentials stop resolving. + InstallDone func() } // StartKit creates and starts a Kit container, then brings it to the state @@ -79,6 +83,9 @@ func StartKit(ctx context.Context, cli *client.Client, s KitSpec) (string, error return fail(fmt.Errorf("install hook %d: %w", i+1, err)) } } + if s.InstallDone != nil { + s.InstallDone() + } for _, f := range s.Launch.Files { if err := writeKitFile(ctx, cli, created.ID, s.Launch.Harness.User, f.Path, f.Content, f.Mode, f.Overwrite); err != nil { return fail(fmt.Errorf("write kit file %s: %w", f.Path, err)) diff --git a/internal/container/kit_test.go b/internal/container/kit_test.go index 15de2c74f..5865f4dfb 100644 --- a/internal/container/kit_test.go +++ b/internal/container/kit_test.go @@ -139,3 +139,24 @@ func TestKitContainerFailingInstallHookIsRemoved(t *testing.T) { t.Fatalf("a failed Kit start left %d container(s) behind", len(list.Items)) } } + +func TestKitContainerEndsTheInstallPhaseBetweenInstallAndStartup(t *testing.T) { + cli := kitClient(t) + s := kitSpec(t, kit.Hook{Argv: []string{"sh", "-c", "touch /tmp/installed"}, User: "0"}) + var containerName string + var sawInstalled, sawStartup bool + s.InstallDone = func() { + containerName = s.Name + code, _, err := ExecIn(context.WithoutCancel(t.Context()), cli, containerName, "0", nil, []string{"test", "-e", "/tmp/installed"}) + sawInstalled = err == nil && code == 0 + code, _, err = ExecIn(context.WithoutCancel(t.Context()), cli, containerName, "0", nil, []string{"test", "-e", "/tmp/startup-uid"}) + sawStartup = err == nil && code == 0 + } + startKit(t, cli, s) + if containerName == "" { + t.Fatal("InstallDone was never called") + } + if !sawInstalled || sawStartup { + t.Fatalf("InstallDone ran with install done=%v and startup done=%v; want after install, before startup", sawInstalled, sawStartup) + } +}