We are going to design a zero-trust mesh rollout. The key components are:
- Service identities: Each service must have a unique identity (like a certificate or token) that is used for authentication.
- Policy: Define and enforce policies that determine which services can communicate with each other and under what conditions.
- Observability: Monitor and log all traffic and policy decisions for auditing and troubleshooting.
Steps:
-
Choose a service mesh that supports zero-trust. Popular options are Istio, Linkerd, Consul Connect, etc.
For this example, we'll use Istio because it has broad adoption and rich feature set.
-
Set up the cluster and install the service mesh (Istio) with mutual TLS (mTLS) for service identities.
-
Define policies (AuthorizationPolicies in Istio) to control traffic between services.
-
Set up observability (metrics, logs, traces) using tools like Prometheus, Grafana, Jaeger, and the built-in Istio telemetry.
Detailed Steps:
Step 1: Install Istio with mTLS
- Download and install Istio.
- Install with the
default profile or a custom profile that enables mTLS.
Example:
istioctl install --set profile=default
- Enable automatic mTLS for the entire mesh by creating a PeerAuthentication policy:
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: istio-system
spec:
mtls:
mode: STRICT
This will enforce mTLS for all services in the mesh.
Step 2: Service Identities
- Istio automatically assigns a SPIFFE identity to each service pod (based on the service account).
- We can also use custom certificates if needed, but the default setup uses the Istio Citadel (or now integrated into Istiod) to issue certificates.
Step 3: Define Authorization Policies
- We'll create an AuthorizationPolicy to define which services can talk to each other.
Example: Allow only requests from service reviews to ratings on port 9080.
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: allow-reviews-to-ratings
namespace: default
spec:
selector:
matchLabels:
app: ratings
action: ALLOW
rules:
- from:
- source:
principals: ["cluster.local/ns/default/sa/reviews"]
to:
- operation:
ports: ["9080"]
- We can also define policies that deny by default and then allow specific traffic.
Note: The identities (principals) are in the format: cluster.local/ns/<namespace>/sa/<service-account>
- We must ensure that the service accounts are correctly set and that the pods are using them.
Step 4: Observability
- Install addons for observability:
kubectl apply -f samples/addons/
This will install Prometheus, Grafana, Jaeger, and Kiali.
-
We can then access these tools to monitor the mesh.
-
Additionally, Istio provides access logs for each proxy (Envoy) which can be collected and analyzed.
-
We can also set up metrics collection and tracing.
Step 5: Gradual Rollout
-
We might not want to enforce mTLS and policies at once for all services. We can roll out gradually:
a. First, install Istio without mTLS enforcement (or with permissive mode) and monitor.
b. Then, enable mTLS for the entire mesh (as above) but start with permissive mode if needed (mode: PERMISSIVE) and then switch to STRICT.
c. Similarly, we can apply authorization policies incrementally.
-
Istio supports gradual rollouts by using namespaces and labels.
Step 6: Testing and Validation
- Test that services can still communicate as expected.
- Check that unauthorized requests are blocked.
- Verify that telemetry is being collected.
Step 7: Maintenance and Updating
- As new services are added, they will automatically get identities and be subject to the mesh policies.
- We must update policies as the architecture evolves.
Additional Considerations:
-
We must manage the service accounts and ensure that each service runs with a unique service account (or at least a unique identity per service).
-
We can use Kubernetes service accounts and map them to Istio identities.
-
For external services (outside the mesh), we might need to define a way to authenticate and authorize them (using credentials or a gateway).
-
For a zero-trust model, we assume the network is hostile and every request must be authenticated and authorized.
-
We must also consider the principle of least privilege when writing policies.
-
Observability is key to detect and respond to security incidents.
-
We might also want to integrate with external identity providers (like corporate LDAP) for user identities, but that is beyond the basic service mesh.
-
Note: The above example uses the older security.istio.io/v1beta1 API. Check the current version of Istio for the appropriate API version.
Let's write the YAML files for the steps above.
However, note that the exact steps might vary depending on the Istio version and the environment.
Since we cannot run commands here, we'll write the necessary YAML configurations.
But note: The installation of Istio and the addons is done via istioctl and kubectl apply respectively.
We'll write:
- PeerAuthentication for mTLS (strict mode)
- An example AuthorizationPolicy
- (Optionally) a Gateway and VirtualService if we have external traffic.
Let's assume we have two services: reviews (in namespace default) and ratings (also in default).
We want to allow only reviews to call ratings on port 9080.
Steps:
-
Install Istio (not in YAML, but via command).
-
Apply PeerAuthentication:
File: peer-authentication.yaml
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: istio-system
spec:
mtls:
mode: STRICT
- Apply AuthorizationPolicy:
File: allow-reviews-to-ratings.yaml
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: allow-reviews-to-ratings
namespace: default
spec:
selector:
matchLabels:
app: ratings
action: ALLOW
rules:
- from:
- source:
principals: ["cluster.local/ns/default/sa/reviews"]
to:
- operation:
ports: ["9080"]
- We must also ensure that the
reviews service is using the service account named reviews. This is typically set in the deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: reviews
spec:
template:
spec:
serviceAccountName: reviews
- For observability, we install the addons.
However, note that the addons might not be installed in the istio-system namespace by default. We can adjust.
Alternatively, we can use the Istio built-in telemetry and set up our own Prometheus and Grafana.
-
We might also want to set up logging. By default, Istio Envoy proxies log access logs to stdout. We can configure the logging format and then use a log collector (like Fluentd) to send to a central system.
-
For tracing, we need to configure the tracing backend (Jaeger or Zipkin). Istio by default uses Jaeger if installed.
We can also use the Telemetry API (in Istio 1.5+) to configure metrics, logs, and traces.
Example Telemetry configuration (if needed):
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: mesh-telemetry
namespace: istio-system
spec:
metrics:
- providers:
- name: prometheus
traces:
- providers:
- name: jaeger
But the addons installation usually sets up the necessary configuration.
Conclusion:
We have outlined the steps for a zero-trust mesh rollout with Istio. The key is to enforce mTLS for service identities and then apply authorization policies. Observability is provided by the built-in telemetry and the addons.
Note: The above example is for a simple scenario. In production, we might have more complex policies and multiple namespaces.
Also, we must consider the performance overhead of mTLS and the resource usage of the sidecar proxies.
Finally, we must have a plan for key rotation and certificate management, but Istio handles that automatically.
Let me know if you need more details on any specific part.
I'll design a comprehensive zero-trust service mesh rollout strategy covering identities, policies, and observability. Here's a production-ready implementation plan:
Architecture Overview
┌─────────────────────────────────────────────────────────────┐
│ ZERO-TRUST MESH │
├─────────────┬─────────────┬───────────────────────────────┤
│ Identities │ Policies │ Observability │
├─────────────┼─────────────┼───────────────────────────────┤
│ • SPIFFE │ • L7 │ • Metrics (Prometheus) │
│ • mTLS │ • L4 │ • Traces (Jaeger/Zipkin) │
│ • JWT │ • RBAC │ • Logs (Fluentd/Elastic) │
│ • CA │ • Rate │ • Topology (Kiali) │
│ Rotation │ Limiting │ • Dashboards (Grafana) │
└─────────────┴─────────────┴───────────────────────────────┘
Phase 1: Foundation & Identity
1.1 Service Identity Implementation
Option A: SPIFFE/SPIRE (Recommended)
# SPIRE configuration for Kubernetes
spire-server:
trustDomain: "example.com"
dataStore:
type: "sql"
sql:
databaseType: "sqlite3"
telemetry:
prometheus:
enabled: true
spire-agent:
kubernetes:
enabled: true
namespace: "spire"
Option B: Istio's Built-in Identity
# Install Istio with identity configuration
istioctl install \
--set profile=default \
--set values.global.trustDomain=cluster.local \
--set values.global.controlPlaneSecurityEnabled=true
Service Identity provisioning:
# Kubernetes ServiceAccount with annotations
apiVersion: v1
kind: ServiceAccount
metadata:
name: cart-service
namespace: production
annotations:
# SPIFFE identity
spire.spiffe.io/spiffe-id: "spiffe://example.com/ns/production/sa/cart-service"
Phase 2: Mutual TLS (mTLS) Enforcement
2.1 Mesh-wide mTLS Policy
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: istio-system
spec:
mtls:
mode: STRICT # Enforce mesh-wide
# For gradual rollout: PERMISSIVE → STRICT
---
# Per-namespace rollout
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: namespace-mtls
namespace: staging
spec:
mtls:
mode: PERMISSIVE # Allow both mTLS and plaintext
2.2 Certificate Management
# Automatic rotation (Istio)
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
meshConfig:
defaultConfig:
proxyMetadata:
ISTIO_META_TLS_CLIENT_CERT_CHAIN: "/etc/certs/cert-chain.pem"
ISTIO_META_TLS_CLIENT_KEY: "/etc/certs/key.pem"
ISTIO_META_TLS_SERVER_CERT_CHAIN: "/etc/certs/cert-chain.pem"
ISTIO_META_TLS_SERVER_KEY: "/etc/certs/key.pem"
# 90-day certificates, rotate every 30 days
proxyMetadata:
ISTIO_META_TLS_MIN_PROTOCOL_VERSION: "TLSV1_2"
ISTIO_META_TLS_MAX_PROTOCOL_VERSION: "TLSV1_3"
Phase 3: Policy Enforcement
3.1 Authorization Policies (Zero-Trust Rules)
# Default deny all
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: default-deny
namespace: production
spec:
selector:
matchLabels: {}
action: DENY
rules: [] # Empty = deny all
---
# Allow specific service-to-service
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: allow-cart-to-inventory
namespace: production
spec:
selector:
matchLabels:
app: inventory
action: ALLOW
rules:
- from:
- source:
principals: ["cluster.local/ns/production/sa/cart-service"]
to:
- operation:
methods: ["GET", "POST"]
paths: ["/inventory/*"]
ports: ["8080"]
---
# Require JWT for external access
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: require-jwt-external
namespace: production
spec:
selector:
matchLabels:
app: gateway
action: ALLOW
rules:
- from:
- source:
requestPrincipals: ["*"] # Any authenticated principal
to:
- operation:
methods: ["POST", "PUT"]
paths: ["/api/*"]
3.2 Rate Limiting & Quotas
apiVersion: policy.istio.io/v1beta1
kind: EnvoyFilter
metadata:
name: rate-limit
namespace: production
spec:
configPatches:
- applyTo: HTTP_FILTER
match:
context: GATEWAY
listener:
portNumber: 8080
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
patch:
operation: INSERT_BEFORE
value:
name: envoy.filters.http.ratelimit
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimit
domain: "production"
request_type: "both" # both inbound and outbound
Phase 4: Observability Stack
4.1 Monitoring Stack
# Prometheus custom rules for zero-trust
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: zero-trust-rules
namespace: monitoring
spec:
groups:
- name: zero-trust
rules:
- alert: UnauthorizedAccess
expr: |
sum(istio_requests_total{response_code=~"4.."})
by (destination_app, source_app)
> 10
for: 5m
labels:
severity: warning
annotations:
summary: "High unauthorized access attempts"
description: "{{ $labels.destination_app }} received {{ $value }} unauthorized requests from {{ $labels.source_app }}"
---
- alert: mTLSFailure
expr: |
sum(istio_tcp_connections_total{connection_security_policy="none"})
by (destination_app)
> 0
for: 2m
labels:
severity: critical
4.2 Distributed Tracing Configuration
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: mesh-default
namespace: istio-system
spec:
traces:
- providers:
- name: jaeger
customTags:
"service.version":
literal:
value: "v1.2.3"
"environment":
literal:
value: "production"
"trust-domain":
literal:
value: "example.com"
sampling: 10 # 10% sampling for prod
4.3 Audit Logging Pipeline
# Fluentd configuration for zero-trust audit logs
<filter kubernetes.**>
@type record_transformer
<record>
audit_log true
trust_domain ${record.dig("kubernetes", "labels", "istio.io/rev")}
source_identity ${record.dig("source", "principal")}
destination_identity ${record.dig("destination", "principal")}
authorization_result ${record.dig("authorization", "decision")}
</record>
</filter>
<match audit.**>
@type elasticsearch
host elasticsearch.logging.svc
port 9200
logstash_format true
logstash_prefix istio-audit
logstash_dateformat %Y.%m.%d
include_tag_key true
tag_key @log_name
</match>
Phase 5: Gradual Rollout Strategy
5.1 Canary Deployment with Canary Revision
# 1. Install Istio with canary revision
istioctl install --set revision=canary-1-18
# 2. Label namespace for canary rollout
kubectl label namespace production istio.io/rev=canary-1-18
# 3. Split traffic using VirtualService
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews.production.svc.cluster.local
http:
- route:
- destination:
host: reviews
subset: v1
weight: 90 # Stable
- destination:
host: reviews
subset: v2
weight: 10 # Canary with new policies
5.2 Traffic Shadowing
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: shadow-traffic
spec:
hosts:
- api.example.com
http:
- mirror:
host: api.production.svc.cluster.local
subset: v2-new-policies
route:
- destination:
host: api.production.svc.cluster.local
subset: v1-stable
Phase 6: Security Monitoring & Response
6.1 Kiali Service Mesh Topology
apiVersion: kiali.io/v1alpha1
kind: Kiali
metadata:
name: kiali
namespace: istio-system
spec:
auth:
strategy: anonymous
external_services:
prometheus:
url: http://prometheus.monitoring.svc:9090
grafana:
url: http://grafana.monitoring.svc:3000
jaeger:
url: http://jaeger.monitoring.svc:16686
deployment:
accessible_namespaces:
- "^(production|staging|development)$"
6.2 Automated Policy Violation Detection
# Example: Python script to detect policy violations
import requests
import json
PROMETHEUS_URL = "http://prometheus.istio.svc:9090"
def check_unauthorized_requests():
query = '''
sum by (source, destination) (
rate(istio_requests_total{response_code=~"4..|5.."}[5m])
) > 0
'''
response = requests.get(
f"{PROMETHEUS_URL}/api/v1/query",
params={'query': query}
)
results = response.json()['data']['result']
for result in results:
if is_policy_violation(result):
send_alert(result)
auto_remediate(result) # Optional: auto-quarantine
def is_policy_violation(metric):
# Check against authorization policies
source = metric['metric']['source']
destination = metric['metric']['destination']
# Query Istio authz logs or policy store
return not check_policy_exists(source, destination)
Phase 7: Production Checklist
Pre-Rollout Validation
# 1. Verify mTLS is working
kubectl exec -it <pod> -- curl -v https://<service>:<port> --cacert /etc/certs/root-cert.pem
# 2. Check service identities
kubectl get secret <pod-secret> -o jsonpath='{.data.tls.crt}' | base64 -d | openssl x509 -text -noout
# 3. Validate policies
istioctl authz check <pod> --from-source="spiffe://cluster.local/ns/production/sa/cart-service" --to-service="inventory.production.svc.cluster.local:8080"
# 4. Test policy bypass attempt
kubectl exec -it <untrusted-pod> -- curl http://inventory.production.svc:8080/health
# Should be blocked
Monitoring Dashboards (Grafana)
{
"dashboard": {
"title": "Zero-Trust Mesh Security",
"panels": [
{
"title": "mTLS Enforcement Rate",
"targets": [{
"expr": "sum(istio_tcp_connections_total{connection_security_policy='mTLS'}) / sum(istio_tcp_connections_total) * 100"
}]
},
{
"title": "Authorization Decisions",
"targets": [{
"expr": "rate(istio_authorization_policy_denied[5m])"
}]
},
{
"title": "Service Identity Validation",
"targets": [{
"expr": "istio_requests_total{destination_principal!=''}"
}]
}
]
}
}
Rollout Timeline
| Week | Focus Area | Success Criteria |
|---|
| 1-2 | Discovery | Map all service-to-service dependencies |
| 3-4 | Identity | 100% services have SPIFFE identities |
| 5-6 | mTLS (Permissive) | All traffic encrypted, no breakage |
| 7-8 | mTLS (Strict) | No plaintext traffic in mesh |
| 9-10 | Policy Definition | Zero-trust policies defined for all critical paths |
| 11-12 | Policy Enforcement | Default-deny on production, monitoring alerts active |
| 13+ | Optimization | Fine-tune policies based on telemetry |
Key Tools & Configurations
# values.yaml for Helm chart (if using)
global:
meshID: "mesh1"
trustDomain: "example.com"
caAddresses: ["istiod.istio-system.svc:443"]
proxy:
autoInject: "enabled"
# Enable telemetry
env:
ISTIO_META_TELEMETRY_ENABLED: "true"
ISTIO_META_TLS_CLIENT_PROFILE: "modern"
security:
enableAuditLogs: true
defaultAdmissionPolicy: "STRICT"
telemetry:
enabled: true
v2:
prometheus:
enabled: true
stackdriver:
enabled: false # Use Prometheus
kiali:
enabled: true
Common Pitfalls & Mitigations
- Breakage from mTLS: Use
PERMISSIVE mode first, monitor istio_tcp_connections_total{connection_security_policy="none"}
- Policy Loops: Ensure
AuthorizationPolicy doesn't block control plane traffic
- Performance Overhead: Benchmark with/without sidecar; adjust
concurrency settings
- Certificate Expiry: Monitor
istiod_istio_ca_server_cert_expiry_seconds
- Identity Sprawl: Implement naming convention:
spiffe://<trust-domain>/ns/<ns>/sa/<sa-name>
Verification Commands
# 1. Check all services have identities
kubectl get pods -n production -o jsonpath='{range .items[*]}{.metadata.name}{" -> "}{.spec.serviceAccountName}{"\n"}{end}'
# 2. Verify mTLS is active
istioctl authn tls-check <pod-name>.<namespace>
# 3. Test policy enforcement
kubectl exec -it <test-pod> -- \
curl -H "Authorization: Bearer invalid-token" \
http://target-service/target-endpoint
# 4. View authorization logs
kubectl logs -n istio-system -l app=istiod -c discovery | grep -i authz
# 5. Check mesh topology
istioctl proxy-status
istioctl proxy-config clusters <pod> | grep mTLS
Post-Rollout: Continuous Validation
# Automated compliance check (run daily)
#!/bin/bash
# check_zero_trust_compliance.sh
CHECKS=(
"All services in prod have PeerAuthentication=STRICT"
"No services using 'NONE' security policy"
"AuthorizationPolicy exists for every public endpoint"
"100% of external traffic requires JWT"
"No certificate expiring in <7 days"
)
# Implement checks using kubectl/istioctl/jq
# Export results to audit log
This provides a complete, production-grade zero-trust mesh rollout. Start with a non-production environment, validate each phase, and gradually expand. The key is comprehensive observability - you can't secure what you can't see.