DevOps

🔁 Secrets Management in CI/CD: How to Stop Hardcoding Credentials

By Ateeq Y Tanoli, · 30 Apr 2026 · 3 min read · 492 words

Secrets Management in CI/CD: How to Stop Hardcoding Credentials

Hardcoding credentials in CI/CD pipelines is one of the most common — and most dangerous — security mistakes in modern software development. A single exposed API key in a GitHub Action YAML file can lead to a full infrastructure compromise. For robust secrets management, 1Password integrates directly with CI/CD pipelines to securely inject credentials without hardcoding them in your codebase.

The Scope of the Problem

Research shows that over 30% of organisations have accidentally committed credentials to source control. Automated scanners from GitHub, GitLab, and third-party services detect thousands of new credential leaks every day. The cost is severe: leaked AWS keys alone have been responsible for data breaches costing companies millions.

Why CI/CD Secrets Leak

CI/CD pipelines are especially vulnerable because they need credentials to:

The pressure to make pipelines work quickly leads developers to hardcode credentials directly in CI configuration files, environment variable stanzas, or deployment scripts.

Best Practice: Dedicated Secrets Managers

Every major CI/CD platform has a built-in secrets manager. Use them instead of environment variables in pipeline definitions.

GitHub Actions:

name: Deploy
on: [push]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to AWS
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        run: |
          aws s3 sync ./dist s3://my-bucket/

GitLab CI:

deploy:
  script:
    - aws s3 sync ./dist s3://my-bucket/
  variables:
    AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID  # Set in CI/CD Settings
    AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY  # Set in CI/CD Settings

CircleCI:

version: 2.1
jobs:
  deploy:
    docker:
      - image: cimg/python:3.11
    steps:
      - checkout
      - run: aws s3 sync ./dist s3://my-bucket/

All three platforms encrypt secrets at rest and mask them in logs automatically.

Preventing Secrets from Entering CI/CD

The best defence is preventing secrets from being committed in the first place. Use these tools:

  1. GitHub Secret Scanning — enabled by default for public repos, available for private repos
  2. GitLeaks — open-source tool that scans for secrets in git history
  3. TruffleHog — entropy-based scanner that finds high-entropy strings
  4. Pre-commit hooks — block commits containing potential secrets

Example pre-commit hook:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.18.0
    hooks:
      - id: gitleaks

Short-Lived Credentials

Where possible, avoid long-lived secrets altogether. Use:

Incident Response Plan

If a credential is leaked despite these precautions:

  1. Immediately revoke the compromised credential
  2. Rotate any credentials that shared the same permissions
  3. Audit logs for unauthorised access using the leaked credential
  4. Scan git history to ensure the credential is fully removed
  5. Post-mortem to understand how the leak happened and prevent recurrence

The shift from hardcoded secrets to proper secrets management is one of the highest-impact security improvements a development team can make. It requires upfront configuration but prevents the most expensive class of security incidents.

Generate a Free Strong Password →

More Password Security Tools

🔑 SecureKeyGen⚔️ TitanPasswords🛡️ Best Password Generator🔐 Free Strong Password⚡ Instant Password🗝️ Iron Vault Keys👨‍👩‍👧‍👦 Safe Pass Builder🛡️ Trusty Password⚙️ StrongPassFactory🔑 SecureKeyGen.org📚 TrustyPassword.org

Why Hardcoded Credentials Are a Ticking Time Bomb

Hardcoding credentials into your codebase is one of the most common and dangerous mistakes in modern software delivery. When an API key, database password, or cloud access token is written directly into a source file, configuration script, or CI/CD pipeline definition, it becomes a permanent liability. Once a secret lands in version control, it lives forever in the commit history—even if you delete it in a later commit. Anyone with repository access, including former employees, contractors, or attackers who breach your Git host, can extract it. Public repositories make this catastrophic: automated bots scan GitHub and other platforms continuously, harvesting exposed keys within minutes of a push.

The consequences range from inflated cloud bills caused by cryptocurrency miners to full data breaches and regulatory penalties. The root problem is that secrets are treated like ordinary code when they require fundamentally different handling.

The Principles of Proper Secrets Management

Effective secrets management rests on a few core ideas that should guide every decision you make in your pipeline:

Using Built-in CI/CD Secret Stores

Every major CI/CD platform offers a native mechanism for storing secrets securely. GitHub Actions provides encrypted secrets at the repository, environment, and organization levels. GitLab CI offers masked and protected variables. CircleCI, Jenkins, and Azure DevOps all have equivalent vaults. These tools encrypt values, hide them from build logs, and inject them as environment variables only when a job runs.

This is the minimum baseline. Instead of writing API_KEY=abc123 into your pipeline file, you reference ${{ secrets.API_KEY }} and store the actual value in the platform's secret manager. Masking ensures that even if a script accidentally prints the value, it appears as asterisks in the output. Protected variables restrict secrets to specific branches, preventing untrusted pull requests from accessing production credentials.

Dedicated Secrets Managers for Scale

As organizations grow, native CI/CD secrets become hard to manage across dozens of repositories and environments. Dedicated tools like HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, and Google Secret Manager centralize everything. They offer dynamic secret generation, automatic rotation, fine-grained access policies, and detailed audit logs.

Vault, for example, can generate a database credential on demand that automatically expires after the job completes. Your pipeline authenticates to Vault, retrieves a temporary secret, uses it, and the credential self-destructs. This dramatically shrinks the attack surface compared to a static password that lives for years.

Going Passwordless with OIDC

The most modern approach eliminates stored secrets entirely. OpenID Connect (OIDC) lets your CI/CD pipeline authenticate to cloud providers using short-lived, signed identity tokens instead of long-lived access keys. GitHub Actions and GitLab can both establish a trust relationship with AWS, Azure, or Google Cloud. When a job runs, it requests a token proving its identity, exchanges it for temporary cloud credentials, and discards them when finished. No secret is ever stored anywhere—there is nothing to leak.

Practical Steps to Stop Hardcoding

By treating secrets as first-class infrastructure rather than throwaway strings, you transform credential management from a liability into a controlled, auditable, and resilient part of your delivery pipeline.

We use cookies to improve your experience. Learn more

Store passwords with NordPass.