Tutorial 12
Scorecards and compile-time policy
These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.
In tutorial 09, you used lib.mkOption and lib.types to validate each option on a single package instance. Some policies, however, belong to the platform team rather than to an individual package author:
- “Every reverse-proxy gateway in our production cluster must set
maxBodySizeexplicitly rather than relying on the1mdefault.” - “No two reverse-proxy gateways across the entire cluster may claim the same
proxyPath.”
In Kix, you enforce these rules at build time using scorecards. Because scorecards evaluate inside Nix against the typed package options, metadata, and full cluster graph, they can check cross-instance invariants that single-manifest YAML linters cannot see.
Prerequisites
Section titled “Prerequisites”- Finish the flavors, roles, and imports tutorial.
- Keep the same
kix-examplescheckout.
Inspect 19-scorecards
Section titled “Inspect 19-scorecards”Open:
1tutorials/19-scorecards/cluster.nix2tutorials/19-scorecards/scorecard.nixIn tutorials/19-scorecards/cluster.nix, the cluster defines two application namespaces (app-v1 and app-v2), each with a backend and a gateway instance:
app-v1.gatewaysetsproxyPath = "/v1/"andmaxBodySize = "10m".app-v2.gatewaysetsproxyPath = "/v2/"andmaxBodySize = "10m".
At the top of cluster.nix, the cluster module inside modules sets scorecard by importing ./scorecard.nix:
kix.buildCluster { name = "19-scorecards";
modules = [ kix.flavors.kind
# `lib` is injected by the NixOS module system — we pull it in # here so we can hand it to ./scorecard.nix on import. ( { ref, lib, ... }: { # ── Scorecard ──────────────────────────────────────────────── # The whole rules block lives in ./scorecard.nix. cluster.nix # stays focused on what the cluster *contains*; the rules file # owns the checks we want to run against it. scorecard = import ./scorecard.nix { inherit lib kix; };
# ... } ) ];}Keeping scorecard policy in a separate file (./scorecard.nix) lets platform teams share a single policy definition across multiple clusters while keeping cluster.nix focused on topology and instances.
Enable Built-In Rules And Severity Controls
Section titled “Enable Built-In Rules And Severity Controls”Open tutorials/19-scorecards/scorecard.nix. At the top of the file, enable, ruleOverrides, and rules configure what the scorecard checks:
{ enable = true;
# Per-rule severity override. Key is `<category>.<rule>`. # Raises a built-in from "warning" to "error" so the build fails # if a probe is missing. ruleOverrides.byRule."reliability.hasProbes".severity = "error";
rules = { # 1. Whole built-in category. Bundles hasProbes, # boundedResources, hasResourceLimits, hasResourceRequests, # gracefulShutdown, hasPDB. reliability = kix.rules.reliability;
# custom rules ... };}Here is what each field controls:
enable = true: Turns on scorecard evaluation duringkix checkandkix build.ruleOverrides.byRule."reliability.hasProbes".severity = "error": Overrides the severity of a single rule (<category>.<rule>) from"warning"to"error".rules = { reliability = kix.rules.reliability; ... }: Selects Kix’s built-inreliabilityrule category (kix.rules.reliability, alongsidekix.rules.security,kix.rules.governance, andkix.rules.architecture) and adds custom rules for this cluster.maxSeverity(optional, defaults to"warning"): Caps the effective severity of every finding in the cluster to"info","warning", or"error". Because the default is"warning", findings from error-severity rules are capped to warnings unless the cluster also setsmaxSeverity = "error".
Write A Package-Level Rule
Section titled “Write A Package-Level Rule”Next, look at the first custom rule in tutorials/19-scorecards/scorecard.nix:
52 custom.proxyMaxBodySizeMustBeExplicit = {53 description = "Reverse-proxy gateways must set maxBodySize explicitly (not the 1m default).";54 level = "package";55 severity = "error";56 tags = [ "reliability" "kix-examples" ];57
58 # Only run on reverse-proxy packages. `appliesTo` receives the59 # package metadata directly, so this checks `meta.provides`.60 appliesTo =61 { meta, ... }:62 builtins.elem "reverse-proxy" (meta.provides or [ ]);63
64 check =65 { config, instanceName, ... }:66 if (config.maxBodySize or "") == "1m" then67 [68 {69 message =70 "instance '${instanceName}' uses the default maxBodySize '1m'. "71 + "nginx rejects larger request bodies — set this explicitly.";72 }73 ]74 else75 [ ];76 };A level = "package" rule runs once per package instance and inspects the package’s meta, config, and built resources:
appliesTo = { meta, ... }: ...: Filters which instances this rule checks. Becausereverse-proxy-package.nixdeclaresmeta.provides = [ "reverse-proxy" ],builtins.elem "reverse-proxy" (meta.provides or [ ])runs this rule only on reverse-proxy instances and skipsecho-serverbackends.check = { config, instanceName, ... }: ...: Inspects the instance’s mergedconfigdirectly. You do not have to parse nginx’sdefault.conftext out of a rendered ConfigMap; you readconfig.maxBodySizeas a structured Nix value. If it equals"1m",checkreturns a finding with a descriptive message.
Write A Cluster-Level Rule
Section titled “Write A Cluster-Level Rule”Some mistakes only appear when you compare multiple instances across the cluster. If app-v1/gateway and app-v2/gateway both configure proxyPath = "/v1/", each instance looks completely valid in isolation, yet their routes collide across the cluster.
To catch that, tutorials/19-scorecards/scorecard.nix defines a helper predicate isProxy and a level = "cluster" rule named custom.noProxyPathCollision:
26 isProxy =27 inst:28 # Cluster-level rules inspect built instances, so the package29 # metadata is under `inst._meta.packageMeta`.30 builtins.elem "reverse-proxy" (inst._meta.packageMeta.provides or [ ]);82 custom.noProxyPathCollision = {83 description = "No two reverse-proxy gateways may share the same proxyPath.";84 level = "cluster";85 severity = "error";86 tags = [87 "routing"88 "kix-examples"89 ];90
91 check =92 { allInstances, ... }:93 let94 # `allInstances` is `{ <ns> = { <name> = instance; }; }`.95 # Flatten into a list of { ns, name, inst } records.96 #97 # `lib.concatLists` is the nixpkgs equivalent of JS's98 # `arr.flat()` — flatten a list of lists into one list.99 # `builtins.attrNames` returns the keys of an attrset.100 flat = lib.concatLists (101 map (102 ns:103 map (name: {104 inherit ns name;105 inst = allInstances.${ns}.${name};106 }) (builtins.attrNames allInstances.${ns})107 ) (builtins.attrNames allInstances)108 );109
110 # Keep only reverse-proxy instances.111 proxies = builtins.filter (e: isProxy e.inst) flat;112
113 # Group by proxyPath → { "/v1/" = [...]; "/v2/" = [...]; }.114 byPath = builtins.foldl' (115 acc: e:116 let117 p = e.inst._meta.config.proxyPath or "?";118 in119 acc // { ${p} = (acc.${p} or [ ]) ++ [ e ]; }120 ) { } proxies;121
122 # Any path with more than one owner is a collision.123 collisions = lib.filterAttrs (_: members: builtins.length members > 1) byPath;124 in125 map (path: {126 message =127 "${toString (builtins.length collisions.${path})} reverse-proxy gateways share proxyPath '${path}': "128 + builtins.concatStringsSep ", " (129 map (e: "${e.ns}/${e.name}") collisions.${path}130 );131 }) (builtins.attrNames collisions);132 };Look at how custom.noProxyPathCollision works:
level = "cluster": Runs once for the entire cluster and receivesallInstances({ <namespace> = { <instance> = inst; }; }).- Filter to reverse proxies: Flattens
allInstancesand usesisProxyto keep only instances whosemeta.providesincludes"reverse-proxy". - Group by
config.proxyPath: Readse.inst._meta.config.proxyPathon every reverse-proxy instance and groups instances by path. - Report collisions: Any
proxyPathclaimed by more than one gateway produces an error finding that lists every colliding<namespace>/<instance>pair.
Run kix check And kix build
Section titled “Run kix check And kix build”Run kix check 19-scorecards:
❱ kix check 19-scorecards
TOOL RESULT DETAILS
eval pass 22 manifests evaluated
scorecard pass 0 errors, 2 warnings, 2 info
reliability.boundedResources (warning), 2:
app-v1/gateway/gateway: container 'nginx' is missing resource settings: requests.cpu, requests.memory, limits.cpu, limits.memory. Set CPU and memory requests and limits. Without a memory limit, a workload can exhaust the node's memory.
app-v2/gateway/gateway: container 'nginx' is missing resource settings: requests.cpu, requests.memory, limits.cpu, limits.memory. Set CPU and memory requests and limits. Without a memory limit, a workload can exhaust the node's memory.
2 info finding(s) not listed; run with -v to list them. Both custom rules pass (0 errors), while the built-in kix.rules.reliability rules report 6 warnings and 2 informational findings across the 24 evaluated manifests. kix build 19-scorecards succeeds and renders all 24 resources:
❱ kix build 19-scorecards Show outputHide output · 667 lines
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kix.run/depends-on: 95gmkzkbdf1k30pp3k54hp8vc8qd54p8,q85cvsj44a56pxm9cx3naj0ywb4bnmcv
kix.run/identity-hash: 011nbqjvmaz0d3nrnq6w3dnv66pfwv1y
kix.run/package: backend
kix.run/package-namespace: app-v1
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/managed-by: kix
app.kubernetes.io/name: backend
name: backend
namespace: app-v1
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: backend
app.kubernetes.io/name: backend
template:
metadata:
annotations:
checksum/config: 59e6c3c05a9d5f93aae11fd69e5b28940015b69402671f5859b225af8e0b89a2
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/name: backend
spec:
containers:
- image: docker.io/nginxinc/nginx-unprivileged:1.30.6-alpine@sha256:f5116ed4606f3eb015dd4a8e28cb9b351476dc0ad4bc6e9f93b19cec130cdf03
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
name: nginx
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
failureThreshold: 1
httpGet:
path: /healthz
port: 8080
periodSeconds: 5
resources:
limits:
cpu: 100m
memory: 64Mi
requests:
cpu: 50m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: config
readOnly: true
- mountPath: /tmp
name: tmp
terminationGracePeriodSeconds: 30
volumes:
- configMap:
name: backend
name: config
- emptyDir: {}
name: tmp
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kix.run/depends-on: 95gmkzkbdf1k30pp3k54hp8vc8qd54p8,vz8jvwngqp8ac8synjqn2zcwpmc4ar9k,requires:mkgdf3yajj0a92l7fspcy7ciykw4dsl1
kix.run/identity-hash: fbrxkfz5xqd1ghkqw363hpvlba42v51s
kix.run/package: gateway
kix.run/package-namespace: app-v1
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/managed-by: kix
app.kubernetes.io/name: gateway
name: gateway
namespace: app-v1
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/name: gateway
template:
metadata:
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/name: gateway
spec:
containers:
- image: nginx:1.27-alpine
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 80
periodSeconds: 10
name: nginx
ports:
- containerPort: 80
name: http
protocol: TCP
readinessProbe:
httpGet:
path: /healthz
port: 80
periodSeconds: 5
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: config
readOnly: true
volumes:
- configMap:
name: gateway
name: config
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kix.run/depends-on: 883jpjfxsaiclk52hbfgjnakw4im51hm,lxi0gciwfx6mgp92319mjxhjwvgkdqhs
kix.run/identity-hash: aj39j3ywdkqjcv333nygsj9ijcif6r29
kix.run/package: backend
kix.run/package-namespace: app-v2
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/managed-by: kix
app.kubernetes.io/name: backend
name: backend
namespace: app-v2
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: backend
app.kubernetes.io/name: backend
template:
metadata:
annotations:
checksum/config: 4c5192f6b90f0c6e3f49ed9c1a26351e8c39fd59716fd6cc07587071ddaae713
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/name: backend
spec:
containers:
- image: docker.io/nginxinc/nginx-unprivileged:1.30.6-alpine@sha256:f5116ed4606f3eb015dd4a8e28cb9b351476dc0ad4bc6e9f93b19cec130cdf03
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
name: nginx
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
failureThreshold: 1
httpGet:
path: /healthz
port: 8080
periodSeconds: 5
resources:
limits:
cpu: 100m
memory: 64Mi
requests:
cpu: 50m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: config
readOnly: true
- mountPath: /tmp
name: tmp
terminationGracePeriodSeconds: 30
volumes:
- configMap:
name: backend
name: config
- emptyDir: {}
name: tmp
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kix.run/depends-on: lxi0gciwfx6mgp92319mjxhjwvgkdqhs,yypaq64gbsgsgvsqn44b31y2r4lcwrdv,requires:mkgdf3yajj0a92l7fspcy7ciykw4dsl1
kix.run/identity-hash: 2myic78xhppfhqhkv9xrrpcnrmsh89s2
kix.run/package: gateway
kix.run/package-namespace: app-v2
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/managed-by: kix
app.kubernetes.io/name: gateway
name: gateway
namespace: app-v2
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/name: gateway
template:
metadata:
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/name: gateway
spec:
containers:
- image: nginx:1.27-alpine
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 80
periodSeconds: 10
name: nginx
ports:
- containerPort: 80
name: http
protocol: TCP
readinessProbe:
httpGet:
path: /healthz
port: 80
periodSeconds: 5
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: config
readOnly: true
volumes:
- configMap:
name: gateway
name: config
---
apiVersion: kix.run/v1alpha1
kind: Activation
metadata:
annotations:
kix.run/built-via: /nix/store/jr65m3rbsmljs8r0klsq63n1f5czwllq-kix-activation-19-scorecards.json
kix.run/depends-on: 354i13x5hiwcmf6fkf8wdvyj4v3q78dc,4sq8laq4iq1acp2kfbc1jidw8h96hb2a,6f3b1011md1xifkrcmrrcby0wbpd6ryl,ivxy7wm88944y8sfgyhj4zniyhf2x9iz,mkgdf3yajj0a92l7fspcy7ciykw4dsl1,zmrfvwmay3n1g1awsp87krkmxwy9hlan
kix.run/identity-hash: q5h4i1ahy6885v4l1rq4bggvnii52ql4
kix.run/package: _cluster
kix.run/package-namespace: _cluster
labels:
app.kubernetes.io/managed-by: kix
kix.run/cluster: 19-scorecards
name: 19-scorecards-q5h4i1ahy688
spec:
instances:
app-v1:
backend: backend
gateway: gateway
app-v2:
backend: backend
gateway: gateway
kube-system:
platform-dns: platform-dns
platform-storage: platform-storage
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
annotations:
kix.run/depends-on: 95gmkzkbdf1k30pp3k54hp8vc8qd54p8,l0yvq498zywhzsr2mdcr0bkc5qq5hyai
kix.run/identity-hash: 354i13x5hiwcmf6fkf8wdvyj4v3q78dc
kix.run/package: _cluster
kix.run/package-namespace: _cluster
kix.run/root: backend
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/managed-by: kix
name: backend
namespace: app-v1
spec:
instanceName: backend
namespaceName: app-v1
package: echo-server
version: "1.30.6"
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
annotations:
kix.run/depends-on: 95gmkzkbdf1k30pp3k54hp8vc8qd54p8,m6k6gpzaqamfwzvbrxlyzy4k0d2r8l32
kix.run/identity-hash: 6f3b1011md1xifkrcmrrcby0wbpd6ryl
kix.run/package: _cluster
kix.run/package-namespace: _cluster
kix.run/root: gateway
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/managed-by: kix
name: gateway
namespace: app-v1
spec:
instanceName: gateway
namespaceName: app-v1
version: "0.0.2"
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
annotations:
kix.run/depends-on: cahr6h996w8b0wnzwhvjlgws2w2s1k4l,lxi0gciwfx6mgp92319mjxhjwvgkdqhs
kix.run/identity-hash: ivxy7wm88944y8sfgyhj4zniyhf2x9iz
kix.run/package: _cluster
kix.run/package-namespace: _cluster
kix.run/root: backend
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/managed-by: kix
name: backend
namespace: app-v2
spec:
instanceName: backend
namespaceName: app-v2
package: echo-server
version: "1.30.6"
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
annotations:
kix.run/depends-on: arf77cch4ssn5l6b27j3dj9w5g58fbar,lxi0gciwfx6mgp92319mjxhjwvgkdqhs
kix.run/identity-hash: zmrfvwmay3n1g1awsp87krkmxwy9hlan
kix.run/package: _cluster
kix.run/package-namespace: _cluster
kix.run/root: gateway
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/managed-by: kix
name: gateway
namespace: app-v2
spec:
instanceName: gateway
namespaceName: app-v2
version: "0.0.2"
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
annotations:
kix.run/depends-on: sj0fv5bs2hnh9zcqdh62ph34l2wm0b1m
kix.run/identity-hash: mkgdf3yajj0a92l7fspcy7ciykw4dsl1
kix.run/import-apiversion: v1
kix.run/import-fqdn: kube-dns.kube-system.svc.cluster.local
kix.run/import-kind: Service
kix.run/import-name: kube-dns
kix.run/mode: import
kix.run/package: _cluster
kix.run/package-namespace: _cluster
labels:
app.kubernetes.io/instance: platform-dns
app.kubernetes.io/managed-by: kix
name: platform-dns
namespace: kube-system
spec:
instanceName: platform-dns
mode: import
namespaceName: kube-system
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
annotations:
kix.run/depends-on: sj0fv5bs2hnh9zcqdh62ph34l2wm0b1m
kix.run/identity-hash: 4sq8laq4iq1acp2kfbc1jidw8h96hb2a
kix.run/import-apiversion: storage.k8s.io/v1
kix.run/import-kind: StorageClass
kix.run/import-name: standard
kix.run/mode: import
kix.run/package: _cluster
kix.run/package-namespace: _cluster
labels:
app.kubernetes.io/instance: platform-storage
app.kubernetes.io/managed-by: kix
name: platform-storage
namespace: kube-system
spec:
instanceName: platform-storage
mode: import
namespaceName: kube-system
---
apiVersion: v1
data:
default.conf: |
server {
listen 8080;
location / {
root /etc/nginx/conf.d;
default_type text/plain;
try_files /message.txt =404;
# nginx refuses a POST for a static file with 405. The
# redirect turns the request into a GET, so every
# method gets the message.
error_page 405 =200 /message.txt;
}
location /healthz {
default_type text/plain;
return 200 'ok\n';
}
}
message.txt: |
Response from app-v1
kind: ConfigMap
metadata:
annotations:
kix.run/depends-on: 95gmkzkbdf1k30pp3k54hp8vc8qd54p8
kix.run/identity-hash: q85cvsj44a56pxm9cx3naj0ywb4bnmcv
kix.run/package: backend
kix.run/package-namespace: app-v1
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/managed-by: kix
name: backend
namespace: app-v1
---
apiVersion: v1
data:
default.conf: |
server {
listen 80;
client_max_body_size 10m;
location /healthz {
default_type text/plain;
return 200 'ok\n';
}
location /v1/ {
proxy_pass http://backend.app-v1.svc.cluster.local:80/;
}
}
kind: ConfigMap
metadata:
annotations:
kix.run/depends-on: 95gmkzkbdf1k30pp3k54hp8vc8qd54p8,l0yvq498zywhzsr2mdcr0bkc5qq5hyai
kix.run/identity-hash: vz8jvwngqp8ac8synjqn2zcwpmc4ar9k
kix.run/package: gateway
kix.run/package-namespace: app-v1
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/managed-by: kix
name: gateway
namespace: app-v1
---
apiVersion: v1
data:
default.conf: |
server {
listen 8080;
location / {
root /etc/nginx/conf.d;
default_type text/plain;
try_files /message.txt =404;
# nginx refuses a POST for a static file with 405. The
# redirect turns the request into a GET, so every
# method gets the message.
error_page 405 =200 /message.txt;
}
location /healthz {
default_type text/plain;
return 200 'ok\n';
}
}
message.txt: |
Response from app-v2
kind: ConfigMap
metadata:
annotations:
kix.run/depends-on: lxi0gciwfx6mgp92319mjxhjwvgkdqhs
kix.run/identity-hash: 883jpjfxsaiclk52hbfgjnakw4im51hm
kix.run/package: backend
kix.run/package-namespace: app-v2
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/managed-by: kix
name: backend
namespace: app-v2
---
apiVersion: v1
data:
default.conf: |
server {
listen 80;
client_max_body_size 10m;
location /healthz {
default_type text/plain;
return 200 'ok\n';
}
location /v2/ {
proxy_pass http://backend.app-v2.svc.cluster.local:80/;
}
}
kind: ConfigMap
metadata:
annotations:
kix.run/depends-on: cahr6h996w8b0wnzwhvjlgws2w2s1k4l,lxi0gciwfx6mgp92319mjxhjwvgkdqhs
kix.run/identity-hash: yypaq64gbsgsgvsqn44b31y2r4lcwrdv
kix.run/package: gateway
kix.run/package-namespace: app-v2
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/managed-by: kix
name: gateway
namespace: app-v2
---
apiVersion: v1
kind: Namespace
metadata:
annotations:
kix.run/identity-hash: 95gmkzkbdf1k30pp3k54hp8vc8qd54p8
kix.run/package: _cluster
kix.run/package-namespace: _cluster
labels:
app.kubernetes.io/managed-by: kix
kubernetes.io/metadata.name: app-v1
name: app-v1
---
apiVersion: v1
kind: Namespace
metadata:
annotations:
kix.run/identity-hash: lxi0gciwfx6mgp92319mjxhjwvgkdqhs
kix.run/package: _cluster
kix.run/package-namespace: _cluster
labels:
app.kubernetes.io/managed-by: kix
kubernetes.io/metadata.name: app-v2
name: app-v2
---
apiVersion: v1
kind: Namespace
metadata:
annotations:
kix.run/identity-hash: sj0fv5bs2hnh9zcqdh62ph34l2wm0b1m
kix.run/package: _cluster
kix.run/package-namespace: _cluster
labels:
app.kubernetes.io/managed-by: kix
kubernetes.io/metadata.name: kube-system
name: kube-system
---
apiVersion: v1
kind: Service
metadata:
annotations:
kix.run/depends-on: 011nbqjvmaz0d3nrnq6w3dnv66pfwv1y,95gmkzkbdf1k30pp3k54hp8vc8qd54p8
kix.run/identity-hash: l0yvq498zywhzsr2mdcr0bkc5qq5hyai
kix.run/package: backend
kix.run/package-namespace: app-v1
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/managed-by: kix
name: backend
namespace: app-v1
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
selector:
app.kubernetes.io/instance: backend
app.kubernetes.io/name: backend
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
annotations:
kix.run/depends-on: 95gmkzkbdf1k30pp3k54hp8vc8qd54p8,fbrxkfz5xqd1ghkqw363hpvlba42v51s
kix.run/identity-hash: m6k6gpzaqamfwzvbrxlyzy4k0d2r8l32
kix.run/package: gateway
kix.run/package-namespace: app-v1
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/managed-by: kix
name: gateway
namespace: app-v1
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app.kubernetes.io/instance: gateway
app.kubernetes.io/name: gateway
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
annotations:
kix.run/depends-on: aj39j3ywdkqjcv333nygsj9ijcif6r29,lxi0gciwfx6mgp92319mjxhjwvgkdqhs
kix.run/identity-hash: cahr6h996w8b0wnzwhvjlgws2w2s1k4l
kix.run/package: backend
kix.run/package-namespace: app-v2
labels:
app.kubernetes.io/instance: backend
app.kubernetes.io/managed-by: kix
name: backend
namespace: app-v2
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
selector:
app.kubernetes.io/instance: backend
app.kubernetes.io/name: backend
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
annotations:
kix.run/depends-on: 2myic78xhppfhqhkv9xrrpcnrmsh89s2,lxi0gciwfx6mgp92319mjxhjwvgkdqhs
kix.run/identity-hash: arf77cch4ssn5l6b27j3dj9w5g58fbar
kix.run/package: gateway
kix.run/package-namespace: app-v2
labels:
app.kubernetes.io/instance: gateway
app.kubernetes.io/managed-by: kix
name: gateway
namespace: app-v2
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app.kubernetes.io/instance: gateway
app.kubernetes.io/name: gateway
type: ClusterIP Trigger The Package-Level Rule
Section titled “Trigger The Package-Level Rule”To make error-severity scorecard findings fail the build instead of being capped at "warning", first add maxSeverity = "error"; to tutorials/19-scorecards/scorecard.nix:
1{2 enable = true;3 maxSeverity = "error";4 # ...5}Next, open tutorials/19-scorecards/cluster.nix and comment out maxBodySize = "10m"; on the gateway in instances.app-v1 so it falls back to the "1m" default:
1gateway = {2 package = reverseProxyPackage;3 config = {4 proxyPath = "/v1/";5 # maxBodySize = "10m";6 };7 deps.backend = ref.app-v1.backend;8};Now run kix check 19-scorecards:
❱ kix check 19-scorecards Because custom.proxyMaxBodySizeMustBeExplicit has severity = "error" and scorecard.maxSeverity = "error" is set, evaluation fails and prints:
1[scorecard:custom.proxyMaxBodySizeMustBeExplicit] app-v1/gateway: instance 'gateway' uses the default maxBodySize '1m'. nginx rejects larger request bodies - set this explicitly.Uncomment maxBodySize = "10m"; in instances.app-v1.gateway.
Trigger The Cluster-Level Collision Rule
Section titled “Trigger The Cluster-Level Collision Rule”Next, in tutorials/19-scorecards/cluster.nix, change proxyPath in instances.app-v2.gateway from "/v2/" to "/v1/" so both namespaces claim "/v1/":
1instances.app-v2.gateway = {2 package = reverseProxyPackage;3 config = {4 proxyPath = "/v1/";5 maxBodySize = "10m";6 };7 deps.backend = ref.app-v2.backend;8};Run kix check 19-scorecards again:
❱ kix check 19-scorecards This time, custom.noProxyPathCollision catches the cross-namespace conflict at build time:
1[scorecard:custom.noProxyPathCollision] : 2 reverse-proxy gateways share proxyPath '/v1/': app-v1/gateway, app-v2/gatewayChange app-v2’s proxyPath back to "/v2/" and remove maxSeverity = "error"; from tutorials/19-scorecards/scorecard.nix so the example returns to its checked-in state, then run kix check 19-scorecards to verify the cluster passes again.
What You Learned
Section titled “What You Learned”You completed the 12-part Kix tutorial path:
-
scorecard.enable = trueruns compile-time policy checks across your cluster -
scorecard.maxSeverity("info","warning", or"error", defaulting to"warning") caps finding severity across the cluster, and settingmaxSeverity = "error"makes error-severity rules fail evaluation -
level = "package"rules inspect an individual instance’smeta,config, and resources without parsing rendered YAML strings -
level = "cluster"rules inspectallInstancesacross all namespaces to catch cross-instance collisions before deployment
Next Steps
Section titled “Next Steps”- Browse the How-to guides for step-by-step recipes on secrets, CRDs, Helm chart adoption, NetworkPolicies, and scorecard customization.
- Read the Explanation pages for deeper dives into the dependency graph, availability synthesis, NetworkPolicy derivation, and Server-Side Apply field ownership.
- Keep the Reference handy while authoring your own clusters and packages.