InfoGrab Docs

TLS를 사용하여 Redis와 Sentinel 보안 설정

요약

TLS(전송 계층 보안)를 사용하여 Redis와 Sentinel 통신을 보안합니다. Redis 또는 Sentinel에 TLS를 활성화하는 경우, 배포에서 Redis와 Sentinel 모두에 TLS를 활성화해야 합니다.

히스토리

TLS(전송 계층 보안)를 사용하여 Redis와 Sentinel 통신을 보안합니다. 표준 TLS(서버 인증서 검증)와 상호 TLS(mTLS, 클라이언트와 서버가 서로 인증) 모두 지원됩니다.

Redis 또는 Sentinel에 TLS를 활성화하는 경우, 배포에서 Redis와 Sentinel 모두에 TLS를 활성화해야 합니다. 동일한 환경에서 TLS와 비TLS 연결을 혼합하면 구성이 복잡해지고 잠재적인 보안 문제가 발생할 수 있습니다.

표준 비TLS 포트를 비활성화하고 TLS 연결만 허용하려면 구성에서 포트를 0으로 설정합니다. 예를 들어:

  • 표준 Redis 포트(6379)를 비활성화하려면 redis['port'] = 0을 추가합니다.
  • 표준 Sentinel 포트(26379)를 비활성화하려면 sentinel['port'] = 0을 추가합니다.

TLS 인증서 및 키 파일 생성#

TLS를 구성하기 전에 다음 인증서와 키를 생성하거나 획득해야 합니다. 이 예시 파일명은 전체적으로 사용됩니다:

  • CA 인증서 (ca.crt): 서버 인증서를 검증하는 인증 기관 인증서.
  • 서버 인증서 (redis-server.crt): Redis 서버용 인증서(CA로 서명).
  • 서버 키 (redis-server.key): Redis 서버 인증서의 개인 키.
  • Sentinel 서버 인증서 (sentinel-server.crt): Sentinel 서버용 인증서(CA로 서명).
  • Sentinel 서버 키 (sentinel-server.key): Sentinel 서버 인증서의 개인 키.
  • 클라이언트 인증서 (redis-client.crt, mTLS용): 클라이언트용 인증서(CA로 서명).
  • 클라이언트 키 (redis-client.key, mTLS용): 클라이언트 인증서의 개인 키.

이 예시에서는 인증서 디렉토리로 /etc/gitlab/ssl/을 사용하지만, 필요한 프로세스가 읽을 수 있도록 적절한 파일 권한이 설정된 경우 어떤 디렉토리에도 인증서를 저장할 수 있습니다.

샘플 인증서 생성 스크립트#

다음 스크립트는 적절한 SAN이 포함된 Redis와 Sentinel용 완전한 인증서 세트를 생성합니다. 실행하기 전에 IP 주소와 호스트명을 실제 인프라와 일치하도록 사용자 정의해야 합니다.

Warning

