配置安全性 CLI Docker 映像
概觀
本主題說明如何配置在容器化環境中執行 ThingWorx 所需的安全性 CLI Docker 映像。
配置安全性 CLI Docker 映像
可以將下列選項新增至檔案的 environment 區段,來控制每個容器的組態。
變數名稱
預設值
註解
KEYSTORE
未設定預設值
設定為 true 可使用 KeyStore 環境變數建立組態檔案。
KEYSTORE_PASSWORD_FILE_PATH
未設定預設值
設定 KeyStore 密碼的路徑。必須設定此內容。
KEYSTORE_PASSWORD_FILE_NAME
未設定預設值
設定 KeyStore 密碼檔案的名稱。
KEYSTORE_FILE_PATH
未設定預設值
設定 KeyStore 檔案的路徑。必須設定此內容。
KEYSTORE_FILE_NAME
未設定預設值
設定 KeyStore 檔案名稱。
DEFAULT_ENCRYPTION_KEY_LENGTH
265 個位元組
設定建立新加密金鑰時使用的預設金鑰長度。此值會影響現有金鑰的大小。
初始化密碼
密碼會使用環境變數傳遞至工具。您可以使用下列兩種方法之一來初始化密碼:
選項 A 
處理以文字 SECRET_ 開頭的所有環境變數。有效的環境變數名稱包括 SECRET_MYSECRETSECRET_SECRET1SECRET_SPECIAL_SECRET_VALUE
環境變數的 <prefix> (例如 SECRET_MYSECRET 中的 SECRET_) 會被抽出並轉換成小寫以供作為金鑰使用。例如,針對 SECRET_MYSECRET 環境變數,mysecret 就是金鑰。環境變數值是要設定的密碼值。
選項 B 
會處理名為 CUSTOM_SECRET_LIST 且值中有 secretKey-envVarName 配對之逗號分隔清單的環境變數。逗號分隔值會權杖化,對於每個 secretKey-envVarName 權杖,會將由 envVarName 表示的環境變數讀入 secretValue 變數中。此 secretKey-secretValue 配對在金鑰庫中設定。
CUSTOM_SECRET_LIST 環境變數的範例值:* mysecretkey1:<具有此金鑰值的環境變數>,mysecretkey2:<具有此金鑰值的環境變數>
金鑰庫的範例構成
以下範例建立了共用的儲存磁碟區。在容器中,它對應至 SecureData,其中配置了金鑰庫與金鑰庫密碼檔案的位置。容器會啟動,並建立或更新金鑰庫值。填入所有值後,容器會結束。
docker-compose.yml
version: '2.3'
volumes:
storage:
services:
secrets:
image: artifactory.rd2.thingworx.io/twxdevops/security-cli:latest
environment:
- "KEYSTORE=true"
- "KEYSTORE_PASSWORD_FILE_PATH=/SecureData"
- "KEYSTORE_FILE_PATH=/SecureData"
- "SECRET_MYSECRET=zyfdzhij"
- "SECRET_SECRET1=mydata1"
- "SECRET_MY_SECRET2=mydata2"
- "SECRET_SPECIAL_SECRET_VALUE=mydata3"
- "TWX_DATABASE_PASSWORD=abcd"
- "LS_PASSWORD=efgh"
- "CUSTOM_SECRET_LIST=encrypt.db.password:TWX_DATABASE_PASSWORD,encrypt.licensing.password:LS_PASSWORD"
volumes:
- storage:/SecureData
欲使用上述檔案,請執行 docker compose up secrets,其會產生下列輸出:
secrets_1 | Running command with config:
secrets_1 | Config(SimpleConfigObject({"output-file":"/opt/cli.conf","sources":{"scripts":[]},"template-file":"/opt/cli.conf.j2","type":"process-template"}))
secrets_1 | Loading config from file /opt/cli.conf
secrets_1 | mysecret stored
secrets_1 | Loading config from file /opt/cli.conf
secrets_1 | secret1 stored
secrets_1 | Loading config from file /opt/cli.conf
secrets_1 | my_secret2 stored
secrets_1 | Loading config from file /opt/cli.conf
secrets_1 | special_secret_value stored
secrets_1 | Loading config from file /opt/cli.conf
secrets_1 | encrypt.db.password stored
secrets_1 | Loading config from file /opt/cli.conf
secrets_1 | encrypt.licensing.password stored
secrets_1 | security-common-cli-docker_secrets_1 exited with code 0
這是否有幫助?