跳到正文
Skillpedia
安全48k · #5017

kubernetes-hardening

它能做什么

这个工具可以帮你让 Kubernetes 环境更安全。它会设置一些规则,保护你的应用和集群本身,防止未经授权的访问和有风险的操作。

适用场景

  • ✓在搭建一个新的 Kubernetes 集群时。
  • ✓当你需要保护运行在 Kubernetes 上的应用时。
  • ✓为了满足安全和合规要求。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/kubernetes-hardening/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/kubernetes-hardening/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“为 production 命名空间配置 Kubernetes,让它使用受限的安全策略。”

每周 5 个新技能,1 分钟读完。

工作原理

它会应用一些叫做“Pod Security Standards”和“Network Policies”的配置。这些设置定义了应用能做什么、不能做什么,以及它们之间和它们与外部之间如何通信。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Kubernetes Hardening

Secure Kubernetes clusters and workloads.

When to Use This Skill

Use this skill when:

  • Hardening Kubernetes clusters
  • Implementing Pod Security Standards
  • Configuring network policies
  • Meeting security compliance

Scope and validation

Confirm the exact cluster/namespace/version and authorized writes before applying policies. Examples are fragments: validate the reviewed image, namespace, service accounts, labels and required runtime storage. Pin the policy version to the target Kubernetes release where supported. Restricted admission controls new/updated pods; it does not retroactively fix running workloads or establish compliance.

Pod Security Standards

# Namespace with restricted policy
apiVersion: v1
kind: Namespace
metadata:
  name: production
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/warn: restricted

Security Context

apiVersion: v1
kind: Pod
metadata:
  name: secure-pod
  labels:
    app: web
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    runAsGroup: 1000
    fsGroup: 1000
    seccompProfile:
      type: RuntimeDefault
  containers:
  - name: app
    image: registry.example.invalid/myapp:REVIEWED_IMMUTABLE_TAG
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop: ["ALL"]

Network Policies

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-web
spec:
  podSelector:
    matchLabels:
      app: web
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: frontend
    ports:
    - port: 8080

RBAC

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: app-reader
rules:
- apiGroups: [""]
  resources: ["pods", "services"]
  verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: app-reader-binding
subjects:
- kind: ServiceAccount
  name: myapp
roleRef:
  kind: Role
  name: app-reader
  apiGroup: rbac.authorization.k8s.io

Best Practices

  • Enable Pod Security Standards
  • Implement network policies
  • Use RBAC with least privilege
  • Enable audit logging
  • Secure etcd with encryption
  • Use service mesh for mTLS
  • Regular security scanning

Related Skills

  • kubernetes-ops (kubernetes-ops) - K8s operations
  • container-hardening (container-hardening) - Container security

Limitations

  • Apply guidance only within authorized scope; test destructive steps in non-production first.
  • Docs-only import: upstream scripts and templates not bundled.

Example

# Read-only first: inventory before any active step.
which <tool> && <tool> --help | head -n 20

Adapted from BagelHole/DevOps-Security-Agent-Skills (MIT); frontmatter, When to Use/Limitations, and safety boundaries added for upstream compliance. Docs-only import: helper scripts and templates not bundled.

NetworkPolicy enforcement requires a supporting CNI. The default-deny example also blocks DNS and dependencies until narrowly scoped rules are added; same-namespace pod selectors do not authorize arbitrary namespaces. Test allowed and denied flows from the real source identities and preserve recovery access. readOnlyRootFilesystem may require bounded writable temporary volumes; do not disable it blindly after a startup error. Kubernetes NetworkPolicy behavior.

常见问题

什么是“Pod Security Standards”?

这是一组规则,用来定义 Kubernetes 集群中运行的容器的安全级别,比如禁止容器以管理员身份运行。

什么是“Network Policies”?

它们相当于集群内部的防火墙。可以控制容器之间以及容器与集群外部之间允许哪些网络流量,确保只有必要的通信才能发生。

这个工具会自动修复安全问题吗?

它会应用新的安全规则,但不会自动修复已经在运行的应用中的问题。在生产环境中应用更改之前,先做测试很重要。

详情

作者的原始描述

Implement Kubernetes security contexts, Pod Security Standards, and network policies.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5017
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能