CA 개인 키(ca.key)는 민감한 정보입니다. 인증서를 생성한 후 CA 개인 키를 오프라인으로 안전하게 저장하고 프로덕션 서버에서 제거하는 것을 고려하세요.

  1. 다음 내용으로 generate-redis-certs.sh 파일을 만듭니다:

    #!/bin/bash
    
    # Configuration: CUSTOMIZE THESE VALUES FOR YOUR INFRASTRUCTURE
    CERT_DIR="/etc/gitlab/ssl"
    CA_CN="redis-ca"
    REDIS_HOSTNAMES="redis-primary,redis-replica-1,redis-replica-2"
    REDIS_IPS="10.0.0.1,10.0.0.2,10.0.0.3"
    SENTINEL_HOSTNAMES="sentinel-1,sentinel-2,sentinel-3"
    SENTINEL_IPS="10.0.0.1,10.0.0.2,10.0.0.3"
    CERT_DAYS=365
    
    mkdir -p "$CERT_DIR"
    
    # Create OpenSSL config for SAN extensions
    cat > /tmp/redis-san.conf << EOF
    [redis_server]
    subjectAltName = DNS:${REDIS_HOSTNAMES},IP:${REDIS_IPS}
    
    [sentinel_server]
    subjectAltName = DNS:${SENTINEL_HOSTNAMES},IP:${SENTINEL_IPS}
    
    [redis_client]
    subjectAltName = DNS:redis-client
    EOF
    
    # Generate CA certificate
    echo "Generating CA certificate..."
    openssl genrsa -out "$CERT_DIR/ca.key" 2048
    openssl req -new -x509 -days "$CERT_DAYS" -key "$CERT_DIR/ca.key" \
      -out "$CERT_DIR/ca.crt" -subj "/CN=$CA_CN"
    
    # Generate Redis server certificate
    echo "Generating Redis server certificate..."
    openssl genrsa -out "$CERT_DIR/redis-server.key" 2048
    openssl req -new -key "$CERT_DIR/redis-server.key" \
      -out "$CERT_DIR/redis-server.csr" -subj "/CN=redis-server"
    openssl x509 -req -days "$CERT_DAYS" -in "$CERT_DIR/redis-server.csr" \
      -CA "$CERT_DIR/ca.crt" -CAkey "$CERT_DIR/ca.key" -CAcreateserial \
      -out "$CERT_DIR/redis-server.crt" \
      -extensions redis_server -extfile /tmp/redis-san.conf
    
    # Generate Sentinel server certificate
    echo "Generating Sentinel server certificate..."
    openssl genrsa -out "$CERT_DIR/sentinel-server.key" 2048
    openssl req -new -key "$CERT_DIR/sentinel-server.key" \
      -out "$CERT_DIR/sentinel-server.csr" -subj "/CN=sentinel-server"
    openssl x509 -req -days "$CERT_DAYS" -in "$CERT_DIR/sentinel-server.csr" \
      -CA "$CERT_DIR/ca.crt" -CAkey "$CERT_DIR/ca.key" -CAcreateserial \
      -out "$CERT_DIR/sentinel-server.crt" \
      -extensions sentinel_server -extfile /tmp/redis-san.conf
    
    # Generate client certificate (for mTLS)
    echo "Generating Redis client certificate..."
    openssl genrsa -out "$CERT_DIR/redis-client.key" 2048
    openssl req -new -key "$CERT_DIR/redis-client.key" \
      -out "$CERT_DIR/redis-client.csr" -subj "/CN=redis-client"
    openssl x509 -req -days "$CERT_DAYS" -in "$CERT_DIR/redis-client.csr" \
      -CA "$CERT_DIR/ca.crt" -CAkey "$CERT_DIR/ca.key" -CAcreateserial \
      -out "$CERT_DIR/redis-client.crt" \
      -extensions redis_client -extfile /tmp/redis-san.conf
    
    # Clean up CSR files and temp config
    rm -f "$CERT_DIR"/*.csr /tmp/redis-san.conf
    
    # Set basic permissions (will be refined in the next steps)
    chmod 600 "$CERT_DIR"/*.key
    chmod 644 "$CERT_DIR"/*.crt
    
    echo "Certificates generated in $CERT_DIR"
    echo "Next: Configure file permissions based on your deployment (separate or shared nodes)"
    
  2. 스크립트에서 다음 변수를 인프라에 맞게 업데이트합니다:

    • REDIS_HOSTNAMES: 모든 Redis 서버 호스트명의 쉼표로 구분된 목록.
    • REDIS_IPS: 모든 Redis 서버 IP 주소의 쉼표로 구분된 목록.
    • SENTINEL_HOSTNAMES: 모든 Sentinel 서버 호스트명의 쉼표로 구분된 목록.
    • SENTINEL_IPS: 모든 Sentinel 서버 IP 주소의 쉼표로 구분된 목록.
    • CERT_DAYS: 인증서 유효 기간(일 단위, 기본값: 365).

    인증서에는 클라이언트가 Redis 또는 Sentinel에 연결하는 데 사용하는 모든 호스트명과 IP 주소가 포함되어야 합니다. 예를 들어 클라이언트가 redis.example.com10.0.0.1에 연결하는 경우 두 가지 모두 SAN에 있어야 합니다.

  3. 스크립트를 실행합니다:

    chmod +x generate-redis-certs.sh
    sudo ./generate-redis-certs.sh
    

인증서 및 키 파일 권한 설정#

기본적으로 GitLab 프로세스는 다른 사용자로 실행됩니다:

  • Redis와 Sentinel 프로세스는 gitlab-redis 사용자로 실행됩니다.
  • Puma(GitLab Rails), Workhorse, KAS 프로세스는 git 사용자로 실행됩니다.

/etc/gitlab/ssl/에 인증서와 키를 배치한 후, 필요한 모든 프로세스가 읽을 수 있도록 충분한 파일 권한을 설정합니다.

별도 노드에서 실행하는 경우#

Redis/Sentinel이 GitLab 애플리케이션과 별도의 노드(다른 머신의 Redis)에서 실행되는 경우:

  1. Redis/Sentinel 노드에서 다음 명령을 실행합니다:

    # Set ownership to the gitlab-redis user (for Redis/Sentinel processes only)
    sudo chown gitlab-redis:gitlab-redis /etc/gitlab/ssl/redis-*.{crt,key}
    sudo chown gitlab-redis:gitlab-redis /etc/gitlab/ssl/sentinel-*.{crt,key}
    sudo chown gitlab-redis:gitlab-redis /etc/gitlab/ssl/ca.crt
    
    # Set restrictive permissions (readable by owner only)
    sudo chmod 600 /etc/gitlab/ssl/redis-*.key
    sudo chmod 600 /etc/gitlab/ssl/sentinel-*.key
    sudo chmod 644 /etc/gitlab/ssl/redis-*.crt
    sudo chmod 644 /etc/gitlab/ssl/sentinel-*.crt
    sudo chmod 644 /etc/gitlab/ssl/ca.crt
    
  2. GitLab 애플리케이션 노드(mTLS 클라이언트 연결용)에서 다음 명령을 실행합니다:

    # For GitLab Rails, Workhorse, and KAS processes (running as 'git' user)
    sudo chown root:git /etc/gitlab/ssl/redis-client.{crt,key}
    sudo chown root:git /etc/gitlab/ssl/ca.crt
    sudo chmod 640 /etc/gitlab/ssl/redis-client.crt
    sudo chmod 640 /etc/gitlab/ssl/redis-client.key
    sudo chmod 644 /etc/gitlab/ssl/ca.crt
    

공유 노드에서 실행하는 경우#

Redis/Sentinel과 GitLab 애플리케이션 프로세스가 동일한 노드에서 실행되는 경우, gitlab-redisgit 사용자 모두 인증서를 읽을 수 있도록 허용해야 합니다. 공유 그룹 방식을 사용합니다.

  1. 공유 노드에서 다음 명령을 실행합니다:

    # Create a shared group for certificate access (if it doesn't exist)
    sudo groupadd -f gitlab-certs
    
    # Add both users to the shared group
    sudo usermod -a -G gitlab-certs gitlab-redis
    sudo usermod -a -G gitlab-certs git
    
    # Set ownership and permissions for server certificates (Redis/Sentinel)
    sudo chown gitlab-redis:gitlab-certs /etc/gitlab/ssl/redis-server.{crt,key}
    sudo chown gitlab-redis:gitlab-certs /etc/gitlab/ssl/sentinel-server.{crt,key}
    sudo chmod 640 /etc/gitlab/ssl/redis-server.key
    sudo chmod 644 /etc/gitlab/ssl/redis-server.crt
    sudo chmod 644 /etc/gitlab/ssl/sentinel-server.key
    sudo chmod 644 /etc/gitlab/ssl/sentinel-server.crt
    
    # Set ownership and permissions for client certificates (GitLab processes)
    sudo chown root:gitlab-certs /etc/gitlab/ssl/redis-client.{crt,key}
    sudo chown root:gitlab-certs /etc/gitlab/ssl/ca.crt
    sudo chmod 640 /etc/gitlab/ssl/redis-client.key
    sudo chmod 644 /etc/gitlab/ssl/redis-client.crt
    sudo chmod 644 /etc/gitlab/ssl/ca.crt
    
  2. 권한 변경 후 GitLab을 재시작합니다:

    sudo gitlab-ctl restart
    
  3. 로그를 확인하여 프로세스가 파일을 읽을 수 있는지 확인합니다:

    sudo gitlab-ctl tail
    

표준 TLS 활성화#

표준 TLS는 클라이언트가 서버의 인증서를 검증하는 방식입니다. 서버는 클라이언트 인증서를 요구하거나 검증하지 않습니다.

Note

다음 예시에 표시된 인증서 파일 경로(예: /etc/gitlab/ssl/redis-server.crt)는 자리 표시자입니다. 인증서 생성 프로세스에서 생성된 실제 파일명을 사용합니다. 위의 샘플 스크립트를 사용한 경우 파일명은 이 예시와 일치합니다.

표준 TLS로 Redis 구성#

TLS로 Redis 기본 인스턴스를 구성합니다:

  1. 기본 Redis 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_master_role']
    
    redis['bind'] = '10.0.0.1'
    redis['port'] = 6379
    redis['password'] = 'redis-password-goes-here'
    
    # Enable TLS for Redis
    redis['tls_port'] = 6380
    redis['tls_cert_file'] = '/etc/gitlab/ssl/redis-server.crt'
    redis['tls_key_file'] = '/etc/gitlab/ssl/redis-server.key'
    redis['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    redis['tls_replication'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

TLS로 Redis 복제본을 구성합니다:

  1. 각 복제본 Redis 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_replica_role']
    
    redis['bind'] = '10.0.0.2'
    redis['port'] = 6379
    redis['password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['master_port'] = 6380  # Use TLS port
    
    # Enable TLS for Redis
    redis['tls_port'] = 6380
    redis['tls_cert_file'] = '/etc/gitlab/ssl/redis-server.crt'
    redis['tls_key_file'] = '/etc/gitlab/ssl/redis-server.key'
    redis['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    redis['tls_replication'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

TLS로 Redis에 연결하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    # Configure Redis with TLS
    gitlab_rails['redis_host'] = '10.0.0.1'
    gitlab_rails['redis_port'] = 6380
    gitlab_rails['redis_password'] = 'redis-password-goes-here'
    
    # Enable TLS for Redis
    gitlab_rails['redis_ssl'] = true
    
    # Provide CA certificate for validation
    gitlab_rails['redis_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

표준 TLS로 Sentinel 구성#

TLS로 Sentinel 서버를 구성합니다:

  1. 각 Sentinel 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_sentinel_role']
    
    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['port'] = 6379
    
    # Enable TLS for Sentinel
    sentinel['bind'] = '10.0.0.1'
    sentinel['port'] = 26379
    sentinel['tls_port'] = 26380
    sentinel['tls_cert_file'] = '/etc/gitlab/ssl/sentinel-server.crt'
    sentinel['tls_key_file'] = '/etc/gitlab/ssl/sentinel-server.key'
    sentinel['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    sentinel['tls_replication'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

TLS로 Sentinel에 연결하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    
    # Configure Sentinels with TLS
    gitlab_rails['redis_sentinels'] = [
      { 'host' => '10.0.0.1', 'port' => 26380 },
      { 'host' => '10.0.0.2', 'port' => 26380 },
      { 'host' => '10.0.0.3', 'port' => 26380 }
    ]
    
    # Enable TLS for Sentinel
    gitlab_rails['redis_sentinels_ssl'] = true
    
    # Provide CA certificate for validation
    gitlab_rails['redis_sentinels_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

상호 TLS(mTLS) 활성화#

상호 TLS는 클라이언트와 서버 모두 인증서를 사용하여 서로 인증해야 합니다.

상호 TLS로 Redis 구성#

mTLS로 Redis 기본 인스턴스를 구성합니다:

  1. 기본 Redis 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_master_role']
    
    redis['bind'] = '10.0.0.1'
    redis['port'] = 6379
    redis['password'] = 'redis-password-goes-here'
    
    # Enable mTLS for Redis
    redis['tls_port'] = 6380
    redis['tls_cert_file'] = '/etc/gitlab/ssl/redis-server.crt'
    redis['tls_key_file'] = '/etc/gitlab/ssl/redis-server.key'
    redis['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    redis['tls_replication'] = 'yes'
    
    # Require client certificate validation
    redis['tls_auth_clients'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

mTLS로 Redis 복제본을 구성합니다:

  1. 각 복제본 Redis 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_replica_role']
    
    redis['bind'] = '10.0.0.2'
    redis['port'] = 6379
    redis['password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['master_port'] = 6380  # Use TLS port
    
    # Enable mTLS for Redis
    redis['tls_port'] = 6380
    redis['tls_cert_file'] = '/etc/gitlab/ssl/redis-server.crt'
    redis['tls_key_file'] = '/etc/gitlab/ssl/redis-server.key'
    redis['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    redis['tls_replication'] = 'yes'
    
    # Require client certificate validation
    redis['tls_auth_clients'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

mTLS로 Redis에 연결하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    # Configure Redis with mTLS
    gitlab_rails['redis_host'] = '10.0.0.1'
    gitlab_rails['redis_port'] = 6380
    gitlab_rails['redis_password'] = 'redis-password-goes-here'
    
    # Enable TLS for Redis
    gitlab_rails['redis_ssl'] = true
    
    # Provide CA certificate for validation
    gitlab_rails['redis_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
    # Provide client certificate and key for mTLS
    gitlab_rails['redis_tls_client_cert_file'] = '/etc/gitlab/ssl/redis-client.crt'
    gitlab_rails['redis_tls_client_key_file'] = '/etc/gitlab/ssl/redis-client.key'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

상호 TLS로 Sentinel 구성#

mTLS로 Sentinel 서버를 구성합니다:

  1. 각 Sentinel 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_sentinel_role']
    
    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['port'] = 6379
    
    # Enable mTLS for Sentinel
    sentinel['bind'] = '10.0.0.1'
    sentinel['port'] = 26379
    sentinel['tls_port'] = 26380
    sentinel['tls_cert_file'] = '/etc/gitlab/ssl/sentinel-server.crt'
    sentinel['tls_key_file'] = '/etc/gitlab/ssl/sentinel-server.key'
    sentinel['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    sentinel['tls_replication'] = 'yes'
    
    # Require client certificate validation
    sentinel['tls_auth_clients'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

mTLS로 Sentinel에 연결하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    
    # Configure Sentinels with mTLS
    gitlab_rails['redis_sentinels'] = [
      { 'host' => '10.0.0.1', 'port' => 26380 },
      { 'host' => '10.0.0.2', 'port' => 26380 },
      { 'host' => '10.0.0.3', 'port' => 26380 }
    ]
    
    # Enable TLS for Sentinel
    gitlab_rails['redis_sentinels_ssl'] = true
    
    # Provide CA certificate for validation
    gitlab_rails['redis_sentinels_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
    # Provide client certificate and key for mTLS
    gitlab_rails['redis_sentinels_tls_client_cert_file'] = '/etc/gitlab/ssl/redis-client.crt'
    gitlab_rails['redis_sentinels_tls_client_key_file'] = '/etc/gitlab/ssl/redis-client.key'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

비밀번호로 Sentinel 보안 설정#

TLS 외에도 Sentinel에 비밀번호 인증을 추가할 수 있습니다. 비밀번호 인증은 선택 사항이지만 추가 보안을 위해 권장됩니다.

Sentinel 비밀번호 구성#

Sentinel 서버에 비밀번호를 설정합니다:

  1. 각 Sentinel 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_sentinel_role']
    
    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['port'] = 6379
    
    # Set Sentinel password
    sentinel['password'] = 'sentinel-password-goes-here'
    
    # TLS configuration (if enabled)
    sentinel['bind'] = '10.0.0.1'
    sentinel['port'] = 26379
    sentinel['tls_port'] = 26380
    sentinel['tls_cert_file'] = '/etc/gitlab/ssl/sentinel-server.crt'
    sentinel['tls_key_file'] = '/etc/gitlab/ssl/sentinel-server.key'
    sentinel['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    sentinel['tls_replication'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

Sentinel로 인증하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    
    # Configure Sentinels with password authentication
    gitlab_rails['redis_sentinels'] = [
      { 'host' => '10.0.0.1', 'port' => 26380 },
      { 'host' => '10.0.0.2', 'port' => 26380 },
      { 'host' => '10.0.0.3', 'port' => 26380 }
    ]
    
    # Set Sentinel password
    gitlab_rails['redis_sentinels_password'] = 'sentinel-password-goes-here'
    
    # Enable TLS for Sentinel (if configured)
    gitlab_rails['redis_sentinels_ssl'] = true
    gitlab_rails['redis_sentinels_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

TLS 구성 확인#

TLS를 구성한 후 연결이 올바르게 작동하는지 확인합니다:

  1. Redis가 TLS 포트(기본값: 6380)에서 수신 대기 중인지 확인합니다:

    sudo netstat -tlnp | grep redis
    

    Redis가 표준 포트(6379)와 TLS 포트(6380) 모두에서 수신 대기 중인 것을 볼 수 있어야 합니다.

  2. Sentinel이 TLS 포트(기본값: 26380)에서 수신 대기 중인지 확인합니다:

    sudo netstat -tlnp | grep sentinel
    

    Sentinel이 표준 포트(26379)와 TLS 포트(26380) 모두에서 수신 대기 중인 것을 볼 수 있어야 합니다.

  3. redis-cli를 사용하여 Redis에 대한 TLS 연결을 테스트합니다:

    redis-cli --tls --cacert /etc/gitlab/ssl/ca.crt --cert /etc/gitlab/ssl/redis-client.crt --key /etc/gitlab/ssl/redis-client.key -h 10.0.0.1 -p 6380 ping
    

    표준 TLS(클라이언트 인증서 없이)의 경우 --cert--key 옵션을 생략합니다.

  4. TLS 관련 오류가 있는지 로그를 모니터링합니다:

    sudo gitlab-ctl tail redis
    sudo gitlab-ctl tail sentinel
    sudo gitlab-ctl tail gitlab-rails
    sudo gitlab-ctl tail gitlab-workhorse
    
  5. GitLab Rails를 실행하는 노드에서 생성된 구성 파일을 확인하여 TLS 설정이 있는지 확인합니다:

    cat /var/opt/gitlab/gitlab-rails/etc/resque.yml
    cat /var/opt/gitlab/gitlab-rails/etc/cable.yml
    

    ssl: true와 인증서 경로가 있는 ssl_params가 표시되어야 합니다.

TLS 구성 참조#

Redis, Sentinel, GitLab 애플리케이션(Rails) 설정 참조.

Redis TLS 설정#

설정 설명
redis['port'] 표준 Redis 포트(비TLS 포트를 비활성화하려면 0으로 설정)
redis['tls_port'] TLS 연결용 포트(기본값: 6380)
redis['tls_cert_file'] 서버 인증서 파일 경로
redis['tls_key_file'] 서버 개인 키 파일 경로
redis['tls_ca_cert_file'] CA 인증서 파일 경로
redis['tls_replication'] 복제에 TLS 활성화(기본값: no)
redis['tls_auth_clients'] 클라이언트 인증서 검증 요구(기본값: no)
redis['master_name'] Redis 마스터 이름(Sentinel에 필요)
redis['master_password'] Redis 마스터 비밀번호(Redis 마스터에 인증이 활성화된 경우에만 Sentinel에 필요)
redis['master_port'] Redis 마스터 포트(복제에 TLS가 활성화된 경우 필요)

Sentinel TLS 설정#

설정 설명
sentinel['port'] 표준 Sentinel 포트(비TLS 포트를 비활성화하려면 0으로 설정)
sentinel['tls_port'] TLS 연결용 포트(기본값: 26380)
sentinel['tls_cert_file'] 서버 인증서 파일 경로
sentinel['tls_key_file'] 서버 개인 키 파일 경로
sentinel['tls_ca_cert_file'] CA 인증서 파일 경로
sentinel['tls_replication'] 복제에 TLS 활성화(기본값: no)
sentinel['tls_auth_clients'] 클라이언트 인증서 검증 요구(기본값: no)
sentinel['password'] Sentinel 인증 비밀번호(선택 사항)

GitLab Rails TLS 설정#

설정 설명
gitlab_rails['redis_ssl'] Redis 연결에 TLS 활성화(기본값: false)
gitlab_rails['redis_sentinels_ssl'] Sentinel 연결에 TLS 활성화(기본값: false)
gitlab_rails['redis_tls_ca_cert_file'] Redis 검증용 CA 인증서 경로
gitlab_rails['redis_tls_client_cert_file'] Redis mTLS용 클라이언트 인증서 경로
gitlab_rails['redis_tls_client_key_file'] Redis mTLS용 클라이언트 개인 키 경로
gitlab_rails['redis_sentinels_password'] Sentinel 인증 비밀번호(선택 사항)
gitlab_rails['redis_sentinels_tls_ca_cert_file'] Sentinel 검증용 CA 인증서 경로
gitlab_rails['redis_sentinels_tls_client_cert_file'] Sentinel mTLS용 클라이언트 인증서 경로
gitlab_rails['redis_sentinels_tls_client_key_file'] Sentinel mTLS용 클라이언트 개인 키 경로
redis_exporter['enable'] 다중 노드 Redis 인스턴스의 Redis 익스포터 비활성화(false로 설정)

문제 해결#

다음 오류가 발생할 수 있습니다:

x509: certificate relies on legacy Common Name field, use SANs instead

이 오류를 방지하려면 인증서를 생성할 때 레거시 Common Name 필드에 의존하지 않고 **SAN(Subject Alternative Names)**을 포함해야 합니다.

TLS를 사용하여 Redis와 Sentinel 보안 설정

Tier: Premium, Ultimate
Offering: GitLab Self-Managed
원문 보기
요약

TLS(전송 계층 보안)를 사용하여 Redis와 Sentinel 통신을 보안합니다. Redis 또는 Sentinel에 TLS를 활성화하는 경우, 배포에서 Redis와 Sentinel 모두에 TLS를 활성화해야 합니다.

히스토리

TLS(전송 계층 보안)를 사용하여 Redis와 Sentinel 통신을 보안합니다. 표준 TLS(서버 인증서 검증)와 상호 TLS(mTLS, 클라이언트와 서버가 서로 인증) 모두 지원됩니다.

Redis 또는 Sentinel에 TLS를 활성화하는 경우, 배포에서 Redis와 Sentinel 모두에 TLS를 활성화해야 합니다. 동일한 환경에서 TLS와 비TLS 연결을 혼합하면 구성이 복잡해지고 잠재적인 보안 문제가 발생할 수 있습니다.

표준 비TLS 포트를 비활성화하고 TLS 연결만 허용하려면 구성에서 포트를 0으로 설정합니다. 예를 들어:

  • 표준 Redis 포트(6379)를 비활성화하려면 redis['port'] = 0을 추가합니다.
  • 표준 Sentinel 포트(26379)를 비활성화하려면 sentinel['port'] = 0을 추가합니다.

TLS 인증서 및 키 파일 생성#

TLS를 구성하기 전에 다음 인증서와 키를 생성하거나 획득해야 합니다. 이 예시 파일명은 전체적으로 사용됩니다:

  • CA 인증서 (ca.crt): 서버 인증서를 검증하는 인증 기관 인증서.
  • 서버 인증서 (redis-server.crt): Redis 서버용 인증서(CA로 서명).
  • 서버 키 (redis-server.key): Redis 서버 인증서의 개인 키.
  • Sentinel 서버 인증서 (sentinel-server.crt): Sentinel 서버용 인증서(CA로 서명).
  • Sentinel 서버 키 (sentinel-server.key): Sentinel 서버 인증서의 개인 키.
  • 클라이언트 인증서 (redis-client.crt, mTLS용): 클라이언트용 인증서(CA로 서명).
  • 클라이언트 키 (redis-client.key, mTLS용): 클라이언트 인증서의 개인 키.

이 예시에서는 인증서 디렉토리로 /etc/gitlab/ssl/을 사용하지만, 필요한 프로세스가 읽을 수 있도록 적절한 파일 권한이 설정된 경우 어떤 디렉토리에도 인증서를 저장할 수 있습니다.

샘플 인증서 생성 스크립트#

다음 스크립트는 적절한 SAN이 포함된 Redis와 Sentinel용 완전한 인증서 세트를 생성합니다. 실행하기 전에 IP 주소와 호스트명을 실제 인프라와 일치하도록 사용자 정의해야 합니다.

Warning

CA 개인 키(ca.key)는 민감한 정보입니다. 인증서를 생성한 후 CA 개인 키를 오프라인으로 안전하게 저장하고 프로덕션 서버에서 제거하는 것을 고려하세요.

  1. 다음 내용으로 generate-redis-certs.sh 파일을 만듭니다:

    #!/bin/bash
    
    # Configuration: CUSTOMIZE THESE VALUES FOR YOUR INFRASTRUCTURE
    CERT_DIR="/etc/gitlab/ssl"
    CA_CN="redis-ca"
    REDIS_HOSTNAMES="redis-primary,redis-replica-1,redis-replica-2"
    REDIS_IPS="10.0.0.1,10.0.0.2,10.0.0.3"
    SENTINEL_HOSTNAMES="sentinel-1,sentinel-2,sentinel-3"
    SENTINEL_IPS="10.0.0.1,10.0.0.2,10.0.0.3"
    CERT_DAYS=365
    
    mkdir -p "$CERT_DIR"
    
    # Create OpenSSL config for SAN extensions
    cat > /tmp/redis-san.conf << EOF
    [redis_server]
    subjectAltName = DNS:${REDIS_HOSTNAMES},IP:${REDIS_IPS}
    
    [sentinel_server]
    subjectAltName = DNS:${SENTINEL_HOSTNAMES},IP:${SENTINEL_IPS}
    
    [redis_client]
    subjectAltName = DNS:redis-client
    EOF
    
    # Generate CA certificate
    echo "Generating CA certificate..."
    openssl genrsa -out "$CERT_DIR/ca.key" 2048
    openssl req -new -x509 -days "$CERT_DAYS" -key "$CERT_DIR/ca.key" \
      -out "$CERT_DIR/ca.crt" -subj "/CN=$CA_CN"
    
    # Generate Redis server certificate
    echo "Generating Redis server certificate..."
    openssl genrsa -out "$CERT_DIR/redis-server.key" 2048
    openssl req -new -key "$CERT_DIR/redis-server.key" \
      -out "$CERT_DIR/redis-server.csr" -subj "/CN=redis-server"
    openssl x509 -req -days "$CERT_DAYS" -in "$CERT_DIR/redis-server.csr" \
      -CA "$CERT_DIR/ca.crt" -CAkey "$CERT_DIR/ca.key" -CAcreateserial \
      -out "$CERT_DIR/redis-server.crt" \
      -extensions redis_server -extfile /tmp/redis-san.conf
    
    # Generate Sentinel server certificate
    echo "Generating Sentinel server certificate..."
    openssl genrsa -out "$CERT_DIR/sentinel-server.key" 2048
    openssl req -new -key "$CERT_DIR/sentinel-server.key" \
      -out "$CERT_DIR/sentinel-server.csr" -subj "/CN=sentinel-server"
    openssl x509 -req -days "$CERT_DAYS" -in "$CERT_DIR/sentinel-server.csr" \
      -CA "$CERT_DIR/ca.crt" -CAkey "$CERT_DIR/ca.key" -CAcreateserial \
      -out "$CERT_DIR/sentinel-server.crt" \
      -extensions sentinel_server -extfile /tmp/redis-san.conf
    
    # Generate client certificate (for mTLS)
    echo "Generating Redis client certificate..."
    openssl genrsa -out "$CERT_DIR/redis-client.key" 2048
    openssl req -new -key "$CERT_DIR/redis-client.key" \
      -out "$CERT_DIR/redis-client.csr" -subj "/CN=redis-client"
    openssl x509 -req -days "$CERT_DAYS" -in "$CERT_DIR/redis-client.csr" \
      -CA "$CERT_DIR/ca.crt" -CAkey "$CERT_DIR/ca.key" -CAcreateserial \
      -out "$CERT_DIR/redis-client.crt" \
      -extensions redis_client -extfile /tmp/redis-san.conf
    
    # Clean up CSR files and temp config
    rm -f "$CERT_DIR"/*.csr /tmp/redis-san.conf
    
    # Set basic permissions (will be refined in the next steps)
    chmod 600 "$CERT_DIR"/*.key
    chmod 644 "$CERT_DIR"/*.crt
    
    echo "Certificates generated in $CERT_DIR"
    echo "Next: Configure file permissions based on your deployment (separate or shared nodes)"
    
  2. 스크립트에서 다음 변수를 인프라에 맞게 업데이트합니다:

    • REDIS_HOSTNAMES: 모든 Redis 서버 호스트명의 쉼표로 구분된 목록.
    • REDIS_IPS: 모든 Redis 서버 IP 주소의 쉼표로 구분된 목록.
    • SENTINEL_HOSTNAMES: 모든 Sentinel 서버 호스트명의 쉼표로 구분된 목록.
    • SENTINEL_IPS: 모든 Sentinel 서버 IP 주소의 쉼표로 구분된 목록.
    • CERT_DAYS: 인증서 유효 기간(일 단위, 기본값: 365).

    인증서에는 클라이언트가 Redis 또는 Sentinel에 연결하는 데 사용하는 모든 호스트명과 IP 주소가 포함되어야 합니다. 예를 들어 클라이언트가 redis.example.com10.0.0.1에 연결하는 경우 두 가지 모두 SAN에 있어야 합니다.

  3. 스크립트를 실행합니다:

    chmod +x generate-redis-certs.sh
    sudo ./generate-redis-certs.sh
    

인증서 및 키 파일 권한 설정#

기본적으로 GitLab 프로세스는 다른 사용자로 실행됩니다:

  • Redis와 Sentinel 프로세스는 gitlab-redis 사용자로 실행됩니다.
  • Puma(GitLab Rails), Workhorse, KAS 프로세스는 git 사용자로 실행됩니다.

/etc/gitlab/ssl/에 인증서와 키를 배치한 후, 필요한 모든 프로세스가 읽을 수 있도록 충분한 파일 권한을 설정합니다.

별도 노드에서 실행하는 경우#

Redis/Sentinel이 GitLab 애플리케이션과 별도의 노드(다른 머신의 Redis)에서 실행되는 경우:

  1. Redis/Sentinel 노드에서 다음 명령을 실행합니다:

    # Set ownership to the gitlab-redis user (for Redis/Sentinel processes only)
    sudo chown gitlab-redis:gitlab-redis /etc/gitlab/ssl/redis-*.{crt,key}
    sudo chown gitlab-redis:gitlab-redis /etc/gitlab/ssl/sentinel-*.{crt,key}
    sudo chown gitlab-redis:gitlab-redis /etc/gitlab/ssl/ca.crt
    
    # Set restrictive permissions (readable by owner only)
    sudo chmod 600 /etc/gitlab/ssl/redis-*.key
    sudo chmod 600 /etc/gitlab/ssl/sentinel-*.key
    sudo chmod 644 /etc/gitlab/ssl/redis-*.crt
    sudo chmod 644 /etc/gitlab/ssl/sentinel-*.crt
    sudo chmod 644 /etc/gitlab/ssl/ca.crt
    
  2. GitLab 애플리케이션 노드(mTLS 클라이언트 연결용)에서 다음 명령을 실행합니다:

    # For GitLab Rails, Workhorse, and KAS processes (running as 'git' user)
    sudo chown root:git /etc/gitlab/ssl/redis-client.{crt,key}
    sudo chown root:git /etc/gitlab/ssl/ca.crt
    sudo chmod 640 /etc/gitlab/ssl/redis-client.crt
    sudo chmod 640 /etc/gitlab/ssl/redis-client.key
    sudo chmod 644 /etc/gitlab/ssl/ca.crt
    

공유 노드에서 실행하는 경우#

Redis/Sentinel과 GitLab 애플리케이션 프로세스가 동일한 노드에서 실행되는 경우, gitlab-redisgit 사용자 모두 인증서를 읽을 수 있도록 허용해야 합니다. 공유 그룹 방식을 사용합니다.

  1. 공유 노드에서 다음 명령을 실행합니다:

    # Create a shared group for certificate access (if it doesn't exist)
    sudo groupadd -f gitlab-certs
    
    # Add both users to the shared group
    sudo usermod -a -G gitlab-certs gitlab-redis
    sudo usermod -a -G gitlab-certs git
    
    # Set ownership and permissions for server certificates (Redis/Sentinel)
    sudo chown gitlab-redis:gitlab-certs /etc/gitlab/ssl/redis-server.{crt,key}
    sudo chown gitlab-redis:gitlab-certs /etc/gitlab/ssl/sentinel-server.{crt,key}
    sudo chmod 640 /etc/gitlab/ssl/redis-server.key
    sudo chmod 644 /etc/gitlab/ssl/redis-server.crt
    sudo chmod 644 /etc/gitlab/ssl/sentinel-server.key
    sudo chmod 644 /etc/gitlab/ssl/sentinel-server.crt
    
    # Set ownership and permissions for client certificates (GitLab processes)
    sudo chown root:gitlab-certs /etc/gitlab/ssl/redis-client.{crt,key}
    sudo chown root:gitlab-certs /etc/gitlab/ssl/ca.crt
    sudo chmod 640 /etc/gitlab/ssl/redis-client.key
    sudo chmod 644 /etc/gitlab/ssl/redis-client.crt
    sudo chmod 644 /etc/gitlab/ssl/ca.crt
    
  2. 권한 변경 후 GitLab을 재시작합니다:

    sudo gitlab-ctl restart
    
  3. 로그를 확인하여 프로세스가 파일을 읽을 수 있는지 확인합니다:

    sudo gitlab-ctl tail
    

표준 TLS 활성화#

표준 TLS는 클라이언트가 서버의 인증서를 검증하는 방식입니다. 서버는 클라이언트 인증서를 요구하거나 검증하지 않습니다.

Note

다음 예시에 표시된 인증서 파일 경로(예: /etc/gitlab/ssl/redis-server.crt)는 자리 표시자입니다. 인증서 생성 프로세스에서 생성된 실제 파일명을 사용합니다. 위의 샘플 스크립트를 사용한 경우 파일명은 이 예시와 일치합니다.

표준 TLS로 Redis 구성#

TLS로 Redis 기본 인스턴스를 구성합니다:

  1. 기본 Redis 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_master_role']
    
    redis['bind'] = '10.0.0.1'
    redis['port'] = 6379
    redis['password'] = 'redis-password-goes-here'
    
    # Enable TLS for Redis
    redis['tls_port'] = 6380
    redis['tls_cert_file'] = '/etc/gitlab/ssl/redis-server.crt'
    redis['tls_key_file'] = '/etc/gitlab/ssl/redis-server.key'
    redis['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    redis['tls_replication'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

TLS로 Redis 복제본을 구성합니다:

  1. 각 복제본 Redis 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_replica_role']
    
    redis['bind'] = '10.0.0.2'
    redis['port'] = 6379
    redis['password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['master_port'] = 6380  # Use TLS port
    
    # Enable TLS for Redis
    redis['tls_port'] = 6380
    redis['tls_cert_file'] = '/etc/gitlab/ssl/redis-server.crt'
    redis['tls_key_file'] = '/etc/gitlab/ssl/redis-server.key'
    redis['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    redis['tls_replication'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

TLS로 Redis에 연결하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    # Configure Redis with TLS
    gitlab_rails['redis_host'] = '10.0.0.1'
    gitlab_rails['redis_port'] = 6380
    gitlab_rails['redis_password'] = 'redis-password-goes-here'
    
    # Enable TLS for Redis
    gitlab_rails['redis_ssl'] = true
    
    # Provide CA certificate for validation
    gitlab_rails['redis_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

표준 TLS로 Sentinel 구성#

TLS로 Sentinel 서버를 구성합니다:

  1. 각 Sentinel 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_sentinel_role']
    
    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['port'] = 6379
    
    # Enable TLS for Sentinel
    sentinel['bind'] = '10.0.0.1'
    sentinel['port'] = 26379
    sentinel['tls_port'] = 26380
    sentinel['tls_cert_file'] = '/etc/gitlab/ssl/sentinel-server.crt'
    sentinel['tls_key_file'] = '/etc/gitlab/ssl/sentinel-server.key'
    sentinel['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    sentinel['tls_replication'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

TLS로 Sentinel에 연결하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    
    # Configure Sentinels with TLS
    gitlab_rails['redis_sentinels'] = [
      { 'host' => '10.0.0.1', 'port' => 26380 },
      { 'host' => '10.0.0.2', 'port' => 26380 },
      { 'host' => '10.0.0.3', 'port' => 26380 }
    ]
    
    # Enable TLS for Sentinel
    gitlab_rails['redis_sentinels_ssl'] = true
    
    # Provide CA certificate for validation
    gitlab_rails['redis_sentinels_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

상호 TLS(mTLS) 활성화#

상호 TLS는 클라이언트와 서버 모두 인증서를 사용하여 서로 인증해야 합니다.

상호 TLS로 Redis 구성#

mTLS로 Redis 기본 인스턴스를 구성합니다:

  1. 기본 Redis 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_master_role']
    
    redis['bind'] = '10.0.0.1'
    redis['port'] = 6379
    redis['password'] = 'redis-password-goes-here'
    
    # Enable mTLS for Redis
    redis['tls_port'] = 6380
    redis['tls_cert_file'] = '/etc/gitlab/ssl/redis-server.crt'
    redis['tls_key_file'] = '/etc/gitlab/ssl/redis-server.key'
    redis['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    redis['tls_replication'] = 'yes'
    
    # Require client certificate validation
    redis['tls_auth_clients'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

mTLS로 Redis 복제본을 구성합니다:

  1. 각 복제본 Redis 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_replica_role']
    
    redis['bind'] = '10.0.0.2'
    redis['port'] = 6379
    redis['password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['master_port'] = 6380  # Use TLS port
    
    # Enable mTLS for Redis
    redis['tls_port'] = 6380
    redis['tls_cert_file'] = '/etc/gitlab/ssl/redis-server.crt'
    redis['tls_key_file'] = '/etc/gitlab/ssl/redis-server.key'
    redis['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    redis['tls_replication'] = 'yes'
    
    # Require client certificate validation
    redis['tls_auth_clients'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

mTLS로 Redis에 연결하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    # Configure Redis with mTLS
    gitlab_rails['redis_host'] = '10.0.0.1'
    gitlab_rails['redis_port'] = 6380
    gitlab_rails['redis_password'] = 'redis-password-goes-here'
    
    # Enable TLS for Redis
    gitlab_rails['redis_ssl'] = true
    
    # Provide CA certificate for validation
    gitlab_rails['redis_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
    # Provide client certificate and key for mTLS
    gitlab_rails['redis_tls_client_cert_file'] = '/etc/gitlab/ssl/redis-client.crt'
    gitlab_rails['redis_tls_client_key_file'] = '/etc/gitlab/ssl/redis-client.key'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

상호 TLS로 Sentinel 구성#

mTLS로 Sentinel 서버를 구성합니다:

  1. 각 Sentinel 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_sentinel_role']
    
    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['port'] = 6379
    
    # Enable mTLS for Sentinel
    sentinel['bind'] = '10.0.0.1'
    sentinel['port'] = 26379
    sentinel['tls_port'] = 26380
    sentinel['tls_cert_file'] = '/etc/gitlab/ssl/sentinel-server.crt'
    sentinel['tls_key_file'] = '/etc/gitlab/ssl/sentinel-server.key'
    sentinel['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    sentinel['tls_replication'] = 'yes'
    
    # Require client certificate validation
    sentinel['tls_auth_clients'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

mTLS로 Sentinel에 연결하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    
    # Configure Sentinels with mTLS
    gitlab_rails['redis_sentinels'] = [
      { 'host' => '10.0.0.1', 'port' => 26380 },
      { 'host' => '10.0.0.2', 'port' => 26380 },
      { 'host' => '10.0.0.3', 'port' => 26380 }
    ]
    
    # Enable TLS for Sentinel
    gitlab_rails['redis_sentinels_ssl'] = true
    
    # Provide CA certificate for validation
    gitlab_rails['redis_sentinels_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
    # Provide client certificate and key for mTLS
    gitlab_rails['redis_sentinels_tls_client_cert_file'] = '/etc/gitlab/ssl/redis-client.crt'
    gitlab_rails['redis_sentinels_tls_client_key_file'] = '/etc/gitlab/ssl/redis-client.key'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

비밀번호로 Sentinel 보안 설정#

TLS 외에도 Sentinel에 비밀번호 인증을 추가할 수 있습니다. 비밀번호 인증은 선택 사항이지만 추가 보안을 위해 권장됩니다.

Sentinel 비밀번호 구성#

Sentinel 서버에 비밀번호를 설정합니다:

  1. 각 Sentinel 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    roles ['redis_sentinel_role']
    
    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    redis['master_ip'] = '10.0.0.1'
    redis['port'] = 6379
    
    # Set Sentinel password
    sentinel['password'] = 'sentinel-password-goes-here'
    
    # TLS configuration (if enabled)
    sentinel['bind'] = '10.0.0.1'
    sentinel['port'] = 26379
    sentinel['tls_port'] = 26380
    sentinel['tls_cert_file'] = '/etc/gitlab/ssl/sentinel-server.crt'
    sentinel['tls_key_file'] = '/etc/gitlab/ssl/sentinel-server.key'
    sentinel['tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    sentinel['tls_replication'] = 'yes'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

Sentinel로 인증하도록 GitLab 애플리케이션을 구성합니다:

  1. GitLab 애플리케이션 서버의 /etc/gitlab/gitlab.rb를 편집합니다:

    redis['master_name'] = 'gitlab-redis'
    redis['master_password'] = 'redis-password-goes-here'
    
    # Configure Sentinels with password authentication
    gitlab_rails['redis_sentinels'] = [
      { 'host' => '10.0.0.1', 'port' => 26380 },
      { 'host' => '10.0.0.2', 'port' => 26380 },
      { 'host' => '10.0.0.3', 'port' => 26380 }
    ]
    
    # Set Sentinel password
    gitlab_rails['redis_sentinels_password'] = 'sentinel-password-goes-here'
    
    # Enable TLS for Sentinel (if configured)
    gitlab_rails['redis_sentinels_ssl'] = true
    gitlab_rails['redis_sentinels_tls_ca_cert_file'] = '/etc/gitlab/ssl/ca.crt'
    
  2. 변경 사항을 적용하려면 GitLab을 재구성합니다.

TLS 구성 확인#

TLS를 구성한 후 연결이 올바르게 작동하는지 확인합니다:

  1. Redis가 TLS 포트(기본값: 6380)에서 수신 대기 중인지 확인합니다:

    sudo netstat -tlnp | grep redis
    

    Redis가 표준 포트(6379)와 TLS 포트(6380) 모두에서 수신 대기 중인 것을 볼 수 있어야 합니다.

  2. Sentinel이 TLS 포트(기본값: 26380)에서 수신 대기 중인지 확인합니다:

    sudo netstat -tlnp | grep sentinel
    

    Sentinel이 표준 포트(26379)와 TLS 포트(26380) 모두에서 수신 대기 중인 것을 볼 수 있어야 합니다.

  3. redis-cli를 사용하여 Redis에 대한 TLS 연결을 테스트합니다:

    redis-cli --tls --cacert /etc/gitlab/ssl/ca.crt --cert /etc/gitlab/ssl/redis-client.crt --key /etc/gitlab/ssl/redis-client.key -h 10.0.0.1 -p 6380 ping
    

    표준 TLS(클라이언트 인증서 없이)의 경우 --cert--key 옵션을 생략합니다.

  4. TLS 관련 오류가 있는지 로그를 모니터링합니다:

    sudo gitlab-ctl tail redis
    sudo gitlab-ctl tail sentinel
    sudo gitlab-ctl tail gitlab-rails
    sudo gitlab-ctl tail gitlab-workhorse
    
  5. GitLab Rails를 실행하는 노드에서 생성된 구성 파일을 확인하여 TLS 설정이 있는지 확인합니다:

    cat /var/opt/gitlab/gitlab-rails/etc/resque.yml
    cat /var/opt/gitlab/gitlab-rails/etc/cable.yml
    

    ssl: true와 인증서 경로가 있는 ssl_params가 표시되어야 합니다.

TLS 구성 참조#

Redis, Sentinel, GitLab 애플리케이션(Rails) 설정 참조.

Redis TLS 설정#

설정 설명
redis['port'] 표준 Redis 포트(비TLS 포트를 비활성화하려면 0으로 설정)
redis['tls_port'] TLS 연결용 포트(기본값: 6380)
redis['tls_cert_file'] 서버 인증서 파일 경로
redis['tls_key_file'] 서버 개인 키 파일 경로
redis['tls_ca_cert_file'] CA 인증서 파일 경로
redis['tls_replication'] 복제에 TLS 활성화(기본값: no)
redis['tls_auth_clients'] 클라이언트 인증서 검증 요구(기본값: no)
redis['master_name'] Redis 마스터 이름(Sentinel에 필요)
redis['master_password'] Redis 마스터 비밀번호(Redis 마스터에 인증이 활성화된 경우에만 Sentinel에 필요)
redis['master_port'] Redis 마스터 포트(복제에 TLS가 활성화된 경우 필요)

Sentinel TLS 설정#

설정 설명
sentinel['port'] 표준 Sentinel 포트(비TLS 포트를 비활성화하려면 0으로 설정)
sentinel['tls_port'] TLS 연결용 포트(기본값: 26380)
sentinel['tls_cert_file'] 서버 인증서 파일 경로
sentinel['tls_key_file'] 서버 개인 키 파일 경로
sentinel['tls_ca_cert_file'] CA 인증서 파일 경로
sentinel['tls_replication'] 복제에 TLS 활성화(기본값: no)
sentinel['tls_auth_clients'] 클라이언트 인증서 검증 요구(기본값: no)
sentinel['password'] Sentinel 인증 비밀번호(선택 사항)

GitLab Rails TLS 설정#

설정 설명
gitlab_rails['redis_ssl'] Redis 연결에 TLS 활성화(기본값: false)
gitlab_rails['redis_sentinels_ssl'] Sentinel 연결에 TLS 활성화(기본값: false)
gitlab_rails['redis_tls_ca_cert_file'] Redis 검증용 CA 인증서 경로
gitlab_rails['redis_tls_client_cert_file'] Redis mTLS용 클라이언트 인증서 경로
gitlab_rails['redis_tls_client_key_file'] Redis mTLS용 클라이언트 개인 키 경로
gitlab_rails['redis_sentinels_password'] Sentinel 인증 비밀번호(선택 사항)
gitlab_rails['redis_sentinels_tls_ca_cert_file'] Sentinel 검증용 CA 인증서 경로
gitlab_rails['redis_sentinels_tls_client_cert_file'] Sentinel mTLS용 클라이언트 인증서 경로
gitlab_rails['redis_sentinels_tls_client_key_file'] Sentinel mTLS용 클라이언트 개인 키 경로
redis_exporter['enable'] 다중 노드 Redis 인스턴스의 Redis 익스포터 비활성화(false로 설정)

문제 해결#

다음 오류가 발생할 수 있습니다:

x509: certificate relies on legacy Common Name field, use SANs instead

이 오류를 방지하려면 인증서를 생성할 때 레거시 Common Name 필드에 의존하지 않고 **SAN(Subject Alternative Names)**을 포함해야 합니다.