Authentik proxy 모드 NPM 설정시 리디렉션 오류? 수정

https://svrforum.com/nas/809186

예전에 달소님 글을 보고 시놀에 설치해서 잘 쓰고 있던 Authentik 

간단하게 요약하자면 인증 서비스 입니다

뭐 이런저런 서비스들을 사용하다보면 기본 로그인 기능이 있지만 뭔가 찜찜할 때

혹은 로그인 기능이 없을 때 여기저기 붙여서 쓸 수 있는 서비스죠

2차 인증 설정한 구글 아이디 같은 보안성이 좀 더 나은 방법으로 로그인도 가능하고요

 

여하튼 잘 쓰고 있다가 

이번에 emulatorjs 라는 서비스를 설치해봤습니다

image.png.jpg

웹으로 에뮬을 실행 시켜주는 서비스죠

 

그런데 로그인 기능이 없다보니 좀 그렇더라고요

물론 이 서비스는 해당 서버의 데이터를 클라이언트 브라우저로 다운 받아서 실행하는 방식이라

서버에 크게 부하가 가지는 않습니다만 그래도 로그인 기능을 추가하기로 했습니다

 

기존에는 Authentik를 사용할 때 

주로 OAuth2/OpenID 프로토콜을 지원하는 서비스에 연동을 해서 사용했는데요

emulatorjs는 로그인 기능 자체가 없어서 proxy pass 모드로 설정을 했습니다

마침 npm을 사용하고 있고

달소님 가이드에 npm에 Authentik proxy pass를 설정하는 방법이 있어서

그대로 진행을 했는데

아래 proxy_pass http://auth.example.com/outpost.goauthentik.io; 항목을 아래처럼 구동중인 호스트:포트로 수정만해주시고 저장해주시면됩니다
proxy_pass http://192.168.1.60:9000/outpost.goauthentik.io;

Loading
Loading

 

# Increase buffer size for large headers
# This is needed only if you get 'upstream sent too big header while reading response
# header from upstream' error when trying to access an application protected by goauthentik
proxy_buffers 8 16k;
proxy_buffer_size 32k;

location / {
    # Put your proxy_pass to your application here
    proxy_pass          $forward_scheme://$server:$port;

    # authentik-specific config
    auth_request        /outpost.goauthentik.io/auth/nginx;
    error_page          401 = @goauthentik_proxy_signin;
    auth_request_set $auth_cookie $upstream_http_set_cookie;
    add_header Set-Cookie $auth_cookie;

    # translate headers from the outposts back to the actual upstream
    auth_request_set $authentik_username $upstream_http_x_authentik_username;
    auth_request_set $authentik_groups $upstream_http_x_authentik_groups;
    auth_request_set $authentik_email $upstream_http_x_authentik_email;
    auth_request_set $authentik_name $upstream_http_x_authentik_name;
    auth_request_set $authentik_uid $upstream_http_x_authentik_uid;

    proxy_set_header X-authentik-username $authentik_username;
    proxy_set_header X-authentik-groups $authentik_groups;
    proxy_set_header X-authentik-email $authentik_email;
    proxy_set_header X-authentik-name $authentik_name;
    proxy_set_header X-authentik-uid $authentik_uid;
}

# all requests to /outpost.goauthentik.io must be accessible without authentication
location /outpost.goauthentik.io {
    proxy_pass          http://auth.example.com/outpost.goauthentik.io;
    # ensure the host of this vserver matches your external URL you've configured
    # in authentik
    proxy_set_header    Host $host;
    proxy_set_header    X-Original-URL $scheme://$http_host$request_uri;
    add_header          Set-Cookie $auth_cookie;
    auth_request_set    $auth_cookie $upstream_http_set_cookie;

    # required for POST requests to work
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
}

# Special location for when the /auth endpoint returns a 401,
# redirect to the /start URL which initiates SSO
location @goauthentik_proxy_signin {
    internal;
    add_header Set-Cookie $auth_cookie;
    return 302 /outpost.goauthentik.io/start?rd=$request_uri;
    # For domain level, use the below error_page to redirect to your authentik server with the full redirect path
    # return 302 https://authentik.company/outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri;
}

요 부분입니다

 

설정을 제대로 했으니 정상 작동해야 하는데 저 같은 경우

 

https://ex.aaa.com:4443/outpost.goauthentik.io/start?rd=/ 

Loading

이런 식으로 뒤에 :4443 포트가 추가가 되는 바람에 Authentik 로그인 창이 안뜨더라고요

https://ex.aaa.com/outpost.goauthentik.io/start?rd=/

Loading

이런 식으로 :4443 부분을 지워야 정상 작동 합니다

저 4443이 npm 포트인데 npm을 443 포트로 설치 한 분들은 문제가 없는 거 같더라고요

 

그래서 찾아보니 해결 방법은 생각보다 간단 했습니다

redirect to a port app.domain:4443 · Issue #3359 · goauthentik/authentik

Fixed
Add
port_in_redirect off;
Above the location block in npm Config

Authentik 깃헙에 가보니 저만 그런 건 아니더라고요

 

NPM 고급 설정 창에

port_in_redirect off;

한 줄 추가하니까 깔끔하게 해결 됐습니다

 

그동안 OAuth2/OpenID 프로토콜 지원 안되면 클플 터널이나 클플 인증을 주로 썼었는데

Authentik도 여기저기 붙여봐야겠습니다

댓글 남기기

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다