Identity & Federation

Bearer tokens, SCRAM-SHA-256, OIDC/SAML SSO, Federated JWTs, LDAP/AD, Kerberos, and mTLS.

2 min read Security & Governance

SpydDB authenticates every connection at a single unified security gateway across SpydWire, PostgreSQL wire, HTTP/1.1, gRPC, and Embedded Web Studio:

MethodCredential FlowSupported Listeners
Static Bearer TokensAuthorization: Bearer <token> or password / DSN tokenSpydWire, HTTP, gRPC, pgwire, Studio
SCRAM-SHA-256Zero-password challenge-response (4096+ iterations, 16B+ salt)SpydWire (StartScram), pgwire, Studio
OIDC / OAuth 2.0 SSOPKCE authorization flow minting short-lived session JWTsStudio, HTTP (/v1/auth/*) -> SpydWire/gRPC
SAML 2.0 SSOIdP XML metadata + signed response verificationStudio, HTTP (/v1/auth/*) -> SpydWire/gRPC
Federated JWTsExternal IdP RS256 / ES256 / HS256 bearer validation via JWKS or secretSpydWire, HTTP, gRPC, pgwire
LDAP / Active DirectoryLDAPS bind + directory group-to-role mappingSpydWire, pgwire, HTTP
Kerberos 5 (GSSAPI)AP-REQ service ticket with anti-replay cache (AES256/AES128)SpydWire, pgwire
Mutual TLS (mTLS)Client X.509 certificate verification against tls.client_caAll TLS listeners

1. Generating SCRAM-SHA-256 Credentials#

Never store raw user passwords in server.json. Generate SCRAM verifiers via spyd-server --hash-password:

sh
printf '%s\n' "$SPYD_PASSWORD" | spyd-server --hash-password alice --iterations 600000

Place the printed verifier block inside "scram": [ ... ] in server.json.

2. Static Tokens with Environment Variable Secret Injection#

Use env:VAR_NAME prefixes so secrets are injected at runtime by systemd, Kubernetes Secrets, Vault, or Docker rather than stored inline:

json
{
  "tokens": [
    {
      "token": "env:SPYD_APP_TOKEN",
      "user": "payments_svc",
      "roles": ["orders_rw"],
      "tenant": 1001,
      "attributes": { "region": "us-east", "workload": "oltp" }
    }
  ],
  "auth_failure_limit": 10,
  "auth_failure_window": "60s"
}

3. Identity Federation Configuration (identity)#

json
{
  "identity": {
    "realm": "spyddb",
    "jwt": {
      "issuer": "https://idp.example.com",
      "audience": "spyddb",
      "algorithms": ["RS256", "ES256"],
      "jwks_url": "https://idp.example.com/.well-known/jwks.json",
      "jwks_ca_file": "/etc/spyd/idp-ca.pem",
      "jwks_refresh_secs": 300,
      "clock_skew_secs": 60,
      "claim_user": "sub",
      "claim_roles": "roles",
      "claim_tenant": "tenant",
      "claim_groups_to_roles": { "db-admins": ["admin"], "analysts": ["readonly"] },
      "default_roles": []
    },
    "minted": {
      "audience": "spyddb",
      "key_file": "/etc/spyd/session-signing.key",
      "lifetime_secs": 900
    },
    "oidc": [{
      "name": "corp",
      "issuer": "https://idp.example.com",
      "client_id": "spyddb",
      "client_secret_file": "/etc/spyd/oidc-secret",
      "redirect_url": "https://db.example.com:8080/v1/auth/corp/callback",
      "scopes": ["openid", "profile", "email"],
      "authorization_endpoint": "https://idp.example.com/authorize",
      "token_endpoint": "https://idp.example.com/token",
      "jwks_uri": "https://idp.example.com/.well-known/jwks.json",
      "ca_file": "/etc/spyd/idp-ca.pem",
      "claim_user": "email",
      "claim_roles": "groups",
      "claim_groups_to_roles": { "sre": ["admin"] },
      "pkce": true
    }],
    "ldap": [{
      "name": "corp-ad",
      "url": "ldaps://dc1.example.com:636",
      "ca_file": "/etc/spyd/dir-ca.pem",
      "bind_dn_template": "{user}@example.com",
      "service_bind_dn": "CN=spyddb,OU=Service,DC=example,DC=com",
      "service_bind_password_file": "/etc/spyd/ldap-bind-pw",
      "base_dn": "dc=example,dc=com",
      "user_filter": "(&(objectClass=user)(sAMAccountName={user}))",
      "group_to_roles": { "CN=Spyd Admins,OU=Groups,DC=example,DC=com": ["admin"] },
      "tls_min_version": "1.2"
    }]
  }
}

4. Network Allowlists & Auth Failure Throttling#

Restrict allowed peer IP ranges before handshake authentication:

json
{
  "network": {
    "allowed_cidrs": ["10.0.0.0/8", "192.168.10.0/24", "2001:db8::/32"]
  }
}

Authentication failures track per peer address inside auth_failure_window; exceeding auth_failure_limit rejects subsequent login attempts fail-closed without resetting on valid tokens elsewhere.

5. Auth Discovery & HTTP Session Endpoints#

  • GET /v1/auth/providers — public endpoint returning configured OIDC/SAML providers for login screens
  • POST /v1/auth/login — username + password / LDAP sign-in returning a minted bearer token
  • POST /v1/auth/logout — revoke an active HTTP session
  • GET /v1/session — inspect authenticated user, database, available databases, roles, tenant, server version/draining status, and effective capability booleans (can_manage, can_maintain, can_manage_extensions, can_read_fleet)
  • GET /v1/admin/identities — audit configured identity providers (secrets redacted)