전공영역 공부 기록

istio keycloak 인증 연동 - 작성중단

악분 2022. 3. 30. 18:58
반응형
업무로서 istio를 사용하지 않아서.. 공부를 중단합니다. ㅜ.ㅜ

 

목차

 

안녕하세요. 이 글은 istio와 keycloak을 연동하여 pod 인증을 소개합니다.

 

1. istio와 keycloak 인증

istio 1.9?버전 부터 외부 컴퍼넌트를 이용하여 인증을 인가를 위임할 수 있습니다. 

 

① istio ingress gateway는 인증이 되었는지 확인합니다. 무조건 인증검사를 하는 것이 아니라 Authorization 헤더에 JWT토큰이 있을때 검사하는 것 같습니다(확인필요)

② 인증이 되어 있지 않다면 외부 ouath2-proxy에게 인증(OAuth2.0 Authorization Code Grant flow)을 위임합니다.

③ ouath2-proxy는 keycloak에게 인증을 요청하고 인증이 성공하면 여러가지 작업 설정 후, ingress gateway에게 토큰을 리턴합니다.

 

2. keycloak 설정

2.1. realm 생성

istio-ingress라는 이름으로 realm을 생성했습니다.

 

2.2 client생성

test1이름으로 client를 생성했습니다.

 

access-type을 confidential로 수정합니다.

 

3. oauth2-proxy 배포

github링크: https://github.com/choisungwook/istio-example/tree/main/keycloak

3.1 namespace 생성

kubectl create ns oauth2-proxy

 

3.2 쿠버네티스 secret 생성

[챕터 2]에서 생성한 client와 client의 secret을 쿠버네티스 secret으로 설정합니다.

apiVersion: v1
kind: Secret
metadata:
  name: oauth2-proxy
  namespace: oauth2-proxy
stringData:
  # change this to your Keycloak Realm Client Id 
  OAUTH2_PROXY_CLIENT_ID: ""
  # change this to your Keycloak Client Secret 
  OAUTH2_PROXY_CLIENT_SECRET: ""
  # Generate by command: openssl rand -base64 32 | tr -- '+/' '-_'
  OAUTH2_PROXY_COOKIE_SECRET: ""

 

3.3 쿠버네티스 deployment 배포

apiVersion: apps/v1
kind: Deployment
metadata:
  name: oauth2-proxy
  namespace: oauth2-proxy
spec:
  selector:
    matchLabels:
      app: oauth2-proxy
  template:
    metadata:
      labels:
        app: oauth2-proxy
    spec:
      containers:
      - name: oauth2-proxy
        image: quay.io/oauth2-proxy/oauth2-proxy:v7.2.1
        args:
        - --provider=oidc
        - --oidc-issuer-url=http://keycloak.infra.svc.cluster.local/auth/realms/istio-ingress # change here
        - --profile-url=http://keycloak.infra.svc.cluster.local/auth/realms/istio-ingress/protocol/openid-connect/userinfo # change here
        - --validate-url=http://keycloak.infra.svc.cluster.local/auth/realms/istio-ingress/protocol/openid-connect/userinfo # change here
        - --set-authorization-header=true
        - --http-address=0.0.0.0:4180
        - --pass-host-header=true
        - --reverse-proxy=true
        - --auth-logging=true
        - --cookie-httponly=true
        - --cookie-refresh=4m
        - --cookie-secure=false
        - --email-domain="*"
        - --pass-access-token=true
        - --pass-authorization-header=true
        - --request-logging=true
        - --set-xauthrequest=true
        - --silence-ping-logging=true
        - --skip-provider-button=true
        - --skip-auth-strip-headers=false
        - --ssl-insecure-skip-verify=true
        - --standard-logging=true
        - --upstream="static://200"
        - --whitelist-domain=".choilab.xyz,.cluster.local" # change here
        env:
        - name: OAUTH2_PROXY_CLIENT_ID
          valueFrom:
            secretKeyRef:
              name: oauth2-proxy
              key: OAUTH2_PROXY_CLIENT_ID
        - name: OAUTH2_PROXY_CLIENT_SECRET
          valueFrom:
            secretKeyRef:
              name: oauth2-proxy
              key: OAUTH2_PROXY_CLIENT_SECRET
        - name: OAUTH2_PROXY_COOKIE_SECRET
          valueFrom:
            secretKeyRef:
              name: oauth2-proxy
              key: OAUTH2_PROXY_COOKIE_SECRET
        resources:
          requests:
            cpu: 10m
            memory: 100Mi
        ports:
        - containerPort: 4180
          protocol: TCP
        readinessProbe:
          periodSeconds: 3
          httpGet:
            path: /ping
            port: 4180

 

3.4 쿠버네티스 service 배포

apiVersion: v1
kind: Service
metadata:
  name: oauth2-proxy
  namespace: oauth2-proxy
spec:
  selector:
    app: oauth2-proxy
  ports:
  - name: http
    port: 4180

 

4. istio 설정

istio-operator로 meshConfig를 설정합니다.

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  name: oauth2-proxy
  namespace: istio-system
spec:
  profile: empty
  meshConfig:
    extensionProviders:
    - name: oauth2-proxy
      envoyExtAuthzHttp:
        service: oauth2-proxy.oauth2-proxy.svc.cluster.local
        port: 4180
        timeout: 1.5s
        includeHeadersInCheck: ["authorization", "cookie"]
        headersToUpstreamOnAllow: ["x-forwarded-access-token", "authorization", "path", "x-auth-request-user", "x-auth-request-email", "x-auth-request-access-token"]
        headersToDownstreamOnDeny: ["content-type", "set-cookie"]

 

 

참고자료

① oauth2-proxy: https://medium.com/@senthilrch/api-authentication-using-istio-ingress-gateway-oauth2-proxy-and-keycloak-part-2-of-2-dbb3fb9cd0d0

② oauth2-proxy: https://medium.com/@senthilrch/api-authentication-using-istio-ingress-gateway-oauth2-proxy-and-keycloak-part-2-of-2-dbb3fb9cd0d0

③ istio-operator: https://ahnseungkyu.com/272

④ oauth2-proxy: https://www.cnblogs.com/gxc888/p/15894466.html

여백

반응형

'전공영역 공부 기록' 카테고리의 다른 글

docker로 postgresql 실행  (0) 2022.04.19
kustomize설치  (0) 2022.04.06
tmux 세션 종료  (0) 2022.03.27
리눅스 쉘 스크립트 에러 핸들링과 dockerfile 적용  (0) 2022.03.27
Istio 트래픽 흐름과 설정 이해  (0) 2022.03.27