Cloud Security··2 min read

Hardening Multi-Tenant Kubernetes Clusters for HIPAA and PIPEDA: Default-Deny NetworkPolicies and RBAC

Shafikul Islam

Shafikul Islam

Backend & Cloud Infrastructure Engineer · Infrastructure & Cloud Team Lead

Hardening Multi-Tenant Kubernetes Clusters for HIPAA and PIPEDA: Default-Deny NetworkPolicies and RBAC

Kubernetes Is Flat by Default (And Why That Breaks Compliance)

Out of the box, Kubernetes networking is completely flat. Unless you explicitly install a CNI policy engine and define NetworkPolicy resources, a compromised frontend pod in a staging namespace can open a direct TCP connection to a production Redis or PostgreSQL pod in another namespace.

When preparing our multi-tenant healthcare infrastructure (emmai.ca) for enterprise security reviews and HIPAA/PIPEDA compliance, we implemented a Zero-Trust Kubernetes hardening baseline.


1. Enforcing Default-Deny Ingress and Egress NetworkPolicies

The first rule deployed to every production namespace is a default-deny-all policy that drops all pod-to-pod traffic unless explicitly whitelisted:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
  namespace: emmai-prod
spec:
  podSelector: {}
  policyTypes:
    - Ingress
    - Egress

Once default-deny is active, we grant narrow, port-specific allow rules. For example, only pods labeled app: emmai-core-api are permitted to open port 5432 to PgBouncer, and only the ingress controller namespace can reach port 8080 on the API pods.


2. Disabling Auto-Mounted ServiceAccount Tokens

By default, Kubernetes mounts a bearer token at /var/run/secrets/kubernetes.io/serviceaccount/token inside every container. If an application suffers a Server-Side Request Forgery (SSRF) or local file inclusion bug, an attacker can read that token and query the Kubernetes API server.

We disabled automatic token mounting on all application pods that do not talk to the Kubernetes API:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: emmai-stateless-api-sa
  namespace: emmai-prod
automountServiceAccountToken: false

3. Blocking Critical CVEs in GitHub Actions with Trivy

Security scanning in production is too late. We added Trivy image scanning directly inside our GitHub Actions build workflow with --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed, ensuring vulnerable base images fail the PR build before ArgoCD ever sees them.

Infrastructure & PostgreSQL Advisory

Scaling Infrastructure or Diagnosing P95 Latency?

I help engineering teams diagnose PostgreSQL indexing bottlenecks, concurrency limits, and K3s/Docker deployments. Book a 20-minute call with me to review your setup.

Related Technical Articles