Join our Newsletter — 33% off our NHI Course
Home› Guides› Application Framework Secrets Guide: Comparing Built-in Stores and…
Guide Secrets Management

Application Framework Secrets Guide: Comparing Built-in Stores and Moving to Vaults

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 14 November 2026 16 min read
On this page

Every web framework ships its own way to keep secrets out of source code, and in most estates those built-in stores quietly become the production secrets platform without anyone deciding they should. ASP.NET Core has Secret Manager and the configuration provider model, Django has SECRET_KEY and whatever the settings module loads, Ruby on Rails has encrypted credentials guarded by a master key, and Spring has property sources, Spring Cloud Config with {cipher} values and Spring Cloud Vault. This guide compares those mechanisms side by side, explains which root secret each one depends on, and sets out a migration path to an external secrets manager with workload identity. It is written for application security engineers, platform teams and architects who run more than one framework and want one consistent standard. Frameworks are listed alphabetically throughout; order is not a ranking.

Key takeaways

  • Every built-in store has a root secret. The Rails master key, the Spring Cloud Config encrypt.key or keystore, the Django SECRET_KEY and the identity that unlocks an ASP.NET Core Key Vault provider are the values that actually need protecting, owning and rotating.
  • Development stores are not production stores. Microsoft documents .NET Secret Manager as a development-only, unencrypted JSON file in the user profile; treat local stores in every framework the same way.
  • Encrypted in Git still means a key somewhere. Rails credentials.yml.enc and Spring {cipher} values can be committed safely only while the decryption key stays out of the repository, images and CI logs.
  • Signing keys need fallback rotation. Django SECRET_KEY_FALLBACKS and the Rails secret_key_base rotation pattern let you replace a session signing key without logging every user out at once.
  • The end state is the same for all four. Load secrets at runtime from an external manager, authenticated by a managed or workload identity, so that the application holds no long-lived bootstrap credential of its own.

What each framework actually provides

The four frameworks solve different parts of the problem. Two (Rails and Spring Cloud Config) encrypt values at rest in files; two (ASP.NET Core and Spring Boot) are primarily configuration loaders that can be pointed at an external store; Django leaves secret loading to the settings module, which is plain Python. The table lists each framework's own mechanism and the root secret it depends on.

FrameworkBuilt-in mechanismWhere values liveRoot secret to protectFramework signing key
ASP.NET CoreConfiguration providers; Secret Manager (dotnet user-secrets) for development; Azure Key Vault configuration provider%APPDATA%\Microsoft\UserSecrets\<UserSecretsId>\secrets.json on Windows for development; environment variables or Key Vault in productionThe credential the app uses to reach Key Vault (preferably a managed identity, so no stored secret)Data Protection key ring (cookies, antiforgery tokens)
Djangosettings.py, which can read os.environ or a file; check --deploy validates SECRET_KEY strengthEnvironment variables, a file readable only by the app user, or a secrets manager called from settingsWhatever credential settings.py uses to fetch secretsSECRET_KEY, with SECRET_KEY_FALLBACKS for rotation
Ruby on RailsEncrypted credentials: config/credentials.yml.enc edited with bin/rails credentials:editThe encrypted YAML file, which may be committed; per-environment files under config/credentials/config/master.key or RAILS_MASTER_KEY (or config/credentials/<env>.key)secret_key_base, stored inside credentials
Spring (Boot and Cloud)Property sources and config trees (configtree:) in Spring Boot; {cipher} values in Spring Cloud Config; Spring Cloud Vaultapplication.properties, mounted files, a Config Server backed by Git, or HashiCorp Vaultencrypt.key (or ENCRYPT_KEY) or the encrypt.keyStore.* keystore and its password; the Vault authentication credentialApplication specific (for example JWT signing keys held as properties)

Each framework's wider hardening is covered in its own guide: see the ASP.NET Core Security Guide, the Django Security Guide, the Ruby on Rails Security Guide and the Java and Spring Security Guide. This page stays on secret storage, rotation and migration.

