assemble-certificates.sh
This script assembles certificates from various sources (environment variables or GitHub secrets) for use in the ComplianceAsCode Builder. It’s particularly useful in CI/CD environments where certificates may need to be split into smaller parts due to size limitations of secrets.
Location
/scripts/assemble-certificates.sh
Purpose
The primary purpose of this script is to:
- Assemble certificates from environment variables
- Handle both single certificates and multi-part certificates
- Verify certificate format (when requested)
- Create appropriate symlinks for compatibility across different workflows
Usage
./scripts/assemble-certificates.sh [OPTIONS]
Options
Option | Description |
---|---|
--output-dir DIR | Specify output directory (default: ./certs/org) |
--verify | Verify certificate format after assembly |
--test-mode | Enable test mode with more lenient verification |
--help | Show help information |
Environment Variables
The script recognizes the following environment variables:
Variable | Description |
---|---|
CA_BUNDLE | Complete certificate bundle (used if available) |
CA_BUNDLE_PART1 through CA_BUNDLE_PART9 | Certificate parts (used if CA_BUNDLE is not available) |
GITHUB_ACTIONS | Set by GitHub Actions, enables test mode |
ACT | Set by Act tool, enables test mode |
TEST_ENVIRONMENT | Can be set manually to enable test mode |
Examples
Basic Usage
./scripts/assemble-certificates.sh
With Verification
./scripts/assemble-certificates.sh --verify
Custom Output Directory
./scripts/assemble-certificates.sh --output-dir ./my-certs/
For Testing Environments
./scripts/assemble-certificates.sh --test-mode
Behavior
The script follows this process:
- Checks for a single certificate in the
CA_BUNDLE
environment variable - If not found, looks for certificate parts in
CA_BUNDLE_PART1
throughCA_BUNDLE_PART9
- Assembles the parts into a single certificate file
- Creates a symlink for compatibility with different workflows
- Optionally verifies the certificate format
Output
The script creates:
- A certificate file at the specified output directory (default:
./certs/org/ca-bundle.pem
) - A symlink named
organization-ca-bundle.pem
pointing to the certificate file
Certificate Verification
When the --verify
option is used, the script will:
- Check that the certificate file exists and has content
- Verify that the file contains a valid certificate format
- Use OpenSSL to validate the certificate (if available)
In test mode, verification is more lenient and will create a placeholder certificate if needed.