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
production pattern with the regular expression that matches your production contexts.Add the configuration
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
--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:
`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:
`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 runs | Answer |
|---|---|
kubectl --context dev get pods | allow |
kubectl --context dev delete pod web-1 | deny |
kubectl apply -f deploy.yaml, any context | deny |
kubectl --context prod-eu get pods | deny |
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
productionpattern matches it, or the line names no--context. Fix the pattern, or pass--context. - A change goes through. Run
npx harness-kit config checkandnpx 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.
Related
Stop force-pushes to shared branches
Refuse every push from the agent that writes main or a release branch, forced or not, and leave moving shared branches to people.
Protect secrets and the harness itself
Refuse every write the agent makes to secrets/ and .env files, and keep it from editing the hooks that guard it.