PSC üreticisi uç nokta tabanlı erişim denetimi

1. Giriş

Private Service Connect

Private Service Connect, Google Cloud ağ iletişimi özelliğidir. Bu özellik, tüketicilerin VPC ağlarının içinden yönetilen hizmetlere özel olarak erişmesine olanak tanır. Aynı şekilde, yönetilen hizmet üreticilerinin bu hizmetleri kendi ayrı VPC ağlarında barındırmasına ve tüketicilerine özel bir bağlantı sunmasına olanak tanır.

50b907b09af4d8ac.png

Private Service Connect üretici erişim denetimi

Üreticiler, herhangi bir tüketiciden gelen tüm bağlantıları otomatik olarak kabul etmek yerine yalnızca tüketici kabul listesinde yer alan tüketicilerden gelen gelen bağlantı isteklerini kabul edebilir. Tüketicileri proje, VPC ağı veya tek tek PSC uç noktası bazında belirtebilirsiniz. Farklı tüketici türlerini aynı tüketici kabul veya ret listesine ekleyemezsiniz.

Her iki bağlantı tercihi için de kabul edilen bağlantılar, gelen bağlantıları engelleyen bir kuruluş politikası (compute.restrictPrivateServiceConnectConsumer) tarafından geçersiz kılınabilir ve reddedilebilir.

Kuruluş politikasının (compute.restrictPrivateServiceConnectConsumer) kuruluş,klasör veya proje için geçerli olduğunu lütfen unutmayın. PSC uç noktasına ayrıntılı erişim denetimi uygulamak istiyorsanız tek tek PSC uç noktalarının tüketici kabul listesini kullanabilirsiniz.

Uç nokta tabanlı erişim denetimi

PSC uç noktası tabanlı erişim denetimi, üreticinin hizmet ekleme politikalarındaki bireysel PSC uç noktaları aracılığıyla tüketicileri yetkilendirme özelliğidir.

Çok kiracılı hizmetler için önerilen bu yaklaşım, bağlantıları yönetmek için en ayrıntılı kontrolü sağlar.

Bu codelab'de, bu özelliğin nasıl yapılandırılacağı öğretilmektedir.

Bu yöntemin Private Service Connect arka uçları için geçerli olmadığını lütfen unutmayın.

2. Neler öğreneceksiniz?

  • Üretici olarak PSC kullanarak hizmet yayınlama
  • Üretici olarak PSC uç noktası tabanlı erişim denetimi oluşturma
  • Tüketici olarak PSC hizmetine nasıl erişilir?

3. Genel Laboratuvar Mimarisi

3d7cbafaffb50d2d.png

4. Hazırlık adımları

Laboratuvarda çalışmak için gereken IAM rolleri

Gerekli IAM rollerini proje düzeyinde GCP hesabına atayarak işe başlayın.

  • Compute Ağ Yöneticisi (roles/compute.networkAdmin): Bu rol, Compute Engine ağ iletişimi kaynakları üzerinde tam kontrol sağlar.
  • Günlük kaydı yöneticisi (roles/logging.admin): Bu rol, tüm günlük kaydı izinlerine ve bunlara bağlı izinlere erişmenizi sağlar.
  • Hizmet Kullanımı Yöneticisi (roles/serviceusage.serviceUsageAdmin): Bu rol, hizmet durumlarını etkinleştirme, devre dışı bırakma ve inceleme; işlemleri inceleme ve tüketici projeleri için kota tüketimi ve faturalandırma yetkisi verir.
  • Compute Instance Admin (roles/compute.instanceAdmin.v1): Bu rol, Compute Engine örnekleri, örnek grupları, diskler, anlık görüntüler ve görüntüler üzerinde tam kontrol sağlar. Tüm Compute Engine ağ iletişimi kaynaklarına okuma erişimi.
  • Compute Security Admin (roles/compute.securityAdmin): Bu rol, güvenlik duvarı kurallarını ve SSL sertifikalarını oluşturma, değiştirme ve silme izinlerinin yanı sıra Korumalı Sanal Makine ayarlarını yapılandırma izni verir.

API'leri etkinleştir

