Tinyauth

Docker

Docker를 사용하여 Tinyauth를 배포하는 방법

Tinyauth를 Docker로 빠르게 배포할 수 있어요. 이 문서에서는 단독 실행, Nginx Proxy Manager 연동, Traefik 연동 예시를 다뤄요.

사전 준비

  • Docker 및 Docker Compose 설치
  • 세션 시크릿과 해시 시크릿 값

설정 파일

모든 예시에서 공통으로 사용할 config.yaml 파일이에요. 필요에 따라 수정해서 사용하세요.

# config.yaml
server:
  public_origin: https://auth.example.com

registration:
  enabled: false

security:
  session_secret: your_session_secret_here_min_16_chars
  hash_secret: your_base64url_hash_secret_here

database:
  type: sqlite
  path: /opt/tinyauth/database.db

clients:
  - id: my-app
    name: My Application
    client_id: my-app-client-id
    client_secret: my-app-client-secret
    redirect_uris:
      - https://app.example.com/callback
    response_types:
      - code
    grant_types:
      - authorization_code
      - refresh_token
    scope: openid profile email

위 예시는 자체 회원가입을 기본적으로 닫아 둔 운영용 시작점이에요. 공개 회원가입이 필요하다면 회원가입 설정 문서처럼 registration.enabled: true를 명시적으로 설정하세요.


단독 실행

가장 간단한 형태로 Tinyauth를 실행하는 예시에요.

Docker Run

docker run -d \
  --name tinyauth \
  -p 8080:8080 \
  -v $(pwd)/config.yaml:/opt/config.yaml:ro \
  -v tinyauth-data:/opt/tinyauth \
  -e NODE_ENV=production \
  --restart unless-stopped \
  ghcr.io/tinyrack-net/tinyauth:latest

Docker Compose

# docker-compose.yml
services:
  tinyauth:
    image: ghcr.io/tinyrack-net/tinyauth:latest
    container_name: tinyauth
    restart: unless-stopped
    ports:
      - '8080:8080'
    environment:
      - NODE_ENV=production
    volumes:
      - ./config.yaml:/opt/config.yaml:ro
      - tinyauth-data:/opt/tinyauth
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp
    user: '1001:1001'
    healthcheck:
      test: ['CMD', 'wget', '-q', '--spider', 'http://localhost:8080/.well-known/openid-configuration']
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  tinyauth-data:

실행 후 http://localhost:8080으로 접속하면 Tinyauth를 확인할 수 있어요.


PostgreSQL과 함께 사용

SQLite 대신 PostgreSQL을 사용하고 싶다면 아래 예시를 참고하세요.

설정 파일

# config.yaml
server:
  public_origin: https://auth.example.com

registration:
  enabled: false

security:
  session_secret: your_session_secret_here_min_16_chars
  hash_secret: your_base64url_hash_secret_here

database:
  type: postgres
  host: postgres
  port: 5432
  user: ${DB_USER:-tinyauth}
  password: ${DB_PASSWORD:-tinyauth}
  name: ${DB_NAME:-tinyauth}

Docker Compose

# docker-compose.yml
services:
  tinyauth:
    image: ghcr.io/tinyrack-net/tinyauth:latest
    container_name: tinyauth
    restart: unless-stopped
    ports:
      - '8080:8080'
    environment:
      - NODE_ENV=production
      - DB_USER=tinyauth
      - DB_PASSWORD=tinyauth
      - DB_NAME=tinyauth
    volumes:
      - ./config.yaml:/opt/config.yaml:ro
    depends_on:
      postgres:
        condition: service_healthy
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp
    user: '1001:1001'
    healthcheck:
      test: ['CMD', 'wget', '-q', '--spider', 'http://localhost:8080/.well-known/openid-configuration']
      interval: 30s
      timeout: 10s
      retries: 3

  postgres:
    image: postgres:17-alpine
    container_name: tinyauth-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: tinyauth
      POSTGRES_PASSWORD: tinyauth
      POSTGRES_DB: tinyauth
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U tinyauth']
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  postgres-data:

Nginx Proxy Manager와 함께 사용

Nginx Proxy Manager를 리버스 프록시로 사용하는 구성이에요. SSL 인증서 관리와 프록시 설정을 웹 UI로 간편하게 할 수 있어요.

설정 파일

server.trust_proxytrue로 설정해서 프록시 헤더를 신뢰하도록 해야 해요.

# config.yaml
server:
  public_origin: https://auth.example.com
  trust_proxy: true

registration:
  enabled: false

security:
  session_secret: your_session_secret_here_min_16_chars
  hash_secret: your_base64url_hash_secret_here

database:
  type: sqlite
  path: /opt/tinyauth/database.db

Docker Compose

