Mastra Platform 推出加密機密資料功能
Introducing Encrypted Secrets for Mastra Platform
Mastra Platform 推出加密機密變數,改為在伺服器啟動時注入執行程序記憶體,而非在建置時寫入。這項功能適用於 LLM API keys、tokens 及其他敏感環境變數;私鑰保留在 KMS,已儲存的機密值在控制台和 API 不會顯示或返回,CLI 拉取亦只列出名稱。現有環境遷移前可檢視變數分類,機密值會原地加密,毋須重新輸入。
To keep our platform and users safe from future incidents, we're introducing encrypted secrets for all projects to protect your LLM API keys, tokens, and other sensitive environment variables. Plaintext secret values are never stored. With this change, secrets stay stored in our platform's key management service and are never written as plaintext to disk, container images, logs, or deploy artifacts, and, importantly, never left in a hosting provider's variable store.
Stolen inference API keys have become one of the fastest ways for attackers to monetize a breach. In October 2026, Wiz Research tracked a "Black October" stretch of security incidents across at least nine AI developer platforms, with attackers hunting stored environment variables for model access. Our own upstream service provider Railway was one of the targets, with attackers going after router and frontier lab API keys stored on their servers.
One of the key problems is that on many platforms, API keys sit in plaintext across variable stores, container images, deploy artifacts, and logs, giving hackers a host of surface areas to attack and discover keys. Combine that vulnerability with powerful, relentless AI agents, and you end up with a recipe for large scale security incidents.
How encrypted secrets work
- When you save a secret: We encrypt it with a unique encryption key and then encrypt that key using a KMS (key management service) managed public key. We store both together as one msec: value in our database. The private key stays in KMS, so database access alone cannot decrypt it.
- When your server starts: Mastra Platform injects your secret values into your running server's process memory at startup—not at build time—and only after a double-key match succeeds.
- Once a secret is saved: You can't read the value back. This is a change from how secrets have historically been accessible in our platform. Going forward, new environments will set secrets to be strictly write-only in both the Mastra Platform dashboard and API, so saved values are never displayed in the UI or returned to clients. In cases where you want a variable to be readable, you can opt that variable out of encryption.
Why startup injection matters
Baking secrets into a build leaves them in every copy of your container image. If an image, build log, deploy artifact, or hosting provider's variable store is leaked, plaintext keys are sitting right there.
With our new encrypted secrets, environment variables and other secrets stay out of builds by default. There’s a narrow exception for private-registry install tokens as they're available only during the install step and are not baked into the image. Unencrypted config variables still pass through as plaintext at build time, so public and client-side config can consume harmless environment variables.
Delivery at startup
- Split-token Authentication: The authorization token is split into two halves. Neither half is enough on its own to fetch your secrets.
- Separated encrypt and decrypt: The platform's API can encrypt secrets, while only the dedicated secrets service can decrypt them for delivery at boot.
- Audited access: Every time a secret is decrypted for a running server, that access is audited.
Using secrets day to day
Every environment variable is either a secret or config. In the dashboard, use the Secret toggle when you save a variable to mark it as a secret or as readable config.
- Write-only across tools: The dashboard and API never return saved secret values. The CLI follows the same rule:
mastra env vars pulllists secret names without writing their values into the file. - Clean rotation: To update or rotate a secret, save the new value from the dashboard. You can't read the old value back. The next time your server starts, it receives your current stored secrets—nothing is baked into an image per deploy.
Next Steps
Existing environments move to encrypted secrets in two steps: you review how your variables were classified, then their values are encrypted in place.
Review encrypted keys
Before an existing environment is switched, your variables are classified as secret or config based on what they look like. You'll see a review banner before values are encrypted, so you can review those and change any that were misclassified. You may want to keep some environment variables readable, so this is your chance to set those correctly.
Migrating to encrypted secrets
- You won’t need to re-enter existing secret values as they will be encrypted in place when your environment migrates.
- You also don't need to change your application code if it already reads environment variables at runtime.
- Once switched, a new deploy or start makes your running app fetch secrets from the platform's KMS at boot, and plaintext values are no longer left in the hosting provider's variable store.
- From then on, treat secrets as write-only: to change one, save a new value.
For more information, see our updated platform docs on encrypted secrets.
來源:Mastra Blog · mastra.ai