0
0

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 1 year has passed since last update.

Cloud Run IAP の嵌り

Posted at

Cloud Run を公開したり、非公開にしてみます。

$ gcloud run services list
$ gcloud run services describe helloworld --platform managed

IAM の orgpoloicy で、当該プロジェクトにおいて、「Domain restricted sharing のポリシー」を、すべて許可にする必要があります。

Cloud Run で、「未認証の呼び出しを許可」する必要があります。

公開の方法は以上です。

では、この Cloud Run サービスを、IAP で守り、非公開にするにはどうしたらよいのか。
https://cloud.google.com/blog/ja/products/gcp/control-access-your-web-sites-identity-aware-proxy

Cloud Run に行きます。
ネットワーキングの「Ingress の制御」を「すべて」に変更します。
「グローバル外部アプリケーション ロードバランサからのトラフィックを許可する」にチェックを入れます。
セキュリティ、認証で、「認証が必要です」に変更します。

ロードバランサーを作成します。

ネットワークサービス > ロードバランシング
アプリケーション ロードバランサ(HTTP/S) > 構成を開始
「インターネットから VM またはサーバーレス サービスへ」
「グローバル外部アプリケーション ロードバランサ」
「続行」をクリック
名前を「for-cloudrun」「HTTPS(HTTP/2 を含む」
https://cloud.google.com/iap/docs/concepts-overview?authuser=1&hl=ja
ここで、リンクをクリックすると、403 となりました。
IPアドレスを直接入れても、403となります。
どうやら、証明書を作ったのですが、24時間待て、となっています。
待ってみます。

バックエンドサービス > cloudrun-helloworld の、左の四角に、チェックを入れます。
右側にペインが出現します。cloudrun-helloworld となっているのを確認します。
「プリンシパルを追加」をクリックします。
メールアドレスを入れます。

403 となり、Your client does not have permission to get URL from this server.と出ています。
ここに関連しているようです。
https://cloud.google.com/run/docs/troubleshooting?hl=ja#unauthorized-client

ここに書いてあることをやってみます。
https://cloud.google.com/iap/docs/enabling-cloud-run?hl=ja#troubleshooting_errors

    IAP は、IAP サービス アカウントの権限を使用して、Cloud Run サービスを呼び出します。Cloud Run 起動元権限が次のサービス アカウントに付与されていることを確認します。 service-[PROJECT-NUMBER]@gcp-sa-iap.iam.gserviceaccount.com

    上記のサービス アカウントに Cloud Run 起動元権限を付与しても問題が解決しない場合は、Cloud Run サービスを再デプロイします。

いや、ここをよく読む必要がありそうだ。
https://cloud.google.com/iap/docs/enabling-cloud-run?hl=ja

結局、以下のようにして出来ました。

IAM に行って、service-[PROJECT-NUMBER]@gcp-sa-iap.iam.gserviceaccount.com を作成する。
その際、Cloud Run 起動元 ロールを付与する。

以上です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?