1 # 터미널 1 wa 2 # 터미널 2 Polaris & Mario 보안 실습 로드맵 # 1. Helm 레포지토리 추가 및 설치 helm repo add fairwinds-stable https://charts.fairwinds.com/stable helm repo update helm install polaris fairwinds-stable/polaris --namespace polaris --create-namespace --set dashboard.enabled=true # 2. 대시보드 외부 노출 (Classic ELB 생성) kubectl patch svc polaris-dashboard -n polaris -p '{"spec": {"type": "LoadBalancer"}}' # 3. 대시보드 접속 주소 확인 (나중에 접속용) kubectl get svc -n polaris polaris-dashboard 3 # [취약한 버전] 리소스 제한 없음, 보안 설정 없음 cat < mario-insecure.yaml apiVersion: apps/v1 kind: Deployment metadata: name: mario-insecure spec: replicas: 1 selector: matchLabels: app: mario-insecure template: metadata: labels: app: mario-insecure spec: containers: - name: mario image: pengbai/docker-supermario EOF kubectl apply -f mario-insecure.yaml 4 # [보안 강화 버전] 리소스 제한, 헬스체크, 비루트 계정 적용 cat < mario-secure.yaml apiVersion: apps/v1 kind: Deployment metadata: name: mario-secure spec: replicas: 1 selector: matchLabels: app: mario-secure template: metadata: labels: app: mario-secure spec: securityContext: runAsNonRoot: true runAsUser: 1000 containers: - name: mario image: pengbai/docker-supermario resources: limits: cpu: 200m memory: 256Mi livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 securityContext: allowPrivilegeEscalation: false EOF kubectl apply -f mario-secure.yaml 5 cat < mario-service.yaml apiVersion: v1 kind: Service metadata: name: mario-service spec: type: LoadBalancer ports: - port: 80 targetPort: 8080 selector: app: mario-insecure # 우선 취약한 버전으로 연결 테스트 EOF kubectl apply -f mario-service.yaml # 접속할 게임 주소(DNS Name) 확인 kubectl get svc mario-service 6 # 1. 마리오 게임용 ELB 보안 그룹 ID 찾기 및 80포트 개방 ELB_SG=$(aws elb describe-load-balancers --region ap-northeast-2 --query 'LoadBalancerDescriptions[?contains(DNSName, `afd671b4`)].SecurityGroups[0]' --output text) aws ec2 authorize-security-group-ingress --region ap-northeast-2 --group-id $ELB_SG --protocol tcp --port 80 --cidr 0.0.0.0/0 # 2. 마리오 NodePort 확인 (3xxxx 번호) MARIO_NP=$(kubectl get svc mario-service -o jsonpath='{.spec.ports[0].nodePort}') # 3. 워커 노드 보안 그룹 ID 찾기 및 NodePort 개방 NODE_SG=$(aws ec2 describe-instances --region ap-northeast-2 --filters "Name=instance-state-name,Values=running" "Name=tag:Name,Values='*nodes*'" --query 'Reservations[0].Instances[0].SecurityGroups[0].GroupId' --output text) aws ec2 authorize-security-group-ingress --region ap-northeast-2 --group-id $NODE_SG --protocol tcp --port $MARIO_NP --cidr 0.0.0.0/0 7 --------------- cat < mario-perfect-100.yaml apiVersion: apps/v1 kind: Deployment metadata: name: mario-perfect namespace: default spec: replicas: 1 selector: matchLabels: app: mario-perfect template: metadata: labels: app: mario-perfect spec: # [Security] 컨테이너 레벨이 아닌 포드 레벨에서도 보안 강화 securityContext: runAsNonRoot: true runAsUser: 1000 fsGroup: 2000 containers: - name: mario image: pengbai/docker-supermario ports: - containerPort: 8080 # 1. [Efficiency] 자원 할당량 및 제한 설정 (빨간색 경고 해결) resources: limits: cpu: 200m memory: 256Mi requests: cpu: 100m memory: 128Mi # 2. [Reliability] 가용성 보장을 위한 헬스 체크 (Liveness/Readiness) livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 periodSeconds: 10 readinessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 periodSeconds: 10 # 3. [Security] 컨테이너 내부 보안 심화 설정 (100점의 핵심) securityContext: allowPrivilegeEscalation: false # 권한 상승 금지 privileged: false # 특권 모드 해제 readOnlyRootFilesystem: false # (참고) 마리오는 쓰기 권한이 필요해 false로 유지 runAsNonRoot: true capabilities: drop: - ALL # 불필요한 리눅스 커널 기능 전체 제거 EOF kubectl apply -f mario-perfect-100.yaml