From e8a98bc98b4e660072fe6fbc76d9e846fb962c23 Mon Sep 17 00:00:00 2001 From: Bianca Date: Thu, 22 Oct 2026 17:29:43 +0200 Subject: [PATCH] feat(backend): close public access and allow only in-cluster callers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RFC v3 Phase 6 (§12). Every caller reaches the backend in-cluster, and the backend has no login of its own anymore: - remove the Ingress for api.polinetwork.org and backend.polinetwork.org - add a NetworkPolicy that admits only admin, web, bot-ts and auth on port 3000 - drop PUBLIC_URL, TRUSTED_ORIGINS, BETTER_AUTH_SECRET and the unused GITHUB_CLIENT_* settings, and their Key Vault mappings --- apps/backend/deployment.yaml | 19 -------------- apps/backend/external-secret.yaml | 9 ------- apps/backend/ingress.yaml | 30 --------------------- apps/backend/kustomization.yaml | 2 +- apps/backend/network-policy.yaml | 43 +++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 59 deletions(-) delete mode 100644 apps/backend/ingress.yaml create mode 100644 apps/backend/network-policy.yaml diff --git a/apps/backend/deployment.yaml b/apps/backend/deployment.yaml index d32dc4c..0a1c694 100644 --- a/apps/backend/deployment.yaml +++ b/apps/backend/deployment.yaml @@ -40,10 +40,6 @@ spec: value: "production" - name: TZ value: "Europe/Rome" - - name: PUBLIC_URL - value: "https://api.polinetwork.org" - - name: TRUSTED_ORIGINS - value: "https://polinetwork.org,https://admin.polinetwork.org,http://localhost:3001,http://localhost:3002" - name: DB_NAME value: "polinetwork_backend" - name: DB_HOST @@ -69,21 +65,6 @@ spec: secretKeyRef: name: azure-kv key: encryption-key - - name: BETTER_AUTH_SECRET - valueFrom: - secretKeyRef: - name: azure-kv - key: auth-secret - - name: GITHUB_CLIENT_SECRET - valueFrom: - secretKeyRef: - name: azure-kv - key: auth-github-id - - name: GITHUB_CLIENT_ID - valueFrom: - secretKeyRef: - name: azure-kv - key: auth-github-secret - name: AZURE_CLIENT_ID valueFrom: secretKeyRef: diff --git a/apps/backend/external-secret.yaml b/apps/backend/external-secret.yaml index e0e2ec2..0630a92 100644 --- a/apps/backend/external-secret.yaml +++ b/apps/backend/external-secret.yaml @@ -24,15 +24,6 @@ spec: - secretKey: encryption-key remoteRef: key: backend-encryption-key - - secretKey: auth-github-id - remoteRef: - key: backend-auth-github-secret - - secretKey: auth-github-secret - remoteRef: - key: backend-auth-github-id - - secretKey: auth-secret - remoteRef: - key: backend-auth-secret - secretKey: db-pass remoteRef: key: postgres-root-password diff --git a/apps/backend/ingress.yaml b/apps/backend/ingress.yaml deleted file mode 100644 index b221d23..0000000 --- a/apps/backend/ingress.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# Cloudflare Tunnel sends every HTTP hostname to Traefik, which routes by host. -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: backend - annotations: - traefik.ingress.kubernetes.io/router.entrypoints: web -spec: - ingressClassName: traefik - rules: - - host: api.polinetwork.org - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: backend-service - port: - number: 3000 - - host: backend.polinetwork.org - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: backend-service - port: - number: 3000 diff --git a/apps/backend/kustomization.yaml b/apps/backend/kustomization.yaml index ecd7176..726e901 100644 --- a/apps/backend/kustomization.yaml +++ b/apps/backend/kustomization.yaml @@ -7,4 +7,4 @@ resources: - namespace.yaml - external-secret.yaml - deployment.yaml - - ingress.yaml + - network-policy.yaml diff --git a/apps/backend/network-policy.yaml b/apps/backend/network-policy.yaml new file mode 100644 index 0000000..3e2519c --- /dev/null +++ b/apps/backend/network-policy.yaml @@ -0,0 +1,43 @@ +# Only the in-cluster callers may reach the backend (RFC v3 §12): the admin +# dashboard and the website (tRPC, esign agent proxy), the Telegram bot (tRPC +# and its socket) and the IdP (access-changed events on /internal/events). +# Nothing reaches it from outside the cluster since the Ingress was removed. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-callers + namespace: backend +spec: + podSelector: + matchLabels: + app: backend + policyTypes: [Ingress] + ingress: + - from: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: admin + podSelector: + matchLabels: + app: admin + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: web + podSelector: + matchLabels: + app: web + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: bot-ts + podSelector: + matchLabels: + app: bot-ts + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: auth + podSelector: + matchLabels: + app: auth + ports: + - port: 3000 + protocol: TCP