"Not a Pentest" Hinweis: Dieser Guide dient der Absicherung eigener Microservices-Infrastrukturen. Kein Angriffs-Tool.
Microservices Security · Zero-Trust Architecture
Microservices Security: Architektur-Patterns
Vollständige Microservices-Absicherung mit Zero-Trust-Architektur, API-Gateway-Security, Service Mesh und Container Security Patterns.
Microservices Security Grundlagen
Grundlegende Security-Prinzipien
- Zero-Trust-Netzwerkarchitektur
- Defense-in-Depth-Strategie
- Minimale Zugriffsprivilegien (Least Privilege)
- Gesicherte Service-zu-Service-Kommunikation
- Umfassende Observability und Logging
Zero-Trust-Architektur
# Zero-Trust Network Policy Example
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: zero-trust-policy
namespace: production
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: api-gateway
- podSelector:
matchLabels:
app: auth-service
ports:
- protocol: TCP
port: 8080
egress:
- to:
- namespaceSelector:
matchLabels:
name: database
- podSelector:
matchLabels:
app: postgres
ports:
- protocol: TCP
port: 5432
# Service Account with RBAC
apiVersion: v1
kind: ServiceAccount
metadata:
name: microservice-sa
namespace: production
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: microservice-role
namespace: production
rules:
- apiGroups: [""]
resources: ["configmaps", "secrets"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: microservice-binding
namespace: production
subjects:
- kind: ServiceAccount
name: microservice-sa
namespace: production
roleRef:
kind: Role
name: microservice-role
apiGroup: rbac.authorization.k8s.ioAPI Gateway Security
# Kong API Gateway Security Configuration
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: rate-limiting
namespace: production
config:
minute: 100
hour: 1000
policy: local
plugin: rate-limiting
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: jwt-auth
namespace: production
config:
key_claim_name: "iss"
secret_is_base64: false
plugin: jwt
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: api-ingress
namespace: production
annotations:
konghq.com/plugins: rate-limiting,jwt-auth
spec:
ingressClassName: kong
rules:
- host: api.example.com
http:
paths:
- path: /v1
pathType: Prefix
backend:
service:
name: user-service
port:
number: 8080
# JWT Authentication Configuration
apiVersion: v1
kind: Secret
metadata:
name: jwt-secret
namespace: production
type: Opaque
stringData:
rsa-key: |
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAzK8Q...
-----END RSA PRIVATE KEY-----Container Security Patterns
# Secure Container Configuration
apiVersion: v1
kind: Pod
metadata:
name: secure-microservice
namespace: production
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
containers:
- name: app
image: nginx:1.21-alpine
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
runAsNonRoot: true
runAsUser: 1000
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "200m"
volumeMounts:
- name: tmp
mountPath: /tmp
- name: cache
mountPath: /var/cache/nginx
volumes:
- name: tmp
emptyDir: {}
- name: cache
emptyDir: {}
# Pod Security Policy
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: restricted-psp
spec:
privileged: false
allowPrivilegeEscalation: false
requiredDropCapabilities:
- ALL
volumes:
- 'configMap'
- 'emptyDir'
- 'projected'
- 'secret'
- 'downwardAPI'
- 'persistentVolumeClaim'
runAsUser:
rule: 'MustRunAsNonRoot'
seLinux:
rule: 'RunAsAny'
fsGroup:
rule: 'RunAsAny'Service Mesh Integration
# Istio Service Mesh Security
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: production
spec:
mtls:
mode: STRICT
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: allow-specific-services
namespace: production
spec:
selector:
matchLabels:
app: user-service
rules:
- from:
- source:
principals: ["cluster.local/ns/production/sa/frontend-sa"]
- to:
- operation:
methods: ["GET", "POST"]
paths: ["/api/v1/*"]
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: user-service
namespace: production
spec:
hosts:
- user-service
http:
- match:
- uri:
prefix: "/health"
route:
- destination:
host: user-service
port:
number: 8080
timeout: 5s
retries:
attempts: 3
perTryTimeout: 2s
---
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: jwt-auth
namespace: production
spec:
selector:
matchLabels:
app: user-service
jwtRules:
- issuer: "https://auth.example.com"
jwksUri: "https://auth.example.com/.well-known/jwks.json"
forwardOriginalToken: trueSecurity Best Practices
Image Security
Use minimal base images, scan for vulnerabilities, and sign images with cosign.
Secrets Management
Never store secrets in containers, use external secret management systems.
Network Segmentation
Implement network policies and service mesh for defense in depth.
Observability
Comprehensive logging, metrics, and tracing for security monitoring.
Weiterführende Ressourcen
Microservices Security Score Calculator — Wie sicher sind deine Microservices?
Beantworte 5 Fragen und erhalte deinen Microservices Security Score (0-100). Dieser Score basiert auf Best Practices aus der Produktion.
Daypass — 24h Full Access für €3
Einmalig pro User/Kreditkarte. Volle 24 Stunden Zugang zu allen Security-Tools.
✓ Security Check✓ Runbooks✓ AI Copilot