|
401 | 401 | kubectl -n tenant-test delete httproute route-hostname-allow-probe --ignore-not-found |
402 | 402 | } |
403 | 403 |
|
| 404 | +@test "cozystack-route-hostname-policy VAP matches the tenant apex case-insensitively" { |
| 405 | + # Defense-in-depth: the route hostname is DNS-1123 lowercase, but the apex |
| 406 | + # operand is the namespace.cozystack.io/host label VALUE, which Kubernetes |
| 407 | + # permits to carry uppercase. Under a mixed-case apex (Test.Example.Org), |
| 408 | + # a lowercase in-apex HTTPRoute (probe.test.example.org) must still be |
| 409 | + # ALLOWED — the VAP normalizes both operands with .lowerAscii(). Without |
| 410 | + # that normalization the VAP compares "probe.test.example.org" against apex |
| 411 | + # "Test.Example.Org" and wrongly denies a legitimate route, so this fails |
| 412 | + # pre-fix and passes post-fix. This is the only runtime shape that |
| 413 | + # exercises .lowerAscii(): an uppercase hostname on the route itself is |
| 414 | + # stripped by built-in DNS-1123 validation before the VAP ever runs. |
| 415 | + # |
| 416 | + # Use a throwaway tenant-* namespace with its own mixed-case apex rather |
| 417 | + # than relabelling the shared tenant-test namespace: an interrupted run or |
| 418 | + # a failed restore would otherwise leave tenant-test mixed-case and poison |
| 419 | + # every later test. The tenant-* prefix is required for the VAP's |
| 420 | + # matchCondition to fire; the CREATE with the host label is admitted |
| 421 | + # because the e2e identity is a trusted caller for the namespace host-label |
| 422 | + # immutability VAP. |
| 423 | + # Pre-clean a stale namespace left by an interrupted prior run (e2e convention). |
| 424 | + kubectl delete namespace tenant-case-probe --ignore-not-found --wait=true --timeout=60s |
| 425 | + kubectl apply -f - <<'EOF' |
| 426 | +apiVersion: v1 |
| 427 | +kind: Namespace |
| 428 | +metadata: |
| 429 | + name: tenant-case-probe |
| 430 | + labels: |
| 431 | + namespace.cozystack.io/host: Test.Example.Org |
| 432 | +EOF |
| 433 | + # Guard against a vacuous pass: the apex must actually be mixed-case. A |
| 434 | + # lowercase apex would admit the route regardless of the fix, and an absent |
| 435 | + # apex would deny it via the fail-closed nil-guard — either way the test |
| 436 | + # would stop proving case-insensitivity. |
| 437 | + apex=$(kubectl get namespace tenant-case-probe -o jsonpath='{.metadata.labels.namespace\.cozystack\.io/host}') |
| 438 | + if [ "$apex" != "Test.Example.Org" ]; then |
| 439 | + echo "SETUP FAILURE: tenant-case-probe apex is not mixed-case (got '$apex')" >&2 |
| 440 | + kubectl delete namespace tenant-case-probe --ignore-not-found --wait=false |
| 441 | + return 1 |
| 442 | + fi |
| 443 | + if output=$(kubectl apply -f - 2>&1 <<'EOF' |
| 444 | +apiVersion: gateway.networking.k8s.io/v1 |
| 445 | +kind: HTTPRoute |
| 446 | +metadata: |
| 447 | + name: route-hostname-case-probe |
| 448 | + namespace: tenant-case-probe |
| 449 | +spec: |
| 450 | + hostnames: |
| 451 | + - "probe.test.example.org" |
| 452 | + rules: |
| 453 | + - backendRefs: |
| 454 | + - name: kubernetes |
| 455 | + namespace: default |
| 456 | + port: 443 |
| 457 | +EOF |
| 458 | +); then |
| 459 | + kubectl delete namespace tenant-case-probe --ignore-not-found --wait=false |
| 460 | + else |
| 461 | + kubectl delete namespace tenant-case-probe --ignore-not-found --wait=false |
| 462 | + echo "BUG: VAP denied a lowercase in-apex HTTPRoute under a mixed-case apex — .lowerAscii() normalization missing or broken" >&2 |
| 463 | + echo "$output" >&2 |
| 464 | + return 1 |
| 465 | + fi |
| 466 | +} |
| 467 | + |
404 | 468 | @test "cozystack-ingress-hostname-policy VAP and binding are installed" { |
405 | 469 | # Legacy-Ingress counterpart of the gateway/route hostname VAPs. Gateway |
406 | 470 | # API is off by default, so tenant apps publish through a legacy |
|
667 | 731 | kubectl -n tenant-test delete ingress ingress-hostname-allow-probe --ignore-not-found |
668 | 732 | } |
669 | 733 |
|
| 734 | +@test "cozystack-ingress-hostname-policy VAP matches the tenant apex case-insensitively" { |
| 735 | + # Defense-in-depth: the Ingress rules[].host and tls[].hosts[] are DNS-1123 |
| 736 | + # lowercase, but the apex operand is the namespace.cozystack.io/host label |
| 737 | + # VALUE, which Kubernetes permits to carry uppercase. Under a mixed-case |
| 738 | + # apex (Test.Example.Org), a lowercase in-apex Ingress (rule host and tls |
| 739 | + # host both probe.test.example.org) must still be ALLOWED — the VAP |
| 740 | + # normalizes both operands with .lowerAscii(). Without that normalization |
| 741 | + # the VAP compares "probe.test.example.org" against apex "Test.Example.Org" |
| 742 | + # and wrongly denies a legitimate Ingress, so this fails pre-fix and passes |
| 743 | + # post-fix. Ingress is the default publish path (Gateway API is off by |
| 744 | + # default) and carries the most complex CEL (both the rule-host and tls-host |
| 745 | + # branches), so it gets its own runtime guard alongside the route test. |
| 746 | + # |
| 747 | + # Use a throwaway tenant-* namespace with its own mixed-case apex rather |
| 748 | + # than relabelling the shared tenant-test namespace: an interrupted run or |
| 749 | + # a failed restore would otherwise leave tenant-test mixed-case and poison |
| 750 | + # every later test. The tenant-* prefix is required for the VAP's |
| 751 | + # matchCondition to fire; the CREATE with the host label is admitted |
| 752 | + # because the e2e identity is a trusted caller for the namespace host-label |
| 753 | + # immutability VAP. |
| 754 | + # Pre-clean a stale namespace left by an interrupted prior run (e2e convention). |
| 755 | + kubectl delete namespace tenant-ingress-case-probe --ignore-not-found --wait=true --timeout=60s |
| 756 | + kubectl apply -f - <<'EOF' |
| 757 | +apiVersion: v1 |
| 758 | +kind: Namespace |
| 759 | +metadata: |
| 760 | + name: tenant-ingress-case-probe |
| 761 | + labels: |
| 762 | + namespace.cozystack.io/host: Test.Example.Org |
| 763 | +EOF |
| 764 | + # Guard against a vacuous pass: the apex must actually be mixed-case. A |
| 765 | + # lowercase apex would admit the Ingress regardless of the fix, and an |
| 766 | + # absent apex would deny it via the fail-closed nil-guard. |
| 767 | + apex=$(kubectl get namespace tenant-ingress-case-probe -o jsonpath='{.metadata.labels.namespace\.cozystack\.io/host}') |
| 768 | + if [ "$apex" != "Test.Example.Org" ]; then |
| 769 | + echo "SETUP FAILURE: tenant-ingress-case-probe apex is not mixed-case (got '$apex')" >&2 |
| 770 | + kubectl delete namespace tenant-ingress-case-probe --ignore-not-found --wait=false |
| 771 | + return 1 |
| 772 | + fi |
| 773 | + if output=$(kubectl apply -f - 2>&1 <<'EOF' |
| 774 | +apiVersion: networking.k8s.io/v1 |
| 775 | +kind: Ingress |
| 776 | +metadata: |
| 777 | + name: ingress-hostname-case-probe |
| 778 | + namespace: tenant-ingress-case-probe |
| 779 | +spec: |
| 780 | + tls: |
| 781 | + - hosts: |
| 782 | + - "probe.test.example.org" |
| 783 | + secretName: noop-tls |
| 784 | + rules: |
| 785 | + - host: "probe.test.example.org" |
| 786 | + http: |
| 787 | + paths: |
| 788 | + - path: / |
| 789 | + pathType: Prefix |
| 790 | + backend: |
| 791 | + service: |
| 792 | + name: noop |
| 793 | + port: |
| 794 | + number: 80 |
| 795 | +EOF |
| 796 | +); then |
| 797 | + kubectl delete namespace tenant-ingress-case-probe --ignore-not-found --wait=false |
| 798 | + else |
| 799 | + kubectl delete namespace tenant-ingress-case-probe --ignore-not-found --wait=false |
| 800 | + echo "BUG: VAP denied a lowercase in-apex Ingress under a mixed-case apex — .lowerAscii() normalization missing or broken" >&2 |
| 801 | + echo "$output" >&2 |
| 802 | + return 1 |
| 803 | + fi |
| 804 | +} |
| 805 | + |
670 | 806 | @test "cozystack-ingress-hostname-policy VAP allows an Ingress host outside the platform root apex" { |
671 | 807 | # Narrow rule: a tenant may route its own domain that lies entirely |
672 | 808 | # outside the platform root apex (example.org). This is the path the |
|
0 commit comments