GCPのIPアドレス範囲をリスト化

IT

やりたいこと

GCPのIPアドレスをnginxに許可するためリストを作成する。

やったこと

GoogleがこのURLで情報を公開しているので

https://www.gstatic.com/ipranges/cloud.json

こんなコマンドで一覧化できる。

curl -s https://www.gstatic.com/ipranges/cloud.json | jq -r '.prefixes[] | if .ipv4Prefix != null then .ipv4Prefix else .ipv6Prefix end'

nginxに許可させるため、さらに以下のようなかんじで加工して.htaccessファイルに出力する処理を日次バッチ化した。

curl -s https://www.gstatic.com/ipranges/cloud.json | jq -r '.prefixes[] | if .ipv4Prefix != null then .ipv4Prefix else .ipv6Prefix end' | sed -e 's/^/allow from /'

参考サイト

Compute Engine Documentation  |  Google Cloud
Find answers to frequently asked questions about Compute Engine.
IT
広告
一郎くんどっとこむ