Share via


Azure Stack Hub 또는 Azure Stack Development Kit에서 Azure CLI에 대한 인증서 설정

이 문서의 단계에 따라 Linux, Mac 및 Windows 클라이언트 플랫폼에서 ASDK(Azure Stack Development Kit) 리소스를 관리하도록 Azure CLI(Command-Line 인터페이스)를 설정합니다. 연결이 끊긴 환경에서 통합 시스템 Azure Stack Hub를 사용하거나 신뢰할 수 있는 루트 프로그램의 CA에서 인증서를 발급하지 않은 경우에도 다음 단계를 수행할 수 있습니다.

이 문서에서는 인증서를 가져오고 원격 관리 컴퓨터에서 인증서를 신뢰하는 것에 대해 설명합니다. Azure CLI를 설치하고 환경에 연결하려면 Azure Stack Hub에 Azure CLI 설치를 참조하세요.

Azure CLI 준비

개발 머신에서 Azure CLI를 사용하려면 Azure Stack Hub에 대한 CA 루트 인증서가 필요합니다. 인증서를 사용하여 CLI를 통해 리소스를 관리합니다.

  • Azure Stack Hub 환경 외부의 워크스테이션에서 CLI를 사용하는 경우 Azure Stack Hub CA 루트 인증서가 필요합니다.

  • 가상 머신 별칭 엔드포인트는 "UbuntuLTS" 또는 "Win2012Datacenter"와 같은 별칭을 제공합니다. 이 별칭은 VM을 배포할 때 이미지 게시자, 제품, SKU 및 버전을 단일 매개 변수로 참조합니다.

다음 섹션에서는 이러한 값을 가져오는 방법을 설명합니다.

Azure Stack Hub CA 루트 인증서 내보내기

CA 루트 인증서를 내보냅니다. ASDK 루트 인증서를 PEM 형식으로 내보내려면 다음을 수행합니다.

  1. Azure Stack Hub 루트 인증서의 이름을 가져옵니다.

    1. Azure Stack Hub 사용자 또는 Azure Stack Hub 관리자 포털에 로그인합니다.
    2. 브라우저 주소 표시줄에서 잠금을 선택합니다.
    3. 팝업 창에서 연결이 안전합니다를 선택합니다.
    4. 인증서 창에서 인증 경로 탭을 선택합니다.
    5. 예를 들어 Azure Stack Hub 루트 인증서의 이름을 적어둡니다. *.<locale>.<FQDN>

    Azure Stack Hub 루트 인증서

  2. Azure Stack Hub에서 Windows VM을 만듭니다.

  3. VM에 로그인하고 관리자 권한 PowerShell 프롬프트를 연 다음, 다음 스크립트를 실행합니다.

      $label = "*.<locale>.<FQDN> from step 1"
      Write-Host "Getting certificate from the current user trusted store with subject CN=$label"
      $root = Get-ChildItem Cert:\CurrentUser\Root | Where-Object Subject -eq "CN=$label" | select -First 1
      if (-not $root)
      {
          Write-Error "Certificate with subject CN=$label not found"
          return
      }
    
    Write-Host "Exporting certificate"
    Export-Certificate -Type CERT -FilePath root.cer -Cert $root
    
  4. Linux의 경우 다음 명령도 필요합니다.

    export REQUESTS_CA_BUNDLE=~/.local/lib/python3.9/site-packages/certifi/cacert.pem
    # RECOMMENDED: set the env var automatically for your subsequent sessions
    echo 'export REQUESTS_CA_BUNDLE=~/.local/lib/python3.9/site-packages/certifi/cacert.pem' >> ~/.bash_profile
    
  5. 인증서를 로컬 컴퓨터에 복사합니다.

가상 머신 별칭 엔드포인트 설정

VM 별칭 파일을 호스트하는 공개적으로 액세스할 수 있는 엔드포인트를 설정할 수 있습니다. VM 별칭 파일은 이미지의 일반 이름을 제공하는 JSON 파일입니다. VM을 Azure CLI 매개 변수로 배포할 때 이름을 사용합니다.

  1. 사용자 지정 이미지를 게시하는 경우 게시하는 동안 지정한 게시자, 제품, SKU 및 버전 정보를 기록해 둡다. 마켓플레이스의 이미지인 경우 cmdlet을 사용하여 Get-AzureVMImage 정보를 볼 수 있습니다.

  2. GitHub에서 샘플 파일을 다운로드합니다.

  3. Azure Stack Hub에서 스토리지 계정을 만듭니다. 완료되면 Blob 컨테이너를 만듭니다. 액세스 정책을 "public"으로 설정합니다.

  4. JSON 파일을 새 컨테이너에 업로드합니다. 이 작업이 완료되면 Blob의 URL을 볼 수 있습니다. Blob 이름을 선택한 다음, Blob 속성에서 URL을 선택합니다.

