# workspace-kubernetes

Lane C implementation of AWP's native Kubernetes `WorkspaceProvider`.

## Mechanics

A workspace profile resolves to deterministic Kubernetes resources:

- ServiceAccount with token automount disabled;
- NetworkPolicy with ingress denied by default and only declared egress;
- PVC for durable WIP when persistence is enabled;
- optional Service only when the profile declares one;
- Pod with non-root execution, RuntimeDefault seccomp, no privilege escalation, all Linux capabilities dropped, read-only root filesystem and explicit CPU/memory bounds;
- `runtimeClassName: gvisor` (or another explicit runtime class) when selected by the immutable profile.

The provider applies resources idempotently, reconciles pod/PVC state, can replace disposable compute while retaining the PVC, computes an immutable checkpoint digest from workspace/PVC identity, and refuses PVC cleanup unless the caller supplies the current digest and explicitly confirms the checkpoint was collected.

`KubernetesApiTransport.fromInCluster()` reads the mounted ServiceAccount bearer token and Kubernetes CA certificate, then uses the CA explicitly for HTTPS to the in-cluster API. Resource mutation uses server-side apply with the AWP workspace field manager.

`destroy()` removes compute/network/service-account resources but deliberately retains durable PVC WIP. This makes logical completion distinct from destructive cleanup.

## Credential boundary

Profiles may project only explicitly declared attempt-scoped secrets. Publication, merge and production-deploy credential purposes are rejected before any resource is created. Pods do not mount Kubernetes service-account tokens by default.

## Execution profile resolution

`resolveExecutionProfile()` follows the approved precedence:

1. `.devcontainer/devcontainer.json` / `.devcontainer.json`;
2. Docker Compose;
3. Dockerfile;
4. mise/Devbox;
5. language/tool manifests;
6. AWP fallback profile for orchestration values not supplied by the project.

The resolver records provenance and flags project declarations that require an image build rather than silently pretending the fallback image is the project-native build result.

## Live proof

`tools/preflight/workspace-wip-smoke.sh` proves PVC WIP survives pod deletion/replacement in an authorized cluster. gVisor compatibility and control-plane/node interruption remain separate live evidence gates and must not be marked green from unit tests alone.