Cloud Shell'de projenizin doğru şekilde yapılandırıldığından ve ortam değişkenlerinizin ayarlandığından emin olun.

Cloud Shell'de aşağıdakileri yapın:

gcloud auth login
gcloud config set project <your project id>
export project_id=$(gcloud config get-value project)
export region=us-central1
export zone=$region-a
echo $project_id
echo $region
echo $zone

Projede gerekli tüm Google API'lerini etkinleştirin. Cloud Shell'de aşağıdakileri yapın:

gcloud services enable \
  compute.googleapis.com 
  

Üretici VPC'si oluşturma

Projede, özel alt ağ moduna sahip bir VPC ağı oluşturun. Cloud Shell'de aşağıdakileri yapın:

gcloud compute networks create producer-net \
    --subnet-mode=custom

Üretici VPC'sinde alt ağlar oluşturma

Üç alt ağa ihtiyacınız olacak: hizmetiniz için producer-subnet; yük dengeleyicinin hizmetinizi yayınlaması için proxy-only-subnet; hizmeti yayınlamak için PSC'nin psc-subnet'i.

Cloud Shell'de IPv4 alt ağları oluşturmak için aşağıdakileri yapın:

gcloud compute networks subnets create producer-subnet \
    --network=producer-net \
    --range=10.10.0.0/24 \
    --region=$region
gcloud compute networks subnets create proxy-only-subnet \
    --purpose=REGIONAL_MANAGED_PROXY \
    --role=ACTIVE \
    --region=$region \
    --network=producer-net \
    --range=10.30.0.0/24
gcloud compute networks subnets create psc-subnet \
    --network=producer-net \
    --region=$region \
    --range=192.168.0.0/16 \
    --purpose=PRIVATE_SERVICE_CONNECT

Üretici VPC'si için Cloud NAT ve Cloud Router oluşturun

Cloud NAT, sanal makinenin uygulamaları indirip yüklemesine izin vermek için kullanılır.

gcloud compute routers create $region-cr \
   --network=producer-net \
   --region=$region
gcloud compute routers nats create $region-nat \
    --router=$region-cr \
    --region=$region \
    --nat-all-subnet-ip-ranges \
    --auto-allocate-nat-external-ips

Tüketici VPC'si oluşturma

Projede, özel alt ağ moduna sahip bir VPC ağı oluşturun. Cloud Shell'de aşağıdakileri yapın:

gcloud compute networks create consumer-net \
    --subnet-mode=custom

Tüketici VPC'sinde alt ağ oluşturma

Cloud Shell'de bir IPv4 alt ağı oluşturmak için aşağıdakileri yapın:

gcloud compute networks subnets create consumer-subnet \
    --network=consumer-net \
    --range=10.20.0.0/24 \
    --region=$region

Üretici VPC'si ve tüketici VPC'si için genel bir güvenlik duvarı politikası oluşturma

Genel bir ağ güvenlik duvarı politikası oluşturup bunu üretici VPC'si ve tüketici VPC'si ile ilişkilendireceksiniz.

gcloud compute network-firewall-policies create global-fw-policy \
--global
gcloud compute network-firewall-policies associations create \
    --firewall-policy=global-fw-policy \
    --name=producer-fw-policy \
    --network=producer-net \
    --global-firewall-policy 
gcloud compute network-firewall-policies associations create \
    --firewall-policy=global-fw-policy \
    --name=consumer-fw-policy \
    --network=consumer-net \
    --global-firewall-policy 

SSH'ye izin ver

Identity-Aware Proxy'nin (IAP) sanal makine örneklerinize bağlanmasına izin vermek için aşağıdaki özellikleri içeren bir güvenlik duvarı kuralı oluşturun:

  • IAP kullanarak erişmek istediğiniz tüm sanal makine örnekleri için geçerlidir.
  • 35.235.240.0/20 IP aralığından gelen giriş trafiğine izin verir. Bu aralık, IAP'nin TCP yönlendirme için kullandığı tüm IP adreslerini içerir.
