svc-infra

Environment Reference

This guide consolidates every environment variable consumed by the svc-infra helpers in FastAPI, jobs, observability, security, and webhooks. Defaults shown below reflect the library's fallbacks when a variable is absent. Where a helper relies on svc_infra.app.pick, the note column calls out the environment-specific behavior.

FastAPI helpers

App bootstrap (easy_service_app / setup_service_api)

VariableDefaultConsumed byNotes
ENABLE_LOGGINGtrueEasyAppOptions.from_env()Disables setup_logging when set to false.
LOG_LEVELAuto (INFO in prod/test, DEBUG in dev/local via pick())easy_service_app()Overrides the log level chosen by svc_infra.app.pick.
LOG_FORMATAuto (JSON in prod, plain elsewhere)easy_service_app()Explicit json or plain format overrides auto-detection.
ENABLE_OBStrueEasyAppOptions.from_env() / easy_service_app()Turns observability instrumentation on/off.
METRICS_PATHNone → falls back to Observability settingsEasyAppOptions.from_env()Use to expose metrics at a non-default path.
OBS_SKIP_PATHSNone → defaults to metrics + health endpointsEasyAppOptions.from_env()Comma/space-separated list of paths skipped by Prometheus middleware.
CORS_ALLOW_ORIGINS"" (no origins)_setup_cors()Adds CORSMiddleware allow-list when non-empty.

SQL helpers (add_sql_db, setup_sql)

VariableDefaultConsumed byNotes
SQL_URL (overridable via dsn_env)requiredadd_sql_db() / setup_sql()Missing value raises RuntimeError; point at your primary database URL.

Mongo helpers (add_mongo_db, init_mongo)

VariableDefaultConsumed byNotes
MONGO_URL / MONGODB_URLmongodb://localhost:27017MongoSettings, add_mongo_db()Primary Mongo connection string; _FILE suffix or MONGO_URL_FILE allow secret mounts.
MONGO_DB / MONGODB_DB / MONGO_DATABASEunset (optional)get_mongo_dbname_from_env()When set, verified against the connected database name.
MONGO_APPNAMEsvc-infraMongoSettingsSets the Mongo client appname.
MONGO_MIN_POOL0MongoSettingsMinimum Motor/Mongo client pool size.
MONGO_MAX_POOL100MongoSettingsMaximum Motor/Mongo client pool size.
MONGO_URL_FILEunsetget_mongo_url_from_env()Alternate secret file path when not using _FILE suffix envs.
/run/secrets/mongo_urlunsetget_mongo_url_from_env()Auto-mounted Docker/K8s secret fallback for the URL.

Auth settings (get_auth_settingsAuthSettings)

Pydantic loads these with the AUTH_ prefix and __ as the nested delimiter.

