anfra docsAlpha
Self-host

Authentication

Put a login in front of a self-hosted anfra project, with the image's built-in login or your own proxy such as Tailscale or Cloudflare Access.

anfra serve has no built-in authentication. To control who can reach a self-hosted project, put an authenticating proxy in front of it. The proxy signs people in on every request, and forwards only signed-in traffic to anfra.

The anfra-hosting image comes with one built in. You can use it, or turn it off and put your own proxy in front:

Built-in loginYour own proxy
Signs people in withUsernames and passwords, or Google and GitHub accountsYour proxy: Tailscale, Cloudflare Access, or any authenticating proxy
Set up withLOGIN_USERS, or a Google or GitHub appNo login settings, plus the proxy
Coding agents sendA password headerWhat your proxy asks for, such as a service token

The built-in login turns on when you set LOGIN_USERS, or a Google or GitHub app. With neither, anfra starts without a login, and its logs warn that anyone who can reach the address can use anfra. If a login setting is there but wrong, anfra doesn't start, and its logs say what to fix.

Authentication controls who can reach the deployment. It does not scope what each user sees. Every user who signs in is served the same apps, queried with the single database user in ANFRA_DATA_SOURCES. Give anfra a read-only database user. permission blocks in your datasets pass validation but aren't applied: every query returns every row. For a role per person, publish to anfra BI Cloud. Its roles decide what each member can do, not which rows they see.

Built-in login

The built-in login in the anfra-hosting image
  • People — Open the link in a browser and sign in on the login page
  • Coding agents — Connect to /mcp and send a password header with each request
  • Your host — Render, Fly.io, your own server... It provides HTTPS
  • anfra-hosting container
  • Caddy — The only entry point. /health goes straight to anfra
  • tinyauth — The login page. Checks every request
  • anfra serve — Data Apps, queries and the MCP server
  • people → host (Sign in)
  • agents → host (Password header)
  • host → caddy (HTTPS)
  • caddy → tinyauth (Signed in?)
  • caddy → anfra (Yes)

The image runs tinyauth, an open-source login page, next to anfra serve. Caddy is the only entry point in the container: it lets /health through without a login, and checks every other request with tinyauth before passing it to anfra. Your host provides HTTPS. Sign-in uses a secure cookie, so it only works over HTTPS, on the address in PUBLIC_URL.

Usernames and passwords

Set LOGIN_USERS to name:password pairs separated by commas:

maria:a-long-password,lee:another-long-password,agent:a-third-long-password

Give each person their own pair, and one to your coding agent. A password can't contain a comma.

To keep plain passwords out of your host's settings, use bcrypt hashes instead. tinyauth makes one:

docker run --rm -it ghcr.io/tinyauthapp/tinyauth:v5.2.0 user create --interactive

It prints a line such as maria:$2a$10$.... Use that pair in LOGIN_USERS. In a Docker Compose file, write each $ as $$.

Google or GitHub accounts

People can sign in with their Google or GitHub account instead of a password.

1. Create an OAuth app

In the Google Cloud console: Create credentials > OAuth client ID, with the application type Web application. Add this Authorized redirect URI:

https://<your-address>/api/oauth/callback/google

2. Add the app's keys

Copy the client ID and client secret from the app you created, and add them as environment variables on your host:

KeyValue
LOGIN_GOOGLE_CLIENT_IDThe Google app's client ID
LOGIN_GOOGLE_CLIENT_SECRETThe Google app's client secret
LOGIN_GITHUB_CLIENT_IDThe GitHub app's client ID
LOGIN_GITHUB_CLIENT_SECRETThe GitHub app's client secret

Add the Google pair, the GitHub pair, or both.

3. Choose who can sign in

Add LOGIN_ALLOWED_EMAILS. It is required: without it, any Google or GitHub account could sign in, so anfra doesn't start.

Specific people, with emails separated by commas:

Everyone at your company, with a pattern between slashes:

/@example\.com$/

Everyone at your company, plus one outside email:

/@example\.com$|^lee@gmail\.com$/

4. Keep a user for your coding agent

Coding agents can't sign in with Google or GitHub. Keep one user for them in LOGIN_USERS, for example agent:a-long-password.

Sign-ins

A sign-in lasts a day. People also sign in again after each redeploy, and each time the host wakes the container from sleep. People sign out at /logout. The login page's Forgot your password? link tells them to ask whoever set up anfra.

To add or remove someone, or change a password, edit the variables and redeploy. Send each teammate the link and their own password through a password manager, not chat or email.

Your own proxy