# docker-compose.yml
services:
  npm:
    image: jc21/nginx-proxy-manager:latest
    container_name: nginx-proxy-manager
    restart: unless-stopped
    ports:
      - '80:80'
      - '443:443'
      - '81:81'
    volumes:
      - npm-data:/data
      - npm-letsencrypt:/etc/letsencrypt

  tinyauth:
    image: ghcr.io/tinyrack-net/tinyauth:latest
    container_name: tinyauth
    restart: unless-stopped
    expose:
      - '8080'
    environment:
      - NODE_ENV=production
    volumes:
      - ./config.yaml:/opt/config.yaml:ro
      - tinyauth-data:/opt/tinyauth
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp
    user: '1001:1001'
    healthcheck:
      test: ['CMD', 'wget', '-q', '--spider', 'http://localhost:8080/.well-known/openid-configuration']
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  npm-data:
  npm-letsencrypt:
  tinyauth-data:

Nginx Proxy Manager 설정

  1. http://localhost:81로 Nginx Proxy Manager 관리 화면에 접속하세요
  2. 기본 관리자 계정으로 로그인하세요 (Email: admin@example.com, Password: changeme)
  3. Proxy Hosts > Add Proxy Host를 클릭하세요
  4. 아래와 같이 설정하세요:
    • Domain Names: auth.example.com
    • Scheme: http
    • Forward Hostname / IP: tinyauth
    • Forward Port: 8080
    • Websockets Support: 활성화
  5. SSL 탭에서 Let's Encrypt 인증서를 발급받으세요

Traefik과 함께 사용

Traefik을 리버스 프록시로 사용하는 구성이에요. Docker 라벨 기반으로 라우팅을 자동 설정할 수 있어요.

설정 파일

Traefik도 마찬가지로 server.trust_proxytrue로 설정해야 해요.

# config.yaml
server:
  public_origin: https://auth.example.com
  trust_proxy: true

registration:
  enabled: false

security:
  session_secret: your_session_secret_here_min_16_chars
  hash_secret: your_base64url_hash_secret_here

database:
  type: sqlite
  path: /opt/tinyauth/database.db

Docker Compose

# docker-compose.yml
services:
  traefik:
    image: traefik:v3.4
    container_name: traefik
    restart: unless-stopped
    command:
      - '--api.insecure=true'
      - '--providers.docker=true'
      - '--providers.docker.exposedbydefault=false'
      - '--entrypoints.web.address=:80'
      - '--entrypoints.websecure.address=:443'
      - '--certificatesresolvers.letsencrypt.acme.httpchallenge=true'
      - '--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web'
      - '--certificatesresolvers.letsencrypt.acme.email=admin@example.com'
      - '--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json'
    ports:
      - '80:80'
      - '443:443'
      - '8081:8080'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - traefik-letsencrypt:/letsencrypt

  tinyauth:
    image: ghcr.io/tinyrack-net/tinyauth:latest
    container_name: tinyauth
    restart: unless-stopped
    expose:
      - '8080'
    environment:
      - NODE_ENV=production
    volumes:
      - ./config.yaml:/opt/config.yaml:ro
      - tinyauth-data:/opt/tinyauth
    labels:
      - 'traefik.enable=true'
      - 'traefik.http.routers.tinyauth.rule=Host(`auth.example.com`)'
      - 'traefik.http.routers.tinyauth.entrypoints=websecure'
      - 'traefik.http.routers.tinyauth.tls.certresolver=letsencrypt'
      - 'traefik.http.services.tinyauth.loadbalancer.server.port=8080'
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp
    user: '1001:1001'
    healthcheck:
      test: ['CMD', 'wget', '-q', '--spider', 'http://localhost:8080/.well-known/openid-configuration']
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  traefik-letsencrypt:
  tinyauth-data:

HTTP에서 HTTPS 리다이렉트

HTTP 요청을 자동으로 HTTPS로 리다이렉트하려면 Traefik 설정에 다음을 추가하세요:

command:
  # ... 기존 설정에 추가
  - '--entrypoints.web.http.redirections.entrypoint.to=websecure'
  - '--entrypoints.web.http.redirections.entrypoint.scheme=https'

보안 권장 사항

  • security.session_secret은 반드시 16자 이상의 랜덤 문자열을 사용하세요
  • security.hash_secret은 base64url 32바이트 값으로 생성하세요
  • 프로덕션 환경에서는 반드시 HTTPS를 적용하세요
  • read_only: trueno-new-privileges 옵션을 사용하세요
  • 비루트 사용자(user: '1001:1001')로 컨테이너를 실행하세요
  • 설정 파일은 읽기 전용(:ro)으로 마운트하세요
  • security.session_secret, security.hash_secret, 데이터베이스 비밀번호 같은 민감한 값은 Docker Secrets이나 환경 변수를 활용하세요