Skip to content

Spec REMOTE-3452: self-hosted Kubernetes network policies - #169

Draft
warp-agent-staging[bot] wants to merge 1 commit into
mainfrom
factory/remote-3452-network-policy-spec
Draft

warp-agent-staging[bot] wants to merge 1 commit into
mainfrom
factory/remote-3452-network-policy-spec

Conversation

@warp-agent-staging

Copy link
Copy Markdown
Contributor

Summary

Spec only for REMOTE-3452. No runtime, protocol, or chart implementation is included.

  • specs/REMOTE-3452/PRODUCT.md records the agreed behavior and exclusions.
  • specs/REMOTE-3452/TECH.md defines assignment plumbing, Cilium/native enforcement, operator prerequisites, terminal failures, safe cleanup, and executable implementation acceptance checks.
  • Incorporates Ben's choices: Cilium when available; one-time DNS snapshots otherwise; explicit operator opt-in; fail the execution when enforcement fails; remove policies only after execution stops, including with --no-cleanup.
  • Explicitly excludes capability negotiation. Old workers ignore unknown JSON fields, so all pool replicas must be upgraded before policy-bearing dispatch.

Validation

  • git diff --cached --check passed before commit.
  • Markdown structure, companion links, and 14 local/pinned-source references checked.
  • Only the two spec files changed. Runtime and live-CNI tests are future implementation requirements, not claimed results.

Approval

Proposed specification awaiting Ben Navetta's approval. Approval is not deployment or feature-flag authorization.

@warp-agent-staging

Copy link
Copy Markdown
Contributor Author

This PR was generated with Warp.

Comment @warp-staging-factory on this PR to send it follow-up work.

View run View conversation View on Slack

Comment thread specs/REMOTE-3452/TECH.md
### 1. Operator configuration and supported boundary
- Add `backend.kubernetes.supports_network_policies: false`. Wire it through `mergeConfig` to `KubernetesBackendConfig.SupportsNetworkPolicies`. Add Helm `kubernetesBackend.supportsNetworkPolicies: false`.
- This is a file/Helm option. Do not add a global CLI boolean that can imply support on Docker, direct, or command backends.
- Add a `network_policy_dns` block under `backend.kubernetes`, with Helm equivalent `kubernetesBackend.networkPolicyDNS`:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty common for the worker to run within the Kubernetes cluster. In that case, can it automatically resolve the cluster's DNS server?

Comment thread specs/REMOTE-3452/TECH.md
- When support is enabled, require nonempty, valid resolver addresses and nonempty namespace/labels. These describe the cluster's trusted DNS service. Use them for native DNS grants and Cilium DNS endpoint selection.
- The native resolver sends lookups to the configured resolver addresses, with bounded UDP/TCP resolution. The task's final DNS configuration must use the same trusted DNS view. Document how to obtain the cluster DNS Service addresses.
- V1 targets ordinary Pod-network tasks with cluster DNS. NodeLocal DNS, custom DNS forwarding, service meshes, and secondary interfaces require operator validation of equivalent enforcement; the worker must not synthesize broad network grants to accommodate them.
- Before enabling support, the operator must install and verify a persistent native egress default-deny policy selecting the reserved label `oz-network-restricted=true`. Ship an example manifest and installation instructions in the worker README. Do not create this baseline moments before each task.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call it warp-network-restricted instead. We should also put the policy in the Helm chart

Comment thread specs/REMOTE-3452/TECH.md
- The operator must verify that the CNI has handled the baseline before enabling support. Kubernetes exposes no portable policy-enforced readiness status. A Helm success or successful policy POST does not satisfy this prerequisite.
- The baseline must not select unrestricted task Pods. Other native, Cilium, or administrative policies must not widen restricted Pods' egress. Admission must preserve the worker's selector labels and the task's network boundary.
- Task identities must not create Pods, modify labels/policies, access a privileged daemon, or escape to host networking. The task ServiceAccount remains separate from the worker's policy-management ServiceAccount.
- Reject restricted templates with `hostNetwork: true`, a privileged container, or added `NET_ADMIN`/`SYS_ADMIN` capabilities. Inspect regular and init containers in the final merged template. Root sidecar-copy init containers remain supported; root UID alone is not privileged mode.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user chooses to weaken their container config, I don't think we need to block it. We should not set these ourselves though

Comment thread specs/REMOTE-3452/TECH.md
- Cluster Service DNAT and Cilium-managed endpoint identity can deny traffic that an IP rule names. Document these provider limits. Never solve reachability by granting an entire cluster/network. Acceptance tests use controlled external destinations and the declared DNS service.
### 4. Launch ordering and failure safety
- Keep nil-policy launches on their existing path. The following state machine applies only to restricted launches.
- Allocate a fresh UUID token for each created Job. Add worker-owned labels `oz-network-restricted=true` and `oz-network-policy-id=<token>` to its Job and Pod template. Operator extra labels must not override these values.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The network policy ID label should also be warp- prefixed. Generally, I think we should reserve that prefix for Warp and not operator labels

Comment thread specs/REMOTE-3452/TECH.md
- Cluster Service DNAT and Cilium-managed endpoint identity can deny traffic that an IP rule names. Document these provider limits. Never solve reachability by granting an entire cluster/network. Acceptance tests use controlled external destinations and the declared DNS service.
### 4. Launch ordering and failure safety
- Keep nil-policy launches on their existing path. The following state machine applies only to restricted launches.
- Allocate a fresh UUID token for each created Job. Add worker-owned labels `oz-network-restricted=true` and `oz-network-policy-id=<token>` to its Job and Pod template. Operator extra labels must not override these values.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a fresh UUID, can we use the run and execution IDs?

Comment thread specs/REMOTE-3452/TECH.md
- Create the Job with `suspend: true`, `backoffLimit: 0`, and `restartPolicy: Never`. Its metadata records launch state `prepared`. Capture its UID before policy creation. A suspended Job starts no init, setup, or task containers.
- Compile and create one provider policy in the task namespace. Select its token label. Store worker/task/execution identity, provider, Job name, and full Job UID in policy labels/annotations.
- Check the API response matches the intended selector and rules. Admission mutation that broadens the policy fails the launch. Unknown timeouts are ambiguous: re-read by name and verify identity/content before proceeding.
- Resume only with a UID/resourceVersion-fenced update that changes `prepared` to `launched` and clears suspension. A conflicting or replaced Job is not safe to resume.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem necessary since we can create the policy before the job?

Comment thread specs/REMOTE-3452/TECH.md
- Never delete the policy in a generic `ExecuteTask` defer. Cleanup is a separate state check. Failure or cancellation can return before Kubernetes has terminated containers.
### 5. Policy cleanup and reconciliation
- Implement policy-only reconciliation at worker startup and every 30 seconds while support is enabled. Scope lists to the configured namespace and worker-pool hash. It does not need server secrets or full run reattachment.
- Do not make the policy a Job-owned garbage-collection dependent. Background Job deletion could garbage-collect the policy while Pods still terminate. Explicit reconciliation controls deletion order.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC, is this something Kubernetes supports?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant