Agent skill

NGINX Ingress Policy CRD Guide

by nginx in nginx/kubernetes-ingress

Step-by-step checklist for adding a new Policy CRD type to the NGINX Ingress Controller, from the Go types and validation to config generation and templates.

Apache-2.0Auto-check passedDevOps & Cloud

Install NGINX Ingress Policy CRD Guide

skills CLI
$ npx skills add nginx/kubernetes-ingress --skill nic-add-policy -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install nginx/kubernetes-ingress nic-add-policy --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/nginx/kubernetes-ingress.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/nic-add-policy .claude/skills/nic-add-policy && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
nic-add-policy
GitHub stars
5.1k
Token cost
~2k tokens
SKILL.md length
712 words
Files
1
Skills in repo
9
Repo updated
First seen
Licence
Apache-2.0

At a glance

Step-by-step checklist for adding a new Policy CRD type to the NGINX Ingress Controller, from the Go types and validation to config generation and templates.

  • Works in 12 steps: Define the CRD type → Regenerate deep copy → Regenerate CRDs → …
  • Implementing a new policy type such as RateLimit, JWTAuth or CORS
  • SKILL.md covers Step 1: Define the CRD type, Step 2: Regenerate deep copy, Step 3: Regenerate CRDs and Step 4: Add validation, plus 12 more sections
  • Calls make and git

What it does

The steps must be followed in order. The first defines the CRD struct in `pkg/apis/configuration/v1/types.go` with kubebuilder markers, adds a pointer field to `PolicySpec`, and observes the naming and pointer conventions for JSON tags and optional fields. Next come `make update-codegen` for deep-copy code and `make update-crds` for the CRD manifests and chart CRDs.

Then validation is added in `pkg/apis/configuration/validation/policy.go` with tests, template structs go into `internal/configs/version2/http.go`, and config generation is added in `internal/configs/policy.go`. The policy is wired into VirtualServer generation and, where applicable, Ingress generation including mergeable Ingress, and finally NGINX template directives are added for both the version 2 and version 1 templates, for NGINX and NGINX Plus. Example policy types include rate limit, JWT, OIDC, WAF, CORS and cache.

When your agent uses it

  • Implementing a new policy type such as RateLimit, JWTAuth or CORS
  • Extending the policy system with a new CRD field
  • Checking that a new policy is wired into both VirtualServer and Ingress generation

Example prompts

  • “Add a new Policy CRD type for request header filtering, following the NIC checklist.”
  • “I added the struct for a new policy; run codegen and CRD generation next.”
  • “Wire my new policy into VirtualServer config generation and add the template directives.”

Requirements

  • A checkout of the NGINX Kubernetes Ingress repository
  • Go and make, for the codegen and CRD targets

Workflow steps

12 steps, taken from the step headings in SKILL.md.

  1. Define the CRD type
  2. Regenerate deep copy
  3. Regenerate CRDs
  4. Add validation
  5. Add template structs
  6. Add config generation
  7. Wire into VirtualServer generation
  8. Wire into Ingress generation (if applicable)
  9. Add NGINX template directives
  10. Update snapshot tests
  11. Update the Helm chart (if policy needs CLI flag or ConfigMap entry)
  12. Add controller support

What it can do on your machine

Read from SKILL.md and the folder at commit 03e1429. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • make
    • git

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

NGINX Ingress Policy CRD Guide loads about 2k tokens when it runs. Until then it costs about 73 tokens; SKILL.md has 712 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~73
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from nginx/kubernetes-ingress at commit 03e1429, republished under its Apache-2.0 licence (© nginx). 712 words, ~1,963 tokens.

