Skip to content
safran

Type to search. Enter opens the first result.

    Secrets

    A profile names its secrets; it never contains them. This page explains the rule, where the values come from in the CLI and in the SDK, how the .env file is parsed, and when a missing token is reported.

    id: jira
    type: jira
    url: https://acme.atlassian.net
    email_env: JIRA_EMAIL      # the name of a variable
    token_env: JIRA_TOKEN      # not the token
    projects: [PAY, MOB, WEB]
    # /work/acme/.env  (next to /work/acme/safran.yaml, never committed)
    JIRA_EMAIL=dev@acme.test
    JIRA_TOKEN=paste-the-api-token-here

    The rule

    Every connector field that needs a secret ends in _env and holds the name of an environment variable. The connector asks for the value by that name at the moment it needs it.

    Two schemas enforce this, so a secret cannot get into a valid profile by accident:

    /**
     * Name of an environment variable. Secrets themselves never belong in a profile, and a pasted
     * token fails this pattern, which is the point.
     */
    export const envVarName = z
      .string()
      .regex(/^[A-Z][A-Z0-9_]*$/, "must be the NAME of an environment variable (e.g. JIRA_TOKEN), not the secret itself");
    
    /**
     * Base URL of a service in a profile: http or https, and nothing a base URL should not carry.
     * Credentials in a URL would put a secret into the profile; a query string or fragment does not
     * survive being joined with a path.
     */
    export const httpUrl = z.url().refine((value) => {
      try {
        const url = new URL(value);
        return (url.protocol === "https:" || url.protocol === "http:") && url.username === "" && url.password === "" && url.search === "" && url.hash === "";
      } catch {
        return false;
      }
    }, "must be a plain http(s) URL without credentials, query string or fragment");

    defined in packages/kit/src/schema.ts

    • _env fields accept only a variable name: an upper-case letter followed by upper-case letters, digits and underscores. A pasted token contains lower-case letters, dashes or dots and fails. So does an e-mail address, and so does a lower-case variable name such as jira_token.
    • URL fields accept only a plain base URL: http or https, without a user name or password, without a query string and without a fragment. https://dev:secret@acme.atlassian.net is rejected.

    Both failures are reported with the path of the field:

    $ safran profile check
    ✘ The profile has 2 configuration problems:
      - trackers.0.email_env: must be the NAME of an environment variable (e.g. JIRA_TOKEN), not the secret itself
      - trackers.0.token_env: must be the NAME of an environment variable (e.g. JIRA_TOKEN), not the secret itself
    → Fix these entries in the profile. `safran plugins` lists the available types and their fields.

    Because of this, the profile can be read aloud, pasted into a ticket or shown to an agent. The get_company_profile tool returns the company's shape, not its connection settings.

    Where the values come from in the CLI

    The CLI builds the environment for a command from two places:

    1. The environment of your shell.
    2. A file named .env in the same directory as the profile file.

    The shell wins. A variable that is already set is never replaced by the file, even when it is set to an empty string. An empty value counts as "not set" when a connector asks for it, so export JIRA_TOKEN= in a shell profile hides the value in .env and the connector then fails with AUTH_MISSING. Unset the variable instead.

    Only that one file is read: not .env.local, not a .env in the directory you run the command from (unless the profile is there). The same applies to safran mcp, so the MCP server finds its tokens next to the profile whichever project Claude Code is opened in.

    safran profile check shows which variables the profile names, whether each is set, and which fields use it. It prints names and never values:

    $ safran profile check
    ✔ safran.yaml is valid
    
      company      acme
      languages    tickets tr, code en
      trackers     jira
      code hosts   azure (azure-repos)
      doc sources  wiki (confluence)
      groups       backend (2), mobile (2), frontend (2) — 6 repos
      teams        Payments, Mobile, Web
      glossary     2 terms
      conventions  2
      embeddings   ollama (bge-m3)
      data         data
    
    ! Low-confidence team mappings to confirm by hand: Mobile
      → Check their `projects` and `repos`, then delete `confidence: low` from the entry.
    
    Environment variables
      name              status   used by
      AZURE_DEVOPS_PAT  set      code.hosts.azure.token_env
      CONFLUENCE_TOKEN  not set  docs.wiki.token_env
      JIRA_EMAIL        set      trackers.jira.email_env, docs.wiki.email_env
      JIRA_TOKEN        set      trackers.jira.token_env
    ! CONFLUENCE_TOKEN is not set; the connectors that use it will fail when called.
      → Export them in your shell, or put them in a .env file next to the profile.
    
    Connectors were built, not called. `safran profile check --online` makes one call to each.

    How the .env file is parsed

    The parser is Safran's own and deliberately small.

    LineResult
    JIRA_TOKEN=abcabc. Spaces around = and around the value are dropped.
    export JIRA_TOKEN=abcThe same; a leading export is allowed.
    JIRA_TOKEN=abc # noteabc. An unquoted value ends at a # that follows whitespace.
    JIRA_TOKEN=abc#defabc#def. A # without whitespace before it is part of the value.
    JIRA_TOKEN='a b # c'a b # c. Single quotes are literal; nothing inside is interpreted.
    JIRA_TOKEN="a\tb"a, a tab, b. Double quotes understand \n, \t, \r, \" and \\.
    # comment, an empty lineSkipped.
    Any line that is not NAME=valueSkipped, without an error.

    Further rules:

    • A name starts with a letter or an underscore and continues with letters, digits and underscores.
    • A value cannot span lines. There is no $OTHER interpolation: a dollar sign is a dollar sign.
    • When a name appears twice in the file, the later line wins.
    • A quoted value whose closing quote is missing runs to the end of the line.
    • A byte-order mark at the start of the file and Windows line endings are accepted.

    Where the values come from in the SDK

    createSafran does not read any .env file. It resolves names in process.env, or in the object you pass as the env option. Pass env to take secrets from wherever you keep them. Only the names the profile mentions are ever looked up:

    secrets.ts
    import { createSafran } from "@safran/core";
    
    /** Reads one secret from a file mounted by your secret manager. */
    async function readSecret(name: string): Promise<string> {
      return (await Bun.file(`/run/secrets/${name}`).text()).trim();
    }
    
    await using safran = await createSafran({
      profile: "/work/acme/safran.yaml",
      env: {
        JIRA_EMAIL: "dev@acme.test",
        JIRA_TOKEN: await readSecret("jira-token"),
        AZURE_DEVOPS_PAT: await readSecret("azure-devops-pat"),
      },
    });
    
    const ticket = await safran.tickets.get("PAY-1423");
    console.log(ticket.title);

    A plugin never reads process.env itself. It receives a context whose secret(name) looks the name up in that environment, so the env option is the single place values enter.

    A missing token fails at first use, not at startup

    Building a connector reads no secret. createSafran, safran profile check and safran status all succeed with nothing set. The error comes from the first call that needs the token, and it names the variable:

    $ safran ticket PAY-1423
    ✘ Environment variable JIRA_TOKEN is not set
    → Export JIRA_TOKEN in your shell, or put it in the .env file next to the profile.

    In code it is a SafranError with the code AUTH_MISSING; the variable name is in details:

    auth-missing.ts
    import { createSafran, isSafranError } from "@safran/core";
    
    await using safran = await createSafran({ profile: "/work/acme/safran.yaml", env: {} });
    
    try {
      await safran.tickets.get("PAY-1423");
    } catch (error) {
      if (!isSafranError(error, "AUTH_MISSING")) throw error;
      console.error(error.message); // Environment variable JIRA_TOKEN is not set
      console.error(error.details?.variable); // JIRA_TOKEN
    }

    This is deliberate: you can validate a profile on a machine that has no tokens (in CI, or before a colleague has created theirs), and an instance that only searches code never needs the tracker token at all.

    A token that is set but wrong is a different error, AUTH_FAILED, raised when the service answers 401 or 403. safran profile check --online and safran doctor are the two commands that find it before you do. See Errors.

    What to keep out of version control

    The repository's own .gitignore ignores safran.yaml, .env, .env.* (except .env.example) and data/, so a profile kept inside the Safran checkout is never committed.

    If you keep the profile in a repository of your own:

    • Never commit .env. It holds the values.
    • Never commit data/. It holds clones of your source code and an index of it.
    • The profile itself holds no secret. It does hold internal facts (project keys, repository names, URLs, team names), so treat it like any internal document.

    What Safran does with a token

    • A connector sends it to the service it is configured for, as that service's API expects.
    • Git receives credentials through the environment of the git process, not inside the clone URL, so they do not end up in a clone's configuration.
    • Error messages and hints are written to be shown to an agent: they contain no tokens and no query strings.

    Security covers the rest: untrusted text, plugin loading, the HTTP server.

    Common mistakes

    • Pasting the token into token_env. The check fails with "must be the NAME of an environment variable". Put the name there and the value in .env.
    • Putting .env next to the code instead of next to the profile. Only the profile's directory is read.
    • An empty variable exported in the shell. It shadows the file; see above.
    • A lower-case variable name. _env fields accept upper-case names only.
    • Credentials in a URL. Use the _env fields the connector provides.