ASP.NET Core: Secret Manager, configuration providers and Key Vault

  • Secret Manager scope: dotnet user-secrets init adds a UserSecretsId GUID to the project file, and dotnet user-secrets set "Section:Key" "value" writes to secrets.json in the user profile. Microsoft's documentation states that Secret Manager does not encrypt the stored secrets, should not be treated as a trusted store and is for development purposes only. WebApplication.CreateBuilder adds user secrets automatically only in the Development environment.
  • Environment variables: they override earlier configuration sources and use a double underscore (__) for hierarchy, because a colon does not work on every platform. Microsoft also warns that environment variables are commonly stored as plain text and are readable if the machine or process is compromised. See Environment Variables vs Secrets Manager.
  • Production store: the Azure Key Vault configuration provider (builder.Configuration.AddAzureKeyVault with the Azure.Extensions.AspNetCore.Configuration.Secrets package) loads secrets as configuration. Key Vault names allow only letters, digits and dashes, so Section--SecretName maps to Section:SecretName.
  • Identity: Microsoft recommends a managed identity for Azure-hosted apps, granted get and list on secrets, with ManagedIdentityCredential suggested for production rather than the broader DefaultAzureCredential chain. Apps outside Azure use an Entra ID application with an X.509 certificate, which becomes the root secret to manage.
  • Reload and isolation: the provider caches secrets for the app's lifetime unless ReloadInterval is set (default null), so a rotated secret is not picked up until reload or restart. Microsoft states that different apps and environments should use separate key vaults, and warns against using name prefixes to hold several apps' or environments' secrets in one vault. See the Azure Key Vault Security Guide.

Django: SECRET_KEY and the settings module

  • What SECRET_KEY signs: sessions (for every backend except the cache backend, or when the default get_session_auth_hash() is used), cookie-based messages, PasswordResetView tokens and any cryptographic signing that does not supply its own key. Django refuses to start if it is not set.
  • Exposure impact: the settings reference warns that running Django with a known SECRET_KEY defeats many of its security protections and can lead to privilege escalation and remote code execution.
  • Loading: the deployment checklist says the production key must be large, random, not used anywhere else and not committed, and shows loading it with os.environ["SECRET_KEY"] or from a file such as /etc/secret_key.txt. Database passwords in DATABASES and third-party API keys deserve the same treatment; Django has no built-in encrypted store, so settings.py is where an external manager is called.
  • Rotation: set a new SECRET_KEY and move the previous value to the start of SECRET_KEY_FALLBACKS, then remove old values from the end once the sessions and reset tokens signed with them may expire. Fallbacks add signing overhead, so remove them after the rotation window. Secret keys are not used for user password hashes, so rotation does not affect stored passwords.
  • Gate: run manage.py check --deploy against production settings in CI; it flags weak or default-looking SECRET_KEY values.

Ruby on Rails: encrypted credentials and the master key

  • Store: secrets live in config/credentials.yml.enc, which cannot be edited directly. bin/rails credentials:edit creates the file and, if none exists, config/master.key. Values are read through Rails.application.credentials, and the bang form (for example Rails.application.credentials.some_api_key!) raises KeyError when a value is blank, which turns a missing secret into a boot-time failure instead of a silent nil.
  • Key: the encrypted file can be committed as long as the master key stays secure; the Rails security guide says plainly not to commit the master key. In production supply it as RAILS_MASTER_KEY from the platform's secret store rather than as a file baked into an image.
  • Per-environment separation: config.credentials.content_path defaults to config/credentials/<Rails.env>.yml.enc when that file exists, and key_path to config/credentials/<Rails.env>.key, falling back to the shared files. Separate production credentials with their own key mean a developer key cannot decrypt production values.
  • Fail closed: config.require_master_key causes the app not to boot when no master key is available.
  • secret_key_base: it is held in credentials and derives the keys that sign and encrypt cookies. The Rails guide notes that changing it expires active sessions and can affect encrypted and signed cookies and Active Storage files, so plan a rotator rather than a straight swap. Generate new values with bin/rails secret.