Download SKILL.mdSave it as .claude/skills/nic-add-policy/SKILL.md (or your agent's skills folder).
name
nic-add-policy
description
Step-by-step checklist for adding a new Policy CRD type to NIC. Use when implementing a new policy like AccessControl, RateLimit, JWTAuth, ExternalAuth, BasicAuth, IngressMTLS, EgressMTLS, OIDC, WAF, APIKey, Cache, or CORS, or extending the policy system with a new policy type.

Adding a New Policy Type

Follow these steps IN ORDER. Each step depends on the previous.

Step 1: Define the CRD type

File: pkg/apis/configuration/v1/types.go

  • Add a new struct (e.g., type MyPolicy struct { ... })
  • Add a *MyPolicy pointer field to PolicySpec
  • Use kubebuilder markers for validation
  • JSON tags: kebab-case for NGINX-proxy fields, camelCase for K8s fields
  • *bool/*int = optional/nullable. Plain bool/int = required or zero-default
  • Booleans defaulting to false must be non-pointer value types

Step 2: Regenerate deep copy

Run make update-codegen to update zz_generated.deepcopy.go.

Step 3: Regenerate CRDs

Run make update-crds to regenerate config/crd/bases/, deploy/crds.yaml, and chart CRDs.

Step 4: Add validation

File: pkg/apis/configuration/validation/policy.go

  • Add validate<MyPolicy>(spec *v1.MyPolicy, fieldPath *field.Path) field.ErrorList
  • Wire into validatePolicySpec() with field count increment and feature gate check
  • Add tests in policy_test.go with valid and invalid cases

Step 5: Add template structs

File: internal/configs/version2/http.go

  • Add struct (e.g., type MyPolicyConfig struct { ... })
  • Add *MyPolicyConfig or fields to Server, Location, or both
  • If the policy needs HTTP-level directives (zones, maps), add fields to VirtualServerConfig

Step 6: Add config generation

File: internal/configs/policy.go

  • Add field(s) to policiesCfg
  • Add add<MyPolicy>Config() method following the pattern below
  • Wire into the switch in generatePolicies()
  • Add tests in policy_test.go

Step 7: Wire into VirtualServer generation

File: internal/configs/virtualserver.go

  • In GenerateVirtualServerConfig(), extract from policiesCfg and assign to version2 fields
  • Use addPoliciesCfgToLocation() for location-level assignment

Step 8: Wire into Ingress generation (if applicable)

File: internal/configs/ingress.go

  • In generateNginxCfg(), extract from policiesCfg and assign to version1 fields
  • Handle mergeable ingress in generateNginxCfgForMergeableIngresses()

Step 9: Add NGINX template directives

  • Version 2: internal/configs/version2/nginx.virtualserver.tmpl and internal/configs/version2/nginx-plus.virtualserver.tmpl
  • Version 1: internal/configs/version1/nginx.ingress.tmpl and internal/configs/version1/nginx-plus.ingress.tmpl
  • Use {{- if }} / {{- with }} guards around directive blocks
  • Template helpers go in internal/configs/version2/template_helper.go and/or internal/configs/version1/template_helper.go, matching the template version you are updating
  • HTTP-level directives (zones, maps) go BEFORE server{}
  • Server-level inside server{}, location-level inside each location{}

Step 10: Update snapshot tests

Files: internal/configs/version2/templates_test.go (VS/VSR/TS), internal/configs/version1/template_test.go (Ingress)

  1. Add the new policy fields to the fixture structs used by the snapshot tests -- a regeneration with no fixture change produces no diff and leaves the policy untested.
  2. Run make test-update-snaps.
  3. git diff -- '**/__snapshots__/**' and confirm your directives render in the golden files for every edition the policy supports. Plus-only policies (OIDC, WAF) must appear in the Plus golden files only; policies available to both editions must appear in both.
  4. Run make test to confirm green, and commit the regenerated golden files with the template change.

If you wired the policy into Ingress (Step 8), version1 snapshots must change too.

Step 11: Update the Helm chart (if policy needs CLI flag or ConfigMap entry)

  • charts/nginx-ingress/values.yaml -- add value with ## doc
  • charts/nginx-ingress/values.schema.json -- add schema entry
  • charts/nginx-ingress/templates/_helpers.tpl -- add CLI arg or ConfigMap key
  • charts/tests/testdata/ -- add test values file
  • charts/tests/helmunit_test.go -- add test case
Show full SKILL.md (271 more words)Show less

Step 12: Add controller support

File: internal/k8s/

  • In syncPolicy(), ensure the new type is handled for VS/VSR/Ingress
  • Check if it needs feature-gate guarding (isPlus, enableOIDC, etc.)

If the policy references secrets:

  • Add every Secret field to policySecretIndexFunc() through collectPolicySecretRefs() or collectWAFSecretRefs().
  • Resolve each reference during extended-resource construction with secretStore.GetSecret(namespacedKey, role).
  • Store the result under secrets.RefKey(namespacedKey, role).
  • Select the role from the reference site's semantics; never infer it from Secret.type or Secret data.
  • Ensure syncPolicy() fans out to every supported VS, VSR, and Ingress consumer.
  • Add index tests covering add, update, delete, cross-namespace references, and duplicate references.

Step 13: Write integration tests

Directory: tests/suite/

  • Create test data YAMLs in tests/data/<feature>/
  • Create test_<feature>_policies_vs.py, _vsr.py, _ingress.py
  • Use @pytest.mark.policies and @pytest.mark.policies_<feature> markers
  • Register the new marker in pyproject.toml -- pytest runs with --strict-markers

Gotchas

  • Never skip make update-codegen after changing types.go -- the build will fail with missing DeepCopy methods
  • Never use raw user strings in NGINX config without containsDangerousChars() validation
  • Both OSS and Plus templates must be updated for policies available to both editions -- they are separate files, each with its own snapshot entries. Plus-only policies (OIDC, WAF) belong in the Plus templates only
  • A policy that reaches a template but has no snapshot fixture ships with zero rendered-output coverage
  • make update-crds also refreshes deploy/crds*.yaml and docs/crd/; charts/nginx-ingress/crds is a symlink to config/crd/bases/
  • If the policy adds telemetry counters, run make telemetry-schema -- CI fails on any diff in internal/telemetry
  • policiesCfg duplicate check must warn and return, not error (exception: addCORSConfig has no duplicate check -- it overwrites, since CORS is additive via headers)

Policy add*Config() Pattern

Every add*Config() method in internal/configs/policy.go follows this pattern:

go
func (p *policiesCfg) addMyPolicyConfig(spec *conf_v1.MyPolicy, key, namespace string,
    secretRefs map[secrets.SecretRefKey]*secrets.SecretReference) *validationResults {
    res := newValidationResults()

    // 1. Duplicate check
    if p.MyPolicy != nil {
        res.addWarningf("MyPolicy policy already configured, ignoring")
        return res
    }

    // 2. Secret resolution (if applicable)
    secretKey := namespace + "/" + spec.Secret
    refKey := secrets.RefKey(secretKey, secrets.RoleExpected)
    secretRef, ok := secretRefs[refKey]
    if !ok || secretRef == nil {
        res.isError = true
        res.addWarningf("secret %s could not be resolved", secretKey)
        return res
    }
    if secretRef.Error != nil {
        res.isError = true
        res.addWarningf("secret %s is invalid: %v", secretKey, secretRef.Error)
        return res
    }

    // 3. Build template struct and assign
    p.MyPolicy = &version2.MyPolicyConfig{
        Field1: spec.Field1,
        Field2: spec.Field2,
        Secret: secretRef.Path,
    }

    return res
}

NGINX Template Pattern

nginx
{{- with $s.MyPolicy }}
my_directive {{ .Value }};
{{- if .OptionalField }}
my_optional_directive {{ .OptionalField }};
{{- end }}
{{- end }}

© nginx, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/nic-add-policy of nginx/kubernetes-ingress.

Open the folder on GitHubat commit 03e1429

Compare with similar skills

NGINX Ingress Policy CRD Guide next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

NGINX Ingress Policy CRD Guide compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
NGINX Ingress Policy CRD Guide this skillnginx/kubernetes-ingress5.1k—~2kAutomated safety check: PassApache-2.0
Nginx To Higress Migrationhigress-group/higress9.5k—~3.9kAutomated safety check: PassApache-2.0
KubeSphere Gateway Managementkubesphere/kubesphere17k—~2.9kAutomated safety check: PassCustom licence
Kubeshark KFL2 Filter Referencekubeshark/kubeshark12k—~3.6kAutomated safety check: PassApache-2.0
Tgf Server Devthkhxm/tgf128—~1.3kAutomated safety check: NotesMIT
Intrinsic Core Debuggingintrinsic-ai/intrinsic-core557—~3.8kAutomated safety check: NotesApache-2.0

Similar skills

  • Nginx To Higress Migration

    higress-group/higress

    Migrate from ingress-nginx to Higress in Kubernetes environments.

    9.5k GitHub stars~3.9k tokensUpdated yesterday
    DevOps & CloudAuto-check passed
  • KubeSphere Gateway Management

    kubesphere/kubesphere

    Installs, uninstalls, checks and troubleshoots the KubeSphere Gateway extension built on ingress-nginx, including gateways stuck in bad states and Helm or pod failures.

    17k GitHub stars~2.9k tokensUpdated 2 mo ago
    DevOps & CloudAuto-check passed
  • Syntax reference for KFL2, the CEL-based display filter language used to search Kubernetes network traffic captured by Kubeshark, loaded before any filter is written.

    12k GitHub stars~3.6k tokensUpdated 2 days ago
    DevOps & CloudAuto-check passed
  • Tgf Server Dev

    thkhxm/tgf

    基于 tgf v2(github.com/thkhxm/tgf/v2)用确定性的 tgfctl 工作流创建、验证和维护 Go 游戏服务器项目。

    128 GitHub stars~1.3k tokensUpdated 2 mo ago
    DatabasesAuto-check: notes
  • Intrinsic Core Debugging

    intrinsic-ai/intrinsic-core

    Meta-level debugging workflows, architectural layer isolation, and progressive disclosure routing across Envoy ingress, Kubernetes pods, Behavior Trees, ObjectWorld synchronization, ICON real-time…

    557 GitHub stars~3.8k tokensUpdated yesterday
    DevOps & CloudAuto-check: notes
  • Aks Deployment Skill

    timothywarner/chatgptclass

    Deploy and operate workloads on Azure Kubernetes Service (AKS) the safe way.

    143 GitHub stars~916 tokensUpdated 20 days ago
    DevOps & CloudAuto-check passed

More from nginx/kubernetes-ingress

All 9 skills in this repo
  • Gives step-by-step checklists for adding Ingress annotations, VirtualServer fields and Helm values to the NGINX Kubernetes Ingress Controller, with common gotchas.

    5.1k GitHub stars~1.4k tokensUpdated yesterday
    Auto-check passed
  • Explains the multi-stage Dockerfile, the 25 image variant combinations, and the Makefile targets for building NGINX Ingress Controller images.

    5.1k GitHub stars~2.9k tokensUpdated yesterday
    Auto-check passed
  • NGINX Ingress Controller Structure

    nginx/kubernetes-ingress

    Maps the NGINX Kubernetes Ingress Controller codebase: repository layout, architectural layers, layer-crossing rules and which files are generated.

    5.1k GitHub stars~3.8k tokensUpdated yesterday
    Auto-check passed
  • NIC Testing Patterns

    nginx/kubernetes-ingress

    Testing conventions for the NGINX Ingress Controller repo: Go table-driven tests, mandatory snapshot regeneration, Helm tests and Python pytest integration tests.

    5.1k GitHub stars~2.8k tokensUpdated yesterday
    Auto-check passed
  • NGINX Ingress CI Pipelines

    nginx/kubernetes-ingress

    Explains how the NGINX Ingress Controller's GitHub Actions workflows, reusable workflows, build matrices and release pipeline fit together across two repositories.

    5.1k GitHub stars~5.1k tokensUpdated yesterday
    Auto-check passed
  • NGINX Ingress Controller Debugging

    nginx/kubernetes-ingress

    Troubleshooting patterns for the NGINX Ingress Controller: reload failures, custom resources that have no effect, controller panics and snapshot test failures.

    5.1k GitHub stars~1.7k tokensUpdated yesterday
    Auto-check passed

Questions about NGINX Ingress Policy CRD Guide

What does NGINX Ingress Policy CRD Guide do?

Step-by-step checklist for adding a new Policy CRD type to the NGINX Ingress Controller, from the Go types and validation to config generation and templates. The steps must be followed in order.go` with kubebuilder markers, adds a pointer field to `PolicySpec`, and observes the naming and pointer conventions for JSON tags and optional fields.

When should I use NGINX Ingress Policy CRD Guide?

NGINX Ingress Policy CRD Guide fits situations like: implementing a new policy type such as RateLimit, JWTAuth or CORS; extending the policy system with a new CRD field; checking that a new policy is wired into both VirtualServer and Ingress generation.

How do I install NGINX Ingress Policy CRD Guide in Claude Code?

Run `npx skills add nginx/kubernetes-ingress --skill nic-add-policy -a claude-code`. Or copy the skill folder (.github/skills/nic-add-policy in nginx/kubernetes-ingress) into .claude/skills/nic-add-policy in your project. Claude Code loads it when a task matches its description.

How do I install NGINX Ingress Policy CRD Guide in Codex?

Run `npx skills add nginx/kubernetes-ingress --skill nic-add-policy -a codex`. Or copy the skill folder (.github/skills/nic-add-policy in nginx/kubernetes-ingress) into .agents/skills/nic-add-policy in your project. Codex loads it when a task matches its description.

Can I use NGINX Ingress Policy CRD Guide in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add nginx/kubernetes-ingress --skill nic-add-policy -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/nic-add-policy, .gemini/skills/nic-add-policy, .github/skills/nic-add-policy and .opencode/skills/nic-add-policy in your project.

What does NGINX Ingress Policy CRD Guide need to run?

Going by SKILL.md and its folder, NGINX Ingress Policy CRD Guide needs the command-line tools its instructions call (make and git). Our summary lists: A checkout of the NGINX Kubernetes Ingress repository; Go and make, for the codegen and CRD targets.

Does NGINX Ingress Policy CRD Guide access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is NGINX Ingress Policy CRD Guide safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does NGINX Ingress Policy CRD Guide use?

NGINX Ingress Policy CRD Guide is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does NGINX Ingress Policy CRD Guide use?

About 2k tokens (SKILL.md is roughly 7.9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to NGINX Ingress Policy CRD Guide?

Skills that share tags, products or a category with NGINX Ingress Policy CRD Guide: Nginx To Higress Migration (higress-group/higress, 9.5k stars), KubeSphere Gateway Management (kubesphere/kubesphere, 17k stars), Kubeshark KFL2 Filter Reference (kubeshark/kubeshark, 12k stars) and Tgf Server Dev (thkhxm/tgf, 128 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains NGINX Ingress Policy CRD Guide?

nginx (a GitHub organization) maintains it in nginx/kubernetes-ingress, which has 5,081 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on October 9, 2026.

Source: nginx/kubernetes-ingress on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.