Skip to content

feat(roadmap): allow scoped review and RAG calls from the implement shell #3563

Closed as not planned

Description

@devops-cli-service

Split from #3041.

The implement agent cannot call devops review on its diff or devops ai rag-query. The shell has a scratch HOME and no key. The job process holds the credentials and clears its dumpable flag (#2667). It runs no git or gh call in the shell. A shell key would undo that design. This part is deferred from #3041. Acceptance criteria: a scoped credential broker SHALL give the shell access only to the review and RAG endpoints; the shell MUST NOT read the job's raw credentials; a test SHALL verify that devops review on the diff and devops ai rag-query run in the runner shell; a test SHALL verify that a call to another gateway endpoint is refused.

Proposed design

Problem statement

The implement step shell cannot call devops review on its diff or devops ai rag-query. The shell has a scratch HOME and no key. The job process holds the gateway credentials and is not dumpable. This change adds a scoped broker that lets the shell reach only the review and RAG gateway endpoints.

Acceptance criteria

Requirement: scoped-broker

The implement runner SHALL start a credential broker that forwards only requests to the review and RAG gateway endpoints.

Scenario: review-and-rag-forwarded

  • WHEN The step shell sends a review request and a RAG request through the broker.
  • THEN Both requests reach the recorded gateway and the broker returns the gateway response.

Requirement: no-raw-credentials

The step shell MUST NOT read the job's raw gateway credentials.

Scenario: shell-environment-has-no-gateway-key

  • WHEN A step runs env and reads every file under its HOME.
  • THEN The output contains no gateway credential and no job process variable.

Requirement: capability-token-scope

The broker SHALL accept a capability token only for the review and RAG endpoints and only while its step runs.

Scenario: token-refused-in-later-step

  • WHEN A later step sends the previous step's capability token to the broker of the later step.
  • THEN The broker returns 401 and forwards no request.

Requirement: other-endpoint-refused

The broker SHALL refuse a call to any gateway endpoint other than review and RAG.

Scenario: disallowed-endpoint-refused

  • WHEN The step shell sends a request to another gateway endpoint through the broker.
  • THEN The broker returns 404 and forwards no request to the gateway.

Requirement: runner-shell-test

An automated test SHALL run devops review on the diff and devops ai rag-query in a runner shell.

Scenario: runner-shell-review-and-rag

  • WHEN The test starts a runner shell with the broker and a recorded gateway.
  • THEN Both commands exit with status 0 and the recorded gateway receives the review and RAG requests.

Requirement: broker-cleanup

The job process SHALL stop the broker and delete the token file and the Caddyfile when the step ends.

Scenario: broker-stopped-after-step

  • WHEN A step ends.
  • THEN The broker process is not running and the token file and Caddyfile do not exist.

Requirement: broker-credential-not-on-disk

The broker process MUST hold the gateway credential in memory and MUST NOT write it to the step's filesystem.

Scenario: broker-filesystem

  • WHEN A step reads every file under the broker's working directory.
  • THEN No file contains the gateway credential.

Requirement: broker-not-dumpable

The broker process MUST clear its dumpable flag before it receives the gateway credential.

Scenario: shell-cannot-read-broker-environment

  • WHEN A step tries to read the environment of the broker process from /proc.
  • THEN The read fails and the output contains no gateway credential.

Requirement: broker-loopback-only

The broker MUST listen only on the loopback address 127.0.0.1.

Scenario: broker-binds-loopback

  • WHEN The broker starts for a step.
  • THEN The broker listens on 127.0.0.1 and not on the pod network address.

Existing Tool Considered

No alternatives check has run. Caddy (Apache-2.0, maintained) covers the reverse proxy, the path allowlist, the credential injection and the localhost listener. It lacks a per-step capability-token minting API, so the job process must write the Caddyfile and the bcrypt hash for each step. That generator costs about 5k tokens to build, 1k tokens per month to keep and fix, and half a day.

Key questions

  • Which process holds the gateway credential and runs the broker?: The job process starts Caddy as a child process for each step. Caddy receives the gateway credential in its environment, and the step shell receives only a capability token. (best practice) [sources: CONTEXT.md]
    • Chosen: Caddy child process of the job process. The job process already holds the credentials and is not dumpable; Caddy holds them for the step.
    • Rejected: Envoy sidecar. It adds a second container and network namespace for a job that already has a job process.
    • Rejected: Scoped gateway key in the shell. The issue body states that a shell key would undo the runner design.
  • What transport does the shell use to reach the broker?: A localhost TCP port on 127.0.0.1 in the runner pod. The job process sets the gateway URL to http://127.0.0.1:<port> and writes the capability token to a file with mode 0600. (best practice) [sources: CONTEXT.md]
    • Chosen: Localhost TCP port. The runner pod is the sandbox, so a loopback port stays inside the pod.
    • Rejected: Unix domain socket. It adds a transport that the gateway client may not support, while the pod boundary already isolates the port.
    • Rejected: Kubernetes Service. It exposes the broker beyond the pod.
  • How does the broker restrict requests to the review and RAG endpoints?: Caddy matches only the exact method and path of the review and RAG endpoints. It returns 404 for every other path and forwards no request. (proposed)
    • Chosen: Path allowlist in Caddy. Caddy's path matcher is declarative, and a test can check a refused path.
    • Rejected: Model allowlist in the gateway. The gateway scopes by model, not by endpoint, and the acceptance criteria name endpoints.
    • Rejected: Network policy. A network policy cannot tell one path from another on the same host.
  • How does the shell authenticate to the broker?: The job process generates a random 256-bit capability token for the step, writes its bcrypt hash into the Caddyfile, and writes the token to a file readable only by the step user. The shell sends the token in an Authorization: Basic header. (proposed)
    • Chosen: Per-step capability token with basic auth. It needs no CA, and it expires with the step.
    • Rejected: mTLS. It needs a CA and certificate rotation for each step.
    • Rejected: No token. Any process in the pod could call the allowed endpoints.
  • When does the broker stop, and what does it delete?: The job process stops Caddy at the end of the step and deletes the token file and the Caddyfile. (proposed)
    • Chosen: Stop at step end and delete files. The token is valid only for the step and leaves no reusable secret.
    • Rejected: Keep the broker for the job. A later step could reuse the token.
    • Rejected: Leave the files for debugging. It leaves a credential on disk.
  • Which open, maintained tool covers the broker?: Caddy covers the reverse proxy, the path allowlist, the credential injection and the localhost listener. It lacks a per-step capability-token minting API, so the job process writes the Caddyfile and the bcrypt hash for each step. (proposed)
    • Chosen: Caddy. It is Apache-2.0, maintained, and supports path matchers, header injection and a localhost listener in one binary.
    • Rejected: Envoy Proxy. It covers the same needs but is heavier to configure and run in the runner pod.
    • Rejected: A Python broker built on http.server. It needs code the project keeps, while Caddy already provides the proxy and auth.
  • How does the broker keep the gateway credential from the step shell?: The job process starts Caddy with PR_SET_DUMPABLE set to 0 before exec, and passes the gateway credential in Caddy's environment. The step shell cannot read the broker's /proc environment. (best practice) [sources: CONTEXT.md]
    • Chosen: Clear the broker's dumpable flag. It matches the job process and hides /proc/<pid>/environ from the step user.
    • Rejected: Run Caddy as a different user. The runner pod has one user and no user namespace.
    • Rejected: Pass the credential in the Caddyfile. It writes the gateway credential to disk and fails the no-disk requirement.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 5, 2026
  2. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    ContributorAuthor

    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/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It is a deferred slice of a larger feature and blocks two agent capabilities but does not block the whole roadmap.
    • Value: Medium. It lets the implement agent call review and RAG, removing two of the most common gaps in its toolset.
    • Effort: Medium. It needs a scoped broker, endpoint allow-listing, credential isolation, and two verification tests.
    • Related: feat(roadmap): the implement agent can use the project's development tools #3041, which asks for a different change. Both concern the implement agent using project tools; #3041 is the umbrella for the full catalog and the candidate is one deferred slice covering the credential broker for review and RAG.
  3. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    ContributorAuthor

    Refine cannot set this item to Ready at e9bf5a9 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

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

    @devops-cli-service
    ContributorAuthor

    Refine cannot set this item to Ready at 8714474. A bot opened the item, so a review of the issue and of the proposal must approve it first. The review found the defects below. A person edits the body to answer them. The next refine round looks at the item again only after a body edit.

    • false_premise at key_questions: How does the broker keep the gateway credential from the step shell?: The Linux kernel resets the dumpable flag to 1 on execve. Clearing it before exec does not protect the Caddy process. Caddy is a third-party binary and cannot clear the flag itself. The broker-not-dumpable criterion therefore fails. Evidence: "The job process starts Caddy with PR_SET_DUMPABLE set to 0 before exec, and passes the gateway credential in Caddy's environment."
  5. dan-petty commented on Nov 6, 2026

    @dan-petty
    Owner

    This item cannot be built as written. I checked the premise against the code, the kernel and the cluster manifests.

    1. The Caddy broker cannot be non-dumpable. The broker-not-dumpable criterion needs the flag cleared before Caddy gets the key. execve sets the flag again. I ran it: a parent that called prctl(PR_SET_DUMPABLE, 0) and then started a child got PR_GET_DUMPABLE = 1 in the child. src/devops_cli/core/process_hardening.py says the same ("a child that the process starts later gets the flag set again on its own exec"). Caddy is a third-party binary and cannot clear the flag itself. The step shell has the same user (uid 1000, one user in the pod), so it can read /proc/<caddy pid>/environ and /proc/<caddy pid>/mem. That puts the raw gateway key in reach of the shell. This is the exact case that feat(k8s): the implement job runs as a cluster Job on a runner image with uv, the dev dependencies and the pinned tools, submitted by the Service #2667 closes for the job process. The refine judge found the same defect.

    2. There are no "review" and "RAG" endpoints. devops review makes model calls through the gateway (/chat/completions). devops ai rag-query embeds the query through the gateway (/embeddings) and then searches Qdrant, which is a separate service with its own URL and API key (qdrant.url, qdrant.api_key). A path allowlist for "review and RAG" is really /chat/completions plus /embeddings plus the Qdrant search path. The first two are the same endpoints the agent's own model uses. So the shell would get a general model client with no step budget or tier accounting, and the refusal test for "another gateway endpoint" would prove little.

    3. The runner pod cannot reach Qdrant. k8s/devops/networkpolicy.yaml admits egress only to DNS, the llm namespace on 4000 and 6379, the OTLP collector and public HTTPS. A broker in the pod does not change this. The RAG half needs a NetworkPolicy change for Qdrant first.

    4. devops review needs more than a key. Its default executor runs scanners in a bubblewrap sandbox, and process_hardening.py says the pod's RuntimeDefault seccomp profile refuses unshare. The runner image also holds none of the review scanners (see feat(roadmap): Add kubectl and kube-linter to runner tool catalog #3562 for the tool set of the image). The criterion "a test SHALL run devops review in the runner shell" depends on both.

    5. Caddy is not in the runner image or tools.lock. The design adds a binary to the image plus a generator for the Caddyfile and the bcrypt hash. It also does not fit "one pull request" with the cluster change in point 3.

    Proposed split:

    • A. Broker in the job process (new issue). The job process is already non-dumpable and holds the key, so a loopback proxy that runs inside it never hands the key to another process. Use a maintained ASGI or HTTP proxy library on 127.0.0.1, a per-step token that dies with the step, and an exact method and path allowlist. It must decide first which gateway paths are allowed and how a shell call is counted against the step budget (point 2).
    • B. NetworkPolicy and Qdrant access for the runner pod (new issue, cluster change). Qdrant needs its own scoped read key and a read-only path allowlist (search only; no write or delete path).
    • C. devops review in the runner shell (new issue). It needs the scanner tools in the image (feat(roadmap): Add kubectl and kube-linter to runner tool catalog #3562) and an executor that works without user namespaces.
      Items A and B then give rag-query; A and C give review.
  6. dan-petty commented on Nov 6, 2026

    @dan-petty
    Owner

    Answer from project standards, under the owner's instruction of 2026-11-05.

    Question: can this item also fix the shell refusals of harmless read commands (grep with alternation, cd, python -c, pipes to head)?

    Answer: this item stays in New. The comment of 2026-11-06 17:14Z shows that the broker cannot be built as written, and no one has changed that. The refusal part belongs to other issues:

    A refusal that teaches the allowed form is a change to implement_shell_refusal.py. It goes to #3520 or #3053, not to the broker. I did not write code for #3563.

    Open point: the split items A (job-process loopback broker), B (NetworkPolicy and Qdrant read key) and C (devops review in the runner) of the comment above are not filed yet. A person must confirm the split before an agent files them.

    Rules: AGENTS.md rule 2 (premise check first), docs/ROADMAP_WORKFLOW.md.

  7. dan-petty commented on Nov 6, 2026

    @dan-petty
    Owner

    Closed as not planned. The item cannot be built as written (premise checks of 2026-11-06 in the comments above), and the split of that comment is now filed:

    The shell refusals of harmless read commands (grep, cd, pipes to head) go to #3520 (Ready), not to this item.

  8. removed
    status/new
    on Nov 6, 2026
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/roadmapsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions