Setting Up Secrets Management in a CI/CD Pipeline

Keys and passwords for services often sit in plain sight — and you only find out after an incident. We set up secrets management in the build pipeline end to end: we separate access, introduce automatic rotation, and hand over ready-to-use policies to the team. This removes manual operations and cuts leak risk many times over.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1365
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

Secret Management in the Build Pipeline: Where Leaks Happen

A secret lives in the pipeline longer than in production: an artifact publication token, an image registry access key, credentials for database migrations.

As long as secret management boils down to a variables file in the repository, every person who can run a build or fork the project gets plaintext access.

Leaks happen not during a breach, but in routine.

A key inserted directly into a step command settles in build logs and remains there even after the job is deleted; project-level environment variables are inherited by all steps, including third-party checks; the dependency cache preserves configurations with tokens between runs.

Organization-level secrets are a separate story: they are visible to all linked repositories, and key leaks surface only through anomalous calls to an external service. Rotating such a key means edits in dozens of places, stopping delivery, and fully rebuilding artifacts.

This is closed not by prohibitions but by a change of model: secrets are stored outside the repository, issued to a step for its execution time, masked in output, separated by environment, and logged on every access. Let's break down how this works in the build pipeline and what changes at each stage.

What Changes After Putting Access in Order

While keys sit in build variables and chat, the leak window is measured by the key's lifetime, not by reaction time.

Manual credential rotation turns into a separate project: the value is changed rarely because each cycle is a request, approval, and synchronized release of all services.

After moving to secret management, key lifetime drops to hours, and rotation happens without stopping the build loop.

Manual key issuance is the most expensive area. The value is copied into chat, it settles in history and local files, and no one knows how many copies exist.

A role model in the vault replaces this: a service gets a secret by its role, not by the presence of a file, and revoking the role closes access immediately across all environments.

Vaults like Vault separate the secret from code: configuration references a path, and the value is injected at startup. Therefore, change delivery time drops to minutes—an edit in the vault does not require code changes, review, or a new release. Rotation stops being an event and becomes a background process.

A separate effect is traceability. Every secret read goes into a journal with role and time, so during incident analysis it is clear which keys were available and when they were revoked.

Both the leak window and change delivery time stop being an "eyeball" estimate—both parameters are visible in metrics.

Options for Storing Credentials: Comparison and Limitations

Choosing a credential store is not about interface convenience, but about the threat model: who gets the secret, for how long, and what remains in the logs. Key encryption is solved separately—where the master key lives and who has the right to use it. And the third question: can access be revoked granularly without immediately reissuing all keys.

External secret references make it possible not to copy the value into the pipeline, but to inject it at execution time—only the secret name remains in artifacts and logs.

The difference between static and dynamic access is more important than the choice of vault itself: dynamic credentials live for the duration of one job and are revoked automatically. Below are the options and their limitations.

Option When it fits Limitations
Environment variables in the built-in CI secret store One environment, few services, credentials change rarely All pipeline steps see the value, there is no issuance log or versioning, rotation is manual
Encrypted files in the repository Infrastructure is described as code, reproducibility is needed The key lives separately, and edit history preserves old values
External secret manager with external secret references Multiple environments and teams, access audit is needed The pipeline needs an authorization method, and if the vault is unavailable the build stops
Dynamic credentials for the duration of a job Critical environments, frequent releases Integration with a secret manager is needed, plus a fallback path if issuance fails

An option that has no clear answer about revocation and rotation should not be taken even for a test environment—there is almost always a path from there to production.

Stages of Implementing Secret Management in the Pipeline

Order matters more than speed here: if you move secrets into a vault without knowing the full usage map, half of the builds fail on the first run. We proceed sequentially—from key inventory to the policies by which the pipeline is maintained further.

  1. Key inventory. We go through repositories, build configurations, variables on build agents, and commit history. The output is a map "secret → owner → jobs and environments that read it".
  2. Environment separation. Each environment has its own set of credentials and its own access level: builds from development branches physically cannot see production values. We keep variable names to avoid rewriting configs.
  3. Vault connection. Secrets move from variables and files into a vault with versioning. A job gets not the key itself, but a short-lived token for its role—a stolen build artifact is useless.
  4. Access policies. Issuance to a service account, not to a person, according to the minimum necessary scope. Rotation on schedule and on event, every read in the audit with job linkage.
  5. Pipeline migration. Configs keep a reference to the secret, not the value. Then a mandatory run and a check of the reverse scenario: access was revoked—the build fails with a clear error, not with an empty variable.
  6. Leak detection. Search for key patterns in the pre-commit hook and in the build itself, including history. Everything found is considered compromised and is changed before switching the pipeline.
  7. Handover of policies. Owners, rotation procedure, environment separation scheme, actions when a leak is suspected. Checks become a mandatory build step—the mode is maintained without manual control.

What We Hand Over: Configurations, Policies, Procedures

Handing over a secret management loop is not an archive with passwords, but a working system that your team can maintain and develop without us.