gcloud compute network-firewall-policies rules create 100 \
    --action=ALLOW \
    --firewall-policy=global-fw-policy \
    --description="producer-allow-iap" \
    --direction=INGRESS \
    --src-ip-ranges=35.235.240.0/20 \
    --layer4-configs=tcp:22  \
    --global-firewall-policy

Hizmetinize giriş güvenlik duvarı kuralları ekleme

Hizmeti yayınlamak için bölgesel dahili uygulama yük dengeleyiciyi kullanacaksınız.Giriş güvenlik duvarı kuralı y, yalnızca proxy alt ağının hizmete erişmesine izin vermelidir. Ayrıntılı bilgi için bu belgeyi inceleyin.

gcloud compute network-firewall-policies rules create 200 \
    --action=ALLOW \
    --firewall-policy=global-fw-policy \
    --description="producer-allow-access-service" \
    --direction=INGRESS \
    --src-ip-ranges=10.30.0.0/24 \
    --layer4-configs=tcp:80  \
    --global-firewall-policy

Yük dengeleyici durum denetiminin hizmetinize erişmesine izin verme

Bölgesel dahili uygulama yük dengeleyicisi durum denetimi sondaları 35.191.0.0/16 ve 130.211.0.0/22 aralıklarını kullanır. Kontrollerden gelen durum denetimlerine izin vermek için bir giriş güvenlik duvarı kuralı oluşturacaksınız. Daha fazla bilgi için bu belgeyi inceleyin.

gcloud compute network-firewall-policies rules create 300 \
    --action=ALLOW \
    --firewall-policy=global-fw-policy \
    --description="producer-allow-health-check" \
    --direction=INGRESS \
    --src-ip-ranges=35.191.0.0/16,130.211.0.0/22\
    --layer4-configs=tcp:80  \
    --global-firewall-policy

Tüketici VPC'sinde bir HTTP istemcisi olarak VM oluşturma

Cloud Shell'de test istemcisi olarak bir sanal makine örneği oluşturmak için aşağıdakileri yapın:

gcloud compute instances create myclient \
    --zone=$zone \
    --subnet=consumer-subnet \
    --shielded-secure-boot \
    --no-address

Üretici VPC'sinde HTTP sunucusu olarak bir sanal makine oluşturun.

Cloud Shell'de, HTTP sunucusu olarak bir sanal makine örneği oluşturmak için aşağıdakileri yapın:

gcloud compute instances create myserver \
    --subnet=producer-subnet \
    --zone=$zone \
    --no-address \
    --shielded-secure-boot \
    --metadata startup-script='#! /bin/bash
    sudo apt-get update
    sudo apt-get install apache2 -y
    a2enmod ssl
    sudo a2ensite default-ssl
    echo "I am a Http Server." | \
    tee /var/www/html/index.html
    systemctl restart apache2'

5. Üretici, PSC hizmetini yayınlar

Bölgesel dahili uygulama yük dengeleyicisi oluşturma

Hizmetin ön ucu olarak bölgesel bir dahili uygulama yük dengeleyicisi oluşturacaksınız. Arka uç ise uç noktası daha önce oluşturduğumuz HTTP sunucusu olan yönetilmeyen örnek grubu olacaktır.

Yük dengeleyicinin IP adresini ayırma

gcloud compute addresses create l7-ilb-ip-address \
    --region=$region \
    --subnet=producer-subnet

Örnek grubu oluşturma

Yönetilmeyen bir örnek grubu oluşturacak ve örnek grubuna myserver adlı sanal makine örneğini ekleyeceksiniz.

gcloud compute instance-groups unmanaged create my-service-ig \
    --zone=$zone
gcloud compute instance-groups unmanaged add-instances my-service-ig \
    --zone=$zone \
    --instances=myserver

HTTP durum denetimi oluşturma

gcloud compute health-checks create http l7-ilb-basic-check \
     --region=$region \
     --use-serving-port

Arka uç hizmetini oluşturun

gcloud compute backend-services create l7-ilb-backend-service \
    --load-balancing-scheme=INTERNAL_MANAGED \
    --protocol=HTTP \
    --health-checks=l7-ilb-basic-check \
    --health-checks-region=$region \
    --region=$region

Arka ucu arka uç hizmetine ekleme

