Network policy architect

From RHEcosystemAppEng/agentic-plugins · View interactive version

Network policy architect is an AI agent skill from the GitHub repository RHEcosystemAppEng/agentic-plugins. Design and validate Kubernetes NetworkPolicies following Zero Trust principles (NIST SP 800-207). Two-tier analysis — architecture review then live cluster verification — produces a verified implementation plan with apply-and-verify results. Use when: - "Create NetworkPolicies for my namespace" - "A

How to use this skill

Skill file

network-policy-architect Skill

Audience: Platform engineers and security architects responsible for Kubernetes network segmentation.

Goal: Design NetworkPolicies that enforce the principle of least privilege at the network layer — every connection must be explicitly justified and authorized.

This skill follows NIST SP 800-207 (Zero Trust Architecture) which states:

"Zero trust assumes there is no implicit trust granted to assets or user accounts based solely on their physical or network location."

Recommendations carry the weight of a security audit. Every rule proposed must be justified. Every port opened must be documented. Every exception must be explicitly acknowledged by the user.

MCP-First Approach: This skill uses MCP tools from openshift-administration server. MCP tools have absolute priority.

CLI Tools Policy:

Prerequisites

Required MCP Servers: openshift-administration — Kubernetes/OpenShift cluster operations (setup guide)

Required MCP Tools (all from openshift-administration server):

Environment Variables:

Verification Steps:

  1. Check openshift-administration MCP server is available
  2. Verify KUBECONFIG is set: test -n "$KUBECONFIG" && echo "✓ Set" || echo "✗ Missing"
  3. Verify cluster access by listing namespaces via namespaces_list
  4. If any check fails → Human Notification Protocol

Human Notification Protocol:

When prerequisites fail:

  1. Stop immediately — No tool calls
  2. Report error:

```

❌ Cannot execute skill: MCP server openshift-administration unavailable

📋 Setup: Configure the openshift MCP server in mcps.json with KUBECONFIG

```

  1. Request decision: "How to proceed? (setup/skip/abort)"
  2. Wait for user input

Security: Never display credential values. Only report whether KUBECONFIG is set.

When to Use This Skill

Use when:

Do NOT use when:

Workflow

This skill operates in two mandatory tiers. Both must be completed before producing the final implementation plan.


Tier 1: Architecture Analysis (Offline)

Objective: Understand the application's communication requirements from source code, documentation, and deployment manifests — before touching a live cluster.

Step 1: Identify All Pod Types

For each pod type in the namespace, document:

Step 2: Identify All Services

For each service:

Step 3: Map Communication Flows

For each pod type, determine:

Step 4: Check for Operator-Managed NetworkPolicies

Some operators create and manage their own NetworkPolicies (e.g., RHBK operator creates keycloak-network-policy). These must NOT be duplicated or overridden — the operator will revert changes. Document them and design around them.

Step 5: Identify Special Networking Cases

Step 6: Draft Initial Rules

For each pod type, propose:

Tier 1 output: Present the communication map and draft rules to the user. Get confirmation before proceeding to Tier 2.


Tier 2: Live Cluster Verification

Objective: Validate the draft rules against a running cluster. Confirm actual pod labels, ports, connections, and behavior.

Prerequisites: User must have an OCP/Kubernetes cluster with the target application deployed and healthy. The openshift-administration MCP server must be connected.

Step 7: Verify Pod Inventory

MCP Tool: pods_list (from openshift-administration)

Parameters:

Expected Output: List of pods with name, status, and ready state.

Error Handling:

Step 8: Verify Pod Labels

MCP Tool: resources_list (from openshift-administration)

Parameters:

Expected Output: Full pod specs including metadata.labels. Confirm labels match the selectors drafted in Tier 1.

Error Handling:

Step 9: Verify Services and Endpoints

MCP Tool: resources_list (from openshift-administration)

Parameters (Services):

Parameters (Endpoints):

Expected Output: Services with ports, selectors, and endpoint addresses.

Error Handling:

Step 10: Verify Routes

MCP Tool: resources_list (from openshift-administration)

Parameters:

Expected Output: Routes with host, TLS termination, and target service.

Error Handling:

Step 11: Verify Existing NetworkPolicies

MCP Tool: resources_list (from openshift-administration)

Parameters:

Expected Output: Existing policies including operator-managed ones. Cross-reference with Tier 1 Step 4 findings.

Error Handling:

Step 12: Verify Container Ports and hostNetwork

MCP Tool: resources_list (from openshift-administration)

Parameters (Deployments):

Repeat for kind: "StatefulSet" and kind: "DaemonSet".

Expected Output: Workload specs including spec.template.spec.containers[].ports and spec.template.spec.hostNetwork.

Error Handling:

Step 13: Review Component Logs

MCP Tool: pods_log (from openshift-administration)

Parameters:

For each pod type, check logs for:

Error Handling:

Step 14: Temporary Apply-and-Verify

Human Confirmation Required — display all policies and wait for approval before applying.

MCP Tool: resources_create_or_update (from openshift-administration)

Parameters:

Apply each proposed NetworkPolicy. Then verify:

Step 15: Record Verification Results

For each verification check, record PASS or FAIL with evidence.

If any check FAILS: Immediately proceed to Step 16 to remove the applied policies before diagnosing the issue. Report the failure evidence to the user and ask how to proceed (fix draft rules and retry, or abort).

Step 16: Clean Up Verification Policies

Human Confirmation Required — list policies and wait for approval.

MCP Tool: resources_delete (from openshift-administration)

Parameters:

Error Handling:


Implementation Plan

After both tiers are complete, produce the final implementation plan.

The plan MUST include:

1. Executive Summary
2. Default-Deny Decision

A default-deny NetworkPolicy MUST be included in every implementation plan.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-in-namespace-<namespace>
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress

If the user decides NOT to implement default-deny, this must be:

3. Per-Pod Policy Rules

For each pod type, document:

| Field | Detail |

|---|---|

| Pod type | Name, labels, workload type |

| Policy name | Kubernetes NetworkPolicy name |

| Ingress rules | Each rule with: port, protocol, source (selector or port-only), justification |

| Egress rules | Each rule with: port, protocol, destination (selector or port-only), justification |

| Why this rule exists | Reference to the communication flow identified in Tier 1 |

| What breaks if removed | Specific failure mode |

4. Known Exceptions

Document each exception:

5. Verification Results

| Verification | Result | Evidence |

|---|---|---|

| All pods Running after NP applied | PASS/FAIL | pods_list output |

| Routes respond | PASS/FAIL | HTTP status codes |

| Dependent apps work | PASS/FAIL | Specific checks performed |

| Pod restart recovery | PASS/FAIL | Logs showing re-attestation/reconnection |

| No new errors in logs | PASS/FAIL | Log excerpts |

6. Implementation Approach

Recommend the deployment method:

7. NIST SP 800-207 Alignment

Map each policy to Zero Trust principles:

Strict Rules

  1. Never skip Tier 2. Architecture analysis alone is insufficient — live verification catches configuration drift, operator-added resources, and undocumented connections.
  2. Never skip default-deny. If the user doesn't want it, document it as a security exception — don't silently omit it.
  3. Justify every open port. "It might be needed" is not a justification. Every ingress and egress rule must trace back to an observed communication flow.
  4. Document every exception. hostNetwork, port-only rules, operator-managed policies — all must be explicitly called out with explanations.
  5. Test before recommending. The temporary apply-and-verify phase is mandatory. Untested policies are proposals, not recommendations.
  6. OVN-Kubernetes awareness. On OpenShift, understand OVN-K-specific behaviors: policy-group labels for router ingress, port 5353 for DNS (not 53), DNAT for K8s API, transit IPs for hostNetwork pods.
  7. Helm template conditions. When creating NetworkPolicy templates gated by values (e.g., enabled: true), always use (eq (.Values.field | toString) "true") — not bare .Values.field. Helm overrides via extraValueFiles and pattern frameworks often pass booleans as strings ("true" not true). Bare boolean evaluation fails silently when the value is a string, causing policies to not render. Apply | toString consistently to ALL condition halves in {{- if and ... }} expressions.
  8. MCP tools first. Always use MCP tools from openshift-administration for cluster operations. Do not use oc or kubectl CLI commands unless no MCP alternative exists.

Dependencies

Required MCP Servers

Required MCP Tools

Related Skills

Reference Documentation

Official: Kubernetes NetworkPolicy API

Official: OpenShift Networking - NetworkPolicy

Official: NIST SP 800-207 - Zero Trust Architecture

Official: Admin Network Policy API

Human-in-the-Loop

This skill performs operations that modify cluster state, requiring explicit user confirmation:

  1. Before applying NetworkPolicies (Step 14)
  1. Before force-restarting pods (Step 14)
  1. Before removing verification policies (Step 16)
  1. Default-deny exception

Never assume approval — always wait for explicit confirmation before apply, delete, or restart operations.

Example Usage

User: "Create NetworkPolicies for the qtodo namespace following Zero Trust principles"

Skill response:

  1. Tier 1: Analyzes qtodo source code and Helm chart, identifies pods (qtodo-app, qtodo-db), services (qtodo, qtodo-db), routes, and communication flows (ingress from router, egress to DB/DNS/Keycloak/Vault).
  2. Presents communication map and draft rules for user review.
  3. Tier 2: Connects to the cluster via MCP, verifies pod labels, services, and existing policies. Temporarily applies draft policies, verifies all pods healthy, routes respond, and logs show no errors, then removes verification policies.
  4. Produces the final implementation plan with default-deny, per-pod rules, exceptions, verification results, and NIST alignment.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.