|
| 1 | +# CI/CD Integration |
| 2 | + |
| 3 | +How to get Infisical secrets into CI/CD pipelines. The recommended approach depends on the platform. |
| 4 | + |
| 5 | +## GitHub Actions (OIDC — recommended) |
| 6 | + |
| 7 | +Zero-secret integration using GitHub's built-in OIDC tokens. No stored secrets needed in GitHub. |
| 8 | + |
| 9 | +### Step 1: Create a machine identity with OIDC auth |
| 10 | + |
| 11 | +In the Infisical dashboard: |
| 12 | +1. Go to Organization Settings > Access Control > Machine Identities |
| 13 | +2. Create an identity and assign a role |
| 14 | +3. Add OIDC Auth with these settings: |
| 15 | + - **OIDC Discovery URL**: `https://token.actions.githubusercontent.com` |
| 16 | + - **Issuer**: `https://token.actions.githubusercontent.com` |
| 17 | + - **Subject**: `repo:<owner>/<repo>:<context>` (e.g., `repo:acme/api:ref:refs/heads/main`) |
| 18 | + - **Audiences**: Your GitHub org URL (e.g., `https://github.com/acme`) |
| 19 | +4. Add the identity to your project with appropriate permissions |
| 20 | + |
| 21 | +### Step 2: Configure the workflow |
| 22 | + |
| 23 | +```yaml |
| 24 | +name: Deploy |
| 25 | + |
| 26 | +permissions: |
| 27 | + id-token: write # Required for OIDC |
| 28 | + contents: read |
| 29 | + |
| 30 | +jobs: |
| 31 | + deploy: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Fetch secrets from Infisical |
| 37 | + uses: Infisical/secrets-action@v1.0.9 |
| 38 | + with: |
| 39 | + method: "oidc" |
| 40 | + identity-id: "<your-identity-id>" |
| 41 | + project-slug: "your-project" |
| 42 | + env-slug: "prod" |
| 43 | + |
| 44 | + - name: Use secrets |
| 45 | + run: | |
| 46 | + echo "Secrets are now available as env vars" |
| 47 | + # e.g., $DATABASE_URL, $API_KEY |
| 48 | +``` |
| 49 | +
|
| 50 | +**Key parameters for the action:** |
| 51 | +- `method`: `"oidc"` for OIDC auth |
| 52 | +- `identity-id`: The machine identity ID (public, safe to commit) |
| 53 | +- `project-slug`: Your Infisical project slug |
| 54 | +- `env-slug`: Environment (dev, staging, prod) |
| 55 | + |
| 56 | +### Troubleshooting GitHub Actions OIDC |
| 57 | + |
| 58 | +- Ensure `id-token: write` permission is set |
| 59 | +- Subject must exactly match the repo and context (branch, tag, or environment) |
| 60 | +- Audience must match the GitHub org URL |
| 61 | +- Project and environment slugs must match what's configured in Infisical |
| 62 | + |
| 63 | +## GitLab CI |
| 64 | + |
| 65 | +### Option 1: CLI with machine identity token |
| 66 | + |
| 67 | +```yaml |
| 68 | +image: ubuntu |
| 69 | +
|
| 70 | +stages: |
| 71 | + - build |
| 72 | +
|
| 73 | +build: |
| 74 | + stage: build |
| 75 | + script: |
| 76 | + - apt update && apt install -y curl bash |
| 77 | + - curl -1sLf 'https://artifacts-cli.infisical.com/setup.deb.sh' | bash |
| 78 | + - apt-get install -y infisical |
| 79 | + - export INFISICAL_TOKEN=$(infisical login --method=universal-auth |
| 80 | + --client-id=$INFISICAL_CLIENT_ID |
| 81 | + --client-secret=$INFISICAL_CLIENT_SECRET |
| 82 | + --plain --silent) |
| 83 | + - infisical run --projectId=$INFISICAL_PROJECT_ID --env=prod -- npm run build |
| 84 | +``` |
| 85 | + |
| 86 | +Store `INFISICAL_CLIENT_ID` and `INFISICAL_CLIENT_SECRET` as GitLab CI/CD variables (Settings > CI/CD > Variables). |
| 87 | + |
| 88 | +### Option 2: OIDC auth (if GitLab supports it for your setup) |
| 89 | + |
| 90 | +GitLab CI can issue OIDC tokens via `CI_JOB_JWT` or `id_tokens`. Configure similarly to GitHub Actions — create a machine identity with OIDC auth, set the issuer to your GitLab instance, and use the JWT to authenticate. |
| 91 | + |
| 92 | +## Other CI/CD platforms |
| 93 | + |
| 94 | +For any CI platform, the pattern is: |
| 95 | + |
| 96 | +1. **Create a machine identity** with an appropriate auth method |
| 97 | +2. **Install the CLI** in the pipeline |
| 98 | +3. **Authenticate**: `infisical login --method=universal-auth --client-id=... --client-secret=... --plain --silent` |
| 99 | +4. **Inject secrets**: `infisical run -- <your-build-command>` |
| 100 | + |
| 101 | +If the CI platform supports OIDC (e.g., CircleCI, Bitbucket), prefer OIDC Auth for zero-secret integration. Otherwise, use Universal Auth with Client ID/Secret stored as CI variables. |
| 102 | + |
| 103 | +## Secret syncs (alternative approach) |
| 104 | + |
| 105 | +Instead of fetching secrets at build time, Infisical can sync secrets directly into your CI/CD platform's native secret store (e.g., GitLab CI/CD Variables). This is a one-way push configured in the Infisical dashboard. Useful if you don't want to install the CLI in your pipeline, but less flexible than runtime injection. |
| 106 | + |
| 107 | +## Security best practices for CI/CD |
| 108 | + |
| 109 | +- **Prefer OIDC over stored credentials** when possible — no secrets to rotate or leak |
| 110 | +- **Scope machine identities tightly** — give each pipeline its own identity with minimum permissions |
| 111 | +- **Use environment-specific identities** — don't let a staging pipeline access production secrets |
| 112 | +- **Pin CLI version** in CI to avoid surprises from upstream updates |
0 commit comments