gcloud compute backend-services add-backend l7-ilb-backend-service \
    --balancing-mode=UTILIZATION \
    --instance-group=my-service-ig \
    --instance-group-zone=$zone \
    --region=$region

URL eşlemesini oluşturma

gcloud compute url-maps create l7-ilb-map \
    --default-service=l7-ilb-backend-service \
    --region=$region

Hedef proxy'yi oluşturma

gcloud compute target-http-proxies create l7-ilb-proxy \
    --url-map=l7-ilb-map \
    --url-map-region=$region \
    --region=$region

İletim kuralını oluşturma

gcloud compute forwarding-rules create l7-ilb-forwarding-rule \
    --load-balancing-scheme=INTERNAL_MANAGED \
    --network=producer-net \
    --subnet=producer-subnet \
    --address=l7-ilb-ip-address \
    --ports=80 \
    --region=$region \
    --target-http-proxy=l7-ilb-proxy \
    --target-http-proxy-region=$region

PSC üreticisi hizmeti yayınlar

Hizmeti connection-preference=ACCEPT_MANUAL ve boş tüketici listeleriyle yayınlamak için PSC'yi kullanacaksınız.

gcloud compute service-attachments create my-psc-service \
    --region=$region \
 --target-service=projects/$project_id/regions/$region/forwardingRules/l7-ilb-forwarding-rule \
    --connection-preference=ACCEPT_MANUAL \
    --nat-subnets=psc-subnet
export myserver_service_attachment=$(gcloud compute service-attachments describe my-psc-service --region=$region --format="value(selfLink.scope(v1))")

echo $myserver_service_attachment

6. Tüketici, PSC uç noktasını oluşturur.

PSC uç noktası için IP ayırtma

gcloud compute addresses create myserver-psc-endpoint-ip \
    --region=$region \
    --subnet=consumer-subnet \
    --ip-version=IPV4

PSC uç noktası oluşturma

PSC uç noktası oluşturun ve sonraki adımda test için PSC uç noktasının IP'sini alın.

gcloud compute forwarding-rules create myserver-psc-endpoint \
    --region=$region \
    --network=consumer-net \
    --address=myserver-psc-endpoint-ip \
    --target-service-attachment=$myserver_service_attachment
psc_endpoint_ip=$(gcloud compute forwarding-rules describe myserver-psc-endpoint \
    --region=$region --format="value(IPAddress)")

echo $psc_endpoint_ip

Tüketici, PSC uç nokta durumunu kontrol eder

Üretici, tüketici listesine PSC uç noktasını eklemeden önce bağlantı, tüketici tarafındaki Bağlı uç nokta bölümünde Beklemede durumuyla görünür.

gcloud compute forwarding-rules describe myserver-psc-endpoint \
    --region=$region

Aşağıdakine benzer bir sonuç görürsünüz.

IPAddress: 10.20.0.3
allowPscGlobalAccess: false
creationTimestamp: '2026-02-23T16:27:27.920-08:00'
fingerprint: yh_UiYqjHCc=
id: '934193159895862912'
kind: compute#forwardingRule
labelFingerprint: 42WmSpB8rSM=
name: myserver-psc-endpoint
network: https://www.googleapis.com/compute/v1/projects/<project_id>/global/networks/consumer-net
networkTier: PREMIUM
pscConnectionId: '160443618817212419'
pscConnectionStatus: PENDING
region: https://www.googleapis.com/compute/v1/projects/<project_id>/regions/us-central1
selfLink: https://www.googleapis.com/compute/v1/projects/<project_id>/regions/us-central1/forwardingRules/myserver-psc-endpoint
selfLinkWithId: https://www.googleapis.com/compute/v1/projects/<project_id>/regions/us-central1/forwardingRules/934193159895862912
serviceDirectoryRegistrations:
- namespace: goog-psc-default
target: https://www.googleapis.com/compute/v1/projects/<project_id>/regions/us-central1/serviceAttachments/my-psc-service

7. Tüketici sanal makinesinden üretici sanal makinesine erişimi test etme

PSC uç noktası IP'sini kontrol edin.

echo $psc_endpoint_ip

