poststarthooks

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package poststarthooks executes post-start hook actions on sandbox pods that have just transitioned Starting → Running. It implements sandboxpool.SandboxReadyHook.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v0.0.5

type Action struct {
	// Exec runs a shell command inside the sandbox container.
	Exec *ExecAction `json:"exec,omitempty"`
	// HTTPPost sends a POST request to an in-sandbox HTTP endpoint via the gateway.
	HTTPPost *HTTPPostAction `json:"httpPost,omitempty"`
}

Action describes a single action to execute after a sandbox becomes Running. Exactly one of Exec or HTTPPost should be set (mirrors k8s ProbeHandler style). The action is serialized as JSON to the SandboxPostStartHooksAnnotationKey pod annotation at claim time, then consumed here when the pod reaches Running.

type ArmNotifier added in v0.0.10

type ArmNotifier interface {
	Notify(sandboxID string, err error)
}

ArmNotifier receives the arming verdict for a claimed sandbox. Declared as an interface so a nil one is a working no-op rather than a panic.

type ExecAction added in v0.0.5

type ExecAction struct {
	// Command is passed to sh -c inside the first container.
	Command string `json:"command"`
}

ExecAction runs a command inside the sandbox container.

type HTTPPostAction added in v0.0.5

type HTTPPostAction struct {
	// Port is the target port of the in-sandbox service (required).
	Port int32 `json:"port"`
	// Path is the request path, e.g. "/init".
	Path string `json:"path"`
	// Body is an arbitrary JSON object serialized as the request body.
	Body map[string]any `json:"body,omitempty"`
	// Headers are extra HTTP headers to include (e.g. for authentication).
	Headers map[string]string `json:"headers,omitempty"`
}

HTTPPostAction sends a POST to a port/path inside the sandbox, routed through the gateway.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner implements sandboxpool.SandboxReadyHook. It reads post-start hook actions from pod annotations and executes them after the sandbox transitions Starting → Running.

func NewRunner

func NewRunner(
	gatewayBaseURL string,
	clientset kubernetes.Interface,
	restConfig *rest.Config,
	crClient client.Client,
	armNotifier ArmNotifier,
) *Runner

NewRunner creates a Runner. gatewayBaseURL may be empty (it is only a fallback for post-start HTTP hooks; the normal path dials the Pod directly). clientset / restConfig may be nil (Exec hooks are skipped); crClient may be nil (the runtime readiness pre-check is skipped); armNotifier may be nil (nobody is waiting on the verdict).

func (*Runner) Arm added in v0.0.10

func (r *Runner) Arm(ctx context.Context, pod *corev1.Pod) error

Arm runs every step that has to succeed before a sandbox may be handed to its caller, and returns the first failure. The step order is a security contract, not a convenience (see the doc comment on OnSandboxReady).

The caller owns the outcome. Arming used to record its verdict on the Pod so the create path could watch for it, which cost one API-server write per sandbox — fanned out to every Pod informer in the cluster — to move a fact between two goroutines. The claim path calls this directly instead and gets the error as a return value.

Exactly one caller may arm a given claim. It is not idempotent: each run mints a fresh per-sandbox CA, and installing a second one after the sandbox already trusts the first breaks interception for connections in flight.

Step 0 exists because a container running the right image is not yet a sandbox that answers. Nothing else waits for the runtime to come up.

func (*Runner) OnSandboxReady

func (r *Runner) OnSandboxReady(ctx context.Context, pod *corev1.Pod)

OnSandboxReady implements sandboxpool.SandboxReadyHook. It is called in a goroutine; errors are logged but never propagated.

The step order is a security contract, not a convenience:

  1. resolve credentials and mint the sandbox's CA (nothing observable yet);
  2. run the post-start hooks, which install that CA in the sandbox's trust store — merged into the same /init call as the user's env vars;
  3. push the egress policy;
  4. arm the sidecar with the credentials.

Arming before the CA is installed would make the sandbox's first intercepted request fail its TLS handshake. Both halves of a partial failure are safe: without step 4 requests leave carrying only a decoy, and without step 2 they do not leave at all. Neither leaks a credential.

func (*Runner) OnSandboxRelease added in v0.0.7

func (r *Runner) OnSandboxRelease(ctx context.Context, pod *corev1.Pod)

OnSandboxRelease implements sandboxpool.SandboxReleaseHook. When the pod returns to the pool (Stopping → Idle), it resets the filter sidecar to fail-closed so a reused pod never carries the previous sandbox's egress rules into the window before the next claim's policy push lands.

func (*Runner) RepushEgressPolicy added in v0.0.10

func (r *Runner) RepushEgressPolicy(ctx context.Context, pod *corev1.Pod) error

RepushEgressPolicy delivers the pod's current egress-policy annotation to its proxy sidecar. It exists for the live-update path: the API server stamps a revised policy and calls this, and the sidecar reloads it for connections opened from then on.

Deliberately narrower than a re-arm. Re-running OnSandboxReady would remint the interception CA and re-install it through envd's /init, which is also the call that carries the sandbox's environment variables — a heavy, lossy way to change an allowlist.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL