Security11 dk okuma10 Kasım 2024

Kubernetes Security: Production Ortamında Yapılması Gerekenler

Cluster yönetimi deneyimimle Kubernetes güvenliği için kritik adımlar. Network policies, RBAC ve secret management.

İçindekiler

Kubernetes Security: Production Ortamında Yapılması Gerekenler

Kubernetes cluster'ları güvenli hale getirmek, sadece cluster'ı kurmak kadar önemli. Bu rehberde, production ortamlarında uyguladığım güvenlik best practice'lerini paylaşıyorum.

RBAC Konfigürasyonu

Principle of least privilege uygulayın. Her kullanıcı sadece ihtiyacı olan kaynaklara erişebilmeli:

rbac-config.yamlYAML
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: developer
rules:
- apiGroups: [""]
  resources: ["pods", "services"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get", "list", "watch", "update", "patch"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: developer-binding
subjects:
- kind: User
  name: developer@company.com
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: developer
  apiGroup: rbac.authorization.k8s.io

Network Policies ile Traffic Kontrolü

Pod'lar arası iletişimi sınırlayın. Default deny policy uygulayın:

network-policies.yamlYAML
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-frontend-to-backend
spec:
  podSelector:
    matchLabels:
      app: frontend
  policyTypes:
  - Egress
  egress:
  - to:
    - podSelector:
        matchLabels:
          app: backend
    ports:
    - protocol: TCP
      port: 8080

Secret Management

Secret'ları güvenli şekilde yönetin. External secret management kullanın:

secret-management.yamlYAML
# AWS Secrets Manager ile secret sync
apiVersion: v1
kind: Secret
metadata:
  name: app-secrets
type: Opaque
data:
  database-password: <base64-encoded-password>
  api-key: <base64-encoded-api-key>

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  template:
    spec:
      containers:
      - name: app
        image: myapp:latest
        env:
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: app-secrets
              key: database-password

Pod Security Standards

Pod Security Standards uygulayarak güvenli pod'lar oluşturun:

pod-security.yamlYAML
apiVersion: v1
kind: Namespace
metadata:
  name: production
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/warn: restricted

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: secure-app
spec:
  template:
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        fsGroup: 2000
      containers:
      - name: app
        image: myapp:latest
        securityContext:
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
          capabilities:
            drop:
            - ALL

İpucu: Regular security scanning yapın. Trivy veya Falco kullanın.

Dikkat: Root olarak çalışan container'ları production'da kullanmayın!

OU

Onur Ulusoy

Senior DevOps Engineer | BaseOpsCloud

5+ yıl enterprise deneyimi ile Kubernetes, cloud altyapı ve DevOps konularında uzman. Azure Solutions Architect Expert sertifikalı. 30+ Kubernetes cluster yönetimi deneyimi.

DevOps Danışmanlığı

Kubernetes & Cloud uzmanı

5+ yıl deneyim
30+ cluster
Azure Expert
KVKK uyumlu