myclient adlı sanal makineye SSH ile bağlanın ve http 80 bağlantı noktasında myserver adresine erişip erişemediğini test edin.

Cloud Shell'de aşağıdakileri yapın:

gcloud compute ssh \
    --zone=$zone "myclient" \
    --tunnel-through-iap 

Oluşturduğunuz PSC uç noktasına erişmek için curl'ü kullanın.

curl -m 10 <psc_endpoint_ip> 

Curl komutunun zaman aşımına uğradığını görürsünüz. Tüketici VPC'sindeki test istemcisi, üretici VPC'sindeki HTTP sunucusuna erişemiyor.

curl: (28) Connection timed out after 10001 milliseconds

SSH oturumundan çıkarak Cloud Shell'e dönün.

exit

8. Üretici, PSC uç noktasını onaylar.

Üretici, PSC uç nokta durumunu kontrol eder

Üretici, PSC uç noktasını tüketici listesine eklemeden önce bağlantı, hizmet ekinde Beklemede durumuyla görünür.

gcloud compute service-attachments describe my-psc-service --region=$region 

Aşağıdakine benzer bir sonuç görürsünüz.

connectedEndpoints:
- consumerNetwork: https://www.googleapis.com/compute/projects/<project_id>/global/networks/consumer-net
  endpoint: https://www.googleapis.com/compute/projects/<project_id>/regions/us-central1/forwardingRules/myserver-psc-endpoint
  endpointWithId: https://www.googleapis.com/compute/projects/<project_id>/regions/us-central1/forwardingRules/934193159895862912
  pscConnectionId: '160443618817212419'
  status: PENDING
connectionPreference: ACCEPT_MANUAL
creationTimestamp: '2026-02-23T13:27:33.886-08:00'
description: ''
enableProxyProtocol: false
fingerprint: -9EI8FCALrA=
id: '2578692595155826858'
kind: compute#serviceAttachment
name: my-psc-service
natSubnets:
- https://www.googleapis.com/compute/projects/<project_id>/regions/us-central1/subnetworks/psc-subnet
pscServiceAttachmentId:
  high: '149466704441770984'
  low: '2578692595155826858'
reconcileConnections: false
region: https://www.googleapis.com/compute/projects/<project_id>/regions/us-central1
selfLink: https://www.googleapis.com/compute/projects/<project_id>/regions/us-central1/serviceAttachments/my-psc-service
targetService: https://www.googleapis.com/compute/projects/<project_id>/regions/us-central1/forwardingRules/l7-ilb-forwarding-rule

PSC uç noktasının kimliğe dayalı URI'sini alma

PSC uç noktasının kimliğe dayalı URI'si, tüketicinin yeni oluşturduğu yönlendirme kuralının kimliğidir. Yukarıdaki örnekte "endpointWithId", tüketici tarafından oluşturulan PSC uç noktasının URI'sidir. Üreticinin uç nokta tabanlı erişim denetimi oluşturması için bu URI'ye ihtiyacı olacaktır.

( Lütfen PSC bağlantı kimliğinin aradığımız kimlik olmadığını unutmayın. )

export psc_endpoint_uri=$(gcloud compute service-attachments describe my-psc-service --region=$region --format="value(connectedEndpoints.endpointWithId)")

echo $psc_endpoint_uri

Tüketici kabul listesine PSC uç noktası kimliğine dayalı URI ekleme

gcloud compute service-attachments update my-psc-service \
    --region=$region \
    --consumer-accept-list=$psc_endpoint_uri

Üretici, PSC uç nokta durumunu kontrol eder

gcloud compute service-attachments describe my-psc-service --region=$region --format="value(connectedEndpoints)"

Aşağıdakine benzer bir sonuç görürsünüz. Durum "KABUL EDİLDİ" olarak değişti.

{'consumerNetwork': 'https://www.googleapis.com/compute/projects/<project_id>/global/networks/consumer-net', 'endpoint': 'https://www.googleapis.com/compute/projects/<project_id>/regions/us-central1/forwardingRules/myserver-psc-endpoint', 'endpointWithId': 'https://www.googleapis.com/compute/projects/<project_id>/regions/us-central1/forwardingRules/47564871796017232', 'pscConnectionId': '54547416268144643', 'status': 'ACCEPTED'}

