PKCS11によるAzureパイプラインの統合
前提条件
Azure DevOps のセットアップ
Azure DevOps上でJavaをサポートする OS を持つ任意のカスタムエージェント(セルフホスティング)。
エージェントにインストールされた JDK
DigiCert® Software Trust Manager Accessの設定(下記参照)
DigiCert® Software Trust Manager PKCS11ライブラリ (クライアントツール)
Client tools
DigiCert® KeyLocker clients can be downloaded as a package.
Download client tools
In the KeyLocker menu, go to Resources > Client tool repository.
Select your operating system, and then select the corresponding download (
) icon next to the desired client.
Create PKCS11 configuration file
To create a configuration file with the path to the shared library:
Open an integrated development environment (IDE) or plain text editor.
Copy and paste the following text into the editor:
Save the file as pkcs11properties.cfg.
Move the pkcs11properties.cfg file to the same location as the PKCS11 library.
Set PATH environment variables
Operating systems use the environment variable called PATH to determine where executable files are stored on your system. Use the PATH environment variable to store the file path to your signing tools to ensure that the CLI can reference these signing tools.
User authentication
KeyLocker enforces multi-factor authentication for security purposes. To access keypairs, certificates, and sign code, you need to set up two types of credentials: An API key and an authentication certificate.
Create an API key
The API key is an authentication method used to verify you as a user and your permissions assigned in DigiCert ONE. The API key provides the first factor authentication.
In DigiCert ONE, select the profile (
) icon, and then select Admin Profile.Under API keys, select Create API key.
For Name, enter a descriptive name for the key.
For End date (optional), enter the date when the key should expire.
Select Create. The API key appears this one time and can't be accessed again. Securely store the API key for future use.
Create an authentication certificate
The client authentication certificate is an authentication method used to verify you as a user and your permissions assigned in DigiCert ONE. The client authentication certificate provides the second factor authentication.
In DigiCert ONE, select the profile (
) icon, and then select Admin Profile.Under Client authentication certificates, select Create client authentication certificate.
For Nickname, enter a descriptive name for the key.
For End date, enter the date when the certificate should expire.
Select the desired Encryption and Signature hash algorithm.
Select Generate certificate. The password appears this one time and can't be accessed again. Download the certificate and securely store the password for future use.
DigiCert® Software Trust Managerのセットアップ
システム変数として設定することで、環境変数が永続的に残るようにしてください。
Variable | Description |
|---|---|
SM_API_KEY | Provide your API token. |
SM_CLIENT_CERT_FILE | Provide your client authentication certificate. |
SM_CLIENT_CERT_PASSWORD | Provide your client certificate password. |
SM_HOST | Provide your host environment. |
PKCS11_CONFIG | Provide the path to the PKCS#11 configuration file. |
SM_TLS_SKIP_VERIFY | Enter true to disable or false to enable TLS verification on the client side. |
Azure DevOpsパイプラインとの統合
パイプライン用の環境変数の設定
クライアントツールがDigiCert® Software Trust Managerと接続してサービスを提供するためには、これらの環境変数が必要です。これらはパイプラインの変数として統合され、Azureは自動的にエージェントの環境変数として注入することができますし、OS 環境レベルで設定することもできます。
variables: - name: SM_CLIENT_CERT_PASSWORD value: <client authentication certificate password> - name: SM_CLIENT_CERT_FILE value: <Path to client authentication certificate file> - name: SM_HOST value: <host url> - name: SM_API_KEY value: <API Token> - name: PKCS11_CONFIG value: <Path to pkcs11properties.cfg>
Sign
An example for an Azure DevOps pipeline step for signing a jar is:
- task: CmdLine@2
displayName: 'Sign Jar'
inputs:
script: 'jarsigner -keystore NONE -storepass NONE -storetype PKCS11 -sigalg SHA256withRSA -providerClass sun.security.pkcs11.SunPKCS11 -providerArg $PKCS11_CONFIG -signedJar <Output path for the signed jar> <Input path for jar to be signed> <certificate alias> -tsa http://timestamp.digicert.com'The input parameters for this example are the path where the signed jar needs to be output, the path to the jar that needs to be signed and the name/alias of the certificate that needs to be used for signing.
注記
PKCS11の設定ファイルは、パイプラインの環境に定義されていました。定義されていない場合は、設定ファイルへのパスで代用可能です。
Verification
An example of an Azure DevOps step that verifies a signed jar:
- task: CmdLine@2
displayName: 'Verify Signed Jar'
inputs:
script: 'jarsigner -verify <path to the signed jar>'このステップでの唯一の入力は、検証する必要がある署名付きjarへのパスです。この段階での入力は、検証が必要な署名付き jarのパスのみです。
サンプルパイプライン
trigger:
- main
pool:
name: 'default'
demands: agent.os -equals Linux
variables:
- name: SM_CLIENT_CERT_PASSWORD
value: gxmiK9Oe72Pn
- name: SM_CLIENT_CERT_FILE
value: "/home/john.doe/smtools/local_pkcs12.p12"
- name: SM_HOST
value: https://clientauth.one.digicert.com
- name: SM_API_KEY
value: 01ff018928e385329550b6e7a1_9b38fc5fbb4ef99ceeb7d61e6984107efa4283583cb7a64f5e292582cd3ed848
- name: PKCS11_CONFIG
value: "/home/john.doe/smtools/pkcs11properties.cfg"
- name: KEYPAIR_NAME
value: "azure-keypair-$(Build.BuildId)"
steps:
- task: Gradle@2
displayName: 'Build'
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
javaHomeOption: 'path'
jdkDirectory: '/usr/lib/jvm/java-11-openjdk-amd64'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
tasks: 'build'
- task: CmdLine@2
displayName: 'Sign Jar'
inputs:
script: 'jarsigner -keystore NONE -storepass NONE -storetype PKCS11 -sigalg SHA256withRSA -providerClass sun.security.pkcs11.SunPKCS11 -providerArg $PKCS11_CONFIG -signedJar $(System.DefaultWorkingDirectory)/app/build/libs/signed.jar $(System.DefaultWorkingDirectory)/app/build/libs/app.jar $KEYPAIR_NAME -tsa http://timestamp.digicert.com'
- task: PublishBuildArtifacts@1
displayName: 'Publish Unsigned Jar'
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/app/build/libs/app.jar'
ArtifactName: 'Unsigned Jar'
publishLocation: 'Container'
- task: PublishBuildArtifacts@1
displayName: 'Publish Signed Jar'
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/app/build/libs/signed.jar'
ArtifactName: 'Signed Jar'
publishLocation: 'Container'
- task: CmdLine@2
displayName: 'Verify Signed Jar'
inputs:
script: 'jarsigner -verify $(System.DefaultWorkingDirectory)/app/build/libs/signed.jar'