Private Service Connect経由でプライベート接続できているか確認してみた

記事タイトルとURLをコピーする

G-gen の藤岡です。当記事では、Google Cloud(旧称 GCP)の Private Service Connect から Google Cloud APIs へのアクセスが Private Service Connect Endpoint 経由でプライベート接続できているか確認する方法を紹介します。

Private Service Connect とは

Private Service Connect とは、 外部 IP を持たない VM やオンプレミスのクライアントから内部ネットワーク経由で Google Cloud APIs や、Google Cloud でホストする独自サービスへアクセスできるようにするための仕組みです。

VPC 内に IP アドレスを持つエンドポイントが作られ、このエンドポイント経由で Google Cloud APIs や独自サービスにアクセスできるようになります。

類似機能として 限定公開の Google アクセス(Private Google Access)があります。この 2 つの違いについては当記事では触れませんので、以下の記事をご参照ください。

blog.g-gen.co.jp blog.g-gen.co.jp

検証の背景

インターネットを経由してないか確認

上述の通り、Private Service Connect を使うことで VM やオンプレミスのクライアントから内部ネットワーク経由で Google Cloud APIs へアクセスできます。しかし、設定に誤りがあった場合や意図しない設定により、Private Service Connect を経由せず、デフォルトルートからインターネットを経由していた、等のケースも考えられます。

そこで、当記事では Private Service Connect を経由して Google Cloud APIs へアクセスしているか確認する方法を紹介します。但し、ここで確認できるのはあくまで VM から Private Service Connect Endpoint までの通信 です。Google Cloud が管理するネットワーク(サービスプロデューサー)はユーザー側で確認はできません。

実施内容

確認方法

Private Service Connect の設定をした上で、VM 上で curl コマンドを実行します。その時の送信元と送信先までのアクセス経路を以下の 2 つの方法で確認します。

  • tcpdump コマンド
  • VPC フローログ

前提

# gcloud CLI のバージョン
fujioka@cloudshell:~ (xxxx)$ gcloud version | grep 'Google Cloud SDK'
Google Cloud SDK 441.0.0
fujioka@cloudshell:~ (xxxx)$
  • VM への接続
  • 当記事で扱わないこと
    • 各リソースの作成に必要な権限

構成図

以下の 2 つの経路で確認します。 Default Internet Gateway からインターネットを経由する場合(赤線)、インターネットに公開されている Cloud Storage のエンドポイント(storage.googleapis.com)へアクセスします。

Private Service Connect を使う場合(青線)、内部ネットワークを経由し、 Cloud Storage のエンドポイント(storage-pscendpoint.p.googleapis.com)へアクセスします。

構成図

構築

プロジェクトの作成と請求先アカウントの紐づけ

プロジェクトを作成し、作成したプロジェクトに請求先アカウントを紐づけます。

$ gcloud projects create ${PROJECT_ID} --name=${PROJECT_NAME} --organization=${ORGANIZATION_ID} && \
gcloud beta billing projects link ${PROJECT_ID} --billing-account=${BILLING_ACCOUNT_ID}

デフォルトプロジェクトのセット

作成したプロジェクトをデフォルトプロジェクトとしてセットし、結果を確認します。

$ gcloud config set project ${PROJECT_ID} && \
gcloud config list project

API の有効化

必要な API を有効化します。

  • Compute Engine API
  • Service Directory API
  • Cloud DNS API
$ gcloud services enable compute.googleapis.com servicedirectory.googleapis.com dns.googleapis.com

VPC とサブネットの作成

VPC とサブネットを作成します。後述の経路の確認で VPC フローログ を使うため有効化します。サンプルレートを 1.0(100%、すべてのログエントリを保持)としていますが、実際に処理されるパケットは平均で約 3% です。

gcloud compute networks create customer-vpc \
    --subnet-mode=custom &&
gcloud compute networks subnets create customer-subnet \
    --network=customer-vpc \
    --range=10.0.0.0/24 \
    --region=asia-northeast1 \
    --enable-flow-logs \
    --logging-flow-sampling=1.0 \
    --enable-private-ip-google-access

コンソールから作成する場合は以下の記事をご参照ください。

blog.g-gen.co.jp

