Software Crafting

Zero-Trust Architecture on EKS: Hardening Node.js Microservices with Istio Service Mesh and mTLS

DDeepak RajputCloud and DevOps10 min read04 Apr 2026Updated 2026-11-07
Five glass shield icons on circular platforms connected by blue and pink light streams on a dark circuit board

TL;DR: This guide demonstrates how to secure Node.js microservices on AWS EKS by implementing a Zero-Trust architecture with the Istio Service Mesh and Envoy sidecars. It covers deploying the Istio CNI plugin via Helm to avoid NET_ADMIN privileges, enforcing mTLS, identity-based AuthorizationPolicy, and setting outboundTrafficPolicy to REGISTRY_ONLY to restrict egress. You'll also learn how to configure Express.js graceful shutdowns to sync with Envoy using the EXIT_ON_ZERO_ACTIVE_CONNECTIONS proxy metadata.

Key Takeaways

  • Deploy the Istio CNI node agent (istio/cni) via Helm so mesh pods no longer need an istio-init container with NET_ADMIN and NET_RAW capabilities.
  • Set outboundTrafficPolicy.mode to REGISTRY_ONLY so sidecars block calls to unregistered external hosts, and back it with an egress gateway and NetworkPolicies, since sidecar-only egress control can be bypassed.
  • Use proxyMetadata.EXIT_ON_ZERO_ACTIVE_CONNECTIONS: "true" so the Envoy sidecar waits for active connections to drain before exiting, instead of exiting on a fixed timer.
  • Implement SIGTERM event listeners in your Express.js applications to close active connections and sync with Kubernetes pod termination lifecycles.
  • Run Node.js services over plain HTTP (e.g., port 3000) and let the injected Envoy sidecars handle mTLS encryption, decryption, and identity-based authorization for in-mesh traffic.

The "castle-and-moat" perimeter model does not hold up well inside a Kubernetes cluster. If you rely only on AWS WAF, an API Gateway and an Ingress Controller, a single vulnerable npm dependency can give an attacker a foothold with access to every internal service.

Imagine this scenario: Your frontend-facing Node.js aggregation service runs in your EKS cluster. A zero-day Remote Code Execution (RCE) vulnerability is discovered in an image parsing library your application uses. An attacker exploits it and gains a shell inside your Node.js container. Because pod-to-pod traffic is unauthenticated and usually plaintext by default, the attacker simply runs curl http://billing-service.default.svc.cluster.local:8080/api/v1/export to extract your entire customer database.

The network trusted the attacker merely because they were inside the perimeter. Security reviews for frameworks such as SOC 2 and HIPAA commonly ask how internal traffic is encrypted and how service-to-service access is restricted.

A Zero-Trust Architecture addresses this. No pod trusts another by default, and every request is encrypted, authenticated, and authorized based on workload identity rather than IP address.

In this guide, we will harden a fleet of Node.js microservices running on AWS EKS using the Istio Service Mesh. We will enforce mutual TLS (mTLS), implement identity-based routing, and restrict egress traffic to prevent data exfiltration.

The Architecture: Istio Control Plane and Envoy Sidecars

To achieve zero trust without rewriting our Node.js applications, we use a service mesh. Istio injects an Envoy proxy as a sidecar container into every pod. Traffic leaving and entering your Node.js container is transparently redirected to the sidecar, so the app still speaks plain HTTP. The Envoy sidecar intercepts this traffic, encrypts it using certificates provisioned by the Istio control plane (istiod), and forwards it to the destination pod's sidecar. The receiving sidecar decrypts the payload and passes it to the destination Node.js app.

