AWS Secrets Manager and AWS KMS: Understanding Secure Credential and Key Management
the article discusses about the use of AWS Secrets manager and KMS as a service for manaing production API Keys
When we build modern applications, especially applications that connect to multiple external services, one problem appears very quickly: where do we safely store all the sensitive credentials our application needs?
A typical application might require a database password, a Jira API token, Slack credentials, Google OAuth secrets, API keys, and other sensitive configuration. Keeping these values directly inside the source code is obviously unsafe, but even storing them in a simple
.env file can become difficult to manage once the application moves into production.This is where AWS Secrets Manager and AWS Key Management Service (KMS) become important.
Although these two services are often used together, they solve two different problems. Secrets Manager is responsible for managing sensitive secrets, while KMS is responsible for managing cryptographic keys used to protect data.
The Problem With Storing Secrets Directly in Your Application
Imagine that you are building a SaaS application such as OpsNinja. Your backend needs to communicate with Jira, Slack, Google Calendar, and a database.
To make those integrations work, you need credentials.
During development, it is common to put them into an environment file:
JIRA_API_KEY=xxxxxxxxSLACK_TOKEN=xxxxxxxxDATABASE_PASSWORD=xxxxxxxxGOOGLE_CLIENT_SECRET=xxxxxxxxThis is convenient during development, but production applications need a stronger approach.
Credentials can accidentally be committed to GitHub, copied into Docker images, exposed through logs, shared with the wrong person, or remain unchanged for years.
There is another problem as well: credentials have a lifecycle.
They need to be created, securely stored, accessed by applications, rotated periodically, and eventually revoked.
Managing that lifecycle manually becomes increasingly difficult as an application grows.
What AWS Secrets Manager Does
AWS Secrets Manager is designed specifically to solve this problem.
Instead of keeping a Jira token or database password inside your application's source code, you can store it inside Secrets Manager.
Your application can then request the secret when it needs it.
For example, instead of the backend directly depending on a hard-coded Jira token, it can request the Jira credentials from Secrets Manager and then use them to communicate with Jira.
This creates an important separation between application code and sensitive credentials.
Your source code contains the logic for communicating with Jira, but the actual Jira credential is maintained separately inside AWS.
Secrets Manager can be used for many types of sensitive information, including database credentials, API keys, OAuth tokens, application credentials, and other secrets.
Why This Is Useful in a Real Application
Consider an application like OpsNinja.
OpsNinja integrates with several external platforms. Each integration may require its own credentials.
Instead of putting all those credentials inside the backend configuration, they can be managed through Secrets Manager.
This gives the development team a centralized location for managing application secrets.
It also means that changing a credential does not necessarily require changing the application source code.
For example, if a Jira token needs to be replaced, the new credential can be managed through Secrets Manager without embedding the new value into the backend codebase.
Secret Rotation
One of the important capabilities of Secrets Manager is secret rotation.
Credentials should not ideally remain valid forever. If a credential is compromised, having a long-lived credential can increase the potential impact.
Secrets Manager supports rotation workflows that allow credentials to be periodically replaced.
This is particularly useful for database credentials and other credentials that support automated rotation.
Instead of treating a password as something that is created once and forgotten, you can treat it as something that has an ongoing lifecycle.
That is an important difference between simply using environment variables and using a dedicated secrets-management system.
But Where Does Encryption Come In?
At this point, another question appears:
If Secrets Manager is storing sensitive information, how is that information protected?
This is where AWS Key Management Service, or AWS KMS, comes into the picture.
AWS KMS is a managed service for creating and controlling cryptographic keys.
The important distinction is:
Secrets Manager manages the secret. KMS manages the encryption keys used to protect data.
For example, a Jira API token is a secret.
An encryption key used to protect that secret is a cryptographic key.
Those are two different things.
Understanding AWS KMS
AWS KMS allows applications and AWS services to use managed cryptographic keys without requiring developers to build their own key-management infrastructure.
KMS can be used for encryption and decryption, as well as other cryptographic operations such as digital signatures and verification.
The major advantage is that you don't have to build and operate your own cryptographic key-management infrastructure.
AWS manages the underlying security infrastructure while giving you control over how keys are used and who is allowed to use them.
Secrets Manager and KMS Working Together
This is where the relationship between the two services becomes interesting.
When you store a secret in Secrets Manager, the secret is encrypted at rest.
Secrets Manager uses AWS KMS as part of this encryption process.
The important concept here is envelope encryption.
Instead of directly using the KMS key to encrypt every piece of secret data, a data encryption key is used to encrypt the actual secret. That data key is then protected using a KMS key.
This approach allows encryption to be efficient while still giving AWS a strong mechanism for protecting and controlling the underlying cryptographic keys.
So when you use Secrets Manager, you don't necessarily need to manually perform encryption and decryption yourself. AWS manages much of this process behind the service interface.
The Role of IAM
There is another important AWS service involved in this security model: AWS Identity and Access Management, or IAM.
Encryption alone isn't enough.
You also need to answer the question:
Who is allowed to access this secret?
For example, your OpsNinja backend may need access to the Jira credentials, but your frontend application shouldn't have access to them.
IAM allows you to define these permissions.
You can create an IAM role for your backend and give that role permission to retrieve a specific secret.
This follows the principle of least privilege.
Instead of giving an application access to everything inside AWS, you give it only the permissions it actually needs.
This becomes particularly important as applications become larger and contain multiple services.
A Practical Example With OpsNinja
Suppose OpsNinja needs to create a Jira issue automatically after identifying a client commitment.
The backend needs a Jira credential to communicate with Jira.
Instead of storing that credential directly inside the backend code, the backend can request it from Secrets Manager.
AWS verifies that the backend's IAM role has permission to retrieve that particular secret.
Secrets Manager retrieves the protected credential and makes it available to the authorized application.
The backend can then use the credential to communicate with Jira.
The developer never needs to put the actual production credential into the source code.
This same approach can be applied to Slack, Google Calendar, databases, and other third-party services.
AWS-Managed Keys vs Customer-Managed Keys
AWS KMS also gives organizations different levels of control over their encryption keys.
An AWS-managed key is maintained by AWS for a particular AWS service. This provides a convenient option when you don't need detailed control over the key lifecycle.
A customer-managed KMS key gives you more control.
You can manage its policies, permissions, lifecycle, and usage according to your application's requirements.
This additional control is useful for applications with more demanding security, compliance, or cross-account requirements, although it also introduces additional management responsibilities.
Secrets Manager and KMS Are Not the Same Thing
This is probably the most important concept to remember.
If you need to store:
- A database password
- A Jira API token
- A Slack OAuth token
- A Google client secret
- An application credential
you are dealing with secrets, so Secrets Manager is the relevant service.
If you need to:
- Create encryption keys
- Control encryption keys
- Encrypt or decrypt data
- Perform cryptographic operations
- Manage the lifecycle of cryptographic keys
you are dealing with key management, so KMS is the relevant service.
The two services complement each other rather than competing with each other.
Why This Matters for Production Applications
The biggest difference between a small personal project and a production SaaS application is often not the basic functionality.
It is how the system handles things like security, access control, credentials, encryption, monitoring, and operational management.
A developer can build an application that works perfectly while still having poor credential-management practices.
Using services such as Secrets Manager and KMS allows these security concerns to become part of the application's architecture rather than something added later.
For a product such as OpsNinja, this becomes particularly important because the application communicates with multiple external systems and handles potentially sensitive client and project information.
Final Takeaway
The easiest way to remember the relationship is:
AWS Secrets Manager manages your secrets.
AWS KMS manages your encryption keys.
IAM controls who is allowed to access them.
Together, these services provide the foundation for securely managing credentials and protecting sensitive information in a production AWS application.
For a developer, the key lesson is not simply to memorize three AWS services. It is to understand the separation of responsibilities:
Secrets are application credentials. Keys are cryptographic assets. Permissions determine who can use them.
Once you understand that distinction, designing secure cloud applications becomes much easier.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article