mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-06 22:53:55 +08:00
ARTEX_RUNNER_BACKEND=kubernetes runs each task in a worker pod behind its own
egress-proxy pod, created through the Kubernetes API (kube_client.go) with no
container runtime socket. Per-task NetworkPolicies are applied before the pods
and removed after them; the runner proves they are in effect before the first
command, runs commands through pods/exec under env -i and artex-exec-wrap, and
re-adopts task pods after a restart. Unit tests run against a fake API
server; this commit keeps the tests for the review items, and the other
unit tests and the live cluster test follow in a separate PR.
Changes since the first review (502e42d):
NetworkPolicies and scope:
- Delete and failed setups delete the task's pods and wait until they are
gone before removing the service and, last, the policies. If a pod
cannot be deleted, the policies stay and the task stays tracked. Pods
get a 1s grace, not 0: a zero grace removes the API object before the
kubelet has stopped the containers.
- applyPolicy replaces an existing policy only when it carries the
runner's labels for the same task, and sends its resourceVersion.
- ARTEX_KUBE_PROXY_DENIED_CIDRS adds to DefaultProxyDeniedCIDRs instead
of replacing it. An empty DNSPodLabels map falls back to k8s-app=kube-dns.
- No scope opens the cluster: ARTEX_KUBE_CLUSTER_CIDRS (pod, service and
node CIDRs) plus metadata, loopback, link-local and the API server
address form a never-reachable list. Each scope ipBlock gets them as
except (a block inside one is dropped), the public rule excepts them,
and the proxy refuses them through ARTEX_NEVER_CIDRS (new
EgressPolicy.Never; Docker does not set it). Without
ARTEX_KUBE_CLUSTER_CIDRS, scope CIDRs overlapping private, loopback or
link-local ranges are dropped (logged), so the scope fails closed.
- Isolation does not rely on an outside default-deny policy: every task
pod has its own Ingress+Egress policy, adopted tasks get theirs applied
again, and before the first command the runner checks that the worker
reaches neither the API server nor a public address directly and that
the proxy cannot reach the API server; setup fails otherwise. A scope
change replaces the worker too, so the checks run in a worker no
command has used.
- The proxy pod uses ndots 1, so scope names are not first looked up as
cluster names.
Exec:
- The worker base env comes after the request env in the env(1) argv.
Refusing PATH, proxy and loader variables (LD_*, BASH_ENV, ...) in a
request is a separate change to the shared ValidateEnv, which also
covers the Docker backend.
- Any exec error after the stream started (cancel, broken stream, read
limit) kills the worker's processes, and so does a wrapper timeout
(exit 124 after at least timeout_ms, the Docker rule).
- Exec, Kill and Delete validate the task ID; Exec validates the request.
Concurrency and cleanup:
- Kill takes the task lock; stored tasks are copied, never changed in
place. A Kill caused by an exec acts only on the worker pod UID that
ran it; pod deletes carry a UID precondition.
- An exec queued behind a Delete returns ErrNotFound instead of creating
the task again. Per-task locks are reference counted and removed.
- A failed setup removes what it created, found by label (a foreign
object with the same name stays). Delete returns ErrNotFound only when
no object of the task exists.
- Recover adopts only pods named artex-w-/artex-p-<hash> and services
with a real ClusterIP; adopted tasks are re-checked on first use.
- Scope hash: full SHA-256; task object names use 128 bits.
Config: http:// API servers are refused, the tasks and audit sub paths
must not be ".", equal or nested, and NewKubernetesBackend documents what
the deployment must provide (PID limits, restricted namespace, quotas,
shared volume, shared Kill).