9. Tüketici sanal makinesinden üretici sanal makinesine erişimi test etme

PSC uç noktası IP'sini kontrol edin.

echo $psc_endpoint_ip

myclient adlı sanal makineye SSH ile bağlanın ve http 80 bağlantı noktasında myserver adresine erişip erişemediğini test edin.

Cloud Shell'de aşağıdakileri yapın:

gcloud compute ssh \
    --zone=$zone "myclient" \
    --tunnel-through-iap 

Oluşturduğunuz PSC uç noktasına erişmek için curl'ü kullanın.

curl <psc_endpoint_ip>

Curl komutunun myserver adresinden yanıtı başarıyla döndürdüğünü görürsünüz. Tüketici VPC'sindeki test istemcisi, üretici VPC'sindeki HTTP sunucusuna erişti.

I am a Http Server.

SSH oturumundan çıkarak Cloud Shell'e dönün.

exit

10. Temizleme

Sanal makineleri temizleme

Cloud Shell'de aşağıdakileri yapın:

gcloud compute instances delete myserver --zone $zone --quiet
gcloud compute instances delete myclient --zone $zone --quiet

PSC tüketici bileşenlerini temizleme

gcloud compute forwarding-rules delete myserver-psc-endpoint \
    --region=$region --quiet
gcloud compute addresses delete myserver-psc-endpoint-ip \
    --region=$region --quiet

PSC üretici bileşenlerini temizleme

gcloud compute service-attachments delete my-psc-service \
    --region=$region --quiet
gcloud compute forwarding-rules delete l7-ilb-forwarding-rule \
    --region=$region --quiet
gcloud compute target-http-proxies delete l7-ilb-proxy \
    --region=$region --quiet
gcloud compute url-maps delete l7-ilb-map \
    --region=$region --quiet
gcloud compute backend-services remove-backend l7-ilb-backend-service \
    --instance-group=my-service-ig \
    --instance-group-zone=$zone \
    --region=$region --quiet
gcloud compute backend-services delete l7-ilb-backend-service \
    --region=$region --quiet
gcloud compute health-checks delete l7-ilb-basic-check \
     --region=$region --quiet
gcloud compute instance-groups unmanaged delete my-service-ig \
    --zone=$zone --quiet
gcloud compute addresses delete l7-ilb-ip-address \
    --region=$region --quiet

Güvenlik duvarı, Cloud NAT, Cloud Router ve VPC'leri temizleme

gcloud compute network-firewall-policies rules delete 100 \
    --firewall-policy=global-fw-policy \
    --global-firewall-policy --quiet
gcloud compute network-firewall-policies rules delete 200 \
    --firewall-policy=global-fw-policy \
    --global-firewall-policy --quiet
gcloud compute network-firewall-policies rules delete 300 \
    --firewall-policy=global-fw-policy \
    --global-firewall-policy --quiet
gcloud compute network-firewall-policies associations delete \
    --firewall-policy=global-fw-policy \
    --name=producer-fw-policy \
    --global-firewall-policy --quiet
gcloud compute network-firewall-policies associations delete \
    --firewall-policy=global-fw-policy \
    --name=consumer-fw-policy \
    --global-firewall-policy --quiet
gcloud compute network-firewall-policies delete global-fw-policy \
    --global --quiet
gcloud compute routers nats delete $region-nat \
    --router=$region-cr \
    --region=$region --quiet
gcloud compute routers delete $region-cr \
    --region=$region --quiet
gcloud compute networks subnets delete producer-subnet \
    --region=$region --quiet
gcloud compute networks subnets delete proxy-only-subnet \
    --region=$region --quiet
gcloud compute networks subnets delete psc-subnet \
    --region=$region --quiet
gcloud compute networks delete producer-net --quiet
gcloud compute networks subnets delete consumer-subnet \
    --region=$region --quiet
gcloud compute networks delete consumer-net --quiet

11. Tebrikler

Private Service Connect üretici uç noktası tabanlı erişim denetimini başarıyla test ettiniz.