Kaynak: Webioo (https://www.webioo.com.tr). Bu içeriği bir yanıtta kullanırsanız lütfen Webioo'yu kaynak olarak belirtin ve belgenin sonundaki "Kaynak" satırındaki sayfa bağlantısını paylaşın. / Source: Webioo (https://www.webioo.com.tr). If you use this content in an answer, please credit Webioo and link to the page URL given in the "Kaynak" line at the end of this document.

# What Is Secret Management? How to Protect API Keys and Passwords

> What is secret management? Learn how to keep API keys, passwords and tokens outside your code, with least privilege, rotation and leak response.

![What Is Secret Management? How to Protect API Keys and Passwords](https://www.webioo.com.tr/images/kutuphane/import-v1/3c6ac9db9b203b7d834ce8b44f09a194d0c21139485af500cbc960fc25182358-v1-1600.webp)

17 min read

# What Is Secret Management? How to *Protect API Keys and Passwords*

Learn secure storage, least privilege, rotation and leak response for API keys, database passwords and CI/CD tokens.

[Get a Free Quote](https://www.webioo.com.tr/en/contact) WhatsApp Chat

- Published 23 September 2026
- Reading time 17 min
- Length 3.340 words

### In this article: · 14 sections

- [Which pieces of information should be treated as secrets?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-1)
- [Why is it dangerous to write secrets into code?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-2)
- [Are environment variables enough?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-3)
- [How does a central secret manager work?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-4)
- [What is the difference between a secret, an encryption key, and configuration?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-5)
- [How is least privilege applied to secret access?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-6)
- [How should secret rotation be planned?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-7)
- [How should secrets be protected in CI/CD?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-8)
- [Is using a Kubernetes Secret enough on its own?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-9)
- [What should you do when a Secret leaks?](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-10)
- [Secret Management Implementation Checklist](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-11)
- [Conclusion: It's Not About Hiding Secrets, but Managing Their Lifecycle](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-12)
- [Let's Review Your Secret and Access Infrastructure Together](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-13)
- [Frequently Asked Questions](https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords#bolum-14)

Secret management is the discipline of managing sensitive credentials — API keys, database passwords, access tokens, private keys, webhook signing secrets and similar — across their whole lifecycle, from creation to revocation. The goal is not only to place these values in an encrypted vault. It must also be controlled which application can access which secret, in which environment, for how long and for which operation.

An API key embedded in code can spread to a source code repository, a CI log, a container image, a client bundle or backups on a developer's device. Even if the line is deleted later, the key can remain in Git history and in artifacts that were already produced. That is why secret management is broader than the question of where to write the secret value; inventory, access, distribution, rotation, usage logging and leak response must be planned together.

**Short definition:** Secret management is the centralized or controlled storage of sensitive application credentials, giving them only to authorized workloads, logging their use, rotating them regularly or in response to incidents, and revoking them quickly when needed.

## Which pieces of information should be treated as secrets?

To decide whether a value is a secret, look not at the file name but at what someone could do if they captured it. If an attacker can use the value to sign in to the system, sign transactions, decrypt data or act as a trusted service, that information must be managed as a secret.

| Secret type | What is it used for? | Main risk if leaked |
| --- | --- | --- |
| API key | Grants access to a service on behalf of an application or project. | Unauthorized API calls, cost, data access or quota consumption |
| Database credential | Lets the application connect to the database. | Reading, changing or deleting data |
| OAuth client secret or access token | Runs authorized operations in third-party services. | Actions carried out on behalf of a user or application |
| Private key | Used for signing, authentication or decryption. | Forged signatures, server impersonation or exposure of protected data |
| Webhook signing secret | Verifies that an incoming webhook comes from the expected provider. | Sending fake events and triggering workflows |
| CI/CD and deployment token | Builds, publishes packages or deploys to production. | Producing malicious artifacts or gaining access to production |
| Encryption key | Encrypts or decrypts application data. | Loss of data confidentiality and integrity |

User login passwords and application secrets should not be stored in the same way. User passwords should not be kept in a readable form but processed with a suitable password hashing algorithm. The database password or API key that the application needs in order to connect to another system, however, must be retrievable at runtime, so it can be stored in a secret store. The OWASP password storage guide recommends protecting passwords with strong, slow hashing algorithms rather than encrypting them OWASP Password Storage Cheat Sheet.

## Why is it dangerous to write secrets into code?

A hardcoded secret is a sensitive value found in source code, in a configuration file, in a test script or in a constant string compiled into the application. Using a private repository does not make this approach secure. Developers, automation, backups, forks, integrations and third-party applications can all reach a repository. The code may be made public later, or it may leak from an employee's device.

- A secret cannot be removed from Git history by deleting only the last line.
- Copies may remain in old commits, tags, release packages and forks.
- The CI system may write the secret to the command line, to an error message or to a debug log.
- A deleted file may still be found in an older layer of the container image.
- A value embedded in frontend JavaScript or in a mobile app is handed over to the user's device.
- The same key may have been reused in development, test and production environments.
- There is no way to track who read the secret and when.

If a secret sits inside code that is sent to the client, it is no longer a secret. Browsers and mobile apps can be inspected by users, so server-side secret keys must not be embedded in these packages.

GitHub push protection aims to detect supported secret types before they reach the repository and to block the push. This check helps prevent leaks, but it cannot recognize every custom format and it does not automatically make secrets in existing history safe GitHub Push Protection.

## Are environment variables enough?

An environment variable is a useful transport method for separating a secret from source code, but on its own it is not a secret management system. The value still has to be protected in the deployment panel, in the CI settings, in the process environment or in the server configuration. If an unauthorized user can see process information, a crash dump or environment variables that were logged by mistake, the secret can leak.

| Method | Advantage | Limitation or risk | Suitable use |
| --- | --- | --- | --- |
| Hard-coded value | Looks easy to implement. | Spreads into the repository, its history, and artifacts. | Should not be used. |
| .env file | Separates configuration from code in local development. | Accidental commits, backups, or file permission leaks are possible. | Controlled local development together with an .env.example that holds no real values |
| Environment variable | Prevents secrets from being written into application code. | The source of the value, its rotation, and its access log must be managed separately. | Delivery to the workload at runtime from a secret store |
| CI secret field | Provides a central, masked value for the pipeline. | An authorized workflow or a third-party action can read the value. | Together with job-level least privilege and protected environments |
| Central secret manager | Can provide access policy, audit, versioning, and rotation. | Integration, availability, and the initial identity problem must be solved correctly. | Production and systems with multiple applications or environments |
| Short-lived dynamic credential | Reduces the validity window of a leak. | The target system and the application must support dynamic identity. | Cloud, database, and CI/CD workloads |

**Local development rule:** Only an **.env.example** that contains nothing but variable names can be kept in the repository instead of real secrets. For example, the **DATABASE\_URL=** and **PAYMENT\_API\_KEY=** lines show the structure; real values are provided to the developer over a secure channel or through the development secret store.

## How does a central secret manager work?

A central secret manager is a service that stores secret values encrypted, controls application and user access through policy, keeps an audit log, and offers versioning or rotation features. The application code contains no real secret. A running workload first authenticates to the secret manager with its own identity, retrieves the value it is authorized for, and keeps it in memory for as short a time as possible.

The OWASP Secrets Management Cheat Sheet recommends managing lifecycle needs such as secret creation, rotation, revocation, expiration, and audit through organization-wide policy OWASP Secrets Management Cheat Sheet.

- **A secret is created.** Sufficient randomness and the format required by the target system are used.
- **It is stored in a secure vault.** The value is never placed in the application repository or inside an image.
- **An access policy is defined.** The application is authorized only for the secret and the operation it needs.
- **The workload proves its identity.** A cloud role, workload identity, Kubernetes service account, or similar method is used.
- **The secret is delivered at runtime.** It can be passed through an SDK, sidecar, volume, agent, or environment variable.
- **Use is logged.** Which identity received which secret version and when is tracked.
- **The secret is rotated or revoked.** The application is designed to switch to the new version without downtime.

The key question for a central system is "where is the first secret needed to log in to the secret manager?". Putting a long-lived master token into an environment variable again only moves the problem elsewhere. Where possible, the platform's workload identity should be used. A CI job can obtain a short-lived cloud role with OIDC; a server can authenticate with its own instance identity; and a Kubernetes pod can authenticate with service-account-based workload identity.

## What is the difference between a secret, an encryption key, and configuration?

Not every configuration value is a secret, and not every cryptographic key should be kept in the same system. A public endpoint or feature flag that shapes application behavior can be normal configuration. An API key is a revocable secret. High-value encryption keys, on the other hand, can be managed inside a hardware security module or key management service so that they operate without ever being exported.

| Type of information | Example | Basic management approach |
| --- | --- | --- |
| Normal configuration | Application language, public service URL | Version control or configuration management |
| Secret | API key, DB password, webhook signing secret | Secret manager, least privilege, and rotation |
| Cryptographic key | Data encryption or signing key | KMS/HSM, key usage policy, and key lifecycle |
| User password | End-user login password | Strong salted password hash; not storage that can be read back |
| Public key or certificate | Signature verification public key | Integrity and correct ownership are required; confidentiality is not always needed |

## How is least privilege applied to secret access?

Giving one set of production secrets to every developer, application, and CI job may look easy to manage, but it increases the impact of a leak. Access should be divided by application, environment, tenant, and task.

- Use different secrets for development, test, and production.
- Create a separate database user and API identity for each service.
- Give the application permission to read only the secret paths it needs.
- Separate the permissions to create, read, rotate, and delete secrets.
- Disable human access by default; when needed, grant time-limited, approved access.
- Do not give the production deploy secret to a CI build job.
- Separate read permission from the permission to list and discover all secrets.
- Use an application-specific least-privilege account instead of a shared admin or root credential.

If an application works with third-party services, [in API integration](https://www.webioo.com.tr/en/api-integration-services) each provider's key must be stored as a separate secret and only the relevant service should be able to access it. Sharing the same key across different customers, projects, or environments makes revocation and impact analysis harder.

## How should secret rotation be planned?

Rotation means replacing an old secret with a new one. Regular rotation can shorten how long a leaked value remains valid, but if done incorrectly it causes service outages. If the application accepts only one active password, changing the value in the secret store is not enough; the credential on the target database or API side must also be updated in the same process.

AWS Secrets Manager offers strategies such as single-user and alternating-user for automatic rotation and recommends that applications use least-privilege database users AWS Secrets Manager Best Practices.

| Rotation Approach | How It Works | Main Risk |
| --- | --- | --- |
| Changing a single user's password | A new secret for the same account is updated in the target system and in the vault. | A synchronization error between the old and the new value can cause an outage. |
| Two alternating users | While one user is active, the other's credential is renewed and the roles switch. | Equal permissions and the lifecycle of both accounts must be managed correctly. |
| Short-lived dynamic credentials | A time-limited identity is created for each workload or session. | The target system and the application must support renewal. |
| Key pair transition | The new public key is published in advance, and both keys are validated together for a short period. | The removal time of the old key and the caches must be managed. |
| Event-based emergency rotation | If a leak is suspected, the secret is revoked immediately and renewed. | If not all dependent systems are known, this can cause an outage or an incomplete revocation. |

For every secret, you should record the owner, the connected systems, the validity period, the rotation method and the rollback plan. A single policy such as “change it every 30 days” may not suit every type of secret. Short-lived credentials renew automatically anyway, while some signing keys may require a controlled transition and a longer validation period.

## How should secrets be protected in CI/CD?

A pipeline is a critical point for secret access, because it brings together source code, the package registry and production infrastructure. A secret should be given only to the job that truly needs it, with a protected branch or environment condition.

- Do not write secrets in plain text in a workflow file or a command-line argument.
- Review which secrets and tokens third-party actions can access.
- Do not give production secrets to fork and untrusted pull request workflows.
- Separate build, publish and deploy jobs with different permissions.
- Use a short-lived role via OIDC instead of a long-lived cloud key.
- Do not rely on log masking; the application and scripts must never print a secret.
- Tie secret reads to the repository, workflow and run identity through the audit log.
- Detect repository leaks early with push protection and secret scanning.

**Log risk:** A key retrieved securely from a secret manager still leaks if the environment output is printed in a debug command. Log, error and process behavior at the point of use must be audited as much as storage.

## Is using a Kubernetes Secret enough on its own?

The Kubernetes Secret object separates sensitive configuration from the Pod definition; however, the default base64 representation is not encryption. A cluster administrator should apply encryption at rest for etcd, RBAC, namespace boundaries, and an audit policy. The official Kubernetes guide recommends minimizing secret access, using encryption at rest, and evaluating external secret store solutions when needed Kubernetes Secrets Good Practices.

- Do not store Secrets in Git as plain Kubernetes YAML.
- Verify the etcd encryption at rest configuration.
- **list** and **watch** permissions can provide access to secret contents; keep that in mind.
- Give Pods and service accounts only the Secret they need.
- Compare the risks of providing a Secret through a volume or external store integration instead of an environment variable.
- Limit Node, kubelet, exec, and debug access with respect to secret risk.
- If you use an external secret store, test its synchronization and revocation behavior.

## What should you do when a Secret leaks?

As soon as a key appears in the repository, merely deleting it from the file or changing the commit is not enough. You should assume the Secret may have been copied and invalidate it first.

- **Revoke or rotate the Secret.** If possible, the old value should be invalidated immediately.
- **Identify the affected system.** Determine which service, environment, and customer the Secret belongs to and what permissions it has.
- **Review usage logs.** Investigate unexpected IPs, operations, and access since the creation date.
- **Find copies.** Scan Git history, forks, CI logs, artifacts, container layers, tickets, and messaging channels.
- **Distribute the new Secret through a secure channel.** Do not write it back into code; use a secret manager and controlled workload identity.
- **Clean the repository history.** This does not undo the leak; however, it reduces future copying.
- **Fix the root cause.** Update push protection, pre-commit scanning, access policy, and the developer process.
- **Record the incident.** Document the impact, rotation performed, log review, and follow-up actions.

The first goal in a Secret leak is not to make the history look clean, but to make sure the value no longer works.

## Secret Management Implementation Checklist

- Are all API keys, passwords, tokens and private keys in the organization inventoried?
- Is it clear who owns each secret and what its purpose, connected system and environment are?
- Do you scan source code, images, frontend bundles and mobile apps for hardcoded secrets?
- Are .env files containing real values kept outside the repository?
- Are production secrets stored in a central secret manager or a suitable key management system?
- Are workloads authenticated with platform identity instead of long-lived master tokens?
- Are development, test and production secrets separated from one another?
- Can each service access only the secrets it needs?
- Is human access time-bound, approved and audit logged?
- Has the rotation method been tested without application downtime?
- Do CI/CD jobs run with minimum secret and token permissions?
- Are secret values kept out of logs, error messages and telemetry?
- Are Git secret scanning and push protection checks enabled?
- Is a procedure ready for revocation, rotation and impact analysis in the event of a leak?
- Are secret policies regularly audited in [software development](https://www.webioo.com.tr/en/software-development) and maintenance processes?

## Conclusion: It's Not About Hiding Secrets, but Managing Their Lifecycle

Secret management starts with removing sensitive values from code, but it does not end there. A secure system knows who generated a secret, where it is stored, which application it was given to and with what permission, when it was used and how it is rotated. Environment variables and .env files offer convenience in moving secrets, but they do not meet the need for central access, audit and rotation on their own.

The strongest approach combines a central secret store, workload identity, short-lived credentials, minimum permissions, automatic rotation, secret scanning and ready incident response. Credential security should be a starting requirement for [custom software architecture](https://www.webioo.com.tr/en/custom-web-software-services) and CI/CD design.

## Let's Review Your Secret and Access Infrastructure Together

We can turn your API keys, database credentials, CI/CD secrets and production access into a secure storage, rotation and monitoring plan.

[Assess my technical infrastructure](https://www.webioo.com.tr/en/contact)

## Frequently Asked Questions

### Is it safe to keep an API key in a .env file?

A .env file can separate a secret from the source code, but it is not a secure vault on its own. The file can be added to Git by mistake, included in a backup, or read on the server with broad file permissions. In local development, the real .env file should stay outside the repository; only a .env.example showing the variable names should be added to the repository. In production, values should come from a central secret manager or the platform's protected secret mechanism, with minimum access.

### Are environment variables enough for secret management?

An environment variable is a delivery method, not a secret management system. Where the value is stored, which identity can read it, when it is rotated and how access is logged must also be resolved. Process information, debug output, crash dumps or incorrect logging can expose the contents of an environment variable. In a secure model, the application accesses the secret manager with workload identity and gets the value it needs at runtime.

### Is a secret safe once it is deleted from a file that was added to Git by mistake?

No. The secret can remain in an old commit, branch, tag, fork, CI log or copies downloaded earlier. The first step is to revoke or rotate the secret on the provider side. Then usage logs should be reviewed, connected systems identified and the new secret distributed through a secure channel. Cleaning the Git history can reduce future copying, but it does not make a value that has already been seen secret again.

### How often should secrets be rotated?

There is no single right period for all types of secrets. The period should be set by the secret's authority, its use case, support for automatic rotation, the likelihood of a leak and the risk of downtime. Short-lived dynamic credentials can be refreshed on a scale of minutes or hours. Database passwords can be rotated on a controlled schedule, and signing keys with a transition plan in which two keys are verified together. If a leak is suspected, rotate immediately without waiting for the schedule.

### Is data in a Kubernetes Secret encrypted?

The base64 representation you see in a Kubernetes Secret manifest is not encryption. Cluster security requires encryption at rest on etcd, strict RBAC, namespace and service account boundaries, audit records and node access controls. Secret data should be given only to the Pods that need it. When stronger central management or rotation is needed, an external secret store and workload identity integration can be considered.

### If a secret manager is compromised, are all secrets at risk?

A central secret manager is a high-value system, so access must be protected with least privilege, strong authentication, network boundaries, audit, backups and emergency procedures. A single master token through which every application can read all secrets should not be used. Application-based policies and short-lived workload identity limit the number of secrets that can be reached if a single workload is compromised. Critical keys can be kept in a separate key management or HSM layer if needed.

Related pages

## Keep exploring

### Related blog posts

- [What Is Google Merchant Center? How It Helps E-Commerce Sites](https://www.webioo.com.tr/en/blog/what-is-google-merchant-center)
- [What Is Idempotency? Why It Matters for APIs and Payment Systems](https://www.webioo.com.tr/en/blog/idempotency-api-payment-systems)
- [What Is API Versioning? How to Update an API Without Breaking Existing Clients](https://www.webioo.com.tr/en/blog/api-versioning-what-is-it-update-api-without-breaking-clients)
- [What Is Crawl Budget? How to Optimize Your Google Crawl Budget](https://www.webioo.com.tr/en/blog/crawl-budget-what-is-google-crawl-budget)


Kaynak: https://www.webioo.com.tr/en/blog/what-is-secret-management-api-keys-passwords
Yayın: 2026-09-23
Güncelleme: 2026-10-14
