Configuring a client certificate for certificate-based authentication
To configure a client certificate in Azure DevOps
- Import your client certificate into Azure DevOps:
- On the Azure DevOps dashboard, click Pipelines to expand it.
- Click Library.
- On the Secure files tab, click + Secure file.
- In the Upload file dialog box, drag and drop the client certificate file, or click Browse to select a client certificate file and click OK.
- Define a variable for the client certificate password:
- On the Azure DevOps dashboard, click Pipelines to expand it.
- Click Library.
- Select your Variable group from the list, and click +Add.
- Enter the name for the password variable, that is, CERT_PASS. Use all caps to distinguish from actual value in the config YAML file.
- Enter the value for the password, and select the lock icon to change this variable type to secret.
- Click Save.
- Edit the config YAML file in the authentication step:
- For authenticationType, enter certBased.
For certificatePath and certificatePassword, enter the variable names that you created in step
- Save the config YAML file.
- Edit the pipeline YAML file to use your client certificate:
- Add the task, enter DownloadSecureFile@1.
- Enter a value for the displayName enclosed in single quotation marks.
For the secureFile, enter the name of the PKCS #12 client certificate name (enclosed in single quotation marks) used to run the pipeline:
Add the Linux sed commands to replace the variable values for the new certificate variables:
- Save the pipeline.
To configure a client certificate in GitHub Actions
There are several methods to add a client certificate for GitHub Actions. We suggest the following procedures for using a password-protected zip file for your client certificate with certificate-based authentication:
Create a password-protected client certificate zip file in your Linux VM by running the following zip command:
zip -P <password> <target-file> <source-file>Replace the variables with a zip file password, target zip file name, and PKCS #12 client certificate source file name.
- Upload the zipped client certificate to your GitHub repository:
- On the GitHub repository Code tab, navigate to your designated directory to upload the zipped client certificate
- Click Add file > Upload files.
- On the Upload page, drag and drop the zipped client certificate, or click choose your files to select the zipped client certificate and click Commit changes.
- Define your repository secret and variables for the client certificate:
- On the GitHub repository Settings tab, to expand the list, click Secrets and variables.
- Click Actions.
Define the secret password for the zipped client certificate in the Secrets tab, and click New repository secret.
- Enter the secret name for the password for the zipped client certificate, that is, ZIP_CERT_PASS
- Enter the secret value for the zipped client certificate password.
- Click Add secret.
- Define the secret password for the client certificate in the Secrets tab, and click New repository secret.
- Enter the secret name for the client certificate password, that is, CERT_PASS_AUTH.
- Enter the secret value for the client certificate password.
- Click Add secret.
- Define the repository variable for the client certificate path in the Variables tab, and select New repository variable.
- Enter the variable name for the client certificate path, that is, CERT_PATH.
- Enter the variable value for the client certificate path.
- Click Add variable.
- Edit the config YAML file in the Authentication step:
- For authenticationType, enter certBased.
For certificatePath and certificatePassword, enter the values that you entered in step 3.
- Save the config YAML file.
Edit the workflow YAML file as follows:
Insert the unzip step below to unzip the password-protected client certificate after the repository checkout step:
- Specify your password for the zipped client certificate and the directory path where the unzipped client certificate will reside.
- (Optional) Specify the -d unzipPath (for example, -d /opt/secret) so that the client certificate is removed after the workflow is complete . If you do not specify -d unzipPath , the client certificate is saved to the default workspace, but it is not deleted at the end of the workflow run.
- name: unzip client certificate
run: |
unzip -P "${{secrets.zip_cert_pass}}" <zipClientCertName>.zip -d <unzipPath>Define the Linux sed command to replace the client certificate variable and secret client certificate password defined in GitHub Actions:
# sed -i "s|CERT_PATH_AUTH|/opt/secret/<clientCertificateName>.p12|" Test_config.yml
# sed -i "s/CERT_PASS_AUTH/${{secrets.cert_pass}}/" Test_config.yml- Save the workflow YAML file.
Variable
Description
zip_cert_pass
Secret variable defined with the password for the zipped client certificate
zipClientCertName
Name of the zipped client certificate
unzipPath
Directory path for the unzipped client certificate
CERT_PATH_AUTH
Variable for the directory path and client certificate file
clientCertificateName
PKCS #12 client certificate used to run pipeline or workflow
BMC AMI SQL Assurance supports PKCS #12 client certificate with DER encoded in binary format only
CERT_PASS_AUTH
Secret password for the client certificate
To configure a client certificate in GitLab CI/CD
There are several methods to add a client certificate to GitLab CI/CD. We suggest the following procedures for using a password-protected zip file for your client certificate with certificate-based authentication:
Create a password-protected client certificate zip file in your Linux VM by running the following zip command:
zip -P <password> <target-file> <source-file>Replace the variables with a zip file password, target zip file name, and PKCS #12 client certificate source file name.
- Upload the zipped client certificate to your GitLab Project repository:
- From the GitLab Project Code menu, select Repository.
- Select your branch to upload the zipped client certificate.
- Click
, and then select Upload file.
- On the Upload new file page, drag or click the upload link to select the zipped client certificate.
- Keep the default commit message or enter a message of your choice.
- Specify the target branch where the zipped client certificate should reside.
- Click Upload file.
- Define your repository variables for the client certificate:
- From the GitLab Project Settings menu, select CI/CD.
- Expand Variables.
- Click Add variable to define the following variables:
Zipped client certificate password:
- Type: Variable (default)
- Environment: All (default)
- Visibility: Masked & Hidden
- Flags: None
- Description: Specify as desired.
- Key: ZIP_CERT_PASS
- Value: Enter the variable value for the zipped client certificate password.
- Click Add variable.
- Client certificate password:
- Type: Variable (default)
- Environment: All (default)
- Visibility: Masked & Hidden
- Flags: Expand variable reference
- Description: Specify as desired.
- Key: CERT_PASS_AUTH
- Value: Enter the value for the client certificate password.
- Click Add variable.
- Client certificate path:
- Type: Variable (default)
- Environment: All (default)
- Visibility: Visible
- Flags: Expand variable reference
- Description: Specify as desired.
- Key: CERT_PATH_AUTH
- Value: Enter the directory path and client certificate file name where the client certificate will reside.
- Click Add variable.
- Edit the config YAML file in the Authentication step:
- For authenticationType, enter certBased.
For certificatePath and certificatePassword, enter the variables that you defined in step 3.
authenticationType: certBased
certificatePath: CERT_PATH_AUTH
certificatePassword: CERT_PASS_AUTH- Save the config YAML file.
- Edit the pipeline YAML file as follows:
Insert the following unzip step, to unzip the password-protected client certificate at the start of the job’s script:
- Specify your password for the zipped client certificate and the directory path where the unzipped client certificate will reside.
(Optional) Specify the -d unzipPath (for example, -d /opt/secret) so that the client certificate is removed after the pipeline is complete. If you do not specify -d unzipPath, the client certificate is saved to the default workspace, but it is not deleted at the end of the pipeline run.
- echo “Unzip client certificate”
- unzip -P "$<zip_cert_pass>” <zipClientCertName>.zip -d <unzipPath>
Define the Linux sed command to replace the client certificate and client certificate password variables defined in GitLab CI/CD:
- sed -i "s|CERT_PATH_AUTH|$CERT_PATH_AUTH|" Test_config.yml
- sed -i "s/CERT_PASS_AUTH/$CERT_PASS_AUTH/" Test_config.yml- Save the pipeline YAML file.
Variable | Description |
---|---|
zip_cert_pass | Variable defined with the password for the zipped client certificate |
zipClientCertName | Name of the zipped client certificate |
unzipPath | Directory path for the unzipped client certificate |
CERT_PATH_AUTH | Variable for the directory path and client certificate file |
clientCertificateName | PKCS #12 client certificate used to run pipeline or workflow BMC AMI SQL Assurance supports PKCS #12 client certificate with DER encoded in binary format only. |
CERT_PASS_AUTH | Variable for the client certificate password |