티스토리 뷰

반응형

문제 발생

클라이언트에서 oathkeeper를 호출할 때에도 어김없이 CORS 문제가 발생했다.

oryd/hydra에서처럼 Docker 컨테이너 환경변수를 설정하면 될 것 같았는데, 환경변수가 뭔가 부족했던건지 제대로 적용이 되지 않았다.
그리고 환경변수에 대한 설명도 제대로 나와있지 않아 어떤 환경변수에 어떤 내용을 넣어야하는지 또한 문제였다.

결국 찾아서 해결한 방법은 oathkeeper의 config.yaml 파일에 CORS를 적용하는 것이다.

 

oryd/oathkeeper에 CORS 적용하기

oryd/oathkeeper:v0.35.1-alpine 이미지를 Docker 컨테이너로 실행한다.

  oathkeeper-proxy:
    image: oryd/oathkeeper:v0.35.1-alpine
    ports:
      - "4455:4455"
    # will add self-signed certificate to the “trusted list” because oathkeeper doesn't trust self-signed certificate
    # https://github.com/ory/oathkeeper/issues/181
    # remove it when using real certificate
    command:  /bin/sh -c "cp /etc/tls/trustbloc-dev-ca.crt /usr/local/share/ca-certificates/;update-ca-certificates;oathkeeper serve proxy --config /oathkeeper/config.yaml"
    user: root
    entrypoint: ""
    environment:
      - LOG_LEVEL=debug
      - PORT=4455
      - ISSUER_URL=https://oathkeeper-proxy.trustbloc.local
      - VIRTUAL_HOST=oathkeeper-proxy.trustbloc.local
      - VIRTUAL_PORT=4455
    restart: on-failure
    volumes:
      - ../oathkeeper:/oathkeeper
      - ../keys/tls:/etc/tls
    networks:
      - demo-net

 

그리고 oathkeeper의 config.yaml 파일에 CORS 설정 부분을 추가한다.

serve:
  proxy:
    port: 4455 # run the proxy at port 4455
    # cors 설정 추가
    cors:
      enabled: true
      allowed_origins:
        - https://trustbloc.local
        - https://*.trustbloc.local
        - https://user.trustbloc.local
  api:
    port: 4456 # run the api at port 4456
    # cors 설정 추가
    cors:
      enabled: true
      allowed_origins:
        - https://trustbloc.local
        - https://*.trustbloc.local
        - https://user.trustbloc.local

serve의 proxy와 api 모두에 cors를 설정해주어야 정상적으로 동작한다.

 

ory/oathkeeper - configuration.md 문서를 잘 살펴보면 환경변수로 설정하게 될 경우 SERVE_API_CORS_ENABLED, SERVE_API_CORS_ALLOWED_ORIGINS, SERVE_PROXY_CORS_ENABLED, SERVE_PROXY_CORS_ALLOWED_ORIGINS를 설정하면 될 것 같다.

 

참고 사이트

ory/oathkeeper Docs - Configuration

 

Configuration | ORY Oathkeeper

ory/oathkeeper Github - configuration.md

 

ory/oathkeeper

A cloud native Identity & Access Proxy / API (IAP) and Access Control Decision API that authenticates, authorizes, and mutates incoming HTTP(s) requests. Inspired by the BeyondCorp / Zero Trust...

github.com

 

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함