
K8s Security
- 11 installs
- 941 repo stars
- Updated April 8, 2026
- rohitg00/kubectl-mcp-server
Helps with security tasks during AI-assisted development.
About
k8s-security is a Claude Code skill for security. It helps solo builders move faster with AI-assisted coding.
- k8s-security
- Security
- AI-coding skill
K8s Security by the numbers
- 11 all-time installs (skills.sh)
- Ranked #1,660 of 2,203 Security skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/rohitg00/kubectl-mcp-server --skill k8s-securityAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 11 |
|---|---|
| repo stars | ★ 941 |
| Last updated | April 8, 2026 |
| Repository | rohitg00/kubectl-mcp-server ↗ |
What it does
Helps with security tasks during AI-assisted development.
Files
Kubernetes Security
Security auditing, RBAC management, and policy enforcement using kubectl-mcp-server tools.
When to Apply
Use this skill when:
- User mentions: "security", "RBAC", "permissions", "policy", "audit", "secrets"
- Operations: security review, permission check, policy enforcement
- Keywords: "who can", "access control", "compliance", "vulnerable"
Priority Rules
| Priority | Rule | Impact | Tools |
|---|---|---|---|
| 1 | Check cluster-admin bindings first | CRITICAL | get_cluster_role_bindings |
| 2 | Audit secrets access permissions | CRITICAL | Review role rules |
| 3 | Verify network isolation | HIGH | get_network_policies |
| 4 | Check policy compliance | HIGH | kyverno_*, gatekeeper_* |
| 5 | Review pod security contexts | MEDIUM | describe_pod |
Quick Reference
| Task | Tool | Example |
|---|---|---|
| List roles | get_roles | get_roles(namespace) |
| Cluster roles | get_cluster_roles | get_cluster_roles() |
| Role bindings | get_role_bindings | get_role_bindings(namespace) |
| Service accounts | get_service_accounts | get_service_accounts(namespace) |
| Kyverno policies | kyverno_clusterpolicies_list_tool | kyverno_clusterpolicies_list_tool() |
RBAC Auditing
List Roles and Bindings
get_roles(namespace)
get_cluster_roles()
get_role_bindings(namespace)
get_cluster_role_bindings()Check Service Account Permissions
get_service_accounts(namespace)Common RBAC Patterns
| Pattern | Risk Level | Check |
|---|---|---|
| cluster-admin binding | Critical | get_cluster_role_bindings() |
| Wildcard verbs (*) | High | Review role rules |
| secrets access | High | Check get/list on secrets |
| pod/exec | High | Allows container access |
See RBAC-PATTERNS.md for detailed patterns and remediation.
Policy Enforcement
Kyverno Policies
kyverno_policies_list_tool(namespace)
kyverno_clusterpolicies_list_tool()
kyverno_policy_get_tool(name, namespace)OPA Gatekeeper
gatekeeper_constraints_list_tool()
gatekeeper_constraint_get_tool(kind, name)
gatekeeper_templates_list_tool()Common Policies to Enforce
| Policy | Purpose |
|---|---|
| Disallow privileged | Prevent root containers |
| Require resource limits | Prevent resource exhaustion |
| Restrict host namespaces | Isolate from node |
| Require labels | Ensure metadata |
| Allowed registries | Control image sources |
Secret Management
List Secrets
get_secrets(namespace)Secret Best Practices
1. Use external secret managers (Vault, AWS SM) 2. Encrypt secrets at rest (EncryptionConfiguration) 3. Limit secret access via RBAC 4. Rotate secrets regularly
Network Policies
List Policies
get_network_policies(namespace)Cilium Network Policies
cilium_policies_list_tool(namespace)
cilium_policy_get_tool(name, namespace)Default Deny Template
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
spec:
podSelector: {}
policyTypes:
- Ingress
- EgressSecurity Scanning Workflow
1. RBAC Audit
get_cluster_role_bindings()
get_roles(namespace)2. Policy Compliance
kyverno_clusterpolicies_list_tool()
gatekeeper_constraints_list_tool()3. Network Isolation
get_network_policies(namespace)
cilium_endpoints_list_tool(namespace)4. Pod Security
get_pods(namespace)
describe_pod(name, namespace)Multi-Cluster Security
Audit across clusters:
get_cluster_role_bindings(context="production")
get_cluster_role_bindings(context="staging")Automated Audit Script
For comprehensive security audit, see scripts/audit-rbac.py.
Related Tools
- RBAC:
get_roles,get_cluster_roles,get_role_bindings - Policy:
kyverno_*,gatekeeper_* - Network:
get_network_policies,cilium_policies_* - Istio:
istio_authorizationpolicies_list_tool,istio_peerauthentications_list_tool
Related Skills
- k8s-policy - Policy management
- k8s-cilium - Cilium network security
RBAC Patterns and Anti-Patterns
Security patterns for Kubernetes RBAC configuration.
Dangerous Patterns (Anti-Patterns)
1. Cluster-Admin for Everyone
# DANGEROUS: Gives full cluster access
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-everyone
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: Group
name: system:authenticatedDetection:
get_cluster_role_bindings()
# Look for cluster-admin bindings to groups/users2. Wildcard Verbs
# DANGEROUS: Allows all actions
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]Detection:
get_cluster_roles()
get_roles(namespace)
# Check for * in verbs3. Secrets Access
# RISKY: Can read all secrets
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list"]Detection:
get_cluster_roles()
# Check for secrets access4. Pod Exec Access
# RISKY: Can execute in containers
rules:
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create"]Secure Patterns
1. Read-Only Viewer
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: namespace-viewer
rules:
- apiGroups: ["", "apps", "batch"]
resources: ["pods", "deployments", "jobs", "services"]
verbs: ["get", "list", "watch"]2. Developer Role
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: developer
rules:
# Read most resources
- apiGroups: ["", "apps"]
resources: ["pods", "deployments", "services", "configmaps"]
verbs: ["get", "list", "watch"]
# Manage deployments
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["create", "update", "patch", "delete"]
# Read logs
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get"]
# Port-forward for debugging
- apiGroups: [""]
resources: ["pods/portforward"]
verbs: ["create"]3. CI/CD Service Account
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: ci-deployer
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "update", "patch"]
- apiGroups: [""]
resources: ["configmaps", "secrets"]
verbs: ["get", "create", "update"]
resourceNames: ["app-config", "app-secrets"] # Specific resources only4. Namespace Admin (Not Cluster)
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: namespace-admin
namespace: my-namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: admin # Built-in admin (not cluster-admin)
subjects:
- kind: User
name: team-leadAudit Checklist
Using MCP Tools
# 1. Check cluster-admin bindings
get_cluster_role_bindings()
# Flag: Any non-system bindings to cluster-admin
# 2. Review cluster roles
get_cluster_roles()
# Flag: Custom roles with wildcard access
# 3. Check namespace roles
for ns in namespaces:
get_roles(namespace=ns)
get_role_bindings(namespace=ns)
# Flag: Overly permissive custom roles
# 4. Review service accounts
get_service_accounts(namespace)
# Flag: Default SA used by workloadsWhat to Look For
| Finding | Risk | Remediation |
|---|---|---|
| cluster-admin to users | Critical | Create scoped roles |
| * verbs | High | Specify exact verbs |
| secrets access | High | Limit to specific secrets |
| pods/exec | Medium | Restrict to specific namespaces |
| Default SA with roles | Medium | Create dedicated SAs |
Best Practices
1. Principle of Least Privilege
- Only grant what's needed
- Use namespace roles, not cluster roles
2. Dedicated Service Accounts
- Don't use default SA
- One SA per workload type
3. Resource Names
- Limit to specific resources when possible
resourceNames: ["specific-secret"]
4. Audit Regularly
- Review bindings monthly
- Check for orphaned roles
5. Namespace Isolation
- Different teams = different namespaces
- RoleBindings per namespace
#!/usr/bin/env python3
"""
RBAC Audit Script
Analyzes RBAC configuration for security issues.
Usage within Claude Code:
This script is called by the k8s-security skill to audit
RBAC configuration and find potential security issues.
"""
import json
import sys
from typing import Any
def audit_rbac(context: str = "") -> dict[str, Any]:
"""
Audit RBAC configuration for security issues.
Args:
context: Optional kubeconfig context
Returns:
Dictionary with audit findings
"""
audit = {
"context": context or "current",
"critical": [],
"high": [],
"medium": [],
"low": [],
"checks_to_run": []
}
# Define checks to run with MCP tools
audit["checks_to_run"] = [
{
"name": "cluster_admin_bindings",
"tool": "get_cluster_role_bindings",
"severity": "critical",
"description": "Check for non-system cluster-admin bindings",
"look_for": "roleRef.name == 'cluster-admin' AND subject not in system:*"
},
{
"name": "wildcard_roles",
"tool": "get_cluster_roles",
"severity": "high",
"description": "Check for roles with wildcard permissions",
"look_for": "rules with '*' in verbs, resources, or apiGroups"
},
{
"name": "secrets_access",
"tool": "get_cluster_roles",
"severity": "high",
"description": "Check for roles with secrets access",
"look_for": "rules with resources=['secrets'] and verbs=['get','list']"
},
{
"name": "pod_exec_access",
"tool": "get_cluster_roles",
"severity": "medium",
"description": "Check for roles with pod/exec access",
"look_for": "rules with resources=['pods/exec'] and verbs=['create']"
},
{
"name": "namespace_admin_bindings",
"tool": "get_role_bindings",
"severity": "medium",
"description": "Check namespace-level admin bindings",
"params": {"all_namespaces": True}
}
]
return audit
def analyze_cluster_role_binding(binding: dict) -> dict[str, Any] | None:
"""
Analyze a ClusterRoleBinding for security issues.
Args:
binding: ClusterRoleBinding data
Returns:
Finding if issue detected, None otherwise
"""
role_ref = binding.get("roleRef", {})
subjects = binding.get("subjects", [])
# Check for cluster-admin bindings
if role_ref.get("name") == "cluster-admin":
non_system_subjects = [
s for s in subjects
if not s.get("name", "").startswith("system:")
]
if non_system_subjects:
return {
"severity": "critical",
"type": "cluster_admin_binding",
"binding": binding.get("metadata", {}).get("name"),
"subjects": non_system_subjects,
"recommendation": "Remove cluster-admin binding, create scoped role instead"
}
return None
def analyze_cluster_role(role: dict) -> list[dict[str, Any]]:
"""
Analyze a ClusterRole for security issues.
Args:
role: ClusterRole data
Returns:
List of findings
"""
findings = []
rules = role.get("rules", [])
role_name = role.get("metadata", {}).get("name", "unknown")
for rule in rules:
verbs = rule.get("verbs", [])
resources = rule.get("resources", [])
api_groups = rule.get("apiGroups", [])
# Check for wildcard verbs
if "*" in verbs:
findings.append({
"severity": "high",
"type": "wildcard_verbs",
"role": role_name,
"rule": rule,
"recommendation": "Specify exact verbs needed"
})
# Check for wildcard resources
if "*" in resources:
findings.append({
"severity": "high",
"type": "wildcard_resources",
"role": role_name,
"rule": rule,
"recommendation": "Specify exact resources needed"
})
# Check for secrets access
if "secrets" in resources and any(v in verbs for v in ["get", "list", "*"]):
findings.append({
"severity": "high",
"type": "secrets_access",
"role": role_name,
"rule": rule,
"recommendation": "Limit secrets access to specific names using resourceNames"
})
# Check for pod/exec access
if "pods/exec" in resources and any(v in verbs for v in ["create", "*"]):
findings.append({
"severity": "medium",
"type": "pod_exec_access",
"role": role_name,
"rule": rule,
"recommendation": "Restrict pod/exec to specific namespaces"
})
return findings
def generate_report(findings: list[dict[str, Any]]) -> str:
"""
Generate human-readable audit report.
Args:
findings: List of findings
Returns:
Formatted report string
"""
report = ["# RBAC Security Audit Report\n"]
by_severity = {
"critical": [],
"high": [],
"medium": [],
"low": []
}
for finding in findings:
severity = finding.get("severity", "low")
by_severity[severity].append(finding)
for severity in ["critical", "high", "medium", "low"]:
items = by_severity[severity]
if items:
report.append(f"\n## {severity.upper()} ({len(items)} findings)\n")
for item in items:
report.append(f"- **{item['type']}**: {item.get('role', item.get('binding', 'N/A'))}")
report.append(f" - Recommendation: {item['recommendation']}")
if not any(by_severity.values()):
report.append("\nNo security issues found.")
return "\n".join(report)
if __name__ == "__main__":
context = sys.argv[1] if len(sys.argv) > 1 else ""
result = audit_rbac(context)
print(json.dumps(result, indent=2))