Secrets and API keys

Four ways to give a provider its API key without putting the key in git. Server environment, CI push, Vault, or set by hand.

The settings file never contains a key. It contains a secret reference: a small object that tells Lunnoa where to find the value. The same shape is used wherever the file takes a secret, and each provider chooses its own source.

json
"apiKey": { "source": "serverEnv", "name": "OPENAI_API_KEY" }

Choose a source

SourceWhere the value livesWhen Lunnoa reads itBest for
serverEnvAn environment variable on the Lunnoa serverAt use time. Never stored in the Lunnoa databaseKubernetes secrets, Docker secrets, variables injected by your platform
envA secret in your CI environment (GitHub or GitLab)Pushed by the pipeline on deploy, then stored encryptedTeams that keep keys in CI and do not want to touch the server
vaultHashiCorp Vault (KV v2)At use time, cached in memory for a few minutesRegulated installs, rotation, central audit of secret access
manualAdmin Space or the APISet by a personA quick start, a one-off key, or a key your pipeline must never see

If you are unsure, start with serverEnv. It needs no extra setup and the key never touches git or CI.

serverEnv

json
{
  "name": "Company OpenAI",
  "provider": "openai",
  "apiKey": { "source": "serverEnv", "name": "OPENAI_API_KEY" },
  "models": ["gpt-6-luna"]
}
KeyRules
nameThe name of an environment variable on the server. Uppercase letters, digits, and underscores, starting with a letter, up to 128 characters

The variable must be set on the server when the file is applied, or the pull fails. Lunnoa reads the value from the server environment each time it needs it and does not store it. To rotate the key, change the variable and restart the server.

Each environment needs its own value. A provider that works in development fails the staging promotion if staging does not have the variable yet.

env

json
{
  "name": "Company OpenAI",
  "provider": "openai",
  "apiKey": { "source": "env", "name": "OPENAI_API_KEY" },
  "models": ["gpt-6-luna"]
}
KeyRules
nameThe name the pipeline pushes the secret under. Same character rules as serverEnv

With env, your pipeline sends the value to Lunnoa. The deploy workflow reads a secret called OPENAI_API_KEY from the GitHub environment and posts it to the secrets endpoint before it asks the install to reload. Lunnoa stores it encrypted.

push-secrets.sh
curl --fail-with-body -X POST \
  -H "Authorization: Bearer your_machine_user_token_here" \
  -H "Content-Type: application/json" \
  -d '{"secrets": {"OPENAI_API_KEY": "sk-..."}}' \
  https://your-deployment.example/api/admin/installation-settings/secrets

Use a machine user token. A workspace API key (lna_...) is not accepted. The response lists the names that were stored and never repeats a value.

If a reference uses env and no value was pushed for that name, the reload fails. To rotate the key, change the CI secret and run the deploy again.

vault

json
{
  "name": "Company OpenAI",
  "provider": "openai",
  "apiKey": { "source": "vault", "path": "lunnoa/prod/openai", "key": "api_key" },
  "models": ["gpt-6-luna"]
}
KeyRequiredRules
pathYesThe secret path inside the KV v2 mount, for example lunnoa/prod/openai. No leading slash and no ... Up to 255 characters
keyYesThe field inside that secret. Up to 128 characters
mountNoThe KV v2 mount. Defaults to LUNNOA_VAULT_MOUNT

How Lunnoa connects to Vault

The Vault connection is configured once on the server, with environment variables. See Environment variables. The settings file only holds the path.

Auth methodUse it when
KubernetesLunnoa runs in a cluster. The pod's service account logs in to Vault
AppRoleLunnoa runs anywhere else and you can place a role id and secret id on the server
Cloud IAM (AWS, GCP, Azure)Lunnoa runs on a cloud VM or service with an attached identity
JWT/OIDCYou already issue workload identity tokens

Give the Lunnoa role a read-only policy on the paths it needs and nothing else.

How the value is used

  • Lunnoa reads the secret when a model call needs it and keeps it in memory only for a short time (five minutes by default). It never writes the value to the database.
  • If the provider answers 401 or 403, Lunnoa fetches the secret again once and retries. A key you rotated in Vault is picked up without a restart.
  • If Vault cannot be reached and there is no cached value, the call fails. Lunnoa does not fall back to another source.

manual

json
{
  "name": "Company OpenAI",
  "provider": "openai",
  "apiKey": { "source": "manual" },
  "models": ["gpt-6-luna"]
}

manual has no other keys. The file creates the provider, and a person adds the key in Admin Space → AI configuration or through the API. Until then the provider shows Secret missing and cannot be used.

A pull never overwrites or clears a manual key. The secret field stays editable in Admin Space even though the rest of a file-owned provider is read-only.

Rules for every source

  • apiKey must be a secret reference object. A plain string such as "apiKey": "sk-..." is rejected and the whole pull fails.
  • Leave apiKey out for providers that need no key, such as ollama.
  • Secret values never appear in the file, in logs, in the reload response, or in Admin Space. Admin Space only shows whether a secret is set or missing.
  • Different providers in one file can use different sources.
  • A secret reference points to a value. It does not copy it, so changing the source of a provider changes where the next call reads from.

Related