셀프 호스팅을 위한 서비스를 구축하다 보면, 접속 주소만 웹브라우저에 넣으면 인증 없이 바로 접속되어 공개되는 서비스가 간혹 있습니다. 개인이 사용하는 것인데 다른 사람이 접속할 필요는 없겠지요. 이에 따라 오픈 소스 인증 및 권한 부여 시스템인 Authentik를 설치하게 되었습니다. 기초지식이 부족한 문외한에게는 어려운 일이더군요. 그래서 창고에 넣어두려 합니다. 나중에 버전 업데이트를 하더라도 수월하게 하고 싶기 때문입니다.
Authentik은 PROXMOX에 우분투 LXC(CPU 4 core, Memory 2G, Bootdisk 8G)를 바탕으로 docker 및 docker-compose를 구성한 상태에서 설치하였습니다. 서버포럼에서 많은 도움을 받았습니다. 감사드립니다.
1️⃣ Authentik의 docker-compose.yml 파일 다운로드
wget https://goauthentik.io/docker-compose.yml
2️⃣ 암호화키 생성 패키지 설치
apt-get install -y pwgen
3️⃣ 비밀 번호와 비밀 키 생성
echo "PG_PASS=$(openssl rand -base64 36 | tr -d '\n')" >> .env
echo "AUTHENTIK_SECRET_KEY=$(openssl rand -base64 60 | tr -d '\n')" >> .env
🧠 제대로 생성된 여부는 nano .env
로 확인
4️⃣ Startup
docker compose pull
docker compose up -d
✳️ 버전 업데이트 시에도 이 명령 사용
5️⃣ 초기 설정 시작(To start the initial setup)
http://<myAuthentikIP>:9000/if/flow/initial-setup/
✳️ 관리자 계정의 username, Email, 비밀번호를 생성합니다.
🧠 포트넘버 뒤까지 '/'를 포함하여 모두 그대로 주소창에 넣어야 초기설정 페이지 진입 가능
🧠 계정 설정을 변경하여야 한다면, 관리자 인터페이스에 시스템 하위의 설정에서 Avatars 항목의 Allow users to change email과 Allow users to change username를 활성화 해야 사용자 인터페이스에서 사용자 세부정보 변경이 가능합니다.
6️⃣ 외부접속 설정
🔶 Sub도메인: authentik.mydomain.org
🔶 NPM(Nginx Proxy Manager) 설정
🧠 Scheme을 http로 설정하면 아래와 같이 나오면서 접속 안되었습니다....
Scheme을 https로 하여야 접속이 이루어졌습니다(왜 그런지는... 전문가분이 좀 알려주셨으면 좋겠습니다).
👉 서버포럼 달소님의 최근 Authentik에 관한 글에 의하면 https로 설정하는 부분도 보이기는 합니다
7️⃣ Authentik에 내 서비스 연결(관리자 인터페이스)
🔶 큰 흐름: 공급자 생성 → 애플리케이션 연결 → Outposts 액션에 추가
🔶 공급자 생성: 애플리케이션 하위의 공급자에서 생성 클릭
🧠 이름은 연결을 원하는 서비스명, 인가 플로우는 default-provider-authorization-explicit-consent (Authorize Application), 외부 호스트는 연결할 서비스 주소 입력
🔶 애플리케이션 연결: 애플리케이션 하위의 애플리케이션에서 생성 클릭
🧠 이름과 슬러그는 내 서비스명, 공급자는 방금 생성한 내 서비스 공급자 선택
🔶 Outposts 액션에 추가
🧠 기본적으로 생성되어 있는 것(authentik Embedded Outpost)의 수정 누르고, Available Applications 아래에 추가할 서비스를 더블클릭하여 오른쪽에 추가, 스크롤 아래로 내려서 고급설정에 3번째 줄을 아래와 같이 수정(외부접속 주소 입력) 후 업데이트 클릭
authentik_host: https://authentik.mydomain.org
8️⃣ NPM에서 연결할 서비스의 설정 추가(Edit Proxy Host의 Advance탭)
🔶 Custom Nginx Configuration에 아래 내용 추가
🧠 33번 줄의 proxy_pass 뒤의 주소만 내 Authentik 내부접속 주소로 변경(http://<myAuthentikIP>:9000)
# 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://<myAuthentikIP>:9000/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;
}
9️⃣ 내 서비스 접속 및 확인
원리를 친절하게 알려 주셔도 잘 못 알아듣는 TED를 또 발견한 좋은 경험이었습니다. 설치 및 접속 테스트를 하면서 가장 애먹었던 부분은 '브라우저의 캐시를 지우고 테스트를 해야 한다!!'(아니면 시크릿창에서 테스트)는 것을 몰랐던 것입니다. 잘못된 설정을 수정했더라도 웹페이지는 갱신되지 않은 이전의 것만 불러왔기 때문에 시행착오만 계속 반복했었거든요. 또 이틀을 순삭 했습니다.
성공해서 다행입니다. 몇 안 되는 셀프호스팅 서비스에 하나씩 붙여보는 중입니다.