4
6

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 5 years have passed since last update.

GKE で Google アカウント認証

Posted at

はじめに

  • GKE の Ingress に Cloud IAP を使った Google アカウント認証を組み込む手順
  • 流れとしてはテスト用のバックエンドサービスと Ingress を作成し、Ingress の IAP を有効にしてアカウント認証できるようにする。

クラスタの作成

  • GCP メニューから Kubernetes Engine > Kubernetes クラスタ > "クラスタを作成" でクラスタを作成
gcloud beta container --project "{PROJECT_ID}" clusters create "cluster-1" --zone "asia-northeast1-a" --username "admin" --cluster-version "1.8.8-gke.0" --machine-type "f1-micro" --image-type "COS" --disk-size "100" --scopes "https://www.googleapis.com/auth/compute","https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "3" --network "default" --enable-cloud-logging --enable-cloud-monitoring --subnetwork "default" --addons HorizontalPodAutoscaling,HttpLoadBalancing,KubernetesDashboard

クラスタへ接続

  • 作成したクラスタへ接続する
gcloud container clusters get-credentials cluster-1 --zone asia-northeast1-a --project {PROJECT_ID}

SSL証明書の作成

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=nginxsvc/O=nginxsvc"
kubectl create secret tls tls-secret --key tls.key --cert tls.crt

バックエンドサービスの作成

kubectl apply -f http-svc.yaml
kubectl patch svc http-svc -p '{"spec":{"type": "LoadBalancer"}}'

Ingress の作成

ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-test
spec:
  tls:
    - hosts:
      - foo.bar.com
      # This assumes tls-secret exists and the SSL 
      # certificate contains a CN for foo.bar.com
      secretName: tls-secret
  rules:
    - host: foo.bar.com
      http:
        paths:
        - path: /*
          backend:
            # This assumes http-svc exists and routes to healthy endpoints
            serviceName: http-svc
            servicePort: 80

ここまでの動作確認

  • 作成した Ingress あてに curl でアクセスして動作確認をする
    • Ingress の IP アドレス割当には時間がかかるのでリクエスト結果のステータスコードが 404 や 500 の場合は少し待ってから確認し直す
curl -Lk https://{INGRESS_IP_ADDR} -H 'Host:foo.bar.com'

ドメイン名の設定

  • 作成した Ingress の IP アドレスで hosts に設定する
{INGRESS_IP_ADDR} foo.bar.com

IAP の設定

  • メニューから "セキュリティ" > "Identity-Aware Proxy"
  • IAP を迂回できるファイアーウォール設定を削除
    • default/http-svc の「警告」を押下
    • 「EDIT FIREWALL」から対象のファイアーウォール設定を削除
  • default/http-svc の IAP を有効にする
    • ドメイン名に foo.bar.com を指定して有効にする
  • Access 欄にアクセス可能なアカウントを追加する

IAP の動作確認

  • https://foo.bar.com にブラウザからアクセスしアカウント認証された後に正常にコンテンツが表示されることを確認
4
6
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
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?