#!/usr/bin/env bash # T95: istio/gateway 차트 values의 securityContext.sysctls가 # sidecar injector webhook(gateway 주입 템플릿)에 의해 덮어써지는지 검증 # 환경: Istio 1.30.0 (istiod + gateway chart, helm repo istio) / k8s 1.30.6 # 결과: result.txt / 판정: verdict.json set -euo pipefail NS=istio-vt-t95 # --- C1·C2: 커스텀 sysctls(safe 2종)로 gateway 배포, webhook 통과 전/후 비교 --- kubectl create ns $NS helm install t95-gw istio/gateway --version 1.30.0 -n $NS -f t95-gateway-values.yaml kubectl -n $NS wait --for=condition=ready pod -l app.kubernetes.io/instance=t95-gw --timeout=90s echo "## C1: Deployment(webhook 전) securityContext — values의 sysctl 2종이 렌더링돼 있어야 함" kubectl -n $NS get deploy t95-gw -o jsonpath='{.spec.template.spec.securityContext}' echo "## C2: 최종 pod(webhook 후) securityContext — 주입 템플릿 값으로 통째 교체됐는지" kubectl -n $NS get pod -l app.kubernetes.io/instance=t95-gw -o jsonpath='{.items[0].spec.securityContext}' echo "## C2b: pod 내부 /proc — ip_local_port_range가 커널 기본값이면 미적용 확정" kubectl -n $NS exec deploy/t95-gw -- \ cat /proc/sys/net/ipv4/ip_local_port_range /proc/sys/net/ipv4/ip_unprivileged_port_start # --- 근거: 주입 템플릿이 pod-level securityContext를 무조건 렌더링 (istiod 차트 원본) --- helm pull istio/istiod --version 1.30.0 --untar -d /tmp/t95-chart sed -n '17,26p' /tmp/t95-chart/istiod/files/gateway-injection-template.yaml # 주입 시점 분기 입력은 injector configmap의 data.values (helm 시점 아님): kubectl -n istio-system get cm istio-sidecar-injector -o jsonpath='{.data.values}' \ | python3 -c "import sys,json; print(json.load(sys.stdin).get('gateways'))" # --- C3(렌더링 검증): 실효 주입 지점 = istiod values gateways.securityContext --- helm get values istiod -n istio-system -o yaml > /tmp/t95-istiod-values-backup.yaml helm template istiod istio/istiod --version 1.30.0 -n istio-system \ -f /tmp/t95-istiod-values-backup.yaml -f t95-istiod-fix-values.yaml \ | python3 -c " import sys, yaml, json for d in yaml.safe_load_all(sys.stdin): if d and d.get('kind')=='ConfigMap' and 'injector' in d['metadata']['name']: vals = json.loads(d['data']['values']) print('gateways.securityContext:', json.dumps(vals['gateways']['securityContext'])) print('분기 존재:', '.Values.gateways.securityContext' in d['data']['config']) " # --- C3 클러스터 확정 (T95에선 미실행 — 공유 컨트롤플레인 변경이라 승인 필요) --- # helm upgrade istiod istio/istiod -n istio-system --version 1.30.0 \ # -f /tmp/t95-istiod-values-backup.yaml -f t95-istiod-fix-values.yaml # kubectl -n $NS rollout restart deploy/t95-gw # webhook은 pod 생성 시점에만 개입 # kubectl -n $NS get pod -l app.kubernetes.io/instance=t95-gw -o jsonpath='{.items[0].spec.securityContext}' # 원복: helm upgrade istiod istio/istiod -n istio-system --version 1.30.0 -f /tmp/t95-istiod-values-backup.yaml # --- 정리 --- helm uninstall t95-gw -n $NS kubectl delete ns $NS