Therefore, the full set of artifacts is handed over: from access issuance configurations to the procedures by which an on-call engineer acts at night without hints. Below is the complete list of what is documented and verified on a live test bench before acceptance.

  • Secret issuance scheme — which services and build loops request what, where the root of trust is stored, how the secret gets into the process, and why it does not remain in environment variables and logs.
  • Policies and roles — a "role → allowed operations with the secret" matrix, separation of read, write, and administration rights, the principle of least privilege for people and service accounts.
  • Access issuance configurations — working vault connection files, templates for new services, and secret mounting rules, so adding the next application does not require rewriting the scheme.
  • Rotation procedure — frequency of change by secret type, owner of each secret, forced rotation procedure during a leak, and behavior of services that did not manage to reread the new value.
  • Revocation and rollback procedure — how to close compromised access in minutes, revoke an account, and return the previous secret version if rotation broke the release.
  • Access documentation — who, on what basis, and for how long received access, how to submit a request, how to pass verification, and how to correctly close access when an employee leaves.
  • Audit and alerts — a log of secret accesses, alert rules for anomalous activity, and a clear procedure for investigating a trigger.
  • On-call shift memo — step-by-step scenarios for typical situations: the secret was not picked up, the build loop failed at the deployment stage, suspected leak.

We go through each item together with your team: the engineer reproduces rotation and revocation on a test loop and makes sure the documentation matches the actual system behavior.

Such a run reveals discrepancies immediately, not at the moment of an incident—and after it, the loop remains manageable by your specialists.

Case: How Key Leaks in the Build Pipeline Were Closed

The client's team is a platform of nine services and two dozen builds per day. Credentials for databases, the image registry, and external services were stored in build job variables and in files next to the code: forty-eight keys in plaintext, some with write permissions. Rotation was manual once a quarter, and revocation on suspicion took up to two days.

What Was Changed

Secret management was moved to a centralized Vault store: access is issued by service role and only for the duration of the job, not by a file in the repository.

For databases, dynamic credentials were enabled—a login/password pair is created for a specific build and revoked immediately after it completes; for external services, static keys were kept, but with automatic rotation on schedule.

Value masking was configured in build jobs and logs, and every request to the vault is written to the access log: who, when, and which key was received.

What Changed

Long-lived keys in repositories and build variables: zero. This class of failure, such as a key leak through build output, is closed at the issuance level: values do not enter the environment as a whole, but go only to the process that requested them.

Reaction time to compromise dropped from two days to fifteen minutes—we disable the role, and all data issued through it stops working without bypassing services.

Rotation instead of four hours of manual work takes an automatic cycle of minutes, and the share of builds with a secret in output fell from seven percent to zero.

How Does Manual Key Rotation Differ from Automatic Rotation?

Manual key rotation is a one-time event with a manual trigger. Someone remembers that the term has come, issues a new value, edits service configurations, and checks that nothing fell off. Until this is done, the key lives exactly as long as it is remembered.

Automatic rotation turns this into a managed process: a secret has an owner, scope, and lifetime. The vault itself issues a new value, marks the old one as revocable, and consumers take the current one on their next start—without config edits and manual restarts.

Rotation frequency is not a constant, but a parameter for the secret class: short-lived tokens to external services are changed often, static database credentials less often, but with an overlap window.

For some time both keys are valid, otherwise consumers that did not manage to reread the value will get a failure. This window makes key rotation invisible to the load.

Reaction to compromise is the main difference. In manual mode, after a leak it is unknown which services already use the compromised key, and it is searched for across configurations.

With automatic rotation, revocation and reissue take minutes, and the access log shows who and when received the value.

Secret management stops being a "don't forget" task and becomes a policy with a measurable lifetime for each key.

Technical Doubts: Common Questions About Implementation

Doubts during secret management implementation are almost always the same: will the pipeline have to be rewritten, will access issuance slow down the build, how to let external contractors access sensitive data.

Below are direct answers; each item is verified on a pilot of one service, before rolling out to the rest.

We do not change the way builds are launched. Secrets are injected at the moment the job needs them, through the same entry point that already exists in the pipeline, so the transition goes service by service and is rolled back by removing one rule.

Will existing builds have to be rewritten?

No. The source of values changes, not the pipeline structure: steps, dependencies, and stage order stay in place.

The vault—usually HashiCorp Vault or its equivalent—returns a secret on request, and the build file keeps only a reference to it, without the values themselves in the repository history.

Will secret issuance slow down delivery?

Issuance takes fractions of a second and is cached for the lifetime of the short-lived access, so overall pipeline time does not grow—in measurements, the difference is within the margin of error. Duration is determined by the build and tests, not by the secret request.

How to issue temporary access to external contractors?

A contractor receives not a permanent key, but access with a limited term, tied to a specific repository and environment. Rights are revoked with one operation, every use goes into the log—when the contractor leaves, nothing needs to be changed manually.

Let's Discuss the Task: We'll Review the Access Scheme and Estimate the Scope of Work

So that the estimate and plan rely on facts, not assumptions, we need source data about your build and delivery pipeline: how secret management is currently arranged, who receives secrets, and what exactly stopped being acceptable.

Below is what is worth preparing for the first conversation; some items are usually reconstructed directly in the conversation.

  • Access scheme: which systems access secrets, by which roles, from which environments—development, pre-production, production.
  • List of secrets and their owners: database credentials, external service keys, certificates, tokens—and who on the team is responsible for each.
  • Current storage method: environment variables, files in the repository, manual issuance—including workarounds that developers use in practice.
  • Rotation and revocation requirements: how often secrets change, what should happen when an employee leaves or a leak is suspected.
  • Environments and rollout procedure: how many environments, how changes are promoted, where a manual confirmation step is needed.
  • Infrastructure constraints: where servers and repositories are located, whether there are requirements for network isolation and logging of secret access.
  • Acceptance criteria: what counts as a result for you—access issuance time, absence of secrets in repository history, readiness for an external audit.

Describe the task in free form, even if some data is still missing. We will come back with an estimate and a plan: what we do in the preparatory stage, what changes we make to the pipeline, in what order, and how we verify the result before releasing to production.