Your own proxy in front of anfra
  • People — Sign in with your identity provider, or are on your tailnet
  • Coding agents — Send a service token, or are on your tailnet
  • Your proxy — Tailscale, Cloudflare Access, or any authenticating proxy
  • anfra-hosting container, LOGIN_DISABLED=true
  • Caddy — Passes every request to anfra
  • anfra serve — Data Apps, queries and the MCP server
  • people → proxy (Sign in)
  • agents → proxy (Token)
  • proxy → caddy (Only signed-in traffic)
  • caddy → anfra

To sign people in with your organization's identity provider, or to keep anfra on a private network, put your own proxy in front and turn off the built-in login.

1. Restrict network access to the proxy

Run anfra on a private network or a port that is not publicly routable, so the proxy is the only path to it. On your own server, publish the port on 127.0.0.1 only. A directly reachable deployment with the login disabled is open to anyone who finds its address.

2. Leave the built-in login off

Don't set LOGIN_USERS or a Google or GitHub app. anfra then starts without a login. Anyone who can reach the address can use anfra and query your data, so never do this on an address that is open to the internet without a proxy in front.

3. Configure the proxy

Any authenticating proxy works. Commonly used options include:

ProxySigns people in withNotes
TailscaleYour tailnetPrivate network, nothing public
Cloudflare AccessGoogle Workspace, Microsoft Entra ID, Okta, email codesManaged service, no proxy to operate
oauth2-proxyAny OIDC providerOpen source, runs next to anfra
PomeriumOIDC and SAML providersOpen source, policies per group
Authelia / AuthentikTheir own user storeNo external provider needed
Google Cloud Identity-Aware ProxyGoogle WorkspaceFor anfra on Cloud Run

Tailscale

Tailscale keeps anfra private: only people and machines on your tailnet can reach it, and nothing is public. Start from anfra on your own server, with Tailscale installed and logged in on it. Everyone who opens anfra, and every machine that runs a coding agent, must be on your tailnet.

In compose.yaml, set the server's tailnet address, and remove LOGIN_USERS:

compose.yaml
    environment:
      PUBLIC_URL: https://<machine>.<tailnet>.ts.net

Run docker compose up -d, then serve it over HTTPS:

tailscale serve --bg 8080

The first time, Tailscale asks you to enable HTTPS certificates for your tailnet. With --bg, it keeps serving after a reboot. Open https://<machine>.<tailnet>.ts.net from any device on the tailnet.

  • Everyone who can reach the server on your tailnet can use anfra. To limit it to a group, restrict access to the server in your tailnet's access policy.
  • tailscale serve status shows what is served, and tailscale serve reset stops it.
  • tailscale funnel would publish the server on the internet. If you use it, keep the built-in login on.

Cloudflare

Cloudflare Tunnel publishes anfra on your own domain without opening a port, and Cloudflare Access signs people in with your identity provider. It needs a domain on Cloudflare. Start from anfra on your own server.

1. Create a tunnel. In Cloudflare Zero Trust: Networking > Tunnels > Create a tunnel. Pick your server's operating system, and run the install command it shows on the server. Open the tunnel's Routes tab, click Add route, and choose Published application. Pick a subdomain and domain, for example data.example.com, and set the Service URL to http://localhost:8080.

2. Protect it with Access. In Zero Trust: Access controls > Applications > Create new application > Self-hosted and private. Add data.example.com as the public hostname, and add an Allow policy for the people who should get in, for example everyone with an email at your company.

3. Leave the built-in login off. In compose.yaml, set PUBLIC_URL: https://data.example.com, remove LOGIN_USERS, and run docker compose up -d.

4. Give coding agents a service token. Agents can't use a browser sign-in. In Zero Trust: Access controls > Service credentials > Service Tokens, create one, and copy its Client ID and Client Secret. On the application, add a policy with the action Service Auth that includes the token. Agents send both values as headers, see Coding agents with MCP.

  • Service tokens expire. Renew them in Service Tokens before then.
  • Quick tunnels (cloudflared tunnel --url, on a trycloudflare.com address) don't support streaming, so coding agents can't connect through them.
  • Without Access, keep the built-in login on. A tunnel alone makes anfra public on your domain.

Coding agents with MCP

Coding agents connect to https://<your-address>/mcp. They can't sign in on a page, so they send a header with each request:

  • Built-in login: Authorization: Basic <value>, from a user in LOGIN_USERS. Print the value with printf 'agent:<agent-password>' | base64 | tr -d '\n'; echo. An agent without a valid password gets 401, not the login page.
  • Tailscale: no header. The agent's machine must be on your tailnet.
  • Cloudflare Access: two headers, CF-Access-Client-Id: <client-id> and CF-Access-Client-Secret: <client-secret>, instead of Authorization.

Treat the header like an API key: anyone with it can query your data. The examples use the built-in login's header.

claude mcp add --transport http anfra https://<your-address>/mcp \
  --header "Authorization: Basic <value>"

For more than one header, repeat --header.

These files hold the agent's password. Keep them out of git.

On this page