建置 Registry

  1. podman 可搜尋下載可用的 images 做為容器,本節為建置一個 image registry server,提供 podman 下載 image 用,不是考試的範圍。
  2. registry 儲存目錄 /opt/registry,先在此目錄下建立 auth, certs, data 三個次目錄,auth 儲存認證用 htpasswd 檔,certs 儲存認證憑證,data 儲存 images。
    [root@registry ~]# mkdir -p /opt/registry/{auth,certs,data}
    
  3. 使用 htpasswd 工具產生存取 registry 所需,含用戶帳密的證書,本範例帳號為 admin,密碼為 xxxxxx。
    1. 選項 b:由命令列提供密碼。
    2. 選項 B:使用 bcrypt 加密密碼。
    3. 選項 c:產生檔案。
    [root@registry ~]# htpasswd -bBc /opt/registry/auth/htpasswd admin xxxxxx
    Adding password for user admin
    
  4. 產生 TLS 金鑰對,其中 CN 要設定為 registry host 的主機名稱。
    [root@registry ~]# openssl req -newkey rsa:4096 -nodes -sha256 \
    -keyout /opt/registry/certs/domain.key -x509 -days 100 \
    -out /opt/registry/certs/domain.crt  \
    -subj '/C=TW/ST=Taiwan/L=CYUT/O=CSIE/CN=registry.csie.cyut.edu.tw'
    Generating a RSA private key
    ....++++
    .....++++
    writing new private key to '/opt/registry/certs/domain.key'
    -----
    
  5. 因為是使用 https 連線,client 必須有證書才能連線,本例 registry host 也當 client 做測試,所以將證書複製到證書存放目錄。
    [root@registry ~]# cp /opt/registry/certs/domain.crt /etc/pki/ca-trust/source/anchors/
    
  6. 更新信任憑證清單。
    [root@registry ~]# update-ca-trust
    
  7. 查詢信任憑證清單,registry.csie.cyut.edu.tw 已出現在清單中。
    [root@registry ~]# trust list | grep csie.cyut
        label: registry.csie.cyut.edu.tw