Skip to content

feat(k8s): a command that probes a network policy path #4407

Closed

Description

@dan-petty

Problem

To prove that the MCP server policies work (#4355), a throwaway pod had to be made by hand with kubectl run --overrides, a restricted security context, a label, and a sleep. The first attempt failed because kube-router programs the policy of a new pod a few seconds after the pod starts (the connection was refused at once, curl exit 7). After a 20 second wait, the allowed pod got HTTP 401 (reached) and the blocked pod got exit 7 (blocked). The steps are easy to get wrong, and the project prefers a devops k8s command over hand-made pods for cluster checks.

What to build

A command, for example devops k8s probe, that runs one throwaway pod with a given label in a given namespace, waits for the policy to be programmed, requests a URL (method, path, no token printed), prints the HTTP status or the curl exit code, and always deletes the pod. It uses a restricted security context that passes Pod Security, a pinned image from the project's allowed registries, and a timeout. --dry-run makes no request. A test uses a fake kubectl edge.

Done when

devops k8s probe --label app.kubernetes.io/name=devops-cli-job --url http://mcp-server.devops.svc.cluster.local:8001/implementation/mcp prints 401, and the same with another label prints a blocked result.

Related: #4355, #4372, #3600.

Proposed design

Problem statement

The project checks a network policy with a hand-made pod. An operator runs kubectl run --overrides with a restricted security context, a label and a sleep. The first attempt fails because kube-router programs the policy of a new pod a few seconds after the pod starts. The manual steps are easy to get wrong and slow to repeat.

The repository already holds that throwaway pod: src/devops_cli/k8s/service_probe.py starts one labeled pod, runs a bounded probe with kubectl exec and deletes the pod, also after a failure.

This change adds devops k8s probe. The command runs one throwaway pod with a given label in a given namespace. It retries until the policy is programmed, requests one URL, and prints the HTTP status or the curl exit code. It always deletes the pod, and --dry-run prints the request plan and touches no cluster.

Acceptance criteria

Requirement: One labeled probe pod

The command SHALL create exactly one pod in the given namespace with the given label and SHALL send each attempt with kubectl exec into that pod.

Scenario: One pod for the whole probe

  • WHEN The operator runs devops k8s probe --namespace devops --label app.kubernetes.io/name=devops-cli-job --url http://mcp-server.devops.svc.cluster.local:8001/implementation/mcp with the process fake.
  • THEN The fake records one kubectl run call that carries namespace devops and label app.kubernetes.io/name=devops-cli-job, and no second run call.

Requirement: Restricted security context

The probe pod MUST set the security context of the shared throwaway pod, so that it passes the restricted Pod Security Standard.

Scenario: Pod spec passes restricted Pod Security

  • WHEN The command builds the pod spec.
  • THEN The spec sets runAsNonRoot: true, a non-zero runAsUser, allowPrivilegeEscalation: false, capabilities.drop: [ALL], seccompProfile.type: RuntimeDefault, readOnlyRootFilesystem: true and automountServiceAccountToken: false.

Requirement: Wait for the policy

The command MUST retry the request while the pod's curl exits 7, until the --wait deadline of 20 seconds, before it makes the measured request.

Scenario: A refused connection is retried

  • WHEN The process fake answers the first two exec calls with exit code 7 and the third with standard output 401.
  • THEN The command makes three exec calls and prints status=401.

Requirement: Blocked result

The command SHALL print the curl exit code when no HTTP response arrives.

Scenario: A blocked path prints the exit code

  • WHEN The process fake answers every exec call with exit code 7 until the wait deadline.
  • THEN The command prints curl_exit=7 and exits 0.

Requirement: Credential off the command line

The command MUST send each header value to curl on standard input and MUST NOT hold it in any command line or in the output.

Scenario: A secret header stays off every argv and out of the output

  • WHEN The operator passes --header 'Authorization: Bearer s3cr3t' and the process fake answers the measured request with status 200.
  • THEN No recorded argv holds s3cr3t, the exec call's standard input holds it, and the standard output and the standard error hold no s3cr3t.

Requirement: Pod deletion

The command MUST delete the probe pod before it exits, including after an error or a timeout.

Scenario: Pod deleted after a failed probe

  • WHEN The process fake fails the first exec call with exit code 2.
  • THEN The fake records one delete pod --ignore-not-found call for the generated pod name, and the command exits non-zero.

Requirement: Probe deadline

The command MUST stop the probe when the overall --timeout deadline of 60 seconds elapses and report a timeout.

Scenario: Deadline stops a slow probe

  • WHEN The process fake does not answer the exec call before the --timeout deadline.
  • THEN The command prints a timeout message, records the pod deletion and exits non-zero.

Requirement: Dry run

The command SHALL create no pod and send no request with --dry-run.

Scenario: Dry run prints the plan only

  • WHEN The operator runs the command with --dry-run.
  • THEN The fake records no run, no exec and no delete call, and the output holds the kubectl run, the curl command line and the URL.

Requirement: Pinned image

The probe pod MUST use an image pinned by digest.

Scenario: The image names a digest

  • WHEN The command builds the pod spec with the default image and with --image.
  • THEN Each image reference holds @sha256:, and a --image value that holds no digest is refused before any kubectl call.

Existing Tool Considered

No alternatives check has run. kubectl is the open, maintained tool that covers the need in part (https://kubernetes.io/docs/reference/kubectl/generated/kubectl_run/). kubectl run, kubectl exec and kubectl delete create the labeled pod, send the request and remove the pod. kubectl lacks a wait for kube-router to program the policy, a restricted security context by default, a printed HTTP status or curl exit code, and guaranteed deletion on a timeout. curlimages/curl is the open, maintained image that supplies curl and its exit codes (https://hub.docker.com/r/curlimages/curl). The project already holds the throwaway pod in src/devops_cli/k8s/service_probe.py:267, so the change extends it with one HTTP attempt and a probe command instead of a second pod path. The written cost is about 25k tokens to build the attempt, the command and their tests, about 5k tokens a year to keep and fix, and half a day of elapsed time.

Key questions

  • Which code runs the probe pod?: The existing module src/devops_cli/k8s/service_probe.py. probe_from_pod starts one labeled pod with kubectl run, runs one kubectl exec per target and deletes the pod, also after a failure. The change adds an HTTP attempt beside _connects and reuses _pod_overrides, _start_pod, _delete_pod and plan_probe_from_pod. It adds no second pod implementation, as the crawl4ai-check spec already requires of the shared probe code. [sources: src/devops_cli/k8s/service_probe.py:267, src/devops_cli/k8s/service_probe.py:306, src/devops_cli/k8s/searxng_check.py:32, openspec/specs/k8s-crawl4ai-check/spec.md:66]
  • Does the command exec into one sleeping pod, or run a new pod for each request?: One pod. The module starts it once with kubectl run and sleep, sends every attempt with kubectl exec, and deletes it once in a finally-shaped block. The label and the pod identity stay constant across the retries, so the policy of one pod is measured. [sources: src/devops_cli/k8s/service_probe.py:282, src/devops_cli/k8s/service_probe.py:298, tests/k8s/test_service_probe.py:39]
  • How does the command wait for kube-router to program the policy?: Retry the request while the pod's curl exits 7 (failed to connect) until --wait elapses, default 20 seconds. Then make one measured request with --max-time. The loop lives in the command, so the command enforces --timeout and each kubectl call stays under the module's 30 second subprocess timeout. Do not use a fixed sleep. (best practice) [sources: src/devops_cli/k8s/service_probe.py:65, src/devops_cli/k8s/service_probe.py:194, https://tmuxai.dev/exit-code/curl-7/]
    • Chosen: Retry on curl exit 7 until a deadline. The retry ends as soon as the path works, it bounds the wait, and it reuses the exit-code parsing that the module already has.
    • Rejected: Fixed sleep of 20 seconds. It wastes 20 seconds when the path is ready at once, and it fails when programming takes longer.
    • Rejected: curl --retry-connrefused inside one exec. The command could not bound each kubectl call under the 30 second subprocess timeout, and it could not report the attempts.
  • Which image does the probe pod run?: curlimages/curl, pinned by digest, with the tag before the digest as PROBE_IMAGE records busybox. The image is a parameter of the shared pod spec, so the busybox pod of the service checks keeps its image. It gives curl's status output and exit codes, and the pod spec sets the non-root user, so the user of the image does not matter. --image allows another image only with a digest. Check once against the pinned digest that sleep and curl run there, as the module records for the busybox applet. (best practice) [sources: https://hub.docker.com/r/curlimages/curl, src/devops_cli/k8s/service_probe.py:62, src/devops_cli/k8s/service_probe.py:144]
    • Chosen: curlimages/curl pinned by digest. It is the official curl image, maintained by the curl docker team, and it gives the HTTP status and the curl exit code that the issue asks for.
    • Rejected: busybox with nc, the current PROBE_IMAGE. It has no curl and no HTTP status, so a blocked path and a refused connection give the same result.
    • Rejected: registry.k8s.io/e2e-test-images/agnhost. It reports reachability, but it gives no curl exit code.
    • Rejected: The devops-cli image. It is large, and its tools are not the subject of the probe.
  • What does --dry-run do?: Render the request plan and stop: the kubectl run with a placeholder for the restricted pod spec, the kubectl exec with the curl command line and the URL, and the kubectl delete. It creates no pod and sends no request. This is the dry-run shape that every k8s command uses, and plan_probe_from_pod already renders the pod part of it. (best practice) [sources: src/devops_cli/k8s/service_probe.py:306, src/devops_cli/commands/k8s/searxng_check.py:101, openspec/specs/k8s-crawl4ai-check/spec.md:9]
    • Chosen: Render the request plan and stop. The operator sees the exact pod and request, nothing touches the cluster, and the command matches the dry-run of the other k8s checks.
    • Rejected: Create the pod and skip the request. It leaves a pod behind for a check that was meant to be safe.
  • How does a header value reach curl without being printed or passed on a command line?: Write the headers as curl config lines (header = "...") to the standard input of kubectl exec -i, with curl -K -. run_subprocess takes input=, and the process fake records stdin, so the test can assert that no argv holds the value. The project already forbids a token on a command line. (best practice) [sources: openspec/specs/k8s-crawl4ai-check/spec.md:41, src/devops_cli/core/process.py:903, tests/support/fakes/process.py:39]
    • Chosen: curl config on standard input. The value stays out of every command line and out of the output, and the process seam records it for the test.
    • Rejected: The value in the exec argv. It puts the token in the process list of the pod and in the kubectl call, which the crawl4ai-check spec forbids.
    • Rejected: An environment variable on the pod. The value lands in the pod object, where anyone with get pods in the namespace reads it.
  • What does the command print, and what exit status does it use?: Print status=<code> when a response arrives, and curl_exit=<code> when the connection fails, with no response body. Exit 0 when the probe measured a result, including a blocked path. Exit non-zero when kubectl fails, the pod does not start, or the overall deadline passes. (best practice) [sources: src/devops_cli/k8s/service_probe.py:80, src/devops_cli/commands/k8s/searxng_check.py:135]
    • Chosen: Print the result and exit 0 on a measurement. A blocked path is a valid result for a policy check, so a script reads the printed value.
    • Rejected: Exit non-zero on a blocked path. The caller cannot tell a blocked path from a broken command.
  • How does the test avoid a cluster?: The test installs the process fake through the process seam and asserts on the recorded argv, standard input and answers. No test starts a pod, calls curl or reaches a host, as the test decision requires of every test of src/. [sources: tests/support/fakes/process.py:28, tests/k8s/test_service_probe.py:19, docs/adr/0007-tests-double-only-process-edges.md:3]
  • Where does the command live?: A probe subcommand of the existing k8s group: the module src/devops_cli/commands/k8s/probe.py, registered with app.command("probe") in src/devops_cli/commands/k8s/__init__.py, next to searxng-check. Its test is tests/k8s/test_k8s_probe.py, next to the other k8s tests. [sources: src/devops_cli/commands/k8s/init.py:60, src/devops_cli/commands/k8s/searxng_check.py:101, tests/k8s/test_searxng_check.py:1]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-21: in-use.
The repository already uses this tool.
Tool: kubernetes/kubectl (https://github.com/kubernetes/kubectl), Apache-2.0, last activity 2026-11-19, maintained.
Reason: Web searches found no dedicated network-policy probe command, only kubectl and a debugging image. kubectl already creates the labeled pod, execs the request and deletes it, but lacks the retry, restricted spec, printed result and cleanup on timeout.

Covers:

  • Creates one labeled pod in a namespace with an inline JSON override
  • Runs a command inside the pod with exec
  • Deletes the pod, with ignore-not-found and a wait option
  • Accepts a pinned image, a restart policy and timeouts

Lacks:

  • No retry until kube-router programs the policy
  • No restricted security context by default
  • No printed HTTP status or curl exit code
  • No guaranteed pod deletion when the overall deadline passes

Activity

  1. added
    source/agent
    type/feature
    scope/k8s
    status/new
    value/medium
    effort/medium
    on Nov 10, 2026
  2. dan-petty commented on Nov 10, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/k8s. The (k8s) scope of the title gives the scope.
    • Priority: P2-Medium. It is a developer diagnostic tool, not a production fix, but it reduces manual error in verifying security policies.
    • Value: Medium. It replaces a fragile manual procedure with a repeatable command for checking network policy paths.
    • Effort: Medium. It needs a new subcommand, pod lifecycle handling, a security context, timeout, dry-run flag, and a test with a fake kubectl.
    • Related: fix(k8s): MCP server policies miss the Service runner Jobs #4355, which asks for a different change. Both concern MCP server network policies, but #4355 fixes the policy labels while the candidate builds a diagnostic command to verify those policies.
  3. added
    priority/p2-medium
    on Nov 10, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 10, 2026
  5. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at efe3884 (see proposed design in issue body).

  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: Searches found no maintained tool that performs the whole probe: the only results were the kubectl primitives the project already uses and the netshoot troubleshooting image, which just supplies curl and other network tools. kubectl covers the pod lifecycle and the in-pod request (run, exec, delete), but not the policy wait, the restricted context, the printed status/exit code or the guaranteed cleanup, so the command still has to be built on top of it.

    The item already names this tool.

    Tool: kubernetes/kubernetes (https://github.com/kubernetes/kubernetes)

    • License: Apache-2.0
    • Last activity: 2026-11-11
    • Maintained: yes

    Covers:

    • Creates one labeled throwaway pod in a namespace with kubectl run
    • Sends the request from inside the pod with kubectl exec (curl)
    • Removes the pod with kubectl delete, including --ignore-not-found

    Lacks:

    • No wait for kube-router to program the policy (retry while curl exits 7)
    • No restricted Pod Security context by default
    • No parsing or printing of the HTTP status or the curl exit code
    • No guaranteed deletion after an error or timeout, and no overall --timeout deadline
    • No --dry-run plan and no image-pinned-by-digest check
    • No way to keep a header value off the argv (curl config on standard input)

    Tools considered:

    Searches run:

    • netshoot kubectl run network troubleshooting container, results: 5
    • kubernetes network policy reachability test CLI open source, results: 5
    • tool to test kubernetes network policy connectivity from a pod, results: 5
    • github nicolaka netshoot network troubleshooting container, results: 5
    • github kubernetes-sigs network policy connectivity probe kubectl plugin, results: 5
    • kubectl network policy test, results: 5
    • netshoot, results: 5
    • network policy tester kubernetes, results: 5
    • kubectl netcheck plugin, results: 5
    • cyclonus network policy, results: 5

    Sources:

    Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.

  7. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: in-use, tool https://github.com/kubernetes/kubernetes. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • kubernetes network policy connectivity test tool, results: 5
    • kubectl plugin test network policy from labeled pod curl, results: 5
    • cyclonus network policy testing kubernetes github, results: 5
    • netshoot container network policy debugging, results: 5
    • kubectl run temporary pod curl check network policy github project, results: 5
    • kubernetes-sigs kubectl network policy test connectivity, results: 5
    • kubectl run documentation kubernetes.io, results: 5
    • curlimages/curl docker image, results: 5
    • nicolaka netshoot github repository, results: 5
    • kubernetes network policy test pod tool alternative, results: 5

    Sources:

  8. added
    owner/service
    on Nov 22, 2026
  9. 19 remaining items

  10. added
    status/planned
    owner/service
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/planned
    status/in-progress
    on Nov 23, 2026
  11. devops-cli-service commented on Nov 23, 2026

    @devops-cli-service
    Contributor

    The draft pull request #6894 holds the final title and body. In mode on of roadmap.fix_checks.mode, the watch row marks it ready when its checks pass, and a fix-checks Job repairs a failed check whose name gives the class test, lint or types. In each other case the watch row stops the item: another failed check, a cancelled check, a conflict, a fix-checks Job that ended with no repair, or another mode.

    Spend: 198 model requests, 22217138 input tokens, 88498 output tokens.

  12. removed
    owner/service
    on Nov 23, 2026
  13. removed
    status/in-review
    on Nov 23, 2026
  14. devops-cli-service commented on Nov 23, 2026

    @devops-cli-service
    Contributor
  15. devops-cli-service commented on Nov 23, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-23 18:26 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/k8ssource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions