본문 바로가기
CSP (Cloud Service Provider)/GCP

보안 웹 프록시(secure-web-proxy) 실습

by BTC_XOXO 2023. 12. 7.

베하~
안녕하세요 3대 5000의 man, xoxo 입니다

저번 시간에 이어 이번 시간에는 GCP 리저널 서비스인 보안 웹 프록시(secure-web-proxy) 실습에 대해서 말씀드리겠습니다.

 

테스트 환경 설정

💡 시작 전 gcloud components update 를 추천드립니다.

 

1. API 활성화

gcloud services enable networksecurity.googleapis.com
gcloud services enable certificatemanager.googleapis.com
gcloud services enable networkservices.googleapis.com

 

 

2. SWP 전용 서브넷 생성

gcloud compute networks subnets create swp-subnet \\
    --purpose=REGIONAL_MANAGED_PROXY \\
    --role=ACTIVE \\
    --region=asia-northeast3 \\
    --network=swp-vpc \\
    --range=172.16.0.0/23

 

3. iap 방화벽 생성(ssh를 위함)

gcloud compute firewall-rules create $prefix-allow-iap-proxy \\
--direction=INGRESS \\
--priority=1000 \\
--network=$prefix-vpc \\
--action=ALLOW \\
--rules=tcp:22 \\
--source-ranges=35.235.240.0/20

TCP 전달을 위한 IAP 사용  |  IAP(Identity-Aware Proxy)  |  Google Cloud

 

TCP 전달을 위한 IAP 사용  |  IAP(Identity-Aware Proxy)  |  Google Cloud

의견 보내기 TCP 전달을 위한 IAP 사용 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 이 페이지에서는 IAP(Identity-Aware Proxy) TCP 전달을 사용하여 외부 IP 주소가

cloud.google.com

 

4. Cloud Router & Cloud NAT 생성

gcloud compute routers create ${prefix}-cr \\
--region=$region \\
--network=${prefix}-vpc
gcloud compute routers nats create $prefix-nat-gw-$region \\
--router=$prefix-cr \\
--router-region=$region \\
--auto-allocate-nat-external-ips \\
--nat-all-subnet-ip-ranges

 

 

5. Gateway Security Policy 생성

cat > /tmp/policy.yaml << EOF
description: Policy to allow .com traffic, then (/index.html), and finally TLS.
name: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy
EOF

gcloud network-security gateway-security-policies import ${prefix}-policy --source=/tmp/policy.yaml --location=${region}

 

6. URL 목록 생성 (관리의 효율성을 위해)

- 이렇게 관리하면 URL 목록만 관리하여 제어할 수 있습니다.

$ URL_LIST_FILE.yaml
name: projects/PROJECT_ID/locations/REGION/urlLists/example-org-allowed-list
values:
  - www.example.com
  - about.example.com
  - "*.google.com"
  - "github.com/example-org/*"

gcloud network-security url-lists import URL_LIST_NAME \\
    --location=REGION \\
    --project=PROJECT_ID \\
    --source=URL_LIST_FILE.yaml

 

7. Gateway Security Policy Rule 생성

cat > /tmp/rule-com.yaml << EOF
name: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy/rules/rule-com
enabled: true
priority: 1
description: Allow .com traffic
basicProfile: ALLOW
sessionMatcher: inUrlList(host(), 'projects/xoxoswp/locations/asia-northeast3/urlLists/dev') # 위에서 만든 url 목록 리스트에 있는 도메인만 아웃바운드 허용
EOF

gcloud network-security gateway-security-policies rules import rule-com --source=/tmp/rule-com.yaml --location=${region} --gateway-security-policy=${prefix}-policy

 

8. 인증서 등록

- 구글이 관리하는 인증서를 만들어야 SWP를 사용할 수 있습니다.

openssl req -x509 -newkey rsa:2048 -keyout /tmp/key.pem -out /tmp/cert.pem -days 365 -subj '/CN=www.codelab-swp.com' -nodes -addext \\
  "subjectAltName = DNS:www.codelab-swp.com"

gcloud certificate-manager certificates create ${prefix}-cert --location=${region} --private-key-file=/tmp/key.pem --certificate-file=/tmp/cert.pem

 

9. SWP 생성

cat > /tmp/gateway.yaml << EOF
name: projects/${project_id}/locations/${region}/gateways/${prefix}-gateway
type: SECURE_WEB_GATEWAY
addresses: [10.10.10.50]
ports: [443]
certificateUrls: [projects/${project_id}/locations/${region}/certificates/${prefix}-cert]
gatewaySecurityPolicy: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy
network: projects/${project_id}/global/networks/${prefix}-vpc
subnetwork: projects/${project_id}/regions/${region}/subnetworks/${prefix}-vpc-subnet
EOF

gcloud network-services gateways import ${prefix}-swp --source=/tmp/gateway.yaml --location=${region}

 

10. 테스트 아키텍처

 

11. VM과 SWP 연결 및 테스트

- Cloud SWP는 명시적 프록시이므로 프록시 IP를 VM에 명시적으로 지정을 해야 사용 가능합니다.

export http_proxy=http://10.10.10.51:80/  
export https_proxy=https://10.10.10.51:443/
curl naver.com -v --proxy-insecure
curl google.com -v --proxy-insecure

정상적으로 access denied 확인 (naver.com), 정상 반환 확인 (google)

 

 

이상으로 보안 웹 프록시에 실습에 대해 알아보았습니다. 

도움이 되었으면 좋겠고 다음에는 더 유익한 정보로 찾아뵙겠습니다 ~

 

 

'CSP (Cloud Service Provider) > GCP' 카테고리의 다른 글

App Engine과 각 언어 환경  (0) 2023.12.22
Resource에 Service Account 연결  (0) 2023.12.08
Bigquery 할당량 및 한도  (0) 2023.11.24
IAM - Condition  (1) 2023.11.24
보안 웹 프록시란(secure-web-proxy)?  (0) 2023.11.23

댓글