Skip to main content
Glama

security_k8s_audit

Audit Kubernetes namespaces to identify security misconfigurations including privileged containers, missing resource limits, and RBAC issues for improved cluster security.

Instructions

Audit Kubernetes namespace for security misconfigurations (privileged containers, missing limits, RBAC issues)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceNoKubernetes namespace to audit (default: 'default')

Implementation Reference

  • The main handler function for the k8s security audit logic.
    export async function k8sSecurityAudit(args: Record<string, unknown>): Promise<string> {
      const api = getCoreV1Api();
      const namespace = (args.namespace as string) || "default";
    
      const findings: AuditFinding[] = [];
    
      // Get pods for security analysis
      const podsRes = await api.listNamespacedPod(namespace);
      const pods = podsRes.body.items;
    
      for (const pod of pods) {
        const podName = pod.metadata?.name || "unknown";
    
        for (const container of pod.spec?.containers || []) {
          const sc = container.securityContext || {};
          const podSc = pod.spec?.securityContext || {};
    
          // Check: Running as root
          if (sc.runAsNonRoot !== true && podSc.runAsNonRoot !== true) {
            findings.push({
              severity: "HIGH",
              category: "Pod Security",
              resource: `${podName}/${container.name}`,
              issue: "Container may run as root",
              recommendation: "Set securityContext.runAsNonRoot: true",
            });
          }
    
          // Check: Privileged container
          if (sc.privileged === true) {
            findings.push({
              severity: "CRITICAL",
              category: "Pod Security",
              resource: `${podName}/${container.name}`,
              issue: "Privileged container",
              recommendation: "Remove privileged: true unless absolutely necessary",
            });
          }
    
          // Check: Missing resource limits
          if (!container.resources?.limits) {
            findings.push({
              severity: "MEDIUM",
              category: "Resource Management",
              resource: `${podName}/${container.name}`,
              issue: "No resource limits set",
              recommendation: "Add CPU and memory limits",
            });
          }
    
          // Check: Read-only root filesystem
          if (sc.readOnlyRootFilesystem !== true) {
            findings.push({
              severity: "LOW",
              category: "Pod Security",
              resource: `${podName}/${container.name}`,
              issue: "Root filesystem is writable",
              recommendation: "Set readOnlyRootFilesystem: true",
            });
          }
        }
    
        // Check: Default service account
        if (!pod.spec?.serviceAccountName || pod.spec.serviceAccountName === "default") {
          findings.push({
            severity: "MEDIUM",
            category: "RBAC",
            resource: podName,
            issue: "Using default service account",
            recommendation: "Create a dedicated service account with minimal permissions",
          });
        }
      }
    
      // Check: Network policies
      try {
        const npRes = await (api as any).listNamespacedNetworkPolicy?.(namespace) ||
          { body: { items: [] } };
        if (npRes.body.items.length === 0) {
          findings.push({
            severity: "HIGH",
            category: "Network Security",
            resource: `namespace/${namespace}`,
            issue: "No NetworkPolicies defined",
            recommendation: "Create NetworkPolicies to restrict pod-to-pod communication",
          });
        }
      } catch {
        // NetworkPolicy API might not be available
      }
    
      // Format report
      if (findings.length === 0) {
        return `Security audit for namespace '${namespace}': No issues found.`;
      }
    
      const bySeverity = {
        CRITICAL: findings.filter((f) => f.severity === "CRITICAL"),
        HIGH: findings.filter((f) => f.severity === "HIGH"),
        MEDIUM: findings.filter((f) => f.severity === "MEDIUM"),
        LOW: findings.filter((f) => f.severity === "LOW"),
      };
    
      const lines = [
        `Security audit for namespace '${namespace}':`,
        `Total findings: ${findings.length} (${bySeverity.CRITICAL.length} critical, ${bySeverity.HIGH.length} high, ${bySeverity.MEDIUM.length} medium, ${bySeverity.LOW.length} low)`,
        "",
      ];
    
      for (const [severity, items] of Object.entries(bySeverity)) {
        if (items.length === 0) continue;
        lines.push(`--- ${severity} ---`);
        for (const f of items) {
          lines.push(`  [${f.category}] ${f.resource}: ${f.issue}`);
          lines.push(`    Fix: ${f.recommendation}`);
        }
        lines.push("");
      }
    
      return lines.join("\n");
    }
  • Tool registration and input schema definition for security_k8s_audit.
      {
        name: "security_k8s_audit",
        description: "Audit Kubernetes namespace for security misconfigurations (privileged containers, missing limits, RBAC issues)",
        inputSchema: {
          type: "object" as const,
          properties: {
            namespace: { type: "string", description: "Kubernetes namespace to audit (default: 'default')" },
          },
        },
      },
    ];
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the action 'audit' and types of misconfigurations but does not disclose critical traits such as whether it requires specific RBAC permissions, if it performs read-only operations (implied but not stated), potential rate limits, output format, or error handling. This leaves significant gaps for a security auditing tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Audit Kubernetes namespace for security misconfigurations') and provides specific examples without unnecessary elaboration. Every word contributes to understanding the tool's function, making it appropriately sized and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of security auditing and the lack of annotations and output schema, the description is incomplete. It does not cover behavioral aspects like permissions needed, safety profile (e.g., read-only vs. destructive), or what the audit output entails. For a tool with no structured data beyond the input schema, more context is needed to adequately guide an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'namespace' parameter documented as 'Kubernetes namespace to audit (default: 'default')'. The description adds no additional parameter semantics beyond what the schema provides, such as format constraints or examples. With high schema coverage, the baseline score of 3 is appropriate, as the description does not compensate but also does not detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'audit' and the resource 'Kubernetes namespace', specifying the purpose as checking for 'security misconfigurations' with concrete examples like 'privileged containers, missing limits, RBAC issues'. This distinguishes it from sibling tools that perform different operations on Kubernetes resources (e.g., k8s_get_pods, k8s_describe_pod) or other security tools (e.g., security_gitleaks_scan).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites (e.g., required permissions, cluster access), exclusions (e.g., what it does not audit), or comparisons to other security tools like security_trivy_scan. Usage is implied only by the tool's name and description, lacking explicit context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/batu-sonmez/infraclaude'

If you have feedback or need assistance with the MCP directory API, please join our Discord server