ファイアウォールルールの作成

Cloud IAP 経由で VM へ SSH 接続するため、35.235.240.0/20 を許可するルールを作成します。

$ gcloud compute firewall-rules create allow-ssh-from-iap \
    --network customer-vpc \
    --direction ingress \
    --action allow \
    --source-ranges 35.235.240.0/20 \
    --rules=tcp:22

Compute Engine の作成

VM を作成します。一時的に外部 IP は付与しています。

$ gcloud compute instances create vm \
    --image=debian-10-buster-v20230711 \
    --image-project debian-cloud \
    --machine-type e2-micro \
    --network=customer-vpc \
    --subnet=customer-subnet \
    --zone asia-northeast1-b

VM に dnsutils をインストール後、外部 IP は外します。

# パッケージのアップデート
fujioka@vm:~$ sudo apt update

# dnsutils のインストール
fujioka@vm:~$ sudo apt install -y dnsutils

この状態では Cloud Storage エンドポイントはインターネット上のアドレス(storage.googleapis.com)が返ってきます。

fujioka@vm:~$ dig storage.googleapis.com

; <<>> DiG 9.11.5-P4-5.1+deb10u9-Debian <<>> storage.googleapis.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37777
;; flags: qr rd ra; QUERY: 1, ANSWER: 16, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;storage.googleapis.com.                IN      A

;; ANSWER SECTION:
storage.googleapis.com. 300     IN      A       142.250.207.48
storage.googleapis.com. 300     IN      A       142.250.196.112
storage.googleapis.com. 300     IN      A       142.250.196.144
storage.googleapis.com. 300     IN      A       172.217.175.80
storage.googleapis.com. 300     IN      A       216.58.220.144
storage.googleapis.com. 300     IN      A       142.250.199.112
storage.googleapis.com. 300     IN      A       172.217.175.112
storage.googleapis.com. 300     IN      A       142.251.222.16
storage.googleapis.com. 300     IN      A       142.251.42.144
storage.googleapis.com. 300     IN      A       142.251.42.176
storage.googleapis.com. 300     IN      A       142.251.42.208
storage.googleapis.com. 300     IN      A       142.251.222.48
storage.googleapis.com. 300     IN      A       172.217.26.240
storage.googleapis.com. 300     IN      A       172.217.31.144
storage.googleapis.com. 300     IN      A       172.217.161.80
storage.googleapis.com. 300     IN      A       142.250.198.16

;; Query time: 4 msec
;; SERVER: 169.254.169.254#53(169.254.169.254)
;; WHEN: Sun Aug 06 22:55:49 UTC 2023
;; MSG SIZE  rcvd: 307

fujioka@vm:~$ 

Private Service Connect の作成

エンドポイントに割り振る内部 IP アドレスを予約します。

gcloud compute addresses create psc-address \
  --global \
  --purpose=PRIVATE_SERVICE_CONNECT \
  --addresses=10.0.20.1 \
  --network=customer-vpc

転送ルールを作成します。

gcloud compute forwarding-rules create pscendpoint \
  --global \
  --network=customer-vpc \
  --address=psc-address \
  --target-google-apis-bundle=all-apis

Private Service Connect の確認

エンドポイントが機能していることを確認します。エンドポイントが機能している場合、以下のように HTTP 204 レスポンス コードが返されます。エンドポイントは、ping(ICMP)に応答しないため以下のように確認します。