인증서 신뢰

ASDK와 함께 Azure CLI를 사용하려면 원격 컴퓨터에서 CA 루트 인증서를 신뢰해야 합니다.

  1. 컴퓨터에서 인증서 위치를 찾습니다. 위치는 Python을 설치한 위치에 따라 달라질 수 있습니다.

  2. 위치를 찾으려면 CMD 프롬프트 또는 관리자 권한 PowerShell 프롬프트를 열고 를 az --version입력합니다. 버전 및 python 위치가 프롬프트에 나타납니다.

    azure-cli                         2.30.0
    
    core                              2.30.0
    telemetry                          1.0.6
    
    Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
    Extensions directory 'C:\Users\username\.azure\cliextensions'
    
    Python (Windows) 3.8.9 (tags/v3.8.9:a743f81, Apr  6 2021, 13:22:56) [MSC v.1928 32 bit (Intel)]
    
    Legal docs and information: aka.ms/AzureCliLegal
    
    Your CLI is up-to-date.
    
    Please let us know how we are doing: https://aka.ms/azureclihats
    and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy
    
  3. Azure CLI에서 Python을 설치한 디렉터리로 변경합니다. 예를 들어 2 cd "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\단계의 위치를 사용합니다.

  4. 다음 명령을 입력합니다.

    .\python -c "import certifi; print(certifi.where())"
    

    그러면 컴퓨터에서 인증서 위치의 경로가 반환됩니다. 특정 경로는 OS 및 설치한 Python 버전에 따라 달라집니다. 예를 들면 다음과 같습니다.

    C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\certifi\cacert.pem
    

    인증서 위치를 기록해 둡다. 다음 단계에서 경로를 사용합니다.

  5. 기존 Python 인증서에 추가하여 Azure Stack Hub CA 루트 인증서를 신뢰합니다.

    $cerFile = "<Fully qualified path to the cer certificate exported from `
    your Azure Stack Hub and saved. For example: C:\Users\user1\Downloads\root.cer"
    $pythonCertStore = <result from step 4>
    
    $cerDir = Split-Path -Parent $cerFile
    $pemFile = "$cerDir\root.pem"
    Write-Host "Converting certificate to PEM format at $pemFile"
    certutil -encode $cerFile $pemFile
    $root = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
    $root.Import($pemFile)
    
    # X509Certificate2.Thumbprint calculates SHA1 hash of the public key. You can get sha1 of the pem file by using openssl, 
    # e.g. openssl x509 -noout -fingerprint -sha1 -inform pem -in ./root.pem
    # Alternatively, 'Get-FileHash' gives the same value (without ':') for the corresponding cer file
    # Since the thumbprint is a unique value for the certificate, it is commonly used to find a particular certificate in a certificate store
    Write-Host "Extracting required information from the cert file"
    $md5Hash    = (Get-FileHash -Path $cerFile -Algorithm MD5).Hash.ToLower()
    $sha1Hash   = (Get-FileHash -Path $cerFile -Algorithm SHA1).Hash.ToLower()
    $sha256Hash = (Get-FileHash -Path $cerFile -Algorithm SHA256).Hash.ToLower()
    
    $issuerEntry  = [string]::Format("# Issuer: {0}", $root.Issuer)
    $subjectEntry = [string]::Format("# Subject: {0}", $root.Subject)
    $labelEntry   = [string]::Format("# Label: {0}", $root.Subject.Split('=')[-1])
    $serialEntry  = [string]::Format("# Serial: {0}", $root.GetSerialNumberString().ToLower())
    $md5Entry     = [string]::Format("# MD5 Fingerprint: {0}", $md5Hash)
    $sha1Entry    = [string]::Format("# SHA1 Fingerprint: {0}", $sha1Hash)
    $sha256Entry  = [string]::Format("# SHA256 Fingerprint: {0}", $sha256Hash)
    $certText = (Get-Content -Path $pemFile -Raw).ToString().Replace("`r`n","`n")
    
    $rootCertEntry = "`n" + $issuerEntry + "`n" + $subjectEntry + "`n" + $labelEntry + "`n" + `
    $serialEntry + "`n" + $md5Entry + "`n" + $sha1Entry + "`n" + $sha256Entry + "`n" + $certText
    
    Write-Host "Adding the certificate content to Python Cert store"
    Add-Content $pythonCertStore $rootCertEntry
    
    Write-Host "Python Cert store was updated to allow the Azure Stack Hub CA root certificate"
    

Azure CLI를 설치하고 연결하는 방법에 대한 지침은 Azure Stack Hub에 Azure CLI 설치를 참조하세요.

다음 단계

Azure Stack Hub에 Azure CLI 설치