鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

dsh-kubectl-guard

按 kubeconfig context 管控 kubectl 调用的策略插件:本地集群外硬拒绝不可逆操作,其余写操作请求人工确认。

安全权限
访问 GitHub
文档README

dsh-kubectl-guard

Awesome

A DeepSeek Harness policy plugin that gates kubectl by kubeconfig context.

Irreversible verbs against a non-local cluster are denied outright. Recoverable writes ask first. Reads and local clusters are untouched.

It registers no tools of its own — it inspects the command argument of shell tool calls, so it covers whatever the agent runs.

Install

Requires pnpm, which dsh plugin shells out to.

From npm:

▼
text
复制代码
dsh plugin --profile web add dsh-kubectl-guard

From source, if you want to hack on it:

▼
text
复制代码
git clone https://github.com/gengwg/dsh-kubectl-guard cd dsh-kubectl-guard dsh plugin --profile web add "$PWD"

Either way, activate it in ~/.dsh/profiles/<profile>/cordis.patch.yml:

▼
yaml
复制代码
- insert: - id: kubectl-guard name: dsh-kubectl-guard

Restart dsh to load it. Installing prints declares no dsh.bundle — installed as a plain dependency; that is expected, since this is a plugin activated by the patch entry above rather than a profile bundle.

Examples

Nothing to invoke. Ask the agent to do its normal work; the guard sits in the tool pipeline and inspects the shell command before it runs.

Blocked, with the cluster name replaced by a per-session pseudonym:

▼
text
复制代码
> delete the stuck nginx pod Error: kubectl-guard: 'delete' is irreversible and ctx#4be1f92a is not a local cluster. Denied.

Asked, so you approve it in the UI before it runs:

▼
text
复制代码
> roll out the new deployment kubectl-guard: 'apply' writes to ctx#4be1f92a, which is not a local cluster. [approve] [deny]

Untouched, because reads are not gated:

▼
text
复制代码
> what pods are failing in kube-system? kubectl get pods -n kube-system --field-selector=status.phase!=Running NAME READY STATUS RESTARTS api-7d9f8c 0/1 CrashLoopBackOff 14

Untouched, because the context is local:

▼
text
复制代码
> wipe the test namespace on my kind cluster kubectl --context kind-dev delete ns test namespace "test" deleted

Dry runs are reads, so they pass and give the agent a way to show you a change before asking for it:

▼
text
复制代码
kubectl apply --dry-run=server -f deploy.yaml # allowed kubectl apply -f deploy.yaml # asks

Turn the guard off for one session without editing config:

▼
text
复制代码
dsh web --patch <(echo '- id: kubectl-guard disabled: true')

Behavior

CommandNon-local contextLocal context
get, describe, logs, topallowallow
auth can-iallowallow
auth reconcileaskallow
config use-context, other mutating config subcommandsaskask
apply, patch, scale, execaskallow
delete, drain, evictdenyallow
scale --replicas=0denyallow
apply --prunedenyallow
replace --forcedenyallow
apply --dry-run=serverallowallow

A context is local only if it matches localContexts. Everything else, including a kubeconfig that cannot be read, is treated as production.

The context is resolved the way the shell would resolve it: an explicit --context wins, then --kubeconfig, then a KUBECONFIG= assignment written inline on the same command line, then the ambient environment. That last case matters -- without it, KUBECONFIG=/path/to/prod kubectl delete ... would be judged against whatever your shell happened to point at.

Config

▼
yaml
复制代码
config: localContexts: [minikube, 'kind-*', docker-desktop] binaries: [kubectl, k] guardedTools: [bash, pwsh] showContextNames: false

showContextNames is off by default: blocked-command messages go to the model, and therefore to the LLM provider. With it off the model sees a stable per-session pseudonym like ctx#4be1f92a instead of your cluster's name.

Failing closed

A gate that can be talked around is worse than none. Anything unparseable — sh -c, command substitution, an unterminated quote — is treated as a mutation: denied if the text contains an irreversible verb, asked otherwise. An unknown verb asks rather than allows.

What this is not

This gates a cooperative agent, not an adversary. It reads the command string the agent asked to run, so anything that hides the binary name from that string defeats it by construction -- $KUBECTL delete ... with the name only in the environment, a shell alias resolved at runtime, a base64 round-trip.

Indirection that still contains the literal name is caught: K=kubectl; $K delete pod foo is denied, because any $ expansion alongside a mention of a guarded binary makes the command opaque, and opaque plus an irreversible verb is a denial. But treat the guard as a seatbelt against a confused agent, not a sandbox against a hostile one. If you need the stronger property, take the credential away rather than filtering the command.

Limitations

  • Only kubectl. helm, argocd and flux are not covered; the verb table is data, so adding them is an edit to src/verbs.js.
  • Pass-through wrappers (sudo, time, nice, ...) are seen through, but only until a bare-token wrapper argument: timeout 30 kubectl delete ... is not gated, because 30 ends the wrapper chain.
  • current-context is read with a line-anchored regex, not a YAML parser. Unreadable or unmatched means production, so the failure direction is safe.
  • The pseudonym salt is per-process: ids are stable within a session, not across restarts.
  • Guards are synchronous, so the deny path does no I/O beyond a cached readFileSync.

Test

▼
text
复制代码
npm test

MIT.

安全权限

快捷安装

复制到终端去安装插件

dshplugin--profilewebaddgithub:gengwg/dsh-kubectl-guard

温馨提示

装插件等于在本机跑第三方代码,权限与你相同,能读文件、用凭据、访问网络,工具审批管不到。请只装可信来源,并尽量锁定 commit。

站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
零感AI零感AI
墨得问题墨得问题
dsh 插件推荐
cc-safety-net
执行前守卫,在工具调用运行前拦截破坏性 Git 与文件系统命令,以及对 SSH 密钥、.env 等机密文件的访问。
dsh-workspace-write-plus
增加工作区修改++权限档,文件工具仍锁在工作区,可用通配符放行 Git Bash 等程序以跳过 Windows 进程沙箱。
user-management
用户管理:给 dsh web 加登录门禁,未登录访问弹登录/注册页,首个注册者自动成为管理员;管理员可管理用户/角色,带登录与访问审计。
dsh-security-guard
DSH 插件安全卫士:28 条规则静态扫描、风险评分、白名单/黑名单、本地 Web 仪表盘与 DSH 内风险弹窗。
dsh-route-fence-linter
审计 profile 内所有插件 HTTP 路由的浏览器信任围栏:插件路由在 Web 服务器的最长前缀匹配中优先,因此缺少围栏的路由会被静默暴露;逐条给出文件与行号级别的证据。