Let's start by installing a production-ready Istio profile on EKS. We'll use Helm to deploy the base CRDs, the Istio CNI node agent, and the istiod control plane in sidecar mode. (Istio's ambient mode, which replaces per-pod sidecars with a per-node proxy, is an alternative; this guide uses sidecars.) Pin --version to the Istio release you have tested; 1.31 is current at the time of writing.

# Add the Istio Helm repository
helm repo add istio https://blob.istio.io/istio-release/charts
helm repo update

# Install base CRDs
helm install istio-base istio/base -n istio-system --set defaultRevision=default --create-namespace

# Install the Istio CNI node agent (before istiod)
helm install istio-cni istio/cni -n istio-system --wait

# Install the Istiod control plane with a custom values file
helm install istiod istio/istiod -n istio-system -f istiod-values.yaml --wait

Without the CNI agent, every mesh pod gets an istio-init container that needs the NET_ADMIN and NET_RAW capabilities to set up traffic redirection, which many security policies forbid. The Istio CNI agent is a chained plugin that runs after the AWS VPC CNI and does that setup from one privileged pod per node instead. Here is the istiod-values.yaml configuration to use:

# istiod-values.yaml
meshConfig:
  accessLogFile: /dev/stdout
  accessLogEncoding: JSON
  enablePrometheusMerge: true
  # Default deny for external traffic to prevent exfiltration
  outboundTrafficPolicy:
    mode: REGISTRY_ONLY
  defaultConfig:
    proxyMetadata:
      # Envoy exits once active connections drain, not on a fixed timer
      EXIT_ON_ZERO_ACTIVE_CONNECTIONS: 'true'
pilot:
  resources:
    requests:
      cpu: 500m
      memory: 2048Mi
  autoscaleEnabled: true
  autoscaleMin: 2
  autoscaleMax: 5

Production Note: REGISTRY_ONLY blocks calls to external hosts that have no ServiceEntry, which also blocks things your pods may silently depend on (package mirrors, telemetry endpoints, AWS APIs). Roll it out per namespace after reviewing access logs, not cluster-wide on day one. If you want help planning that rollout, see our DevOps and Cloud Deployment Services.

Bootstrapping Node.js Microservices for Mesh Injection

With the control plane running, we need to prepare our Node.js services. With a sidecar mesh, your application code does not handle certificates or TLS handshakes for internal traffic.

Here is a standard, lightweight Express.js service (server.js). Notice the lack of HTTPS configuration: it just listens on port 3000. We also include a graceful shutdown handler to pair with Istio's EXIT_ON_ZERO_ACTIVE_CONNECTIONS setting.

// server.js
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;

app.get('/api/data', (req, res) => {
  res.json({ status: 'secure', data: 'Confidential financial record' });
});

const server = app.listen(PORT, '0.0.0.0', () => {
  console.log(`Node.js service listening on port ${PORT}`);
});

// Ensure graceful shutdown when Kubernetes terminates the pod
process.on('SIGTERM', () => {
  console.log('SIGTERM received. Shutting down gracefully...');
  server.close(() => {
    console.log('Process terminated');
    process.exit(0);
  });
});

To deploy this securely, we use a multi-stage Docker build to keep the attack surface minimal:

# Dockerfile
FROM node:24-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .

FROM node:24-alpine
WORKDIR /app
COPY --from=builder /app ./
# Enforce production environment and unprivileged execution
ENV NODE_ENV=production
USER node
EXPOSE 3000
CMD ["node", "server.js"]

The important step happens in the Kubernetes Deployment. Enable automatic sidecar injection and assign a dedicated Kubernetes ServiceAccount (KSA). Istio issues each workload a certificate whose identity is a SPIFFE ID (Secure Production Identity Framework for Everyone) derived from the namespace and ServiceAccount, for example spiffe://cluster.local/ns/secure-apps/sa/billing-api-sa.

# deployment.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: billing-api-sa
  namespace: secure-apps
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: billing-api
  namespace: secure-apps
spec:
  replicas: 3
  selector:
    matchLabels:
      app: billing-api
  template:
    metadata:
      labels:
        app: billing-api
        # Tells the Istio mutating webhook to inject the Envoy proxy
        sidecar.istio.io/inject: 'true'
    spec:
      serviceAccountName: billing-api-sa
      containers:
        - name: node-app
          image: my-registry/billing-api:v1.2.0
          ports:
            - containerPort: 3000
          securityContext:
            runAsNonRoot: true
            readOnlyRootFilesystem: true

When you apply this YAML, the resulting pod will contain two containers: node-app and istio-proxy.

Enforcing Strict mTLS Across the EKS Cluster

By default, Istio uses PERMISSIVE mode, accepting both plaintext and mTLS traffic. That eases migration but still lets clients without a sidecar connect in plaintext. STRICT mode rejects plaintext traffic to the workloads it covers.

Apply it mesh-wide (in the root namespace, usually istio-system), per namespace, or per workload using the PeerAuthentication resource.

# strict-mtls.yaml
apiVersion: security.istio.io/v1
kind: PeerAuthentication
metadata:
  name: default-strict-mtls
  namespace: secure-apps
spec:
  mtls:
    mode: STRICT

Apply the policy:

kubectl apply -f strict-mtls.yaml

Once applied, if an attacker runs a pod without an Envoy sidecar and attempts to curl your billing API, the connection is reset because the server sidecar requires a client certificate. You can inspect the effective policies for a pod with istioctl:

POD_NAME=$(kubectl get pod -l app=billing-api -n secure-apps -o jsonpath='{.items[0].metadata.name}')

# Show the effective PeerAuthentication (mTLS mode) and routing for the pod
istioctl experimental describe pod $POD_NAME -n secure-apps

# List the authorization policies applied to the pod's sidecar
istioctl experimental authz check $POD_NAME -n secure-apps

Warning: Before enforcing STRICT mode, make sure every caller of the affected workloads is in the mesh. Traffic from an AWS Load Balancer must enter through the Istio ingress gateway (which originates mTLS to the services), not straight to pod IPs, and kubelet health probes need Istio's probe rewriting (on by default). Check access logs in PERMISSIVE mode first for plaintext callers.

Implementing Identity-Based Routing and Authorization

mTLS proves who is making the request, but it doesn't determine if they are allowed to make it. In a zero-trust model, we apply the principle of least privilege.

Suppose our frontend-ui service needs to read data from the billing-api service. No other service in the cluster should be allowed to access the billing API.

We define this rule with an AuthorizationPolicy. It allows the identity of the frontend-ui ServiceAccount to call specific methods and paths on billing-api. Once any ALLOW policy selects a workload, requests that match no ALLOW rule are denied. For a namespace-wide default deny, also add an AuthorizationPolicy with an empty spec: {}.

# authorization-policy.yaml
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: require-frontend-identity
  namespace: secure-apps
spec:
  selector:
    matchLabels:
      app: billing-api
  action: ALLOW
  rules:
    - from:
        - source:
            # Principal = SPIFFE ID without the spiffe:// prefix: <trust-domain>/ns/<namespace>/sa/<service-account>
            principals: ['cluster.local/ns/secure-apps/sa/frontend-ui-sa']
      to:
        - operation:
            methods: ['GET']
            paths: ['/api/data']

If a compromised pod (e.g., inventory-job) tries GET /api/data, the billing-api sidecar reads the principal cluster.local/ns/secure-apps/sa/inventory-job-sa from the client certificate, finds no matching rule, and returns HTTP 403 with RBAC: access denied.

Egress Control: Preventing Data Exfiltration

Egress control is an often overlooked part of zero trust. By default, Kubernetes pods can open outbound connections to the internet. An attacker with code execution will try to download tooling or send data to an external server.

We already established this baseline by setting outboundTrafficPolicy.mode: REGISTRY_ONLY in our istiod-values.yaml earlier. Because of this, if your Node.js application tries to reach api.stripe.com, it will fail by default. We must explicitly allow access to authorized external services using a ServiceEntry.

# stripe-egress.yaml
apiVersion: networking.istio.io/v1
kind: ServiceEntry
metadata:
  name: stripe-api
  namespace: secure-apps
spec:
  hosts:
    - api.stripe.com
  ports:
    - number: 443
      name: https
      protocol: HTTPS
  resolution: DNS
  location: MESH_EXTERNAL

With this entry, the sidecar allows TLS traffic to api.stripe.com, while requests to unregistered external hosts are blocked. This reduces the blast radius of Server-Side Request Forgery (SSRF) and exfiltration, but it does not eliminate them: SSRF can still target allowed hosts and internal services, and Istio's own documentation notes that sidecar-based egress control can be bypassed by a malicious application. For enforceable egress control, route external traffic through an Istio egress gateway and use Kubernetes NetworkPolicies (or VPC security groups) so pods cannot reach the internet directly.

SOC2 Compliance and Audit Logging

Audit frameworks such as SOC 2 expect you to log and review access to sensitive systems. Because Envoy sits in the path of every mesh request, its access logs are a useful source of evidence for service-to-service access, both allowed and denied.

Istio's Telemetry API configures Envoy access logs without restarting workloads.

# telemetry-logging.yaml
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
  name: mesh-default
  namespace: istio-system
spec:
  accessLogging:
    - providers:
        - name: envoy
      # Log all traffic (can be filtered for errors in production to save costs)
      match:
        mode: CLIENT_AND_SERVER

With accessLogFile: /dev/stdout and accessLogEncoding: JSON set in our Helm values, Envoy writes a JSON log line for every request. You can use Fluent Bit or the AWS CloudWatch agent as a DaemonSet to scrape these logs and forward them to AWS CloudWatch Logs or an ELK stack.

An abbreviated log line from the billing-api sidecar for the denied request looks like this:

{
  "method": "GET",
  "path": "/api/data",
  "response_code": 403,
  "response_code_details": "rbac_access_denied_matched_policy[none]",
  "upstream_cluster": "inbound|3000||",
  "downstream_remote_address": "10.0.1.45:49152",
  "upstream_service_time": null
}

response_code_details shows the request was denied by the RBAC filter before it reached the Node.js process (upstream_service_time is null). The default format does not include the caller's identity. To record it, use a custom format through an envoyFileAccessLog extension provider in meshConfig.extensionProviders that adds %DOWNSTREAM_PEER_URI_SAN%, so each line also carries the caller's SPIFFE ID.

Wrapping Up

A zero-trust setup on EKS with Istio moves service-to-service security out of Node.js application code and into the platform: mTLS encrypts and authenticates traffic between sidecars, AuthorizationPolicy restricts which identities may call which endpoints, and REGISTRY_ONLY plus an egress gateway and NetworkPolicies restrict outbound traffic. A mesh does not replace patching dependencies, least-privilege IAM for pods, or application-level authorization.

Moving a live cluster to strict mTLS without downtime takes staged rollout: PERMISSIVE first, access-log review, then STRICT namespace by namespace.

Sources

Available for Work

Need help building this in production?

SoftwareCrafting is a full-stack dev agency - we ship fast, scalable React, Next.js, Node.js, React Native & Flutter apps for global clients.

Get a Free Consultation

Frequently Asked Questions

What does zero trust mean inside a Kubernetes cluster?

No service is trusted because it is inside the network. Every call between services is authenticated, encrypted, and checked against a policy that says which service may call which.

How does Istio provide mutual TLS?

Istio injects an Envoy sidecar next to each pod and issues each workload a certificate tied to its service identity. The sidecars encrypt and authenticate traffic between services, so application code does not need to handle certificates.

How do you control which services can talk to each other?

Use Istio AuthorizationPolicy resources that allow specific source identities to call specific services, paths, or methods, and deny everything else by default.

How do you stop data being sent out of the cluster?

Restrict egress so pods can only reach approved external hosts, for example with an egress gateway and ServiceEntry resources, and log all outbound traffic so unexpected destinations are caught.

About the author

Deepak Rajput

Founder and CEO of SoftwareCrafting

Deepak Rajput is the Founder and CEO of SoftwareCrafting in Delhi and writes about web, mobile, backend, cloud, security, and engineering leadership.

Writes about Next.js, Node.js, React Native, PostgreSQL, AWS, Kubernetes.

View author profile

Last updated: 2026-11-07