andresleecom/kube-guard
andresleecom/kube-guard ยท 0 stars ยท 1 plugin
Marketplace
Install
/plugin marketplace add andresleecom/kube-guardRun inside Claude Code, then install plugins from it. Check the repo's README before you run it.
Plugins 1
After adding the marketplace, install one with /plugin install <name>@kube-guard.
- 1kube-guardContext safety + guardrails for AI agents on Kubernetes: per-context policies, safe switching, temporary leases, and allow/ask/deny on every kubectl/helm command.
/plugin install kube-guard@kube-guard
Files
๐ก๏ธ kube-guard
Give your Claude Code agent kubectl โ with a seatbelt.
A PreToolUse hook that classifies every kubectl/helm command by blast radius and allows, asks, or denies it before it runs. Reads flow through; production deletes don't.
The problem
An AI agent with kubectl access is one hallucinated command away from kubectl delete namespace prod, a drain, an apply to the wrong context, or a get secret -o yaml that leaks credentials into the transcript. Permission prompts help โ until you run in acceptEdits or --dangerously-skip-permissions and rubber-stamp everything.
"Your AI agent should not have direct kubectl access." โ and yet you want it to help.
The solution
kube-guard is a pure Claude Code plugin (hook + skill + command, zero dependencies) that sits in front of the agent's shell. Every Bash command is parsed; any kubectl/helm invocation is classified and gated:
| Class | Examples | Default verdict (strict) |
|---|---|---|
| READ | get, describe, logs, top, rollout status, helm list |
โ allow |
| WRITE | apply, scale, patch, edit, rollout restart, helm upgrade |
โ ๏ธ ask (confirm) |
| DESTRUCTIVE | delete, drain, taint, replace --force, helm uninstall |
๐ deny |
| HIGH-RISK | exec, run, cp, port-forward, config view, get secret -o yaml |
๐ deny |
Plus cross-cutting guards: protected contexts/namespaces (anything matching prod, production, *-prod, kube-system, โฆ) escalate every mutation to deny, and the guard fails closed โ if it can't verify a command (eval, pipe-to-shell, subshells, intra-word quoting like k'ubectl', unknown verbs), it asks or denies rather than guessing.
A few things the classifier is deliberately careful about:
--dry-runis a safe preview.apply/delete/scale โฆ --dry-run=server|clientmutate nothing, so they're recognised as no-ops and allowed (but--dry-run=nonereally applies, so it isn't).- Secret dumps are hard to sneak past.
get secret -o yamlis blocked and so are-oyaml(no space), comma lists (secrets,configmaps), fully-qualified names (secret.v1.core/x),--template/--go-template, andhelm get values/manifest/all. - RBAC privilege escalation is gated.
kubectl auth reconcile,create clusterrolebinding โฆ --clusterrole=cluster-admin, andapply --pruneare escalated, not waved through as ordinary writes. - When it blocks, it explains. A denied command comes back with the reason and a concrete next step (
--dry-run=server,/klease,-o name, โฆ) so the agent self-corrects instead of retrying blind.
agent โ kubectl delete ns prod โ ๐ DESTRUCTIVE on protected context โ denied (logged)
agent โ kubectl apply -f d.yaml โ โ ๏ธ WRITE โ asks you to confirm
agent โ kubectl get pods โ โ
READ โ allowed
Install
/plugin marketplace add andresleecom/kube-guard
/plugin install kube-guard@kube-guard
Requires kubectl on your PATH (which you already have). Zero npm dependencies.
Why it's different
It gates execution, even when you've turned permissions off:
- A
deny/askfrom kube-guard applies regardless of permission mode โ even with--dangerously-skip-permissions, a protected-context delete still stops. - It catches kubectl anywhere in a command (
cd x && kubectl delete โฆ, env-prefixes, pipes), not just as the first word. - It resolves your current context so guards work even when the command omits
--context. - Every decision is written to a private, gitignored audit log (
.claude/kube-guard/audit.jsonl), with secrets redacted.
| kube-guard | k8sgpt | kagent | KubeShark (skill) | |
|---|---|---|---|---|
| Gates command execution (allow/ask/deny) | โ | โ (read-only diag) | โ (RBAC only) | โ (advisory) |
| Protected-context / blast-radius guard | โ | โ | โ | โ |
| Per-context and per-namespace policies | โ | โ | โ | โ |
| Per-resource allow/denylist (never delete nodes/CRDs/โฆ) | โ | โ | โ | โ |
| Temporary context leasing (prod for 1 cmd / N min) | โ | โ | โ | โ |
| Blocks secret dumps & exec | โ | n/a | โ | โ |
| Works in IDE, no in-cluster agent | โ | โ | โ | โ |
| Audit log | โ | โ | partial | โ |
| Zero dependencies | โ | โ | โ | โ |
Configuration
Config is layered (later wins): plugin defaults โ ~/.claude/kube-guard.config.json (global, every project) โ <project>/.claude/kube-guard.config.json โ KUBE_GUARD_MODE env. Set a posture once, globally, and it holds everywhere.
Levels (postures)
Every command is judged at the level of its target context (the --context flag, or your live current context):
| Level | Reads | Writes | Destructive | High-risk |
|---|---|---|---|---|
readonly |
allow | deny | deny | deny |
strict (default) |
allow | ask | deny | deny |
standard |
allow | ask | ask | deny |
audit |
allow | allow | allow | allow (logged) |
Multiple clusters โ per-context policies
Different clusters, different postures. Map context globs to levels:
// ~/.claude/kube-guard.config.json
{
"defaultMode": "strict",
"contextPolicies": [
{ "match": ["*prod*", "*live*", "my-prod-cluster"], "level": "readonly" },
{ "match": ["*stag*"], "level": "strict" },
{ "match": ["kind-*", "minikube", "*dev*"], "level": "audit" }
],
// optional: give specific namespaces their own posture (composed strictest
// with the context level, so a guarded namespace holds even on a lax cluster)
"namespacePolicies": [
{ "match": ["prod", "*-prod"], "level": "readonly" }
],
// optional: tighten-only rules per resource kind (never loosen the verdict)
"resourceRules": [
{ "kinds": ["node", "namespace", "pvc", "*.cattle.io"],
"verbs": ["delete", "drain", "taint"], "verdict": "deny" }
],
"protectedNamespaces": ["kube-system", "prod", "*prod*"],
"allowExec": false, // set true to downgrade exec/cp/run from deny โ ask
"allowSecretRead": false // set true to downgrade secret dumps โ ask
}
Unlisted contexts fall back to defaultMode. Config is accumulated across layers for the protection arrays (contextPolicies/namespacePolicies/protected*), so a global prod guard can't be silently dropped by a project config. Legacy protectedContexts (a flat list) still works and maps to readonly. Run /kube-guard doctor to print the effective config and catch typo'd keys/levels (which would otherwise weaken the posture silently).
namespacePoliciesโ same shape ascontextPolicies, but matched against the target namespace; the effective posture is the stricter of the context level and the namespace level.resourceRulesโ{ kinds, verbs, verdict }rules that can only tighten a verdict (e.g. "neverdeletenodes/namespaces/PVCs/CRDs"), never loosen it. With no rules configured, behaviour is unchanged.
Switch & lease (multi-cluster, safely)
/kctxโ list contexts with their level and switch safely; kube-guard confirms when you enter a guarded cluster and lets dev/local through freely. Solves the "I thought I was on staging but I was on prod" footgun./kleaseโ the context leash: temporarily relax areadonly(prod) cluster for one command or N minutes, then it auto-reverts. Lease only the exception you need:# prod, but writable (with confirmation) for the next single command: node "$CLAUDE_PLUGIN_ROOT/scripts/lease.mjs" my-prod-cluster --once --level strict
Inspect and operate with /kube-guard:
/kube-guardโ show the active policy and recent decisions./kube-guard doctorโ validate the config + install (Node/kubectl, effective config, current context's level, active leases, and warnings for typo'd keys/levels)./kube-guard summarizeโ roll up the audit log (counts by verdict/class, denies by context, top denied commands; supports--since 24h,--deny-only,--context <glob>).
Or dry-run a single command through the classifier without executing it:
node "$CLAUDE_PLUGIN_ROOT/scripts/explain.mjs" "kubectl delete ns prod".
FAQ
Does it slow down every Bash command? Negligibly โ the hook fast-exits unless the command contains kubectl/helm.
What if kube-guard itself errors? It fails closed: an internal error returns ask, never a silent allow.
Can the agent bypass it? Obfuscation (eval, | sh, $(...), backtick command-substitution, base64, unknown verbs) is treated as unverifiable and denied/asked โ and relevance is decided after tokenization, so intra-word quoting (k'ubectl' delete) can't hide the tool name either.
Can I let the agent preview risky changes? Yes โ --dry-run=server/client is treated as a read-only preview and allowed, even on a readonly context. That's the safe way to let it show you a diff before you lease the real change.
Does it send anything anywhere? No. Everything is local; the only outbound calls are the kubectl reads you'd run anyway.
Windows? Yes โ pure Node.js hooks, no bash/jq.
Security
See SECURITY.md for the threat model. kube-guard is a guardrail, not a sandbox: it reduces blast radius but does not replace Kubernetes RBAC. Combine it with least-privilege credentials.
Roadmap
- GitOps remediation: propose fixes as reviewable PRs instead of mutating the cluster.
- Cost / right-sizing recommendations with dollar impact.
- Incident loop: triage โ fix โ PR โ postmortem.
-
require dry-run + diffbefore apply; guardWrite/Editof dangerous manifests. - Blast-radius preview before destructive ops (count affected resources).
- Per-context policies & multi-cluster awareness (v0.2.0).
- Context leasing โ temporary, auto-reverting prod access (v0.2.0).
- Per-namespace policies & per-resource-kind rules.
-
--dry-runawareness โ previews are recognised and allowed (the enabling half of "require dry-run"). - Config validation +
/kube-guard doctor; queryable audit log via/kube-guard summarize.
Contributing
Issues and PRs welcome. The plugin is deliberately small and dependency-free โ the classifier (scripts/classify.mjs) is pure and covered by node --test, which runs in CI across {Windows, macOS, Linux} ร Node {18, 20, 22}. Add a failing case to test/classify.test.mjs first. See CONTRIBUTING.md for the house rules.
License
MIT ยฉ Andres Lee
{
"name": "kube-guard",
"description": "Give your Claude Code agent kubectl with a seatbelt: classify and gate every kubectl/helm command before it runs.",
"owner": {
"name": "Andres Lee",
"email": "hola@andreslee.com"
},
"plugins": [
{
"name": "kube-guard",
"version": "0.2.0",
"source": "./",
"description": "Context safety + guardrails for AI agents on Kubernetes: per-context policies, safe switching, temporary leases, and allow/ask/deny on every kubectl/helm command.",
"category": "security",
"homepage": "https://github.com/andresleecom/kube-guard"
}
]
}Facts
- Kind
- Marketplace
- Repo
- andresleecom/kube-guard
- Group
- Uncategorized
- Stars
- 0
- Marketplace name
- kube-guard
- Owner
- Andres Lee
- License
- MIT
- Language
- JavaScript
- Created
- 2026-06-05
- Last push
- 2026-07-26
- Topics
- ai-agents, claude-code, claude-plugin, devops, guardrails, helm, kubectl, kubernetes, security, sre
- Plugins
- 1
- 1obra/superpowersobra/superpowersAn agentic skills framework & software development methodology that works.297.9k
- 2affaan-m/everything-claude-codeaffaan-m/ECCThe agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.277.5k
- 3anthropics/skillsanthropics/skillsPublic repository for Agent Skills180.6k
- 4f/prompts.chatf/prompts.chatf.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source โ self-host for your organization with complete privacy.172.7k
- 5anthropics/claude-codeanthropics/claude-codeClaude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.150.3k
- 6nextlevelbuilder/ui-ux-pro-max-skillnextlevelbuilder/ui-ux-pro-max-skillAn AI skill that provides design intelligence for building professional UI/UX across multiple platforms.135k
