태그 및 서브넷을 필터링하도록 Google Cloud 방화벽을 구성합니다.

태그 및 서브넷을 필터링하도록 Google Cloud 방화벽을 구성합니다.

저는 Google Cloud Compute Engine 인스턴스에서 PostgreSQL을 실행하고 있으며 PostgreSQL은 현재 어디서나 연결을 허용하도록 구성되어 있습니다. 매번 서버에 로그인할 필요 없이 방화벽을 사용하여 액세스를 제어한다는 아이디어입니다.

현재 나는 다른 어떤 것도 잘못 구성되지 않았는지 확인하기 위해 라는 방화벽 규칙을 development-allow-psql모든 곳에서 허용하도록 설정했습니다.

Targets: All instances on network
Source Filter: IP Ranges
Source IP Ranges: 0.0.0.0/0
Second Source Filter: None
Specified protocols and ports: tcp:5432

달리기

psql "dbname=mydb host=__.___.__.__ user=myuser password=mypassword port=5432"

즉시 연결되지만 액세스를 허용하려는 인스턴스뿐만 아니라 어디에서나 연결됩니다.

이러한 인스턴스는 다음 설정으로 인스턴스를 생성하도록 구성된 템플릿을 Instance Group통해 자동으로 생성됩니다 .Instance Template

Network tags: myapp-api, http-server, https-server
Network: development
Subnetwork: development (with address range 10.154.0.0/20)

myapp-api이 DB 인스턴스에 대한 액세스를 태그가 있거나 서브네트워크가 있거나 둘 다 있는 인스턴스로 제한하고 싶습니다 10.154.0.0/20. 그래서 방화벽 설정을 다음과 같이 변경합니다.

Targets: Specified target tags
Target tags: myapp-api
Source Filter: Subnets
Subnets: 10.154.0.0/20
Second Source Filter: None
Specified protocols and ports: tcp:5432

이는 psql이전에 실행한 명령에 대한 액세스를 차단합니다. (psql 명령은 를 통해 액세스할 수 있는 docker 인스턴스에서 실행되고 있습니다 docker exec -ti -u0 my-instance-api-dev-small bash.)

내가 지금으로 바꾸면

Targets: All instances on the network
Source Filter: Subnets
Subnets: 10.154.0.0/20
Second Source Filter: Source tags
Source tags: myapp-api
Specified protocols and ports: tcp:5432

여전히 모든 액세스를 차단합니다. 이제 두 번째 소스 필터를 제거하고 서브넷에서만 필터링해도 여전히 액세스할 수 없습니다.

Targets: All instances on the network
Source Filter: Subnets
Subnets: 10.154.0.0/20
Second Source Filter: None
Specified protocols and ports: tcp:5432

태그 필터의 서브넷 소스 필터를 교체하는 경우:

Targets: All instances on the network
Source Filter: Source tags
Source tags: myapp-api
Second Source Filter: None
Specified protocols and ports: tcp:5432

... 아직 접근할 수 없습니다.

서브넷의 소스 필터를 선택하고 모든 서브넷을 선택하는 경우에도 동일합니다.

다음으로 전환:

Targets: All instances on the network
Source Filter: IP ranges
Source IP ranges: 0.0.0.0/0
Second Source Filter: Source tags
Source tags: myapp-api
Specified protocols and ports: tcp:5432

소스 태그를 지정하더라도 모든 사람(Google Cloud 외부 포함)이 다시 한 번 연결할 수 있습니다.

IP 주소 범위를 10.154.0.0/20으로 다시 변경하면 모든 사람이 차단됩니다.

Targets: All instances on the network
Source Filter: IP ranges
Source IP ranges: 10.154.0.0/20
Second Source Filter: Source tags
Source tags: myapp-api
Specified protocols and ports: tcp:5432

예를 들어 IP 범위를 인스턴스의 외부 IP 주소로 바꾸는 것은 35.189.124.141/32작동하지만 이러한 IP 주소는 임시이므로 자동 확장이 새 IP 주소로 더 많은 인스턴스를 추가할 때마다 방화벽 규칙을 업데이트해야 하므로 이는 해결책이 아닙니다.

특정 서브넷 및/또는 특정 태그의 인스턴스만 허용하도록 방화벽을 구성하려면 어떻게 해야 합니까? 내가 하고 있는 일이 효과가 없는 것 같습니다.

답변1

데이터베이스 인스턴스의 외부 IP 주소에서 내부 IP 주소로 전환하면 갑자기 위의 모든 조합이 작동합니다.

psql "dbname=mydb host=internal-ip-address-here user=myuser password=mypassword port=5432"

태그를 사용할 때 방화벽은 외부 IP 주소 대신 내부 IP 주소를 확인합니다.

Targets: All instances on the network
Source Filter: Subnets
Subnets: 10.154.0.0/20
Second Source Filter: Source tags
Source tags: myapp-api
Specified protocols and ports: tcp:5432

관련 정보