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?

ローカルK8sで独自ホスト(myapp.k8s.orb.local)+HTTPSでAuth0を使う

Posted at

目的: localhost ではなく myapp.k8s.orb.local を使い、Auth0の要件(localhost以外はHTTPS必須)を満たしてログインできるようにする。


1) mkcert で開発用TLS証明書を作る(ローカルCAを信頼)

brew install mkcert nss   # 初回のみ
mkcert -install           # ローカルCAをキーチェーンに登録
mkdir -p {work_dir}/certs
cd {work_dir}/certs
env TRUST_STORES=system mkcert myapp.k8s.orb.local   # フラグ無しで実行

ls -l   # => myapp.k8s.orb.local.pem / myapp.k8s.orb.local-key.pem ができる

実行ログ(参考):

Created a new certificate valid for the following names 📜
 - "myapp.k8s.orb.local"

The certificate is at "./myapp.k8s.orb.local.pem" and the key at "./myapp.k8s.orb.local-key.pem" ✅

生成物(例):

  • myapp.k8s.orb.local.pem
  • myapp.k8s.orb.local-key.pem

2) Ingress用のTLS Secretを作成

cd {work_dir}/certs
kubectl create secret tls myapp-orb-tls \
  --cert=myapp.k8s.orb.local.pem \
  --key=myapp.k8s.orb.local-key.pem

3) Ingress をHTTPS化

変更点

  • metadata.annotations:
    • nginx.ingress.kubernetes.io/ssl-redirect: "false""true"(HTTPアクセスをHTTPSへ強制リダイレクト)
  • spec.tls: 新規追加
    • hosts: myapp.k8s.orb.local
    • secretName: myapp-orb-tls(mkcertで発行した証明書を格納したSecret)
  • spec.rules[].host:
    • localhostmyapp.k8s.orb.local

これにより、myapp.k8s.orb.local でTLS終端されたIngressが有効になり、Auth0の要件(localhost以外はHTTPS必須)を満たす構成になります。

ingress.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: auth0-train
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
    - hosts:
        - myapp.k8s.orb.local
      secretName: myapp-orb-tls
  rules:
    - host: myapp.k8s.orb.local
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: auth0-train
                port:
                  number: 80

適用:

kubectl apply -f ingress.yml

4) Auth0 の許可URLをHTTPSに更新

  • Allowed Callback URLs: https://myapp.k8s.orb.local
  • Allowed Logout URLs: https://myapp.k8s.orb.local
  • Allowed Web Origins: https://myapp.k8s.orb.local

補足:

  • SPA側は redirect_uri: window.location.origin なのでコード変更不要
  • localhost 以外のホスト名では Auth0 は HTTPS を要求(これが今回HTTPS化する理由)

5) 動作確認

open https://myapp.k8s.orb.local
  • 「接続は保護されています」表示(mkcertのCAを信頼済みならOK)
  • Login → Universal Login(Authorize App 表示はテナント設定でスキップ可)
  • ログイン後、https://myapp.k8s.orb.local/?code=... に帰還しアプリが認証状態になる
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?