ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 인증키 생성 (smallstep)
    IT 발자취.../리눅스 2022. 9. 8. 08:29
    현재 문서는 "서비스메시마스터" - 안잔리카트리,비크람 카트리 지음 서적의 11장 보안기능 내용 중 발췌한 부분입니다.
    istio 도메인이 중간에 보이는 것은 문서를 그대로 가져왔기 때문으로, 본인 환경에 맞게 설정하길 바랍니다.

     

    단방향 TLS나 상호 TLS를 사용하려면 개인 키, 서버 인증서 및 루트 인증서가 필요하다. CA에서 가져오거나 자체적으로 생성할 수 있다. 몇 단계의 커맨드 라인을 사용해 인증서와 키를 생성한다. 이를 위해 스텝 CLI를 설치해야 한다.

     

    스텝 CLI 설치

    https://github.com/smallstep/cli

     

    GitHub - smallstep/cli: 🧰 A zero trust swiss army knife for working with X509, OAuth, JWT, OATH OTP, etc.

    🧰 A zero trust swiss army knife for working with X509, OAuth, JWT, OATH OTP, etc. - GitHub - smallstep/cli: 🧰 A zero trust swiss army knife for working with X509, OAuth, JWT, OATH OTP, etc.

    github.com

    스몰스텝은 애플리케이션에 PKI를 설정하기 위해 쉽고 사용하기 쉬운 도구를 제공하는 오픈소스 소프트웨어다. 스텝 CLI를 설치하려면 다음 단계를 따른다.

     

    리눅스 기준 (다른 OS는 위 공식 문서를 참고)

    wget https://dl.step.sm/gh-release/cli/docs-cli-install/v0.21.0/step-cli_0.21.0_amd64.deb
    sudo dpkg -i step-cli_0.21.0_amd64.deb

     

    개인 키, 서버 및 루트 인증서 생성

    일반적으로, 컴퓨터 이름에 발급된 인증서가 중간자 공격(man in the middle attack)을 방지하는데 적합한지 확인하려는 경우 GeoTrust, DitiCert, GlobalSignㄷ 또는 GoDaddy와 같은 CA 프로바이더로부터 인증서를 받는다. 인증서 발급 범위는 서비스 메시 구현을 사용한 서비스 이름을 사용해 수행된다. 기존 프로바이더로부터 서명된 루트 인증서를 얻거나 자체 루트 및 중간 인증서를 사용해 인증서를 발급할 수 있다. 이 개념을 상펴보고자 간단한 오픈소스 smallstep.com 방식을 사용해 자체 CA를 사용한다.

     

    1. 디렉토리를 생성하고 step 명령을 사용해 root --profile 로 루트 인증서를 생성한다.

    2. 루트 키를 암호화하기 위한 암호를 지정한다. 간단히 password 문자열을 password로 사용할 수 있다.

    $ mkdir -p ~/step
    $ cd ~/step
    
    $ step certifiacte create --profile root-ca "My Root CA" root-ca.crt root-ca.key
    Please enter the password to encrypt the private key: password
    
    # This password is used to encrypt root-ca.key
    Your certificate has been saved in root-ca.crt.
    Your private key has been saved in root-ca.key.

    3. 신뢰 체인을 설정하기 위해 중간 CA를 만들어 본다.

    $ step certificate create istio.io istio.crt istio.key --profile intermediacte-ca --ca ./root-ca.crt --ca-key ./root-ca.key
    Please enter the password to decrypt ./root-ca.key: password
    # step asks for root-ca.key password so it can use it to sign istio.crt
    Please enter the password to encrypt the private key: password
    # This password is used to encrypt istio.key
    
    Your certificate has been saved in istio.crt.
    Your private key has been saved in istio.key.

    4. X.509 인증서를 만든다.

    root-ca.key와 istio.key 서명 키가 암호화돼도 괜찮다. 그러나 암호화를 해제하려면 httpbin.key와 bookinfo.key가 필요하다. 이는 --no-password와 --insecure CLI 플러그를 전달해 단계적으로 수행된다. 인증서의 기본 유효 기간은 24시간이지만 --not-after 플래그를 사용하고 유효성을 2,160시간(90일)으로 지정한다. 인증서 유효성이 만료되면 새 인증서를 만들고 시크릿을 업데이트해 인증서를 교체해야할 수 있다.

    $ step certificate create httpbin.istio.io httpbin.crt httpbin.key --profile leaf --ca istio.crt --ca-key istio.key --no-password --insecure --not-after 2160h
    Please enter the password to decrypt istio.key: password
    # Specify password used to create intermediate CA
    
    Your certificate has been saved in httpbin.crt.
    Your private key has been saved in httpbin.key.
    루트 및 중간 인증서는 암호를 사용해 생성되므로 암호가 있는 인증된 사용자만 리프(leaf) 인증서를 생성할 수 있다. no-password 플래그는 암호화되지 않은 리프 인증서를 만드는 데 사용된다.

    5. 스텝 CLI는 인증서를 검사 및 확인하고 인증서의 유효성이 90일 인지 확인하는데 사용할 수 있는 옵션을 제공한다.

    $ step certifiacte inspect httpbin.crt --short

    6. 다음 명령을 실행해 리프 인증서의 유효성을 확인한다. 리턴 코드는 0이어야 한다.

    $ step certifiacte veritfy httpbin.crt -roots istio.crt
    
    $ echo $?
    0

     

     

    RSA를 사용해 클라이언트 인증서와 키 생성

    $ step certificate create httpvin.istio.io client.crt client.key --profile leaf --ca istio.crt --ca-key istio.key --no-password --insecure --kty RSA --size 2048
    Please enter the password to decrypt istio.key: 
    Your certificate has been saved in client.crt.
    Your private key has been saved in client.key.
    
    
    ### root-ca와 중간 기관에서 인증서 체인을 만든다.
    $ step certificate bundle root-ca.crt istio.crt ca-chain.crt
    Your certificate has been saved in ca-chain.crt.

     

     

    'IT 발자취... > 리눅스' 카테고리의 다른 글

    kubernetes 관리용 CLI 설치 리스트  (0) 2022.09.06
    [리눅스] PAM이란?  (0) 2021.06.23
    [명령어] apt remove vs purge 차이  (0) 2018.12.13

    댓글

Designed by Gintire