Skip to Content
harness-kit

Keep kubectl read-only

Let the agent read the cluster but refuse every change, and keep it out of production contexts entirely.

You'll: let the agent run kubectl get, describe and logs, refuse anything that changes the cluster, and refuse production outright.

Before you start

You need the kit installed and your hooks synced; see Quick start. Replace the production pattern with the regular expression that matches your production contexts.

Add the configuration

harness.config.ts
import { defineConfig } from '@microeinhundert/harness-kit';

/**
 * kubectl kept read-only: reading verbs pass, anything that changes the cluster is refused, and every context named
 * `prod-…` is refused outright, reads included.
 */
export default defineConfig({
  policies: [
    {
      id: 'kubectl',
      options: {
        preset: 'kubectl',
        production: ['^prod-'],
      },
      use: 'command-policy',
    },
  ],
});

The kubectl preset is a ready-made command table; production names your production contexts by regular expression. Then run npx harness-kit settings sync.

A command without a context counts as production

When the line names no --context and the kit cannot tell the current one, it assumes production and refuses. Tell the agent to always pass --context.

Try it

Ask the agent to "deploy the new manifest". It runs kubectl apply -f deploy.yaml:

What the agent reads
`kubectl apply -f deploy.yaml` is refused: the kubectl command table never allows `apply`.
Fix: Do not run it; if it is needed, ask the developer to run it by hand.

Reading production is refused too:

What the agent reads
`kubectl --context prod-eu get pods` is refused: context `prod-eu` is a production context, where the kubectl command table allows only local commands.
Fix: Do not run it; if it is needed, ask the developer to run it by hand.

What it catches

The agent runsAnswer
kubectl --context dev get podsallow
kubectl --context dev delete pod web-1deny
kubectl apply -f deploy.yaml, any contextdeny
kubectl --context prod-eu get podsdeny
sh -c "kubectl delete pod web-1"deny

If it does not work

  • A read is refused in a context that is not production. Your production pattern matches it, or the line names no --context. Fix the pattern, or pass --context.
  • A change goes through. Run npx harness-kit config check and npx harness-kit settings sync. See also A call is refused that should pass for the reverse case.
  • A person needs one change. Override the Policy for one session, or run the command yourself.

  • Commands: command tables in full.
  • Overrides: let a person allow kubectl rollout restart for a session.

On this page