Zie619/n8n-workflows · warning · HTTPException

Reindexing endpoint is disabled. Set ADMIN_TOKEN environment

Error message

Reindexing endpoint is disabled. Set ADMIN_TOKEN environment variable to enable.

What it means

A 503 from POST /api/reindex raised when the ADMIN_TOKEN environment variable is not set on the server. The endpoint is deliberately disabled-by-default: without a configured token there is no way to authenticate the admin action, so the handler refuses with this message rather than allowing unauthenticated reindexing. It is a configuration state, not a transient failure — retrying without changes will always return 503.

Source

Thrown at api_server.py:596

    admin_token: Optional[str] = Query(None, description="Admin authentication token"),
):
    """Trigger workflow reindexing in the background (requires authentication)."""
    # Security: Rate limiting
    client_ip = request.client.host if request.client else "unknown"
    if not check_rate_limit(client_ip):
        raise HTTPException(
            status_code=429, detail="Rate limit exceeded. Please try again later."
        )

    # Security: Basic authentication check
    # In production, use proper authentication (JWT, OAuth, etc.)
    # For now, check for environment variable or disable endpoint

    expected_token = os.environ.get("ADMIN_TOKEN", None)

    if not expected_token:
        # If no token is configured, disable the endpoint for security
        raise HTTPException(
            status_code=503,
            detail="Reindexing endpoint is disabled. Set ADMIN_TOKEN environment variable to enable.",
        )

    if admin_token != expected_token:
        print(f"Security: Unauthorized reindex attempt from {client_ip}")
        raise HTTPException(status_code=401, detail="Invalid authentication token")

    def run_indexing():
        try:
            db.index_all_workflows(force_reindex=force)
            print(f"Reindexing completed successfully (requested by {client_ip})")
        except Exception as e:
            print(f"Error during reindexing: {e}")

    background_tasks.add_task(run_indexing)
    return {"message": "Reindexing started in background", "requested_by": client_ip}

View on GitHub (pinned to 94007c1445)

Solutions

  1. Set ADMIN_TOKEN in the server's environment (export ADMIN_TOKEN=... before uvicorn, or add it to the service/container env).
  2. Restart the API process so it picks up the variable.
  3. Retry as POST /api/reindex?admin_token=<token> (token is read from the query parameter).
  4. Use a long random value and pass it over a trusted channel; the check is a direct equality comparison, not constant-time.

Example fix

# before
uvicorn api_server:app  # no ADMIN_TOKEN -> 503

# after
export ADMIN_TOKEN="$(openssl rand -hex 32)"
uvicorn api_server:app
# then: curl -X POST 'http://host/api/reindex?admin_token=<that value>'
Defensive patterns

Strategy: try-catch

Validate before calling

import os, requests

def reindex_enabled(base):
    # cheap probe: disabled endpoint answers 503 without side effects
    r = requests.post(f'{base}/api/reindex')
    return r.status_code != 503

# or check your own server config before calling:
assert os.environ.get('ADMIN_TOKEN'), 'Set ADMIN_TOKEN before enabling /api/reindex'

Try / catch

try:
    r = client.post(f'/api/reindex?admin_token={TOKEN}')
    r.raise_for_status()
except HTTPError as e:
    if e.response.status_code == 503:
        raise SystemExit('Reindex disabled: set ADMIN_TOKEN on the server and restart, then retry')
    if e.response.status_code == 401:
        raise SystemExit('Bad admin token')

Prevention

When it happens

Trigger: Any POST /api/reindex against a server launched without ADMIN_TOKEN in its environment (fresh clone, systemd unit missing the variable, container without the env var).

Common situations: New deployments where the operator never configured the token; env vars lost when switching from shell to service manager; .env file present but not loaded into the process environment.

Related errors


AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15). Data as JSON: /api/errors/44959bb676703c58. Report an issue: GitHub.