From c0f48a71e82f3ed5980ed45c731bf0635f5e26ad Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:43:54 +0000 Subject: [PATCH 1/2] =?UTF-8?q?feature:=20baseline=20de=20seguran=C3=A7a?= =?UTF-8?q?=20GKE=20(s5.4):=20PSS=20restricted,=20actuator=20restrito,=20G?= =?UTF-8?q?ateway=20s=C3=B3=20HTTPS=20com=20SSL=20policy=20TLS=201.2+,=20v?= =?UTF-8?q?erify-security-baseline.sh=20no=20kind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Matthew Guerra --- ci/kind/backing-services.yaml | 32 ++++ ci/kind/setup.sh | 27 ++- ci/kind/values-kind-gateway.yaml | 2 + ci/kind/verify-helm-smoke.sh | 19 +- ci/kind/verify-security-baseline.sh | 167 ++++++++++++++++++ deploy/helm/axon-trader/README.md | 7 +- .../helm/axon-trader/templates/gateway.yaml | 29 +++ .../helm/axon-trader/templates/httproute.yaml | 15 ++ deploy/helm/axon-trader/values.yaml | 4 + docs/migration/security-baseline.md | 50 ++++++ .../components/cluster-env/kustomization.yaml | 4 + .../components/rabbitmq/rabbitmqcluster.yaml | 26 +++ infra/k8s/overlays/prod/cluster.env.example | 1 + infra/k8s/overlays/prod/kustomization.yaml | 1 - .../k8s/overlays/staging/cluster.env.example | 1 + infra/k8s/platform/gateway.yaml | 14 ++ infra/k8s/platform/namespace.yaml | 5 +- infra/k8s/scripts/validate.sh | 2 +- infra/terraform/envs/prod/outputs.tf | 1 + infra/terraform/envs/staging/outputs.tf | 1 + infra/terraform/modules/gke-platform/main.tf | 10 ++ .../terraform/modules/gke-platform/outputs.tf | 5 + .../tests/gke_platform.tftest.hcl | 5 + .../src/main/resources/application.properties | 3 +- .../src/main/resources/application.properties | 3 +- 25 files changed, 410 insertions(+), 24 deletions(-) create mode 100755 ci/kind/verify-security-baseline.sh create mode 100644 docs/migration/security-baseline.md diff --git a/ci/kind/backing-services.yaml b/ci/kind/backing-services.yaml index 3fb6de5..051f1db 100644 --- a/ci/kind/backing-services.yaml +++ b/ci/kind/backing-services.yaml @@ -13,6 +13,14 @@ spec: metadata: labels: {app.kubernetes.io/name: mysql} spec: + # Pod Security Standard `restricted` (setup.sh labels the kind namespace enforce=restricted, as on GKE). + securityContext: + runAsNonRoot: true + runAsUser: 999 + runAsGroup: 999 + fsGroup: 999 + seccompProfile: + type: RuntimeDefault containers: - name: mysql image: mysql:5.7 @@ -30,11 +38,18 @@ spec: exec: command: ["sh", "-c", "mysql -uroot -p\"$MYSQL_ROOT_PASSWORD\" -e 'select 1' enginedb"] periodSeconds: 5 + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] volumeMounts: - {name: initdb, mountPath: /docker-entrypoint-initdb.d, readOnly: true} + - {name: data, mountPath: /var/lib/mysql} volumes: - name: initdb configMap: {name: mysql-initdb} + - name: data + emptyDir: {} --- apiVersion: v1 kind: Service @@ -59,6 +74,14 @@ spec: metadata: labels: {app.kubernetes.io/name: rabbitmq} spec: + # Pod Security Standard `restricted` (setup.sh labels the kind namespace enforce=restricted, as on GKE). + securityContext: + runAsNonRoot: true + runAsUser: 999 + runAsGroup: 999 + fsGroup: 999 + seccompProfile: + type: RuntimeDefault containers: - name: rabbitmq image: rabbitmq:3.7-management @@ -75,6 +98,15 @@ spec: command: ["rabbitmq-diagnostics", "-q", "ping"] periodSeconds: 10 timeoutSeconds: 10 + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] + volumeMounts: + - {name: data, mountPath: /var/lib/rabbitmq} + volumes: + - name: data + emptyDir: {} --- apiVersion: v1 kind: Service diff --git a/ci/kind/setup.sh b/ci/kind/setup.sh index f56bd17..dfdc482 100644 --- a/ci/kind/setup.sh +++ b/ci/kind/setup.sh @@ -1,4 +1,4 @@ -# Sourced by verify-axon-routing.sh, verify-helm-smoke.sh and verify-deploy-rollback.sh (expects CLUSTER, NS, k and fail from the caller). +# Sourced by verify-axon-routing.sh, verify-helm-smoke.sh, verify-deploy-rollback.sh and verify-security-baseline.sh (expects CLUSTER, NS, k and fail from the caller). # kind_setup: kind cluster, local images, throwaway Secrets, the MySQL/RabbitMQ stand-ins (ci/kind/kustomization.yaml), # then `helm upgrade --install` of deploy/helm/axon-trader with ci/kind/values-kind.yaml. With ESARCH_KIND_GATEWAY=1 # it also installs Envoy Gateway and renders the chart's Gateway + HTTPRoute (ci/kind/values-kind-gateway.yaml). @@ -24,6 +24,9 @@ kind_cluster() { fi done kubectl --context "kind-$CLUSTER" create namespace "$NS" --dry-run=client -o yaml | kubectl --context "kind-$CLUSTER" apply -f - >/dev/null + # Same Pod Security Standard as infra/k8s/platform/namespace.yaml: anything not `restricted` is rejected at admission. + kubectl --context "kind-$CLUSTER" label namespace "$NS" --overwrite pod-security.kubernetes.io/enforce=restricted \ + pod-security.kubernetes.io/enforce-version=v1.33 pod-security.kubernetes.io/warn=restricted >/dev/null local mysql_password rabbitmq_password app mysql_password=$(openssl rand -hex 16) rabbitmq_password=$(openssl rand -hex 16) @@ -75,6 +78,28 @@ YAML kind_setup() { kind_cluster; kind_install; } +# kind_probe : curl from a throwaway pod (restricted securityContext) carrying that +# app label. Blocked means curl timed out (exit 28) without ever connecting (time_connect 0), i.e. a NetworkPolicy +# dropped the SYN; anything else (HTTP status, a protocol error from MySQL/AMQP, or a response timeout after the +# connect) means the TCP connection was accepted. Prints "blocked" or "open(rc=N)". +kind_probe() { + local labels="esarch-probe=1" + [ "$2" != - ] && labels="$labels,app.kubernetes.io/name=$2" + k run "np-$1" --image=curlimages/curl:8.16.0 --image-pull-policy=IfNotPresent --restart=Never --labels="$labels" \ + --dry-run=client -o json \ + --command -- sh -c "t=\$(curl -s -o /dev/null -w '%{time_connect}' --connect-timeout 5 -m 8 http://$3:$4/); echo rc=\$? connect=\$t" | + jq '.spec.automountServiceAccountToken = false + | .spec.securityContext = {runAsNonRoot: true, runAsUser: 100, runAsGroup: 101, seccompProfile: {type: "RuntimeDefault"}} + | .spec.containers[0].securityContext = {allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, capabilities: {drop: ["ALL"]}}' | + k apply -f - >/dev/null + k wait --for=jsonpath='{.status.phase}'=Succeeded "pod/np-$1" --timeout=120s >/dev/null || true + local out rc connect + out=$(k logs "np-$1" | grep '^rc=' || true) + rc=$(sed -n 's/^rc=\([0-9]*\).*/\1/p' <<<"$out"); connect=$(sed -n 's/.*connect=//p' <<<"$out") + k delete pod "np-$1" --wait=false >/dev/null + if [ "$rc" = 28 ] && [ "${connect:-0}" = 0.000000 ]; then echo blocked; else echo "open(rc=$rc)"; fi +} + # Eureka helpers (need EUREKA_URL, jq and fail()). registry() { curl -sf -H 'Accept: application/json' "$EUREKA_URL/eureka/apps" | jq -r ' diff --git a/ci/kind/values-kind-gateway.yaml b/ci/kind/values-kind-gateway.yaml index 0fcc061..85cc632 100644 --- a/ci/kind/values-kind-gateway.yaml +++ b/ci/kind/values-kind-gateway.yaml @@ -5,6 +5,8 @@ route: parentRefs: - name: axon-trader sectionName: http + # kind has no certificate: the stand-in Gateway is HTTP-only, so no HSTS (GKE serves the app on HTTPS only). + hsts: "" gateway: create: true className: envoy-gateway diff --git a/ci/kind/verify-helm-smoke.sh b/ci/kind/verify-helm-smoke.sh index e65d791..7b69733 100755 --- a/ci/kind/verify-helm-smoke.sh +++ b/ci/kind/verify-helm-smoke.sh @@ -65,27 +65,12 @@ appURL=http://localhost:$APP_PORT engineURL=http://localhost:$ENGINE_PORT proxyU bash ci/local/verify-local.sh echo "== 3. NetworkPolicies" -# probe : curl from a throwaway pod carrying that label. Blocked means curl timed -# out (exit 28) without ever connecting (time_connect 0), i.e. the policy dropped the SYN; anything else (HTTP status, -# a protocol error from MySQL/AMQP, or a response timeout after the connect) means the TCP connection was accepted. -# Hosts are ClusterIPs so the result does not depend on DNS egress. +# Probe pods borrow the apps' labels (kind_probe in setup.sh). Hosts are ClusterIPs so the result does not depend on DNS egress. ip() { k get svc "$1" -o jsonpath='{.spec.clusterIP}'; } -probe() { - local labels="esarch-probe=1" - [ "$2" != - ] && labels="$labels,app.kubernetes.io/name=$2" - k run "np-$1" --image=curlimages/curl:8.16.0 --image-pull-policy=IfNotPresent --restart=Never --labels="$labels" \ - --command -- sh -c "t=\$(curl -s -o /dev/null -w '%{time_connect}' --connect-timeout 5 -m 8 http://$3:$4/); echo rc=\$? connect=\$t" >/dev/null - k wait --for=jsonpath='{.status.phase}'=Succeeded "pod/np-$1" --timeout=120s >/dev/null || true - local out rc connect - out=$(k logs "np-$1" | grep '^rc=' || true) - rc=$(sed -n 's/^rc=\([0-9]*\).*/\1/p' <<<"$out"); connect=$(sed -n 's/.*connect=//p' <<<"$out") - k delete pod "np-$1" --wait=false >/dev/null - if [ "$rc" = 28 ] && [ "${connect:-0}" = 0.000000 ]; then echo blocked; else echo "open(rc=$rc)"; fi -} status=0 src() { if [ "$1" = - ]; then echo 'unlabelled pod'; else echo "$1 pod"; fi; } expect() { # want name label service port - local got; got=$(probe "$2" "$3" "$(ip "$4")" "$5") + local got; got=$(kind_probe "$2" "$3" "$(ip "$4")" "$5") if [ "${got%%(*}" = "$1" ]; then echo "OK $2: $(src "$3") -> $4:$5 $got" else echo "FAIL $2: $(src "$3") -> $4:$5 $got (want $1)" >&2; status=1; fi } diff --git a/ci/kind/verify-security-baseline.sh b/ci/kind/verify-security-baseline.sh new file mode 100755 index 0000000..9ab08ce --- /dev/null +++ b/ci/kind/verify-security-baseline.sh @@ -0,0 +1,167 @@ +#!/usr/bin/env bash +# s5.4 security baseline for deploy/helm/axon-trader on kind (the GKE staging re-check is separate and still owed): +# 1. Pod Security Standard: the namespace enforces `restricted` (setup.sh, as infra/k8s/platform/namespace.yaml); +# a server-side dry run reports no violating pod, a root pod is rejected, every container runs as a non-zero uid; +# 2. NetworkPolicies: blocked curls from throwaway pods (unlabelled, trader-ui, discovery-server, trader-app -> trader-ui) +# next to the allowed s3.5 flows; egress to a policy-free target and the internet is reported (kind CNI); +# 3. credentials: the Secret values generated for this run appear nowhere in the Helm values, the rendered +# manifests, ConfigMaps or pod specs (only secretKeyRef/envFrom), nor in the images' config; +# 4. actuator: through the Gateway nothing under /actuator or /api/actuator is served; in-cluster only +# health/info/prometheus (+ data-initializer on trader-app) are exposed, env/beans/heapdump answer 404; +# 5. HTTPS-only (static): the staging/prod chart and the platform Gateway serve the app on HTTPS only, HTTP +# listeners only 301 to HTTPS, HSTS is set and a TLS 1.2+ SSL policy is attached. +# Build the images first (see verify-axon-routing.sh). Needs docker, kind, kubectl, helm, kustomize and jq. +# ESARCH_KIND_KEEP=1 keeps the cluster afterwards. Never touches GCP or TAS. +set -euo pipefail +cd "$(dirname "$0")/../.." + +CLUSTER=${ESARCH_KIND_CLUSTER:-esarch-sec} +NS=axon-trader +LOGS=${ESARCH_LOGS:-/tmp/esarch-kind-sec} +APP_PORT=${ESARCH_APP_PORT:-18080} +ENGINE_PORT=${ESARCH_ENGINE_PORT:-18081} +GATEWAY_PORT=${ESARCH_GATEWAY_PORT:-18088} +mkdir -p "$LOGS" +k() { kubectl --context "kind-$CLUSTER" -n "$NS" "$@"; } +PIDS=() +cleanup() { + for p in "${PIDS[@]:-}"; do [ -n "$p" ] && { pkill -P "$p"; kill "$p"; } 2>/dev/null || true; done + k delete pod -l esarch-probe=1 --ignore-not-found --wait=false >/dev/null 2>&1 || true + if [ "${ESARCH_KIND_KEEP:-0}" != 1 ]; then kind delete cluster --name "$CLUSTER" >/dev/null 2>&1 || true; fi +} +trap cleanup EXIT +fail() { echo "FAIL: $*" >&2; exit 1; } +status=0 +check() { if [ "$1" = ok ]; then echo "OK $2"; else echo "FAIL $2" >&2; status=1; fi; } +APPS="discovery-server trading-engine trader-app trader-ui" + +echo "== 0. kind cluster, stand-ins, Envoy Gateway and the axon-trader Helm chart" +# shellcheck source=ci/kind/setup.sh +. ci/kind/setup.sh +ESARCH_KIND_GATEWAY=1 kind_setup +k wait --for=condition=Accepted gateway/axon-trader --timeout=300s >/dev/null +kubectl --context "kind-$CLUSTER" -n envoy-gateway-system wait --for=condition=Available deploy \ + -l gateway.envoyproxy.io/owning-gateway-name=axon-trader --timeout=300s >/dev/null + +echo "== 1. Pod Security Standard restricted" +kubectl --context "kind-$CLUSTER" get ns "$NS" -o json | jq -c '.metadata.labels | with_entries(select(.key | startswith("pod-security")))' +[ "$(kubectl --context "kind-$CLUSTER" get ns "$NS" -o jsonpath='{.metadata.labels.pod-security\.kubernetes\.io/enforce}')" = restricted ] && + check ok "namespace enforces restricted" || check fail "namespace does not enforce restricted" +warn=$(kubectl --context "kind-$CLUSTER" label --dry-run=server --overwrite ns "$NS" pod-security.kubernetes.io/enforce=restricted 2>&1 | grep -i warning || true) +[ -z "$warn" ] && check ok "dry-run enforce=restricted: no running pod violates it" || { echo "$warn"; check fail "pods violate restricted"; } +root_out=$(k run psa-root-probe --image=curlimages/curl:8.16.0 --restart=Never --overrides='{"spec":{"securityContext":{"runAsUser":0}}}' --command -- true 2>&1 || true) +k delete pod psa-root-probe --ignore-not-found --wait=false >/dev/null 2>&1 +grep -q 'violates PodSecurity "restricted' <<<"$root_out" && check ok "root pod rejected: $(grep -o 'violates PodSecurity[^:]*' <<<"$root_out")" || + { echo "$root_out"; check fail "root pod was not rejected"; } +for d in $APPS mysql rabbitmq; do + uid=$(k exec "deploy/$d" -c "$(k get deploy "$d" -o jsonpath='{.spec.template.spec.containers[0].name}')" -- id -u) + [ "$uid" != 0 ] && check ok "$d runs as uid $uid" || check fail "$d runs as root" +done +k get pods -o json | jq -r '.items[] | .metadata.name as $p | .spec.containers[] | + "\($p)/\(.name) runAsNonRoot=\(.securityContext.runAsNonRoot // "pod") readOnlyRootFilesystem=\(.securityContext.readOnlyRootFilesystem // false) caps.drop=\(.securityContext.capabilities.drop // [] | join(","))"' | + grep -v '^np-' + +echo "== 2. NetworkPolicies (blocked = no TCP connect within 5 s)" +ip() { k get svc "$1" -o jsonpath='{.spec.clusterIP}'; } +expect() { # want name label host port + local got; got=$(kind_probe "$2" "$3" "$4" "$5") + [ "${got%%(*}" = "$1" ] && check ok "$2: ${3/#-/unlabelled} pod -> $4:$5 $got" || check fail "$2: ${3/#-/unlabelled} pod -> $4:$5 $got (want $1)" +} +expect open app-to-engine trader-app "$(ip trading-engine)" 8080 +expect open app-to-rabbitmq trader-app "$(ip rabbitmq)" 5672 +expect open engine-to-mysql trading-engine "$(ip mysql)" 3306 +expect blocked other-to-app - "$(ip trader-app)" 8080 +expect blocked other-to-engine - "$(ip trading-engine)" 8080 +expect blocked other-to-mysql - "$(ip mysql)" 3306 +expect blocked other-to-ui - "$(ip trader-ui)" 8080 +expect blocked ui-to-app trader-ui "$(ip trader-app)" 8080 +expect blocked ui-to-rabbitmq trader-ui "$(ip rabbitmq)" 5672 +expect blocked eureka-to-engine discovery-server "$(ip trading-engine)" 8080 +expect blocked app-to-ui trader-app "$(ip trader-ui)" 8080 +# Egress allow-list: a target pod in a namespace without NetworkPolicies, and an internet address. kindnet +# (kube-network-policies) enforces the ingress rules above but on some hosts lets egress through, so these are +# reported, not gated; the egress deny has to be shown on GKE Dataplane V2 (live staging re-check). +kubectl --context "kind-$CLUSTER" create namespace np-egress-target --dry-run=client -o yaml | kubectl --context "kind-$CLUSTER" apply -f - >/dev/null +kubectl --context "kind-$CLUSTER" -n np-egress-target run egress-target --image=esarch/trader-ui:latest --image-pull-policy=Never \ + --port=8080 --dry-run=client -o json | + jq '.spec.securityContext = {runAsNonRoot: true, runAsUser: 101, seccompProfile: {type: "RuntimeDefault"}} + | .spec.containers[0].securityContext = {allowPrivilegeEscalation: false, capabilities: {drop: ["ALL"]}}' | + kubectl --context "kind-$CLUSTER" apply -f - >/dev/null +kubectl --context "kind-$CLUSTER" -n np-egress-target expose pod egress-target --port=8080 --dry-run=client -o yaml | + kubectl --context "kind-$CLUSTER" apply -f - >/dev/null +kubectl --context "kind-$CLUSTER" -n np-egress-target wait --for=condition=Ready pod/egress-target --timeout=120s >/dev/null +target=$(kubectl --context "kind-$CLUSTER" -n np-egress-target get svc egress-target -o jsonpath='{.spec.clusterIP}') +expect open other-to-target - "$target" 8080 +for a in trader-app trading-engine discovery-server trader-ui; do + echo "INFO $a pod -> egress-target:8080 $(kind_probe "$a-tgt" "$a" "$target" 8080) (want blocked; kind CNI egress, re-check on GKE)" +done +for a in trader-app trader-ui; do + echo "INFO $a pod -> 1.1.1.1:80 $(kind_probe "$a-net" "$a" 1.1.1.1 80) (want blocked; kind CNI egress, re-check on GKE)" +done +kubectl --context "kind-$CLUSTER" delete namespace np-egress-target --wait=false >/dev/null + +echo "== 3. No credentials in Helm values, manifests, ConfigMaps, pod specs or images" +secrets=$(k get secret backing-credentials trader-app-secrets trading-engine-secrets -o json | jq -r '.items[].data[] | @base64d' | sort -u) +leak() { local f=$1 s; while read -r s; do [ -n "$s" ] && grep -qF "$s" "$f" && return 0; done <<<"$secrets"; return 1; } +helm --kube-context "kind-$CLUSTER" -n "$NS" get values axon-trader --all -o yaml >"$LOGS/values.yaml" +helm --kube-context "kind-$CLUSTER" -n "$NS" get manifest axon-trader >"$LOGS/manifest.yaml" +k get configmap,deploy -o yaml >"$LOGS/objects.yaml" +for f in values.yaml manifest.yaml objects.yaml; do + leak "$LOGS/$f" && check fail "a generated credential appears in $f" || check ok "no credential in $f ($(wc -l <"$LOGS/$f") lines)" +done +literal=$(k get deploy -o json | jq -r '.items[] | .metadata.name as $d | .spec.template.spec.containers[].env[]? | + select((.name | test("PASS|SECRET|TOKEN|KEY|CREDENTIAL"; "i")) and has("value")) | "\($d) \(.name)"') +[ -z "$literal" ] && check ok "credential-like env vars only come from secretKeyRef/envFrom" || check fail "literal credential env: $literal" +for app in $APPS; do + docker image inspect "esarch/$app:latest" --format '{{json .Config.Env}} {{json .Config.Labels}}' >"$LOGS/image-$app.json" + grep -qiE 'password|secret|token|apikey' "$LOGS/image-$app.json" && check fail "esarch/$app image config mentions a credential" || + check ok "esarch/$app image env/labels hold no credential" +done + +echo "== 4. Actuator exposure" +envoy_svc=$(kubectl --context "kind-$CLUSTER" -n envoy-gateway-system get svc \ + -l gateway.envoyproxy.io/owning-gateway-name=axon-trader,gateway.envoyproxy.io/owning-gateway-namespace="$NS" \ + -o jsonpath='{.items[0].metadata.name}') +kubectl --context "kind-$CLUSTER" -n envoy-gateway-system port-forward "svc/$envoy_svc" "$GATEWAY_PORT:80" >"$LOGS/pf-gateway.log" 2>&1 & PIDS+=($!) +k port-forward svc/trader-app "$APP_PORT:8080" >"$LOGS/pf-app.log" 2>&1 & PIDS+=($!) +k port-forward svc/trading-engine "$ENGINE_PORT:8080" >"$LOGS/pf-engine.log" 2>&1 & PIDS+=($!) +sleep 4 +code() { curl -s -o "$LOGS/body" -w '%{http_code}' -m 10 "$@"; } +for path in /actuator/env /actuator/health /api/actuator/env /api/actuator/health /api/actuator/heapdump \ + /api/command/../actuator/env /api/query/..%2factuator/env /api/command/actuator/env; do + c=$(code --path-as-is "http://localhost:$GATEWAY_PORT$path") + # trader-ui answers unknown paths with the SPA index (200 text/html) and /api/* with 404; neither is actuator JSON. + grep -q '"propertySources"\|"_links"\|"status":"UP"' "$LOGS/body" && check fail "Gateway $path -> $c serves actuator" || + check ok "Gateway $path -> $c (not actuator)" +done +for t in "trader-app $APP_PORT health:200 info:200 prometheus:200 env:404 beans:404 heapdump:404 configprops:404 loggers:404 mappings:404" \ + "trading-engine $ENGINE_PORT health:200 info:200 prometheus:200 env:404 beans:404 heapdump:404 configprops:404 loggers:404 mappings:404"; do + set -- $t; app=$1 port=$2; shift 2 + exposed=$(curl -s -m 10 "http://localhost:$port/actuator" | jq -r '._links | keys | map(select(. != "self")) | join(",")') + echo " $app (in-cluster) /actuator links: $exposed" + for e in "$@"; do + c=$(code "http://localhost:$port/actuator/${e%%:*}") + [ "$c" = "${e##*:}" ] && check ok "$app in-cluster /actuator/${e%%:*} -> $c" || check fail "$app in-cluster /actuator/${e%%:*} -> $c (want ${e##*:})" + done +done + +echo "== 5. HTTPS-only (rendered staging/prod chart and platform Gateway)" +H=deploy/helm/axon-trader +for env in staging prod; do + out=$(helm template axon-trader "$H" -f "$H/values-$env.yaml") + routes=$(grep -A3 'parentRefs:' <<<"$out") + grep -q 'sectionName: https$' <<<"$routes" && ! grep -q 'sectionName: http$' <<<"$routes" && + check ok "$env: app HTTPRoute attaches to the https listener only" || check fail "$env: app HTTPRoute not HTTPS-only" + grep -q 'name: Strict-Transport-Security' <<<"$out" && check ok "$env: HSTS set on routed responses" || check fail "$env: no HSTS" + out=$(helm template axon-trader "$H" -f "$H/values-$env.yaml" --set gateway.create=true) + grep -q 'axon-trader-http-to-https' <<<"$out" && grep -q 'statusCode: 301' <<<"$out" && + check ok "$env: chart-owned Gateway redirects its HTTP listener (301)" || check fail "$env: chart-owned Gateway serves plain HTTP" +done +plat=$(kustomize build infra/k8s/platform) +grep -q 'sectionName: http$' <<<"$plat" && grep -q 'statusCode: 301' <<<"$plat" && check ok "platform Gateway: HTTP listener only 301s to HTTPS" || + check fail "platform Gateway: no HTTP->HTTPS redirect" +grep -q 'kind: GCPGatewayPolicy' <<<"$plat" && grep -q 'sslPolicy:' <<<"$plat" && check ok "platform Gateway: SSL policy attached (Terraform: MODERN, TLS 1.2+)" || + check fail "platform Gateway: no SSL policy" + +[ "$status" = 0 ] || fail "security baseline checks failed" +echo "PASS: restricted PSS, NetworkPolicy denials, no credentials, actuator internal-only, HTTPS-only Gateway config" diff --git a/deploy/helm/axon-trader/README.md b/deploy/helm/axon-trader/README.md index f23f4fa..4776d4d 100644 --- a/deploy/helm/axon-trader/README.md +++ b/deploy/helm/axon-trader/README.md @@ -34,7 +34,9 @@ chart. `/` goes to `trader-ui`; `/api/command/*` and `/api/query/*` go to `trader-app` with `/api` stripped, the same contract as `docker/local-proxy`. Other `/api` paths fall through to nginx, which answers 404, so `/actuator` stays cluster-internal (CHG-12). `GCPBackendPolicy` gives `trader-app` a 3600 s backend timeout for the order-book SSE -stream; `HealthCheckPolicy` points the load balancer at `/actuator/health` and `/healthz`. +stream; `HealthCheckPolicy` points the load balancer at `/actuator/health` and `/healthz`. `route.hsts` sets +`Strict-Transport-Security` on every routed response; with `gateway.create: true` the HTTP listener only redirects +to HTTPS (`gateway.httpsRedirect`). ## NetworkPolicies (TAS NET-1, NET-2) @@ -63,6 +65,9 @@ never matches. The engine Deployment uses `strategy: Recreate` so a rollout neve staging, prod and kind values (CI: `.github/workflows/helm.yml`). - `ci/kind/verify-helm-smoke.sh`: installs the chart on kind with MySQL/RabbitMQ stand-ins and Envoy Gateway, runs the Postman smoke collection and the UI/Gateway checks (`ci/local/verify-local.sh`), then probes the NetworkPolicies. +- `ci/kind/verify-security-baseline.sh`: the s5.4 security baseline on kind (namespace `enforce=restricted`, blocked + NetworkPolicy curls, no credentials in values/manifests/images, actuator internal-only, HTTPS-only Gateway config); + findings in `docs/migration/security-baseline.md`. - `ci/kind/verify-axon-routing.sh`: Axon command routing over Eureka with two replicas per app, on the same chart. - `ci/kind/verify-deploy-rollback.sh`: the staging deploy logic (`ci/deploy/helm-deploy.sh`, run by `.github/workflows/deploy-staging.yml`) on kind: upgrade, rollout wait, newman smoke and e2e pass, then a crash-looping diff --git a/deploy/helm/axon-trader/templates/gateway.yaml b/deploy/helm/axon-trader/templates/gateway.yaml index 7871fc2..2c363dc 100644 --- a/deploy/helm/axon-trader/templates/gateway.yaml +++ b/deploy/helm/axon-trader/templates/gateway.yaml @@ -27,3 +27,32 @@ spec: from: Same {{- end }} {{- end }} +{{- if and .Values.gateway.create .Values.gateway.httpsRedirect }} +{{- $listeners := .Values.gateway.listeners }} +{{- $hasHttps := false }} +{{- range $listeners }}{{ if eq .protocol "HTTPS" }}{{ $hasHttps = true }}{{ end }}{{ end }} +{{- if $hasHttps }} +{{- range $listeners }} +{{- if eq .protocol "HTTP" }} +--- +# Plain HTTP only redirects to HTTPS (same as http-to-https in infra/k8s/platform/gateway.yaml). +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ $.Values.gateway.name }}-{{ .name }}-to-https + labels: + {{- include "axon-trader.labels" $ | nindent 4 }} +spec: + parentRefs: + - name: {{ $.Values.gateway.name }} + sectionName: {{ .name }} + rules: + - filters: + - type: RequestRedirect + requestRedirect: + scheme: https + statusCode: 301 +{{- end }} +{{- end }} +{{- end }} +{{- end }} diff --git a/deploy/helm/axon-trader/templates/httproute.yaml b/deploy/helm/axon-trader/templates/httproute.yaml index c93e997..718dab9 100644 --- a/deploy/helm/axon-trader/templates/httproute.yaml +++ b/deploy/helm/axon-trader/templates/httproute.yaml @@ -24,6 +24,13 @@ spec: path: type: ReplacePrefixMatch replacePrefixMatch: /{{ . }} + {{- with $.Values.route.hsts }} + - type: ResponseHeaderModifier + responseHeaderModifier: + set: + - name: Strict-Transport-Security + value: {{ . | quote }} + {{- end }} backendRefs: - name: trader-app port: 8080 @@ -32,6 +39,14 @@ spec: - path: type: PathPrefix value: / + {{- with .Values.route.hsts }} + filters: + - type: ResponseHeaderModifier + responseHeaderModifier: + set: + - name: Strict-Transport-Security + value: {{ . | quote }} + {{- end }} backendRefs: - name: trader-ui port: 8080 diff --git a/deploy/helm/axon-trader/values.yaml b/deploy/helm/axon-trader/values.yaml index 5903519..8223ffd 100644 --- a/deploy/helm/axon-trader/values.yaml +++ b/deploy/helm/axon-trader/values.yaml @@ -30,6 +30,8 @@ route: apiPrefixes: - command - query + # Strict-Transport-Security on every routed response (the Gateway only serves the app over HTTPS); "" disables it. + hsts: "max-age=31536000; includeSubDomains" # Gateway. GKE environments use the platform Gateway (infra/k8s/platform/gateway.yaml) with the Certificate Manager # map holding the Google-managed certificate; set create: true to have the chart own an equivalent one instead. @@ -41,6 +43,8 @@ gateway: certificateMap: "" # Terraform output gateway_address_name (reserved global address). addressName: "" + # With an HTTPS listener present, every HTTP listener gets a 301-to-HTTPS HTTPRoute and nothing else. + httpsRedirect: true listeners: - name: https protocol: HTTPS diff --git a/docs/migration/security-baseline.md b/docs/migration/security-baseline.md new file mode 100644 index 0000000..cfcb17d --- /dev/null +++ b/docs/migration/security-baseline.md @@ -0,0 +1,50 @@ +# GKE security baseline (s5.4) + +Checked on kind with `ci/kind/verify-security-baseline.sh` (the merged chart `deploy/helm/axon-trader` with +`ci/kind/values-kind*.yaml`, namespace labelled `pod-security.kubernetes.io/enforce=restricted`) plus a static review of +the chart rendered with `values-staging.yaml` / `values-prod.yaml` and of `infra/k8s`. There is no GCP staging cluster +yet: **the live re-check on GKE staging is still owed** (same script sections 1-4 against the real namespace, plus the +items marked "GKE re-check" below). + +## Findings + +| # | Item | Before | Status | +| --- | --- | --- | --- | +| F1 | Pod Security Standard | `infra/k8s/platform/namespace.yaml` enforced `baseline` (warn/audit `restricted`) | **Fixed**: `enforce: restricted` (pinned `v1.33`). RabbitMQ operator pods get a restricted `override` (seccomp, no privilege escalation, `drop: [ALL]`, uid 999); the prod patch no longer replaces `containers`. Chart, smoke and check Jobs were already compliant. | +| F2 | Restricted PSS on kind | kind namespace had no PSS label; MySQL/RabbitMQ stand-ins and the NetworkPolicy probe pods ran as root | **Fixed**: `ci/kind/setup.sh` labels the namespace `enforce=restricted` for every kind check; stand-ins run as uid 999 with seccomp/`drop: [ALL]`; probe pods (`kind_probe`) use a restricted securityContext. | +| F3 | NetworkPolicies | Ingress default-deny plus per-app allow-lists (s3.5) | **OK** (no change): every ingress path outside the s3.5 flows is a blocked curl (unlabelled, trader-ui, discovery-server and trader-app -> trader-ui pods); the s3.5 flows connect. | +| F4 | Egress deny | Chart egress policies allow only s3.5 flows, DNS and (GKE) metadata/Google APIs; `trader-ui` none | **GKE re-check owed**: policies render correctly, but kind's CNI (kindnet / kube-network-policies) did not enforce egress on this host: chart pods reached a policy-free in-cluster target and `1.1.1.1:80`. The script reports these as INFO; the deny must be shown on GKE Dataplane V2 before acceptance. | +| F5 | Credentials | Secrets from ExternalSecrets (Secret Manager) via Workload Identity KSAs; kind generates throwaway Secrets | **OK** (no change): generated secret values appear in no Helm value, rendered manifest, ConfigMap or pod spec; credential env vars come only from `secretKeyRef`/`envFrom`; image config and Trivy secret scan clean. | +| F6 | Env dumps | `management.endpoints.web.exposure.include=*` in the base `application.properties` of trader-app and trading-engine (the `kubernetes` profile already narrowed it) | **Fixed**: base exposure is `health,info,prometheus` (+ `data-initializer` on trader-app), so `/actuator/env`, `configprops`, `heapdump`, `beans` etc. are gone on every profile (TAS, local, GKE). | +| F7 | Actuator public exposure | HTTPRoute routes only `/`, `/api/command/*`, `/api/query/*` | **OK** (no change): nothing under `/actuator` or `/api/actuator` (incl. `..` / `%2f` traversal) reaches an actuator through the Gateway. | +| F8 | In-cluster `info` and `data-initializer` | Not public, reachable only from NetworkPolicy peers | **Accept**: needed by the smoke/e2e scripts (`/actuator/info`, `POST /actuator/data-initializer`); `data-initializer` seeds demo data, keep or drop is a human decision. | +| F9 | HTTPS-only | Platform Gateway: HTTPS listener + HTTP listener that only 301s; chart-owned Gateway (`gateway.create: true`) served the app on its HTTP listener; no HSTS; LB default SSL policy (COMPATIBLE, TLS 1.0+) | **Fixed**: Terraform `google_compute_ssl_policy` (MODERN, TLS 1.2+) attached with a `GCPGatewayPolicy`; chart-owned Gateway gets an HTTP->HTTPS 301 route; `route.hsts` adds `Strict-Transport-Security` on routed responses. kind keeps an HTTP-only stand-in (`hsts: ""`). GKE re-check: `curl -I http://` -> 301, `openssl s_client -tls1_1` refused. | +| F10 | Trivy CVEs | CI gate with `ci/trivy/critical-baseline.yaml` | **Accept (d-runtime)**: 48 distinct critical CVEs on the three JVM images (Boot 2.0.3 / Spring 5.0.7 / Java 8 libraries), all already in the baseline (expires 2027-05-01), no new ones; trader-ui (alpine 3.24) has none critical/high. List below. | + +## Critical CVEs kept with the Boot 2.0 / Java 8 runtime + +Trivy 0.76.0, `--severity CRITICAL`, images built from this branch (trading-engine 42, trader-app 47, discovery-server +37 distinct; 48 overall). No OS-package criticals (eclipse-temurin 8 on ubuntu 24.04). Clearing them needs the runtime +upgrade the d-runtime decision deferred. + +| Library | CVEs | IDs | +| --- | --- | --- | +| `dom4j 1.6.1` | 1 | CVE-2020-10683 | +| `freemarker 2.3.28` | 1 | CVE-2026-84939 | +| `h2 1.4.197` | 2 | CVE-2021-42392, CVE-2022-23221 | +| `jackson-databind 2.8.11` | 20 | CVE-2018-11307, CVE-2018-14718, CVE-2018-14719, CVE-2018-14720, CVE-2018-14721, CVE-2018-19360, CVE-2018-19361, CVE-2018-19362, CVE-2018-7489, CVE-2019-14379, CVE-2019-14540, CVE-2019-16335, CVE-2019-16942, CVE-2019-16943, CVE-2019-17267, CVE-2019-17531, CVE-2019-20330, CVE-2020-8840, CVE-2020-9547, CVE-2020-9548 | +| `jackson-databind 2.9.6` | 19 | CVE-2018-14718, CVE-2018-14719, CVE-2018-14720, CVE-2018-14721, CVE-2018-19360, CVE-2018-19361, CVE-2018-19362, CVE-2019-14379, CVE-2019-14540, CVE-2019-16335, CVE-2019-16942, CVE-2019-16943, CVE-2019-17267, CVE-2019-17531, CVE-2019-20330, CVE-2020-8840, CVE-2020-9546, CVE-2020-9547, CVE-2020-9548 | +| `jetty-server 9.2.24.v20180105` | 2 | CVE-2017-7657, CVE-2017-7658 | +| `netty-codec-http 4.1.25.Final` | 1 | CVE-2019-20444 | +| `netty-handler 4.1.25.Final` | 1 | CVE-2026-75595 | +| `spring-beans 5.0.7.RELEASE` | 1 | CVE-2022-22965 | +| `spring-boot-actuator-autoconfigure 2.0.3.RELEASE` | 1 | CVE-2023-20873 | +| `spring-boot-starter-web 2.0.3.RELEASE` | 1 | CVE-2022-22965 | +| `spring-boot-starter-webflux 2.0.3.RELEASE` | 1 | CVE-2022-22965 | +| `spring-security-core 5.0.6.RELEASE` | 1 | CVE-2022-22978 | +| `spring-security-web 5.0.6.RELEASE` | 3 | CVE-2022-22978, CVE-2024-38821, CVE-2026-22732 | +| `spring-web 5.0.7.RELEASE` | 1 | CVE-2016-1000027 | +| `spring-webflux 5.0.7.RELEASE` | 1 | CVE-2022-22965 | +| `spring-webmvc 5.0.7.RELEASE` | 2 | CVE-2022-22965, CVE-2026-47884 | +| `tomcat-embed-core 8.5.31` | 10 | CVE-2018-8014, CVE-2020-1938, CVE-2025-24813, CVE-2026-41293, CVE-2026-43512, CVE-2026-43515, CVE-2026-55276, CVE-2026-65182, CVE-2026-65905, CVE-2026-68525 | +| `xstream 1.4.10` | 2 | CVE-2013-7285, CVE-2019-10173 | diff --git a/infra/k8s/components/cluster-env/kustomization.yaml b/infra/k8s/components/cluster-env/kustomization.yaml index 652b998..dafcd0f 100644 --- a/infra/k8s/components/cluster-env/kustomization.yaml +++ b/infra/k8s/components/cluster-env/kustomization.yaml @@ -36,6 +36,10 @@ replacements: - select: {kind: Gateway, name: axon-trader} fieldPaths: - "metadata.annotations.[networking.gke.io/certmap]" + - source: {kind: ConfigMap, name: cluster-env, fieldPath: data.SSL_POLICY_NAME} + targets: + - select: {kind: GCPGatewayPolicy, name: axon-trader} + fieldPaths: [spec.default.sslPolicy] - source: {kind: ConfigMap, name: cluster-env, fieldPath: data.SMOKE_HOSTNAME} targets: - select: {kind: HTTPRoute, name: hello-world} diff --git a/infra/k8s/components/rabbitmq/rabbitmqcluster.yaml b/infra/k8s/components/rabbitmq/rabbitmqcluster.yaml index 7368d6a..4137c1e 100644 --- a/infra/k8s/components/rabbitmq/rabbitmqcluster.yaml +++ b/infra/k8s/components/rabbitmq/rabbitmqcluster.yaml @@ -28,3 +28,29 @@ spec: additionalConfig: | vm_memory_high_watermark.relative = 0.6 disk_free_limit.absolute = 1GB + # Pod Security Standard `restricted` (namespace enforce label in platform/namespace.yaml): the operator's + # default pod runs as uid 999 but sets neither seccomp nor allowPrivilegeEscalation/capabilities. + override: + statefulSet: + spec: + template: + spec: + securityContext: + runAsNonRoot: true + runAsUser: 999 + runAsGroup: 999 + fsGroup: 999 + seccompProfile: + type: RuntimeDefault + initContainers: + - name: setup-container + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] + containers: + - name: rabbitmq + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] diff --git a/infra/k8s/overlays/prod/cluster.env.example b/infra/k8s/overlays/prod/cluster.env.example index 40fa96f..63ac1cd 100644 --- a/infra/k8s/overlays/prod/cluster.env.example +++ b/infra/k8s/overlays/prod/cluster.env.example @@ -6,6 +6,7 @@ TRADER_APP_GSA=prod-trader-app@axon-trader-prod-placeholder.iam.gserviceaccount. TRADING_ENGINE_GSA=prod-trading-engine@axon-trader-prod-placeholder.iam.gserviceaccount.com GATEWAY_ADDRESS_NAME=esarch-prod-gateway CERT_MAP_NAME=esarch-prod-gateway +SSL_POLICY_NAME=esarch-prod-gateway SMOKE_HOSTNAME=trader.example.com SMOKE_SECRET_ID=platform-smoke-test CLOUDSQL_INSTANCE_CONNECTION_NAME=axon-trader-prod-placeholder:us-central1:esarch-prod-mysql diff --git a/infra/k8s/overlays/prod/kustomization.yaml b/infra/k8s/overlays/prod/kustomization.yaml index c1eef19..cd8154c 100644 --- a/infra/k8s/overlays/prod/kustomization.yaml +++ b/infra/k8s/overlays/prod/kustomization.yaml @@ -30,7 +30,6 @@ patches: spec: template: spec: - containers: [] topologySpreadConstraints: - maxSkew: 1 topologyKey: topology.kubernetes.io/zone diff --git a/infra/k8s/overlays/staging/cluster.env.example b/infra/k8s/overlays/staging/cluster.env.example index 5b49151..2e9087c 100644 --- a/infra/k8s/overlays/staging/cluster.env.example +++ b/infra/k8s/overlays/staging/cluster.env.example @@ -6,6 +6,7 @@ TRADER_APP_GSA=staging-trader-app@axon-trader-staging-placeholder.iam.gserviceac TRADING_ENGINE_GSA=staging-trading-engine@axon-trader-staging-placeholder.iam.gserviceaccount.com GATEWAY_ADDRESS_NAME=esarch-staging-gateway CERT_MAP_NAME=esarch-staging-gateway +SSL_POLICY_NAME=esarch-staging-gateway SMOKE_HOSTNAME=hello.staging.example.com SMOKE_SECRET_ID=platform-smoke-test CLOUDSQL_INSTANCE_CONNECTION_NAME=axon-trader-staging-placeholder:us-central1:esarch-staging-mysql diff --git a/infra/k8s/platform/gateway.yaml b/infra/k8s/platform/gateway.yaml index 3c80e94..b11416e 100644 --- a/infra/k8s/platform/gateway.yaml +++ b/infra/k8s/platform/gateway.yaml @@ -25,6 +25,20 @@ spec: namespaces: from: Same --- +# TLS 1.2+ (MODERN profile) on the HTTPS listener: the SSL policy comes from Terraform (modules/gke-platform). +apiVersion: networking.gke.io/v1 +kind: GCPGatewayPolicy +metadata: + name: axon-trader +spec: + default: + sslPolicy: SSL_POLICY_NAME + targetRef: + group: gateway.networking.k8s.io + kind: Gateway + name: axon-trader +--- +# The HTTP listener only redirects: nothing is served over plain HTTP. apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: diff --git a/infra/k8s/platform/namespace.yaml b/infra/k8s/platform/namespace.yaml index 44e346e..dfa5d6a 100644 --- a/infra/k8s/platform/namespace.yaml +++ b/infra/k8s/platform/namespace.yaml @@ -4,6 +4,9 @@ metadata: name: axon-trader labels: app.kubernetes.io/part-of: axon-trader - pod-security.kubernetes.io/enforce: baseline + # Every workload in the namespace (chart, RabbitMQ, smoke and check Jobs) runs non-root under `restricted` + # (s5.4, proven on kind by ci/kind/verify-security-baseline.sh). + pod-security.kubernetes.io/enforce: restricted + pod-security.kubernetes.io/enforce-version: v1.33 pod-security.kubernetes.io/warn: restricted pod-security.kubernetes.io/audit: restricted diff --git a/infra/k8s/scripts/validate.sh b/infra/k8s/scripts/validate.sh index c7b6187..71eabbf 100755 --- a/infra/k8s/scripts/validate.sh +++ b/infra/k8s/scripts/validate.sh @@ -30,7 +30,7 @@ for target in addons/eso addons/cert-manager addons/rabbitmq-operator overlays/s echo "==> kustomize build ${target} | kubeconform" rendered="${work}/$(echo "${target}" | tr '/' '-').yaml" kustomize build --enable-helm "${work}/${target}" >"${rendered}" - if grep -nE '(PROJECT_ID|CLUSTER_NAME|CLUSTER_LOCATION|_GSA|GATEWAY_ADDRESS_NAME|CERT_MAP_NAME|SMOKE_HOSTNAME|SMOKE_SECRET_ID|CLOUDSQL_INSTANCE_CONNECTION_NAME)$' "${rendered}"; then + if grep -nE '(PROJECT_ID|CLUSTER_NAME|CLUSTER_LOCATION|_GSA|GATEWAY_ADDRESS_NAME|CERT_MAP_NAME|SSL_POLICY_NAME|SMOKE_HOSTNAME|SMOKE_SECRET_ID|CLOUDSQL_INSTANCE_CONNECTION_NAME)$' "${rendered}"; then echo "unreplaced cluster-env placeholder in ${target}" >&2 exit 1 fi diff --git a/infra/terraform/envs/prod/outputs.tf b/infra/terraform/envs/prod/outputs.tf index 575bb50..c8523ad 100644 --- a/infra/terraform/envs/prod/outputs.tf +++ b/infra/terraform/envs/prod/outputs.tf @@ -88,6 +88,7 @@ output "kustomize_env" { TRADING_ENGINE_GSA = module.foundation.service_account_emails["trading-engine"] GATEWAY_ADDRESS_NAME = module.gke_platform.gateway_address_name CERT_MAP_NAME = module.gke_platform.certificate_map_name + SSL_POLICY_NAME = module.gke_platform.ssl_policy_name SMOKE_HOSTNAME = var.gateway_hostnames[0] SMOKE_SECRET_ID = module.gke_platform.smoke_test_secret_id diff --git a/infra/terraform/envs/staging/outputs.tf b/infra/terraform/envs/staging/outputs.tf index 575bb50..c8523ad 100644 --- a/infra/terraform/envs/staging/outputs.tf +++ b/infra/terraform/envs/staging/outputs.tf @@ -88,6 +88,7 @@ output "kustomize_env" { TRADING_ENGINE_GSA = module.foundation.service_account_emails["trading-engine"] GATEWAY_ADDRESS_NAME = module.gke_platform.gateway_address_name CERT_MAP_NAME = module.gke_platform.certificate_map_name + SSL_POLICY_NAME = module.gke_platform.ssl_policy_name SMOKE_HOSTNAME = var.gateway_hostnames[0] SMOKE_SECRET_ID = module.gke_platform.smoke_test_secret_id diff --git a/infra/terraform/modules/gke-platform/main.tf b/infra/terraform/modules/gke-platform/main.tf index 6db85d3..eab2127 100644 --- a/infra/terraform/modules/gke-platform/main.tf +++ b/infra/terraform/modules/gke-platform/main.tf @@ -42,6 +42,16 @@ resource "google_certificate_manager_certificate_map" "gateway" { labels = var.labels } +# TLS 1.2+ with the MODERN profile on the Gateway's HTTPS proxy (GCPGatewayPolicy in infra/k8s/platform/gateway.yaml). +# Without it the load balancer uses the COMPATIBLE profile and still accepts TLS 1.0/1.1. +resource "google_compute_ssl_policy" "gateway" { + project = var.project_id + name = "${local.name}-gateway" + description = "TLS policy of the ${var.environment} Gateway." + profile = "MODERN" + min_tls_version = "TLS_1_2" +} + resource "google_certificate_manager_certificate_map_entry" "gateway" { for_each = toset(var.hostnames) diff --git a/infra/terraform/modules/gke-platform/outputs.tf b/infra/terraform/modules/gke-platform/outputs.tf index 9511160..8b80527 100644 --- a/infra/terraform/modules/gke-platform/outputs.tf +++ b/infra/terraform/modules/gke-platform/outputs.tf @@ -13,6 +13,11 @@ output "certificate_map_name" { value = google_certificate_manager_certificate_map.gateway.name } +output "ssl_policy_name" { + description = "SSL policy for the Gateway's GCPGatewayPolicy (spec.default.sslPolicy)." + value = google_compute_ssl_policy.gateway.name +} + output "certificate_map_entries" { description = "Certificate map entry hostnames." value = sort(keys(google_certificate_manager_certificate_map_entry.gateway)) diff --git a/infra/terraform/modules/gke-platform/tests/gke_platform.tftest.hcl b/infra/terraform/modules/gke-platform/tests/gke_platform.tftest.hcl index b25b69d..c1ca1ab 100644 --- a/infra/terraform/modules/gke-platform/tests/gke_platform.tftest.hcl +++ b/infra/terraform/modules/gke-platform/tests/gke_platform.tftest.hcl @@ -42,6 +42,11 @@ run "gateway_certificate_and_smoke_secret" { error_message = "Only the trader-app workload may read the smoke-test secret." } + assert { + condition = output.ssl_policy_name == "esarch-staging-gateway" && google_compute_ssl_policy.gateway.min_tls_version == "TLS_1_2" && google_compute_ssl_policy.gateway.profile == "MODERN" + error_message = "The Gateway SSL policy must require TLS 1.2+ with the MODERN profile." + } + assert { condition = output.smoke_test_secret_id == "platform-smoke-test" error_message = "Smoke-test secret id unexpected." diff --git a/trader-app/src/main/resources/application.properties b/trader-app/src/main/resources/application.properties index 10c77da..115af2f 100644 --- a/trader-app/src/main/resources/application.properties +++ b/trader-app/src/main/resources/application.properties @@ -13,7 +13,8 @@ axon.amqp.transaction-mode=publisher_ack # Actuator management.endpoints.enabled-by-default=true -management.endpoints.web.exposure.include=* +# Only what the probes, scrapers and smoke checks call (s5.4); never env, beans, heapdump, etc. +management.endpoints.web.exposure.include=health,info,prometheus,data-initializer # Set the general logging level within the application logging.level.io.pivotal.refarch=DEBUG diff --git a/trading-engine/src/main/resources/application.properties b/trading-engine/src/main/resources/application.properties index 6af1fbe..d8bd22c 100644 --- a/trading-engine/src/main/resources/application.properties +++ b/trading-engine/src/main/resources/application.properties @@ -3,7 +3,8 @@ #spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect # management.endpoints.enabled-by-default=true -management.endpoints.web.exposure.include=* +# Only what the probes, scrapers and smoke checks call (s5.4); never env, beans, heapdump, etc. +management.endpoints.web.exposure.include=health,info,prometheus axon.distributed.enabled=true axon.distributed.spring-cloud.fallback-to-http-get=false From 3f83f7c8dd00bbbd2781dca38175144656e2d23f Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:56:50 +0000 Subject: [PATCH 2/2] =?UTF-8?q?bug:=20kind=5Fprobe=20s=C3=B3=20conta=20flu?= =?UTF-8?q?xo=20permitido=20como=20open=20quando=20o=20TCP=20conectou=20(r?= =?UTF-8?q?c=207=20falha);=20alvo=20de=20egress=20por=20IP=20do=20pod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Matthew Guerra --- ci/kind/setup.sh | 15 +++++++++++---- ci/kind/verify-security-baseline.sh | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ci/kind/setup.sh b/ci/kind/setup.sh index dfdc482..47aef3c 100644 --- a/ci/kind/setup.sh +++ b/ci/kind/setup.sh @@ -79,9 +79,11 @@ YAML kind_setup() { kind_cluster; kind_install; } # kind_probe : curl from a throwaway pod (restricted securityContext) carrying that -# app label. Blocked means curl timed out (exit 28) without ever connecting (time_connect 0), i.e. a NetworkPolicy -# dropped the SYN; anything else (HTTP status, a protocol error from MySQL/AMQP, or a response timeout after the -# connect) means the TCP connection was accepted. Prints "blocked" or "open(rc=N)". +# app label. Prints one of: +# blocked curl timed out (exit 28) without ever connecting (time_connect 0): a NetworkPolicy dropped the SYN; +# open(...) TCP connected: HTTP answer (0), a non-HTTP greeting from MySQL/AMQP (1, "HTTP/0.9 not allowed"), +# empty reply / recv error (52/56), or a response timeout after the connect (28, time_connect > 0); +# error(...) anything else, e.g. connection refused (7) or DNS failure (6): neither proves a flow open nor blocked. kind_probe() { local labels="esarch-probe=1" [ "$2" != - ] && labels="$labels,app.kubernetes.io/name=$2" @@ -97,7 +99,12 @@ kind_probe() { out=$(k logs "np-$1" | grep '^rc=' || true) rc=$(sed -n 's/^rc=\([0-9]*\).*/\1/p' <<<"$out"); connect=$(sed -n 's/.*connect=//p' <<<"$out") k delete pod "np-$1" --wait=false >/dev/null - if [ "$rc" = 28 ] && [ "${connect:-0}" = 0.000000 ]; then echo blocked; else echo "open(rc=$rc)"; fi + case "$rc,${connect:-0}" in + 28,0.000000) echo blocked ;; + 0,* | 1,* | 52,* | 56,*) echo "open(rc=$rc connect=${connect}s)" ;; + 28,*) echo "open(rc=28 connect=${connect}s)" ;; + *) echo "error(rc=${rc:-none} connect=${connect:-none}s)" ;; + esac } # Eureka helpers (need EUREKA_URL, jq and fail()). diff --git a/ci/kind/verify-security-baseline.sh b/ci/kind/verify-security-baseline.sh index 9ab08ce..6c65399 100755 --- a/ci/kind/verify-security-baseline.sh +++ b/ci/kind/verify-security-baseline.sh @@ -61,7 +61,7 @@ k get pods -o json | jq -r '.items[] | .metadata.name as $p | .spec.containers[] "\($p)/\(.name) runAsNonRoot=\(.securityContext.runAsNonRoot // "pod") readOnlyRootFilesystem=\(.securityContext.readOnlyRootFilesystem // false) caps.drop=\(.securityContext.capabilities.drop // [] | join(","))"' | grep -v '^np-' -echo "== 2. NetworkPolicies (blocked = no TCP connect within 5 s)" +echo "== 2. NetworkPolicies (blocked = no TCP connect within 5 s; open = TCP connected; refused/DNS errors fail)" ip() { k get svc "$1" -o jsonpath='{.spec.clusterIP}'; } expect() { # want name label host port local got; got=$(kind_probe "$2" "$3" "$4" "$5") @@ -85,12 +85,12 @@ kubectl --context "kind-$CLUSTER" create namespace np-egress-target --dry-run=cl kubectl --context "kind-$CLUSTER" -n np-egress-target run egress-target --image=esarch/trader-ui:latest --image-pull-policy=Never \ --port=8080 --dry-run=client -o json | jq '.spec.securityContext = {runAsNonRoot: true, runAsUser: 101, seccompProfile: {type: "RuntimeDefault"}} - | .spec.containers[0].securityContext = {allowPrivilegeEscalation: false, capabilities: {drop: ["ALL"]}}' | - kubectl --context "kind-$CLUSTER" apply -f - >/dev/null -kubectl --context "kind-$CLUSTER" -n np-egress-target expose pod egress-target --port=8080 --dry-run=client -o yaml | + | .spec.containers[0].securityContext = {allowPrivilegeEscalation: false, capabilities: {drop: ["ALL"]}} + | .spec.containers[0].readinessProbe = {tcpSocket: {port: 8080}, periodSeconds: 2}' | kubectl --context "kind-$CLUSTER" apply -f - >/dev/null kubectl --context "kind-$CLUSTER" -n np-egress-target wait --for=condition=Ready pod/egress-target --timeout=120s >/dev/null -target=$(kubectl --context "kind-$CLUSTER" -n np-egress-target get svc egress-target -o jsonpath='{.spec.clusterIP}') +# Pod IP, not the ClusterIP: right after Ready, kube-proxy may still REJECT the endpoint-less Service (curl exit 7). +target=$(kubectl --context "kind-$CLUSTER" -n np-egress-target get pod egress-target -o jsonpath='{.status.podIP}') expect open other-to-target - "$target" 8080 for a in trader-app trading-engine discovery-server trader-ui; do echo "INFO $a pod -> egress-target:8080 $(kind_probe "$a-tgt" "$a" "$target" 8080) (want blocked; kind CNI egress, re-check on GKE)"