Secrets
Set, list, delete, and type Rayfin secrets so functions can read server-only values without exposing them to client code.
Rayfin stores application secrets on the deployed Fabric app so functions can read server-only values without shipping them to the browser.
Warning
A publishable key (RAYFIN_PUBLIC_PUBLISHABLE_KEY) is safe in client code because it identifies the app. A secret value is a credential. Never put a secret in RAYFIN_PUBLIC_*, frontend code, source control, logs, or chat.
Deploy before managing secrets
Secrets attach to an existing Fabric app deployment:
npx rayfin upWithout an active deployment, secret commands fail with:
❌ No remote endpoint configured
Run 'rayfin up' first to deploy your item to Fabric.Set one secret interactively
npx rayfin secret set OPENAI_KEY --describe="OpenAI API key for summarizeText"The CLI prompts for the value with masked input. The value is sent to the deployed item and is not written to disk.
--describe must use equals syntax. This is rejected:
npx rayfin secret set OPENAI_KEY --describe "OpenAI API key"The exact error is:
❌ --describe requires the = syntax: --describe="My description"
Use '--describe="My description"' instead of '--describe "My description"'.Descriptions are stored as secret metadata in rayfin/rayfin.yml:
secrets:
- name: OPENAI_KEY
description: OpenAI API key for summarizeTextThe CLI then regenerates secrets.generated.ts in the src/ folder of your functions package (services.functions.path, so rayfin/functions/src/ by default), printing its path when the file changes, so functions can read the secret as ctx.Secrets.OPENAI_KEY.
Set a secret from stdin
Use --stdin for scripts and CI jobs that can supply the value securely:
printf '%s' "$OPENAI_KEY" | npx rayfin secret set OPENAI_KEY --stdinIf stdin is empty, the CLI fails with:
No secret value was provided on stdin.Bulk-set secrets from a dotenv file
npx rayfin secret set --env-file rayfin/.env.secretsOPENAI_KEY=sk-local-authoring-value
DATABASE_PASSWORD='quoted values are unwrapped'Blank lines and # comments are ignored. Keys are used verbatim as secret names. Do not commit .env.secrets.
Like a single secret set, a bulk set records every uploaded name in rayfin/rayfin.yml — names only, without descriptions — and regenerates secrets.generated.ts, so each one is available as ctx.Secrets.<KEY>. In 1.x, --env-file uploaded the values without recording names or updating types. Changed in 2.0
✅ Secrets applied (2/2 uploaded)
📝 Added secret metadata for 2 secret(s) to rayfin/rayfin.yml
🧬 Updated secret types in rayfin/functions/src/secrets.generated.tsThe metadata line appears only when names were added, and the types line only when the generated file changed. The path is relative to the directory you run the command from.
Invalid combinations fail before any upload:
| Invalid command | Error |
|---|---|
rayfin secret set NAME --env-file rayfin/.env.secrets | ❌ Do not pass <name> with --env-file |
rayfin secret set --stdin --env-file rayfin/.env.secrets | ❌ --stdin and --env-file cannot be used together |
rayfin secret set --env-file missing.env | ❌ Env file not found: <path> |
rayfin secret set --env-file empty.env | ❌ No KEY=VALUE entries found in <path> |
Rotate a secret
Run secret set again with the same name. The new value replaces the old value.
npx rayfin secret set OPENAI_KEY --describe="OpenAI API key for summarizeText"Deployed functions can cache secret values for a few minutes, so a rotated value can take a few minutes to reach them. Keep the old credential valid until the new one is in use. Changed in 2.0
List secrets
npx rayfin secret listThe command returns names and timestamps only. Values are never returned.
Use JSON output for scripts:
npx rayfin --json secret listDelete a secret
npx rayfin secret delete OPENAI_KEY
npx rayfin secret delete OPENAI_KEY --yesDeleting a secret removes its metadata from rayfin.yml and regenerates the typed secrets file so stale ctx.Secrets.OPENAI_KEY references stop compiling.
If the secret is not found, the CLI reports:
❌ Secret "OPENAI_KEY" was not found. It may already be deleted, or secret management may not be enabled for this item.
Run 'rayfin secret list' to see existing secrets.Read secrets from functions
Functions read declared secrets through ctx.Secrets:
import {
UserDataFunctions,
type RayfinContext,
} from '@microsoft/fabric-user-data-functions';
export type AppSchema = Record<string, never>;
const udf = new UserDataFunctions();
udf.func(
'hasOpenAiKey',
async (ctx: RayfinContext<AppSchema>): Promise<boolean> => {
return ctx.Secrets.OPENAI_KEY.length > 0;
},
[],
);See Secrets in functions for the generated secrets.generated.ts model and local development fallback.
Troubleshooting
The command refuses to prompt
Symptom: rayfin secret set <NAME> exits instead of asking for a value.
Cause: stdin is not a TTY or CI=true is set.
Fix: run it from an interactive terminal, or pipe the value with --stdin.
Authentication failed
Symptom: the command reports that it could not acquire an authentication token.
Cause: you are not signed in, your cached sign-in expired, or the machine cannot use the OS keychain.
Fix: run npx rayfin login. In containers or restricted environments, add --encryption-fallback-enabled if login reports a keychain error.
Permission denied
Symptom: setting, listing, or deleting a secret fails with a permission error.
Cause: the signed-in account does not have access to the target Fabric workspace or app item.
Fix: run npx rayfin login again and choose an account with workspace access. Confirm the active deployment with npx rayfin up status.
A function cannot read a declared secret
Symptom: a function throws No value available for secret '<NAME>'. Ensure it is declared in rayfin.yml and set with 'rayfin secret set'.
Cause: the name exists in rayfin.yml, but no deployed secret value or local process.env value is available.
Fix: run npx rayfin secret set <NAME> for deployed functions, or add a local-only value under Values in rayfin/functions/local.settings.json while debugging locally.
A function still reads the old value
Symptom: after rayfin secret set, a deployed function keeps using the previous value.
Cause: deployed functions can cache secret values for a few minutes. Changed in 2.0
Fix: wait a few minutes, then invoke the function again. Keep the old credential valid until then.
In my Rayfin 2.0 project, configure a server-side secret named <NAME>.
First ensure the app has been deployed with `npx rayfin up`. Set the secret with `npx rayfin secret set <NAME> --describe="<purpose>"`, using the masked prompt unless I explicitly provide a secure stdin source. Never ask me to paste the secret value into chat, and never put it in source code or a RAYFIN_PUBLIC_* variable. Confirm the name appears in `npx rayfin --json secret list`, check that rayfin/rayfin.yml has a secrets entry with only name and description, confirm the CLI regenerated secrets.generated.ts in the functions package's src/ folder, and show how a function reads it with `ctx.Secrets.<NAME>`.Deployment pipelines
Prepare Rayfin apps for Microsoft Fabric Deployment Pipelines by resolving runtime config instead of baking stage values into the bundle.
Observability
Send a deployed Fabric app's browser telemetry to its own Application Insights resource and query it with rayfin telemetry — enable, deploy, instrument, verify, investigate, and disable.