설명
모든 IPv4 주소에 TCP 22를 허용하면 경로가 있는 클라이언트가 SSH 연결을 시도할 수 있습니다. Compute Engine API에서 출발지 대역과 출발지 태그는 어느 하나만 일치해도 허용합니다.
잠재적 영향
유출된 SSH 키가 있으면 승인되지 않은 출발지에서도 계정 로그인을 시도할 수 있습니다.
해결 방법
IAP 또는 VPN 등 승인된 경로를 먼저 시험하고 필요한 관리 출발지와 대상 VM에만 TCP 22를 허용하세요. 다른 규칙과 우선순위, OS Login·키·IAM 권한을 확인한 뒤 허용할 연결과 차단할 연결을 시험하세요.
예시
네트워크를 생략하면 기본 VPC가 사용됩니다. 실제 프로젝트와 서비스 계정 JSON 파일을 지정하세요. 첫 태스크는 과거 예시로, google.cloud 1.14.0은 이 source_tags, source_ranges, target_tags 조합을 거부합니다.
변경 전
yaml
- name: ssh_unrestricted
google.cloud.gcp_compute_firewall:
name: test-object
allowed:
- ip_protocol: tcp
ports:
- "22"
target_tags:
- test-ssh-server
- staging-ssh-server
source_tags:
- test-ssh-clients
project: "{{ project_id }}"
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
state: present
source_ranges:
- "0.0.0.0/0"
첫 태스크가 나타내는 API 규칙에서 출발지 태그는 0.0.0.0/0을 제한하지 않습니다. 대상 태그는 적용할 VM을 선택합니다.
변경 후
yaml
- name: ssh_restricted
google.cloud.gcp_compute_firewall:
name: test-object
allowed:
- ip_protocol: tcp
ports:
- "22"
target_tags:
- test-ssh-server
- staging-ssh-server
project: "{{ project_id }}"
auth_kind: serviceaccount
service_account_file: /tmp/auth.pem
state: present
source_ranges:
- "203.0.113.10/32"
고정된 관리 호스트가 직접 연결한다면 203.0.113.10/32를 해당 호스트의 IPv4 주소(/32)로 바꾸세요. IAP TCP 전달을 이용한다면 IAP의 IPv4 소스 대역 35.235.240.0/20을 사용하세요.