Argo CD Security Best Practices – ป้องกัน Cluster จากการโจมตี
Argo CD เป็นเครื่องมือ GitOps ที่มีประสิทธิภาพสำหรับการ deploy application ไปยัง Kubernetes cluster อย่างอัตโนมัติ อย่างไรก็ตาม การใช้งาน Argo CD ต้องติดตามความปลอดภัยเพื่อป้องกันการโจมตี และการเข้าถึงโดยไม่ได้รับอนุญาต บทความนี้จะแนะนำ best practices ในการรักษาความปลอดภัยของ Argo CD cluster ของคุณ
1. การตั้งค่า RBAC (Role-Based Access Control) ให้มีประสิทธิภาพ
RBAC เป็นแนวหน้าสำคัญในการควบคุมการเข้าถึง Argo CD โดยต้องกำหนดสิทธิ์ของผู้ใช้อย่างเหมาะสม
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: argocd-deployer
namespace: argocd
rules:
- apiGroups: ["argoproj.io"]
resources: ["applications"]
verbs: ["get", "list", "watch"]
- apiGroups: ["argoproj.io"]
resources: ["applications/action"]
verbs: ["create"]
- apiGroups: ["argoproj.io"]
resources: ["applications"]
resourceNames: ["my-app"]
verbs: ["sync"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argocd-deployer-binding
namespace: argocd
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: argocd-deployer
subjects:
- kind: User
name: [email protected]
apiGroup: rbac.authorization.k8s.io
หลักการสำคัญคือ principle of least privilege – ให้สิทธิ์เฉพาะที่ผู้ใช้ต้องการใช้งาน ไม่ใช่สิทธิ์ทั้งหมด
2. การป้องกันด้วย Network Policies
Network Policies ช่วยให้คุณสามารถควบคุมการเข้าถึงระหว่าง pods และ services ในภายในคลัสเตอร์
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: argocd-network-policy
namespace: argocd
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: argocd-server
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
role: developer
- namespaceSelector:
matchLabels:
name: ci-cd
ports:
- protocol: TCP
port: 8080
egress:
- to:
- namespaceSelector: {}
ports:
- protocol: TCP
port: 443
- to:
- podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- protocol: UDP
port: 53
ตรวจสอบให้แน่ใจว่า network policies ได้รับการ enforce อย่างถูกต้องเพื่อป้องกันการเข้าถึงที่ไม่ได้รับอนุญาต
3. การเข้ารหัส TLS/SSL และการสื่อสารปลอดภัย
การใช้ TLS/SSL เป็นสิ่งจำเป็นเพื่อเข้ารหัสการสื่อสารระหว่าง client และ Argo CD server
kubectl create secret tls argocd-tls \
--cert=path/to/cert.pem \
--key=path/to/key.pem \
-n argocd
kubectl patch ingress argocd-server \
-n argocd \
-p '{"spec":{"tls":[{"hosts":["argocd.example.com"],"secretName":"argocd-tls"}]}}'
เมื่อ deploy บน Cloud VPS เช่น ผู้ให้บริการโฮสติ้ง Cloud VPS ให้ใช้ TLS certificates ที่ได้รับการรับรองจากผู้ออกใบรับรองที่เชื่อถือได้เพื่อให้มั่นใจในความปลอดภัยของข้อมูลระหว่างการส่งผ่านเครือข่าย
4. การจัดการ Secrets อย่างปลอดภัย
Secrets ใน Argo CD ต้องเก็บรักษาอย่างระมัดระวัง โดยการใช้เครื่องมือเช่น Sealed Secrets หรือ External Secrets Operator
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
name: git-credentials
namespace: argocd
spec:
encryptedData:
password: AgCpq8u7H2I0vK3...
username: AgBvP9mL2j5x3K...
template:
type: Opaque
metadata:
name: git-credentials
namespace: argocd
ใช้ External Secrets Operator เพื่อให้ Secrets ไม่ถูกเก็บในโครงสร้างข้อมูล Git repository
5. การตั้งค่า Audit Logging เพื่อการตรวจสอบ
Audit Logging ช่วยให้คุณสามารถติดตามการกระทำทั้งหมดในระบบ Argo CD
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-server-config
namespace: argocd
data:
server.insecure: "false"
server.disable.auth: "false"
server.x.frame.options: "SAMEORIGIN"
application.instanceLabelKey: "argocd.argoproj.io/instance"
application.resourceTrackingMethod: "annotation"
url: "https://argocd.example.com"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-rbac-cm
namespace: argocd
data:
policy.csv: |
p, role:admin, applications, *, */*, allow
p, role:read-only, applications, get, */*, allow
g, team-lead, role:admin
policy.default: "role:read-only"
6. การแยก Namespaces เพื่อเพิ่มความปลอดภัย
ควรแยก Argo CD ออกจากการทำงานของ applications อื่น ๆ โดยใช้ namespace ที่แตกต่างกัน
kubectl create namespace argocd
kubectl create namespace argocd-staging
kubectl create namespace argocd-production
# กำหนด network policies สำหรับแต่ละ namespace
kubectl label namespace argocd-production environment=production
kubectl label namespace argocd-staging environment=staging
7. การ Harden Cluster และป้องกันการโจมตี
การ harden cluster ประกอบด้วยหลายขั้นตอน เช่น ปิด insecure APIs และการตั้งค่า SecurityContext อย่างถูกต้อง
apiVersion: v1
kind: Pod
metadata:
name: argocd-server
namespace: argocd
spec:
securityContext:
runAsNonRoot: true
runAsUser: 999
fsGroup: 999
seccompProfile:
type: RuntimeDefault
containers:
- name: argocd-server
image: argoproj/argocd:v2.x.x
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
volumeMounts:
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
emptyDir: {}
ใช้ Pod Security Policies หรือ Pod Security Standards เพื่อให้ pods ทั้งหมดต้องปฏิบัติตามมาตรฐานความปลอดภัย
8. การตรวจสอบและปรับปรุงระบบอย่างต่อเนื่อง
การตรวจสอบความปลอดภัยอย่างเป็นประจำถือเป็นส่วนสำคัญของการรักษาความปลอดภัย Argo CD
# ตรวจสอบสถานะของ Argo CD
argocd admin settings list
# ดูประวัติการเข้าถึง
kubectl logs -n argocd deployment/argocd-server | grep "action"
# ทำการ scan vulnerabilities ใน images
trivy image argoproj/argocd:v2.x.x
# ตรวจสอบ RBAC configuration
kubectl get roles,rolebindings -n argocd
9. การใช้ Argo CD กับ Cloud Infrastructure
เมื่อ deploy Argo CD บน Cloud VPS Infrastructure เช่น ผู้ให้บริการโฮสติ้ง Cloud VPS ให้ประกอบด้วยการตั้งค่าต่อไปนี้:
- ติดตั้ง Kubernetes cluster ด้วยเวอร์ชันที่อัพเดตล่าสุด
- เปิดใช้งาน API server authentication และ authorization
- ตั้งค่า firewall rules เพื่อยอมรับการเชื่อมต่อเฉพาะจากแหล่งที่มั่นใจได้เท่านั้น
- ใช้ private networks เพื่อการสื่อสารระหว่าง nodes
- ตั้งค่า backup และ disaster recovery plan
10. สรุปและข้อเสนอแนะ
การรักษาความปลอดภัยของ Argo CD ต้องใช้วิธีการแบบ defense-in-depth ที่รวมกันหลายชั้น การใช้ RBAC, Network Policies, TLS/SSL, Secret Management, Audit Logging และ Cluster Hardening ร่วมกันจะสร้าง security posture ที่แข็งแกร่ง
เมื่อ deploy บน ผู้ให้บริการโฮสติ้ง Cloud VPS ให้มั่นใจว่าคุณได้ทำตามทุกขั้นตอนข้างต้นเพื่อให้ได้ระดับความปลอดภัยสูงสุด นอกจากนี้ ให้ทำการอัพเดท components ทั้งหมดเป็นประจำ และ monitor logs เพื่อเฉพาะตัวอย่างการโจมตี

