nginx/kubernetes-ingress/nic-add-policy
Claude Code and agent skill by nginx/kubernetes-ingress
- community
Checking that the SKILL.md file is still in the repository.
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.
Install
npx vskill@latest install nginx/kubernetes-ingress/nic-add-policySKILL.md
The same SKILL.md was published earlier as nginx/kubernetes-ingress/nic-add-policy.
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
*MyPolicypointer field toPolicySpec - Use kubebuilder markers for validation
- JSON tags: kebab-case for NGINX-proxy fields, camelCase for K8s fields
*bool/*int= optional/nullable. Plainbool/int= required or zero-default- Booleans defaulting to
falsemust 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.gowith valid and invalid cases
Step 5: Add template structs
File: internal/configs/version2/http.go
- Add struct (e.g.,
type MyPolicyConfig struct { ... }) - Add
*MyPolicyConfigor fields toServer,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
switchingeneratePolicies() - Add tests in
policy_test.go
Step 7: Wire into VirtualServer generation
File: internal/configs/virtualserver.go
- In
GenerateVirtualServerConfig(), extract frompoliciesCfgand assign toversion2fields - Use
addPoliciesCfgToLocation()for location-level assignment
Step 8: Wire into Ingress generation (if applicable)
File: internal/configs/ingress.go
- In
generateNginxCfg(), extract frompoliciesCfgand assign toversion1fields - Handle mergeable ingress in
generateNginxCfgForMergeableIngresses()
Step 9: Add NGINX template directives
- Version 2:
internal/configs/version2/nginx.virtualserver.tmplandinternal/configs/version2/nginx-plus.virtualserver.tmpl - Version 1:
internal/configs/version1/nginx.ingress.tmplandinternal/configs/version1/nginx-plus.ingress.tmpl - Use
{{- if }}/{{- with }}guards around directive blocks - Template helpers go in
internal/configs/version2/template_helper.goand/orinternal/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 eachlocation{}
Step 10: Update snapshot tests
Files: internal/configs/version2/templates_test.go (VS/VSR/TS), internal/configs/version1/template_test.go (Ingress)
- 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.
- Run
make test-update-snaps. 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.- Run
make testto 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##doccharts/nginx-ingress/values.schema.json-- add schema entrycharts/nginx-ingress/templates/_helpers.tpl-- add CLI arg or ConfigMap keycharts/tests/testdata/-- add test values filecharts/tests/helmunit_test.go-- add test case
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()throughcollectPolicySecretRefs()orcollectWAFSecretRefs(). - 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.typeor 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.policiesand@pytest.mark.policies_<feature>markers - Register the new marker in
pyproject.toml-- pytest runs with--strict-markers
Gotchas
- Never skip
make update-codegenafter changingtypes.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-crdsalso refreshesdeploy/crds*.yamlanddocs/crd/;charts/nginx-ingress/crdsis a symlink toconfig/crd/bases/- If the policy adds telemetry counters, run
make telemetry-schema-- CI fails on any diff ininternal/telemetry policiesCfgduplicate check must warn and return, not error (exception:addCORSConfighas 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:
NGINX Template Pattern
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/nic-add-policy/SKILL.md
Popularity
- Repository stars
- 5,081
- Repository forks
- 2,051
- 7-day trend score
- 43
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/nginx/kubernetes-ingress/nic-add-policy)