🚀Feature request: Allow easy overriding of secrets-store in .dev.vars
#13268
Replies: 5 comments
-
|
Could you expand on your proposed |
Beta Was this translation helpful? Give feedback.
-
|
@penalosa Just like when developing hyperdrive locally, you can directly set the local database connection string through the I think secrets-store is also the best, because I am very distressed now. I have three related workers, and I use secrets-store to facilitate the management of some keys. My compatible code in a single worker is as follows: type ENV = { xxxxx_KEY: string | {get: () => Promise<string>} }
const key = typeof env.xxxxx_KEY === "string" ? env.xxxxx_KEY : await env.xxxxx_KEY.get();This is very convenient for local development, but when encountering multiple collaborations, for example: wrangler dev --cwd /workers/a -c wrangler.jsonc -c ../b/wrangler.jsonc -c ../c/wrangler.jsoncNeed to start a worker, but the configuration of a worker in wrangler.jsonc: "services": [
{ "binding": "A", "service": "a-worker" },
{ "binding": "B", "service": "b-worker" },
]Since a and b depend on different secrets-stores, the previous compatible code is no longer available, and child workers are forced to enable local secrets-store binding. It would be much simpler if it was allowed to override in SECRETS_STORE_SECTET_xxxxx_KEY=xxxThis allows the bound secrets-store to be directly overwritten during local development, and the local one will be used when the .dev.vars of the dependent worker also has the corresponding configuration.
Now secrets-store uses the |
Beta Was this translation helpful? Give feedback.
-
|
Now I have configured more than a dozen different secrets-stores in my account, and they are bound to one or more by different workers. But some workers depend on other workers, and they together form a business logic or workflow. This causes a lot of trouble for using secrets-store locally and starting local development with multiple So I hope to be able to configure the secrets-store for local development directly in |
Beta Was this translation helpful? Give feedback.
-
|
I ran into the same challenge that setting up local secret store for local development is unnecessarily difficult compared to the I scripted a workaround:
@ Cloudflare team: It would be great if .secretsMake sure to .gitignore this! KEY="top-secret"
ANOTHER="super-secret"load-secret-store.shNote this starts with a clean aka empty local secret store by removing all local stores using a simple #!/bin/bash
# Update secrets in local Cloudflare Secret Store
set -e
SECRET_STORE_ID="$1"
FILE="$2"
if [ -z "$SECRET_STORE_ID" ] || [ -z "$FILE" ]; then
echo "Usage: load-secret-store.sh <secret-store-id> <secrets-file>"
echo
echo "Load secrets from <secrets-file> into a local Cloudflare wrangler secret store."
echo
echo "<secret-store-id> Cloudflare secret store ID (same as in production)"
echo
echo "<secrets-file> Properties file with secrets in the following format:"
echo
echo " # comment"
echo " ONE=\"top-secret\""
echo " TWO=\"super-secret\""
exit 1
fi
# Clean local secret store
rm -rf .wrangler/state/v3/secrets-store
while IFS='=' read -r key value; do
# Skip empty lines and comments
if [[ -z "$key" || "$key" =~ ^# ]]; then
continue
fi
# Trim whitespace
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# 'secret create' does create OR update
echo "$value" | WRANGLER_LOG=error npx wrangler secrets-store secret create $SECRET_STORE_ID --scopes workers --name "$key" > /dev/null
done < "$FILE"package.jsonI am using it with these npm run scripts in my {
"scripts": {
"predev": "./load-secret-store.sh {SECRET_STORE_ID} .secrets",
"dev": "wrangler dev"
},
"devDependencies": {
"wrangler": "^4.31.0"
}
}Local dev server is then started with |
Beta Was this translation helpful? Give feedback.
-
|
Tried using remote secrets store and local .dev.vars - and it turned out - when running it locally, the secrets store [local] binding overrides the .dev.vars variable. What's the best practice here? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the solution
In the local workers development process, when a worker depends on other workers, and the dependent worker depends on secrets-store secret, this will cause great trouble to the local development process.
When not depending on other workers, we can create an env variable and determine whether it is a string or an Object with a
get()method when using it, for example:But this is not a panacea. When one of my workers needs to depend on another worker, and the other worker depends on SecretsStoreSecret, problems arise. Even if I declare
{ "binding": "API", "service": "api-core", "environment": "dev" },, it doesn't work at all. Always appears:And
wrangler secrets-store secretis very inconvenient, it needs to be configured once for each worker. The essence of secrets-store is to share secrets between workers.**Just like Hyperdrive, we can use special variables to override bindings. This can be very useful during development.
Especially when we need to make changes to multiple workers at the same time.**
Beta Was this translation helpful? Give feedback.
All reactions