Auth0 inside Istio

Auth0 inside Istio

ย 

๊ตฌํ˜„ํ•˜๊ณ  ์‹ถ์€ ์‹œ๋‚˜๋ฆฌ์˜ค

  1. Istio์—์„œ JWT ํ† ํฐ ์ธ์ฆํ•œ๋‹ค.
    1. ์ธ์ฆ ์‹คํŒจ๋ฉด ๋ฐ”๋กœ ์ธ์ฆ ์‹คํŒจ ์ฒ˜๋ฆฌ
  1. ์ธ์ฆ ํ†ต๊ณผ ํ›„ ์„œ๋น„์Šค์—์„œ ์ด API์— ๋Œ€ํ•œ ์œ ์ €์˜ ๊ถŒํ•œ์ด ์žˆ๋Š”์ง€ ์ฒดํฌ
    1. ์—†๋‹ค๋ฉด ๊ถŒํ•œ์ด ์—†๋‹ค๋Š” ์—๋Ÿฌ ๋ฆฌํ„ด
ย 

RequestAuthentication

  • forwardOriginalToken
    • true๋ฅผ ํ•˜๋ฉด ๊ธฐ์กด ํ† ํฐ์ด ๋‹ค์Œ ์ปจํ…Œ์ด๋„ˆ๋“ค๊นŒ์ง€ ๊ณ„์† ํฌ์›Œ๋”ฉ ๋œ๋‹ค.
    • false๋ฉด ์ธ์ฆ๋งŒ ๋˜๊ณ  ์ดํ›„ ํ—ค๋”์—์„œ ๋น ์ง„๋‹ค.
      • ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋“ค์—๊ฒŒ ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•ด์•ผํ•œ๋‹ค.
      Example
      apiVersion: security.istio.io/v1beta1 kind: RequestAuthentication metadata: name: jwt-example spec: selector: matchLabels: app: my-app jwtRules: - issuer: "https://my-auth0-domain.auth0.com/" jwksUri: "https://my-auth0-domain.auth0.com/.well-known/jwks.json" forwardOriginalToken: true
  • claimsToHeaders
    • In this example, the claimsToHeaders field specifies that the "user_id" claim should be mapped to the "X-User-Id" HTTP header. When a request is authenticated using this RequestAuthentication resource, the JWT will be validated and the "user_id" claim will be extracted.
    • Then, an HTTP header called "X-User-Id" will be added to the request with the value of the "user_id" claim. The request will then be forwarded to the upstream service with this additional header.
    • Using the claimsToHeaders field, you can map JWT claims to any HTTP header that you want to include in your requests. This can be useful for propagating user information, such as user IDs or email addresses, to your upstream services.
    • Example
      apiVersion: security.istio.io/v1beta1 kind: RequestAuthentication metadata: name: my-jwt-rule spec: selector: matchLabels: app: my-app jwtRules: - issuer: "https://my-auth0-domain.auth0.com/" jwksUri: "https://my-auth0-domain.auth0.com/.well-known/jwks.json" claimsToHeaders: X-User-Id: "user_id" X-User-GroupId: "group_id" # group_id๋„ JWT์—์„œ ์กด์žฌํ•œ๋‹ค๋ฉด
  • forwardOriginalToken falseํ•˜๊ณ  claimsToHeaders์—์„œ user_id ์“ด๋‹ค๋ฉด?
    • token์ด ํฌ์›Œ๋”ฉ๋˜์ง€ ์•Š์œผ๋‹ˆ ํ•˜์œ„ ์„œ๋น„์Šค(FastAPI)์—์„œ JWT๋ฅผ ํ†ตํ•ด ์œ ์ €์— ๊ด€ํ•œ ์ •๋ณด๋ฅผ ์•Œ ์ˆ˜ ์—†์Œ.
    • claimsToHeaders์— user_id๋ฅผ ๊ฐ€์ ธ์™€ X-User-Id๋กœ ์„ค์ •ํ•˜๋‹ˆ ํ•˜์œ„ ์„œ๋น„์Šค(FastAPI)์—์„œ๋Š” ํ—ค๋”์—์„œ X-User-Id๋ฅผ ๊ฐ€์ ธ์™€์„œ ์œ ์ €์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์•Œ ์ˆ˜ ์žˆ์Œ.
    • ย 
      ย