fujioka@vm:~$ curl -v 10.0.20.1/generate_204
* Expire in 0 ms for 6 (transfer 0x5636b4fb80f0)
*   Trying 10.0.20.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x5636b4fb80f0)
* Connected to 10.0.20.1 (10.0.20.1) port 80 (#0)
> GET /generate_204 HTTP/1.1
> Host: 10.0.20.1
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 204 No Content
< Content-Length: 0
< Cross-Origin-Resource-Policy: cross-origin
< Date: Sun, 06 Aug 2023 22:56:48 GMT
< 
* Connection #0 to host 10.0.20.1 left intact
fujioka@vm:~$ 

443 ポートでも成功します。

fujioka@vm:~$ curl -v 10.0.20.1:443/generate_204
* Expire in 0 ms for 6 (transfer 0x5591c9b4c0f0)
*   Trying 10.0.20.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x5591c9b4c0f0)
* Connected to 10.0.20.1 (10.0.20.1) port 443 (#0)
> GET /generate_204 HTTP/1.1
> Host: 10.0.20.1:443
> User-Agent: curl/7.64.0
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host 10.0.20.1 left intact
curl: (52) Empty reply from server
fujioka@vm:~$ 

エンドポイントを作成すると、そのエンドポイントを使用して利用可能 API とサービスの DNS レコードが Service Directory によって作成されます。

Private Service Connect によって作られたゾーン

Service Directory によって作成されたレコードにより、Cloud Storage のエンドポイント(storage-pscendpoint.p.googleapis.com)へ内部ネットワークでアクセスできています。

fujioka@vm:~$ dig storage-pscendpoint.p.googleapis.com

; <<>> DiG 9.11.5-P4-5.1+deb10u9-Debian <<>> storage-pscendpoint.p.googleapis.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25971
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;storage-pscendpoint.p.googleapis.com. IN A

;; ANSWER SECTION:
storage-pscendpoint.p.googleapis.com. 60 IN A   10.0.20.1

;; Query time: 9 msec
;; SERVER: 169.254.169.254#53(169.254.169.254)
;; WHEN: Sun Aug 06 23:03:30 UTC 2023
;; MSG SIZE  rcvd: 81

fujioka@vm:~$ 

storage.googleapis.com はエンドポイント作成前と変わらずインターネット上に公開されているアドレスが返ってきます。

fujioka@vm:~$ dig storage.googleapis.com

; <<>> DiG 9.11.5-P4-5.1+deb10u9-Debian <<>> storage.googleapis.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29405
;; flags: qr rd ra; QUERY: 1, ANSWER: 16, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;storage.googleapis.com.                IN      A

;; ANSWER SECTION:
storage.googleapis.com. 300     IN      A       142.250.196.112
storage.googleapis.com. 300     IN      A       142.250.196.144
storage.googleapis.com. 300     IN      A       172.217.175.80
storage.googleapis.com. 300     IN      A       216.58.220.144
storage.googleapis.com. 300     IN      A       142.250.199.112
storage.googleapis.com. 300     IN      A       142.251.222.16
storage.googleapis.com. 300     IN      A       142.251.42.144
storage.googleapis.com. 300     IN      A       142.251.42.176
storage.googleapis.com. 300     IN      A       142.251.42.208
storage.googleapis.com. 300     IN      A       142.251.222.48
storage.googleapis.com. 300     IN      A       172.217.26.240
storage.googleapis.com. 300     IN      A       172.217.31.144
storage.googleapis.com. 300     IN      A       142.250.198.16
storage.googleapis.com. 300     IN      A       172.217.31.176
storage.googleapis.com. 300     IN      A       172.217.161.48
storage.googleapis.com. 300     IN      A       142.250.207.16

;; Query time: 6 msec
;; SERVER: 169.254.169.254#53(169.254.169.254)
;; WHEN: Sun Aug 06 23:03:54 UTC 2023
;; MSG SIZE  rcvd: 307

fujioka@vm:~$ 

ここまでで以下の構成となっています。

再掲:構成図

これ以降は、Cloud Storage のエンドポイントをインターネット経由のエンドポイント(storage.googleapis.com)と Private Service Connect 経由のエンドポイント(storage-pscendpoint.p.googleapis.com)のどちらにアクセスしているか確認する方法を紹介します。

経路の確認

バケットの作成

確認用にバケットを作成します。

$ gcloud storage buckets create gs://test-bucket-20230807 -l asia-northeast1 --uniform-bucket-level-access

storage.googleapis.com

Default Internet Gateway 経由で Cloud Storage のエンドポイント(storage.googleapis.com)へアクセスしている時の結果を確認します。

curl コマンド

curl コマンドで確認します。問題なく結果が返ってきます。

fujioka@vm:~$ curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://storage.googleapis.com/storage/v1/b?project=$(gcloud config get-value project)"
{
  "kind": "storage#buckets",
  "items": [
    {
      "kind": "storage#bucket",
      "selfLink": "https://www.googleapis.com/storage/v1/b/test-bucket-20230807",
      "id": "test-bucket-20230807",
      "name": "test-bucket-20230807",
      "projectNumber": "012345",
      "metageneration": "1",
      "location": "ASIA-NORTHEAST1",
      "storageClass": "STANDARD",
      "etag": "CAE=",
      "timeCreated": "2023-08-06T12:53:47.056Z",
      "updated": "2023-08-06T12:53:47.056Z",
      "iamConfiguration": {
        "bucketPolicyOnly": {
          "enabled": true,
          "lockedTime": "2023-11-04T12:53:47.056Z"
        },
        "uniformBucketLevelAccess": {
          "enabled": true,
          "lockedTime": "2023-11-04T12:53:47.056Z"
        },
        "publicAccessPrevention": "inherited"
      },
      "locationType": "region"
    }
  ]
}
fujioka@vm:~$ 

tcpdump コマンド

上記の curl 実行時に、別ターミナルから tcpdump でアクセス先を確認します。

この 216.58.220.112 は先程 dig で返ってきた storage.googleapis.com のアドレスです。

fujioka@vm:~$ sudo tcpdump -nn -tttt dst port 443
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens4, link-type EN10MB (Ethernet), capture size 262144 bytes

2023-08-06 23:07:25.122857 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [S], seq 289325051, win 65320, options [mss 1420,sackOK,TS val 2811924983 ecr 0,nop,wscale 7], length 0
2023-08-06 23:07:25.123628 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [.], ack 3659639751, win 511, options [nop,nop,TS val 2811924983 ecr 1285463732], length 0
2023-08-06 23:07:25.124890 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [P.], seq 0:517, ack 1, win 511, options [nop,nop,TS val 2811924985 ecr 1285463732], length 517
2023-08-06 23:07:25.125667 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [.], ack 4321, win 491, options [nop,nop,TS val 2811924985 ecr 1285463734], length 0
2023-08-06 23:07:25.126753 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [P.], seq 517:597, ack 4321, win 501, options [nop,nop,TS val 2811924986 ecr 1285463734], length 80
2023-08-06 23:07:25.126993 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [P.], seq 597:643, ack 4383, win 501, options [nop,nop,TS val 2811924987 ecr 1285463735], length 46
2023-08-06 23:07:25.127043 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [P.], seq 643:692, ack 4383, win 501, options [nop,nop,TS val 2811924987 ecr 1285463735], length 49
2023-08-06 23:07:25.127145 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [P.], seq 692:727, ack 4383, win 501, options [nop,nop,TS val 2811924987 ecr 1285463735], length 35
2023-08-06 23:07:25.127292 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [P.], seq 727:1640, ack 4414, win 501, options [nop,nop,TS val 2811924987 ecr 1285463735], length 913
2023-08-06 23:07:25.127412 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [P.], seq 1640:1671, ack 4414, win 501, options [nop,nop,TS val 2811924987 ecr 1285463735], length 31
2023-08-06 23:07:25.308584 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [P.], seq 1671:1695, ack 5654, win 501, options [nop,nop,TS val 2811925168 ecr 1285463916], length 24
2023-08-06 23:07:25.308882 IP 10.0.0.2.50926 > 216.58.220.112.443: Flags [R.], seq 1695, ack 5655, win 501, options [nop,nop,TS val 2811925169 ecr 1285463917], length 0
^C
12 packets captured
12 packets received by filter
0 packets dropped by kernel
fujioka@vm:~$ 

VPC フローログ

VM(10.0.0.2)から Cloud Storage エンドポイントアドレス( 216.58.220.112 )へのフローログです。

{
  "insertId": "1w9cwmwfsezc3l",
  "jsonPayload": {
    "bytes_sent": "4504",
    "reporter": "SRC",
    "start_time": "2023-08-06T23:07:25.123378275Z",
    "packets_sent": "16",
    "connection": {
      "dest_ip": "216.58.220.112",
      "src_port": 50926,
      "protocol": 6,
      "dest_port": 443,
      "src_ip": "10.0.0.2"
    },
    "end_time": "2023-08-06T23:07:25.308756331Z"
  },
  "resource": {
    "type": "gce_subnetwork",
    "labels": {
      "subnetwork_id": "5059267080321417437",
      "project_id": "xxxxx",
      "location": "asia-northeast1-b",
      "subnetwork_name": "customer-subnet"
    }
  },
  "timestamp": "2023-08-06T23:07:36.397651875Z",
  "logName": "projects/xxxx/logs/compute.googleapis.com%2Fvpc_flows",
  "receiveTimestamp": "2023-08-06T23:07:36.397651875Z"
}

Cloud Storage エンドポイントアドレス( 216.58.220.112 )から VM(10.0.0.2)へのフローログです。

{
  "insertId": "1w9cwmwfsezc3m",
  "jsonPayload": {
    "end_time": "2023-08-06T23:07:25.308756331Z",
    "connection": {
      "protocol": 6,
      "dest_ip": "10.0.0.2",
      "src_ip": "216.58.220.112",
      "dest_port": 50926,
      "src_port": 443
    },
    "reporter": "DEST",
    "bytes_sent": "248",
    "start_time": "2023-08-06T23:07:25.123378275Z",
    "packets_sent": "16"
  },
  "resource": {
    "type": "gce_subnetwork",
    "labels": {
      "location": "asia-northeast1-b",
      "subnetwork_id": "5059267080321417437",
      "subnetwork_name": "customer-subnet",
      "project_id": "xxxx"
    }
  },
  "timestamp": "2023-08-06T23:07:36.397651875Z",
  "logName": "projects/xxxx/logs/compute.googleapis.com%2Fvpc_flows",
  "receiveTimestamp": "2023-08-06T23:07:36.397651875Z"
}

storage-pscendpoint.p.googleapis.com

内部ネットワークを経由し、 Cloud Storage のエンドポイント(storage-pscendpoint.p.googleapis.com)へアクセスしている時の結果を確認します。

curl コマンド

curl コマンドで確認します。問題なく結果が返ってきます。

fujioka@vm:~$ curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://storage-pscendpoint.p.googleapis.com/storage/v1/b?project=$(gcloud config get-value project)"
{
  "kind": "storage#buckets",
  "items": [
    {
      "kind": "storage#bucket",
      "selfLink": "https://www.googleapis.com/storage/v1/b/test-bucket-20230807",
      "id": "test-bucket-20230807",
      "name": "test-bucket-20230807",
      "projectNumber": "012345",
      "metageneration": "1",
      "location": "ASIA-NORTHEAST1",
      "storageClass": "STANDARD",
      "etag": "CAE=",
      "timeCreated": "2023-08-06T12:53:47.056Z",
      "updated": "2023-08-06T12:53:47.056Z",
      "iamConfiguration": {
        "bucketPolicyOnly": {
          "enabled": true,
          "lockedTime": "2023-11-04T12:53:47.056Z"
        },
        "uniformBucketLevelAccess": {
          "enabled": true,
          "lockedTime": "2023-11-04T12:53:47.056Z"
        },
        "publicAccessPrevention": "inherited"
      },
      "locationType": "region"
    }
  ]
}
fujioka@vm:~$ 

tcpdump コマンド

上記の curl 実行時に、別ターミナルから tcpdump でアクセス先を確認します。 この 10.0.20.1 は Private Service Connect Endpoint のアドレスです。

fujioka@vm:~$ sudo tcpdump -nn -tttt dst port 443
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens4, link-type EN10MB (Ethernet), capture size 262144 bytes

2023-08-06 23:11:40.027044 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [S], seq 2145849587, win 65320, options [mss 1420,sackOK,TS val 3419769925 ecr 0,nop,wscale 7], length 0
2023-08-06 23:11:40.027954 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [.], ack 1219629433, win 511, options [nop,nop,TS val 3419769926 ecr 250771621], length 0
2023-08-06 23:11:40.029234 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [P.], seq 0:517, ack 1, win 511, options [nop,nop,TS val 3419769927 ecr 250771621], length 517
2023-08-06 23:11:40.062691 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [.], ack 7041, win 479, options [nop,nop,TS val 3419769960 ecr 250771656], length 0
2023-08-06 23:11:40.062707 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [.], ack 9835, win 467, options [nop,nop,TS val 3419769960 ecr 250771656], length 0
2023-08-06 23:11:40.064094 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [P.], seq 517:597, ack 9835, win 501, options [nop,nop,TS val 3419769962 ecr 250771656], length 80
2023-08-06 23:11:40.064468 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [P.], seq 597:643, ack 9897, win 501, options [nop,nop,TS val 3419769962 ecr 250771658], length 46
2023-08-06 23:11:40.064537 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [P.], seq 643:692, ack 9897, win 501, options [nop,nop,TS val 3419769962 ecr 250771658], length 49
2023-08-06 23:11:40.064576 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [P.], seq 692:727, ack 9897, win 501, options [nop,nop,TS val 3419769962 ecr 250771658], length 35
2023-08-06 23:11:40.064691 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [P.], seq 727:1650, ack 9897, win 501, options [nop,nop,TS val 3419769962 ecr 250771658], length 923
2023-08-06 23:11:40.064777 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [P.], seq 1650:1681, ack 9928, win 501, options [nop,nop,TS val 3419769962 ecr 250771658], length 31
2023-08-06 23:11:40.240570 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [.], ack 11099, win 501, options [nop,nop,TS val 3419770138 ecr 250771834], length 0
2023-08-06 23:11:40.240903 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [P.], seq 1681:1705, ack 11130, win 501, options [nop,nop,TS val 3419770138 ecr 250771834], length 24
2023-08-06 23:11:40.241162 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [R], seq 2145851293, win 0, length 0
2023-08-06 23:11:40.241170 IP 10.0.0.2.52156 > 10.0.20.1.443: Flags [R.], seq 1705, ack 11169, win 501, options [nop,nop,TS val 3419770139 ecr 250771834], length 0
^C
15 packets captured
15 packets received by filter
0 packets dropped by kernel
fujioka@vm:~$ 

VPC フローログ

VM(10.0.0.2)からPrivate Service Connect Endpoint(10.0.20.1)へのフローログです。

{
  "insertId": "rr9iweg19nih87",
  "jsonPayload": {
    "start_time": "2023-08-06T23:11:04.052467571Z",
    "packets_sent": "8",
    "reporter": "SRC",
    "connection": {
      "src_port": 49890,
      "src_ip": "10.0.0.2",
      "protocol": 6,
      "dest_port": 443,
      "dest_ip": "10.0.20.1"
    },
    "rtt_msec": "0",
    "bytes_sent": "1944",
    "end_time": "2023-08-06T23:11:04.261488665Z"
  },
  "resource": {
    "type": "gce_subnetwork",
    "labels": {
      "location": "asia-northeast1-b",
      "subnetwork_id": "5059267080321417437",
      "subnetwork_name": "customer-subnet",
      "project_id": "xxxx"
    }
  },
  "timestamp": "2023-08-06T23:11:16.402034721Z",
  "logName": "projects/xxxx/logs/compute.googleapis.com%2Fvpc_flows",
  "receiveTimestamp": "2023-08-06T23:11:16.402034721Z"
}

Private Service Connect Endpoint(10.0.20.1)から VM(10.0.0.2)へのフローログです。

{
  "insertId": "rr9iweg19nih88",
  "jsonPayload": {
    "bytes_sent": "10442",
    "packets_sent": "20",
    "end_time": "2023-08-06T23:11:04.261488665Z",
    "reporter": "DEST",
    "rtt_msec": "0",
    "connection": {
      "dest_port": 49890,
      "src_ip": "10.0.20.1",
      "src_port": 443,
      "dest_ip": "10.0.0.2",
      "protocol": 6
    },
    "start_time": "2023-08-06T23:11:04.052467571Z"
  },
  "resource": {
    "type": "gce_subnetwork",
    "labels": {
      "location": "asia-northeast1-b",
      "subnetwork_id": "5059267080321417437",
      "subnetwork_name": "customer-subnet",
      "project_id": "xxxx"
    }
  },
  "timestamp": "2023-08-06T23:11:16.402034721Z",
  "logName": "projects/xxxx/logs/compute.googleapis.com%2Fvpc_flows",
  "receiveTimestamp": "2023-08-06T23:11:16.402034721Z"
}

デフォルトルートの削除

デフォルトルートを削除します。これによって、Default Internet Gateway へのルートがなくなめ、Cloud Storage のエンドポイントの storage.googleapis.com へアクセスできなくなり、storage-pscendpoint.p.googleapis.com へアクセスできれば、Private Service Connect を経由していることが証明されます。

デフォルトルート削除時の構成

# デフォルトルートの削除前
fujioka@cloudshell:~ (xxxxj)$ gcloud compute routes list
NAME: default-route-cfca000dac79779e
NETWORK: customer-vpc
DEST_RANGE: 10.0.0.0/24
NEXT_HOP: customer-vpc
PRIORITY: 0

NAME: default-route-edbfb93b447ab755
NETWORK: customer-vpc
DEST_RANGE: 0.0.0.0/0
NEXT_HOP: default-internet-gateway
PRIORITY: 1000
fujioka@cloudshell:~ (xxxxj)$

# デフォルトルートの削除
fujioka@cloudshell:~ (xxxxj)$ gcloud compute routes delete default-route-edbfb93b447ab755
The following routes will be deleted:
 - [default-route-edbfb93b447ab755]

Do you want to continue (Y/n)?  Y

Deleted [https://www.googleapis.com/compute/v1/projects/xxxx/global/routes/default-route-edbfb93b447ab755].
fujioka@cloudshell:~ (xxxxj)$

# デフォルトルートの削除後
fujioka@cloudshell:~ (xxxxj)$ gcloud compute routes list
NAME: default-route-cfca000dac79779e
NETWORK: customer-vpc
DEST_RANGE: 10.0.0.0/24
NEXT_HOP: customer-vpc
PRIORITY: 0
fujioka@cloudshell:~ (xxxxj)$

結果

storage.googleapis.com

storage.googleapis.com へアクセスできなくなりました。

fujioka@vm:~$ curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://storage.googleapis.com/storage/v1/b?project=$(gcloud config get-value project)"
curl: (28) Connection timed out after 300001 milliseconds
fujioka@vm:~$ ^C

storage-pscendpoint.p.googleapis.com

storage-pscendpoint.p.googleapis.com へは問題なくアクセスできます。

fujioka@vm:~$ curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://storage-pscendpoint.p.googleapis.com/storage/v1/b?project=$(gcloud config get-value project)"
{
  "kind": "storage#buckets",
  "items": [
    {
      "kind": "storage#bucket",
      "selfLink": "https://www.googleapis.com/storage/v1/b/test-bucket-20230807",
      "id": "test-bucket-20230807",
      "name": "test-bucket-20230807",
      "projectNumber": "012345",
      "metageneration": "1",
      "location": "ASIA-NORTHEAST1",
      "storageClass": "STANDARD",
      "etag": "CAE=",
      "timeCreated": "2023-08-06T12:53:47.056Z",
      "updated": "2023-08-06T12:53:47.056Z",
      "iamConfiguration": {
        "bucketPolicyOnly": {
          "enabled": true,
          "lockedTime": "2023-11-04T12:53:47.056Z"
        },
        "uniformBucketLevelAccess": {
          "enabled": true,
          "lockedTime": "2023-11-04T12:53:47.056Z"
        },
        "publicAccessPrevention": "inherited"
      },
      "locationType": "region"
    }
  ]
}
fujioka@vm:~$ 

以上から、Private Service Connect が機能しており、内部ネットワークでアクセスできていることがわかります。

その他の確認方法

当記事では、複数の観点から確認をしましたが、Network Intelligence Center の接続テストでも Private Service Connect を宛先として指定できます。但し、こちらも同様に確認できるのは VM から Private Service Connect Endpoint までの通信です。Google Cloud が管理するネットワーク(サービスプロデューサー)はユーザー側で確認はできません。

藤岡 里美 (記事一覧)

クラウドソリューション部

数年前までチキン売ったりドレスショップで働いてました!2022年9月 G-gen にジョイン。ハイキューの映画を4回は見に行きたい。

Google Cloud All Certifications Engineer / Google Cloud Partner Top Engineer 2024