ย
๊ตฌํํ๊ณ ์ถ์ ์๋๋ฆฌ์ค
- Istio์์ JWT ํ ํฐ ์ธ์ฆํ๋ค.
- ์ธ์ฆ ์คํจ๋ฉด ๋ฐ๋ก ์ธ์ฆ ์คํจ ์ฒ๋ฆฌ
- ์ธ์ฆ ํต๊ณผ ํ ์๋น์ค์์ ์ด API์ ๋ํ ์ ์ ์ ๊ถํ์ด ์๋์ง ์ฒดํฌ
- ์๋ค๋ฉด ๊ถํ์ด ์๋ค๋ ์๋ฌ ๋ฆฌํด
ย
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
claimsToHeadersfield specifies that the "user_id" claim should be mapped to the "X-User-Id" HTTP header. When a request is authenticated using thisRequestAuthenticationresource, 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
claimsToHeadersfield, 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๋ฅผ ๊ฐ์ ธ์์ ์ ์ ์ ๋ํ ์ ๋ณด๋ฅผ ์ ์ ์์.
ย
ย