1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

IAP for TCP forwarding で SSHの送信元IPアドレスを制限する

Posted at

はじめに

IAP for TCP forwarding で SSHの送信元IPアドレスを制限する方法について記載します。結論としては、VPC Service Controlを使用して制限することが可能です。

GCPで接続元のIPアドレスを制限する方法

GCPで接続元のIPアドレスを制限する方法は、Firewall ruleとAccess context managerの2つが使用できます。Access context managerは以下のようにネットワークを設定できます。

image.png

Access context managerは単体では使用せず、他のサービスと組み合わせて使用します。他のサービスとは、具体的には、「VPC Service Controls」「Context-aware access」「IAM Conditions」になります。

上記が、IAP for TCP forwardingとして組み合わせて使用できるか確認していきます。
1.FirewallのIngressルール
2.Context-aware access for the Cloud Console and the Google Cloud APIs
https://cloud.google.com/beyondcorp-enterprise/docs/securing-console-and-apis
3.IAP + VPC Service Controls(VPC-SC)
https://cloud.google.com/iap/docs/securing-tcp-with-vpc-sc
4.IAP + Context-aware access
https://cloud.google.com/iap/docs/cloud-iap-context-aware-access-howto

FirewallのIngressルール

IAP for TCP forwardingを使用するには、Firewall ruleとしてIP 範囲 35.235.240.0/20 からの上り(内向き)トラフィックを許可します。
https://cloud.google.com/iap/docs/using-tcp-forwarding?hl=ja#create-firewall-rule

35.235.240.0/20は、Googleが使用するIPアドレス帯となり、ユーザが許可したい任意のネットワークを指定することができません。そのため、FirewallでSSHの送信元IPアドレスを制限することはできません。

Context-aware access for the Cloud Console and the Google Cloud APIs

GCPは、認証時の送信元IPアドレス制限として、Context-aware access for the Cloud Console and the Google Cloud APIsを使用することができます。
https://cloud.google.com/beyondcorp-enterprise/docs/securing-console-and-apis

こちらは、記載したとおりGoogleのコンソールにログインする際や、API実行時に認証する際に対するアクセス制御となるため、IAP for TCP forwardingを使用したSSH接続時の送信元IPアドレスを制限することはできません。

IAP + VPC Service Controls(VPC-SC)

IAP for TCP forwarding とVPC−SCを組み合わせると、SSH接続時の送信元IPアドレスを制限することができます。
実際に試してみます。

以下を参考にIAP for TCP forwardingを有効にします。
https://cloud.google.com/iap/docs/using-tcp-forwarding

VPC-SCの境界に該当のプロジェクトを追加し、Restricted serviceにIAPを追加します。Shared VPCを使用している場合は、host projectとservice projectの両方をサービス境界に追加します。
image.png

Google cloud consoleからsshをしてみます。

image.png

SSH接続が拒否されました。
image.png

gcloudコマンドでsshをしてみます。

こちらも、SSH接続が拒否されました。

$  gcloud compute ssh bastion --zone asia-northeast1-b
External IP address was not found; defaulting to using IAP tunneling.
ERROR: (gcloud.compute.start-iap-tunnel) Error while connecting [4054: "Request is prohibited by organization's policy. ID: 3FdzVQ5u4jIuETm3PpuR58Fz5htLS-971K3VL4fy9geh4_B856aVAg"].
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535
ERROR: (gcloud.compute.ssh) [/usr/local/bin/ssh] exited with return code [255].

Access context managerで任意の送信元IPからのアクセスを許可します。

image.png

VPC-SCで上記のAccess context managerのポリシーを Access Levelsに設定します。
image.png

Google cloud consoleからsshをしてみます。

image.png

接続できました。
image.png

gcloudコマンドでsshをしてみます。

こちらも、接続できました。

$  gcloud compute ssh bastion --zone asia-northeast1-b
External IP address was not found; defaulting to using IAP tunneling.
Updating project ssh metadata...⠹Updated [https://www.googleapis.com/compute/v1/projects/app-dev-256209].                             
Updating project ssh metadata...done.                                                                                                 
Waiting for SSH key to propagate.
Warning: Permanently added 'compute.3051378218933375262' (ECDSA) to the list of known hosts.
Linux bastion 4.19.0-14-cloud-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
matsushi@bastion:~$ 

IAP + Context-aware access

https://cloud.google.com/iap/docs/cloud-iap-context-aware-access-howto
これもできるはずなんですが、なぜかcondtionsを設定するところでエラーになって実機確認できませんでした。。また別途試してみます。。

image.png

image.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?