VariableDefaultConsumed byNotes
AUTH_JWT__SECRETrequired when JWT auth enabledAuthSettings.jwt.secretPrimary HS256 signing secret.
AUTH_JWT__LIFETIME_SECONDS604800 (7 days)AuthSettings.jwt.lifetime_secondsAdjusts refresh token lifetime.
AUTH_JWT__OLD_SECRETS__*[]AuthSettings.jwt.old_secretsAccepted legacy secrets during rotation.
AUTH_PASSWORD_CLIENTS__{n}__CLIENT_ID[]AuthSettings.password_clients[*].client_idRegister password clients (list entries indexed by {n}).
AUTH_PASSWORD_CLIENTS__{n}__CLIENT_SECRET[]AuthSettings.password_clients[*].client_secretSecret per password client.
AUTH_REQUIRE_CLIENT_SECRET_ON_PASSWORD_LOGINfalseAuthSettings.require_client_secret_on_password_loginEnforces client secret on password grant.
AUTH_MFA_DEFAULT_ENABLED_FOR_NEW_USERSfalseAuthSettings.mfa_default_enabled_for_new_usersEnable TOTP by default on signup.
AUTH_MFA_ENFORCE_FOR_ALL_USERSfalseAuthSettings.mfa_enforce_for_all_usersForce MFA globally.
AUTH_MFA_ENFORCE_FOR_TENANTS[]AuthSettings.mfa_enforce_for_tenantsTenant allow-list requiring MFA.
AUTH_MFA_ISSUER"svc-infra"AuthSettings.mfa_issuerLabel for TOTP apps.
AUTH_MFA_PRE_TOKEN_LIFETIME_SECONDS300AuthSettings.mfa_pre_token_lifetime_secondsLifespan of MFA pre-token.
AUTH_MFA_RECOVERY_CODES8AuthSettings.mfa_recovery_codesNumber of recovery codes issued.
AUTH_MFA_RECOVERY_CODE_LENGTH10AuthSettings.mfa_recovery_code_lengthDigits per recovery code.
AUTH_EMAIL_OTP_TTL_SECONDS300AuthSettings.email_otp_ttl_secondsEmail OTP validity window.
AUTH_EMAIL_OTP_COOLDOWN_SECONDS60AuthSettings.email_otp_cooldown_secondsCooldown between OTP sends.
AUTH_EMAIL_OTP_ATTEMPTS5AuthSettings.email_otp_attemptsMaximum OTP attempts before lock.
AUTH_SMTP_HOSTNoneAuthSettings.smtp_hostSMTP hostname (required for prod email).
AUTH_SMTP_PORT587AuthSettings.smtp_portSMTP port.
AUTH_SMTP_USERNAMENoneAuthSettings.smtp_usernameSMTP username.
AUTH_SMTP_PASSWORDNoneAuthSettings.smtp_passwordSMTP password/secret.
AUTH_SMTP_FROMNoneAuthSettings.smtp_fromDefault From address.
AUTH_AUTO_VERIFY_IN_DEVtrueAuthSettings.auto_verify_in_devAuto-confirms accounts outside prod.
AUTH_GOOGLE_CLIENT_IDNoneAuthSettings.google_client_idBuilt-in Google OAuth client ID.
AUTH_GOOGLE_CLIENT_SECRETNoneAuthSettings.google_client_secretBuilt-in Google OAuth secret.
AUTH_GITHUB_CLIENT_IDNoneAuthSettings.github_client_idGitHub OAuth client ID.
AUTH_GITHUB_CLIENT_SECRETNoneAuthSettings.github_client_secretGitHub OAuth secret.
AUTH_MS_CLIENT_IDNoneAuthSettings.ms_client_idMicrosoft OAuth client ID.
AUTH_MS_CLIENT_SECRETNoneAuthSettings.ms_client_secretMicrosoft OAuth secret.
AUTH_MS_TENANTNoneAuthSettings.ms_tenantMicrosoft tenant ID.
AUTH_LI_CLIENT_IDNoneAuthSettings.li_client_idLinkedIn OAuth client ID.
AUTH_LI_CLIENT_SECRETNoneAuthSettings.li_client_secretLinkedIn OAuth secret.
AUTH_OIDC_PROVIDERS__{n}__NAME[]AuthSettings.oidc_providers[*].nameCustom OIDC providers (list entries indexed by {n}).
AUTH_OIDC_PROVIDERS__{n}__ISSUER[]AuthSettings.oidc_providers[*].issuerOIDC issuer URL.
AUTH_OIDC_PROVIDERS__{n}__CLIENT_ID[]AuthSettings.oidc_providers[*].client_idOIDC client ID.
AUTH_OIDC_PROVIDERS__{n}__CLIENT_SECRET[]AuthSettings.oidc_providers[*].client_secretOIDC client secret.
AUTH_OIDC_PROVIDERS__{n}__SCOPE"openid email profile"AuthSettings.oidc_providers[*].scopeAdditional OIDC scopes.
AUTH_POST_LOGIN_REDIRECThttp://localhost:3000/appAuthSettings.post_login_redirectDefault redirect after login.
AUTH_REDIRECT_ALLOW_HOSTS_RAW"localhost,127.0.0.1"AuthSettings.redirect_allow_hosts_rawCSV/JSON allow-list for redirects.
AUTH_SESSION_COOKIE_NAME"svc_session"AuthSettings.session_cookie_nameSession cookie key.
AUTH_AUTH_COOKIE_NAME"svc_auth"AuthSettings.auth_cookie_nameAuth cookie key.
AUTH_SESSION_COOKIE_SECUREfalseAuthSettings.session_cookie_secureMarks session cookie Secure.
AUTH_SESSION_COOKIE_SAMESITE"lax"AuthSettings.session_cookie_samesiteSameSite policy.
AUTH_SESSION_COOKIE_DOMAINNoneAuthSettings.session_cookie_domainExplicit cookie domain.
AUTH_SESSION_COOKIE_MAX_AGE_SECONDS14400 (4 hours)AuthSettings.session_cookie_max_age_secondsSession cookie lifetime.

Jobs helpers

VariableDefaultConsumed byNotes
JOBS_DRIVERmemoryJobsConfig, easy_jobs()Choose redis to activate Redis-backed queue.
REDIS_URLredis://localhost:6379/0easy_jobs() (Redis driver)Redis connection string when JOBS_DRIVER=redis.
JOBS_SCHEDULE_JSONunsetschedule_from_env()JSON array of scheduler tasks (name, interval_seconds, target).

Observability helpers

VariableDefaultConsumed byNotes
METRICS_ENABLEDtrueObservabilitySettingsGate for Prometheus middleware registration.
METRICS_PATH/metricsObservabilitySettings, add_observability()Metrics endpoint path.
METRICS_DEFAULT_BUCKETS0.005,0.01,0.025,0.05,0.1,0.25,0.5,1.0,2.0,5.0,10.0ObservabilitySettingsHistogram buckets for request latency.
SVC_INFRA_DISABLE_PROMETHEUSunset ("1" disables)metrics.asgiSkip Prometheus setup when toggled.
SVC_INFRA_RATE_WINDOWunsetcloud_dash.push_dashboards_from_pkg()Overrides $__rate_interval in dashboards.
SVC_INFRA_DASHBOARD_REFRESH5scloud_dash.push_dashboards_from_pkg()Grafana dashboard auto-refresh interval.
SVC_INFRA_DASHBOARD_RANGEnow-6hcloud_dash.push_dashboards_from_pkg()Default Grafana time range start.

Security helpers

The primitives under svc_infra.security rely on configuration objects passed from application code; they do not read environment variables directly beyond the shared AuthSettings listed above.

Webhook helpers

Current webhook helpers (fastapi.require_signature, InMemoryWebhookSubscriptions, WebhookService) rely on dependency injection for secrets and stores and do not read environment variables directly.