Spring: property sources, Spring Cloud Config and Spring Cloud Vault

  • Property source order: in Spring Boot, OS environment variables override config data such as application.properties, and command line arguments override both. A secret placed in a later source silently wins, which matters when auditing where a value really came from.
  • Config trees: spring.config.import=optional:configtree:/etc/config/ exposes each mounted file as a property named after its path, which suits Kubernetes Secret volumes and Docker secrets at /run/secrets/. The Spring Boot documentation notes the drawbacks of environment variables for values meant to be secret.
  • Encryption: the Spring Boot reference directs encrypted credential storage to Spring Cloud Vault, and offers EnvironmentPostProcessor as a hook for custom decryption.
  • Spring Cloud Config {cipher}: values prefixed {cipher} are decrypted by the Config Server before being sent to clients over HTTP. The key is either symmetric (encrypt.key, ideally supplied as ENCRYPT_KEY) or an RSA keystore (encrypt.keyStore.location, password, alias, type); the documentation describes asymmetric keys as superior in security terms. The /encrypt and /decrypt endpoints are assumed to be secured and reachable only by authorised agents, so protect them like an administrative API.
  • Client-side decryption and rotation: setting spring.cloud.config.server.encrypt.enabled=false makes the server pass ciphertext through for clients to decrypt, which spreads key management to every client. Multiple keys are selected with a {key:alias} prefix; changing keys means every client updates its ciphertexts to the new alias.
  • Spring Cloud Vault: provides client-side support for externalised configuration from HashiCorp Vault, including static secrets and dynamic credentials for databases such as MySQL and PostgreSQL. See the HashiCorp Vault Guide and, for management endpoints that can expose resolved properties, the Spring Boot Actuator and Management Endpoint Security Guide.

Choosing between the built-in store and an external manager

SituationBuilt-in store is reasonableMove to an external manager
Local developmentYes: Secret Manager, a git-ignored .env, development credentials filesOnly if developers need shared non-production secrets
One small app, one environment, few secretsEncrypted credentials or {cipher} values, with the key in the platform secret storeWhen a second team or environment appears
Several apps or frameworksNo: each stack grows its own key handlingYes: one policy, one audit trail, one rotation process
Database and cloud credentialsOnly for static values with a rotation runbookYes: dynamic or short-lived credentials where the manager supports them
Regulated workloads needing access logsNo: file-based stores have no per-read audit trailYes: the OWASP cheat sheet lists who requested, approved and used each secret as audit events
Secret shared by many servicesNo: re-encrypting and redeploying every app is slowYes: rotate once, apps reload or restart

Small teams: the platform's native secret store (cloud secrets manager or Kubernetes Secrets with encryption at rest) holding the single framework root key is a proportionate first step. Larger estates: standardise on one or two managers, as the OWASP Secrets Management Cheat Sheet recommends, and make the framework store a development convenience only. For the trade-off in detail see Centralised vs Decentralised Secrets Management.

Migrating from framework stores to an external manager

  1. Inventory per framework. Search repositories and images for config/master.key, credentials/*.key, secrets.json, ENCRYPT_KEY, encrypt.key, {cipher}, SECRET_KEY = literals and passwords in application.properties or appsettings.json. Run secret scanning across history, not only the main branch. See the Git Secret Scanning Guide.
  2. Assign owners and classify. Record for each secret the application, environment, owner, consumers and rotation method. Framework signing keys (SECRET_KEY, secret_key_base, Data Protection keys) are a separate class because rotating them affects user sessions.
  3. Give each app an identity. Use a managed identity, Kubernetes service account or workload identity federation to authenticate to the manager, so the migration does not simply move a static bootstrap secret. See the NHI Authentication Guide.
  4. Wire the loader. ASP.NET Core: AddAzureKeyVault or the equivalent provider for your cloud. Django: read from the manager's SDK or from files injected by the platform in settings.py. Rails: supply RAILS_MASTER_KEY from the manager first, then move individual values into the manager and read them at boot. Spring: spring.config.import with Spring Cloud Vault or a config tree populated by an operator.
  5. Pilot in a non-production environment. Run with both sources present, the external one taking precedence, and confirm with a startup check that every required value resolved from the manager. Use the fail-closed options: Rails require_master_key and bang accessors, Django's refusal to start without SECRET_KEY.
  6. Rotate as you move. Every secret that lived in a file, image or Git history is treated as exposed: issue a new value in the manager, deploy, then revoke the old one. For signing keys use SECRET_KEY_FALLBACKS or a cookie rotator. See the Secrets Rotation Runbook Template.
  7. Remove the old store. Delete committed key files, purge history where policy requires (see How to Remove Secrets From Git History), drop {cipher} values and the Config Server key once no client uses them.
  8. Rollback plan. Keep the previous configuration source deployable but empty of live values for one release, so a loader failure can be reverted by configuration rather than by restoring old secrets.

Detection and measurement

  • Repository and image scanning: pre-commit and CI rules for master.key, *.key under config/credentials, secrets.json, ENCRYPT_KEY and literal SECRET_KEY assignments, plus container image scans.
  • Manager audit logs: alert on reads of production secrets by identities other than the owning application, and on access denied bursts after a deployment.
  • Config Server: log and alert on calls to /encrypt and /decrypt from outside the expected administrative network.
  • Runtime exposure: check that management endpoints, debug pages and error reports do not print configuration (Django DEBUG must be off in production; Actuator env and heapdump stay restricted).
MetricTarget
Production apps loading secrets from an external manager100% of in-scope apps
Framework root keys (master.key, encrypt.key, keystores) found in repositories or imagesZero new findings; legacy findings rotated
Apps authenticating to the manager with a managed or workload identityRising to all apps on supported platforms
Median time from secret exposure alert to rotationHours, not days
Signing keys with a documented rotation date in the last 12 monthsAll production apps

Common failure patterns

  • Development store in production: Secret Manager files, a committed .env or development credentials copied onto a server because they worked locally. See Environment Variables and .env Files.
  • Key next to the ciphertext: master.key or ENCRYPT_KEY committed beside credentials.yml.enc or {cipher} values, or written into a Dockerfile ENV line, which turns encryption into obfuscation.
  • One key for every environment: a single master key or Config Server key decrypting development and production alike, so every developer laptop is a path to production values.
  • Signing keys on developer machines: framework and token signing keys copied to laptops outside a managed store, and not rotated when the people who held them leave. In the Coupang breach, a former engineer used a token signing key that was never revoked or rotated after his departure to forge customer access tokens.
  • Static bootstrap secret: moving to a vault but authenticating with a long-lived token or client secret in an environment variable, which recreates the original problem one level up. See the Secret Zero Bootstrap Guide.
  • Cached values after rotation: the Key Vault provider caches until reload, and Spring and Rails read most configuration at boot, so a rotated secret is ignored until restart unless reload is designed in.

Framework mapping

FrameworkReferenceHow it applies
NIST SP 800-53 Rev 5IA-5(7) No Embedded Unencrypted Static AuthenticatorsNo passwords or keys in source, properties files or images
NIST SP 800-53 Rev 5SC-12 Cryptographic Key Establishment and Management; SC-28 Protection of Information at RestMaster keys, encrypt.key and keystores managed as cryptographic keys
NIST SP 800-53 Rev 5CM-6 Configuration SettingsFail-closed settings such as require_master_key and DEBUG off
NIST CSF 2.0PR.AA-01; PR.DS-01Service credentials managed by the organisation; data at rest protected
OWASP ASVS 5.0V13.3.1; V13.3.2A secrets management solution for backend secrets; least privilege on secret access
MITRE ATT&CKT1552.001 Credentials In FilesAdversaries search files and repositories for keys such as master.key and properties passwords

Practitioner checklist

  • Inventory every framework root key (master.key, RAILS_MASTER_KEY, encrypt.key, keystores, the app's vault credential) and give each an owner.
  • Confirm no development store (secrets.json, development credentials, .env) is used in any production deployment.
  • Use per-environment Rails credentials and separate key vaults per app and environment.
  • Restrict Spring Cloud Config /encrypt and /decrypt to administrators, and prefer an RSA keystore over a shared symmetric key.
  • Run manage.py check --deploy in CI for Django and enable config.require_master_key for Rails.
  • Document a fallback-based rotation for SECRET_KEY, secret_key_base and Data Protection keys and test it in staging.
  • Authenticate apps to the secrets manager with managed or workload identities, not static tokens.
  • Scan repositories, history and images for framework key files, and rotate anything found.
  • Design for reload or rolling restart so rotated secrets take effect promptly.

Standards and references

Related NHI Mgmt Group resources: Secrets Management Guide · Ruby on Rails Security Guide · ASP.NET Core Security Guide · Spring Boot Actuator and Management Endpoint Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 14 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.