跳至主要內容
hs-sql-agent
2.0.2
文件 2.0.2
文件 維運

設定參考

hs-sql-agent 2.0.2 的 source-backed environment 與 runtime configuration reference。

單一 instance 從 .env.example 開始;除非 runtime state 必須跨 instance 共用,否則可先使用 process-local provider。
Distributed 使用 Postgres control-plane storage,加上 Redis-backed cache、limits、policy sync、delivery sync 與 SQL concurrency。
Embedded .NET 新整合使用 capability-specific options;HsSqlAgentServiceOptions 只保留給 legacy aggregate compatibility。

Checked-in 的 v2.0.2 .env.example 是預設 Compose deployment path 的 environment inventory。本頁以該檔案的 environment variable 名稱為基準;若 sample comment 與 v2.0.2 runtime validation 不一致,則以 executable runtime code 為準。

Application 與 control plane

Variable.env.example 範例/預設用途
ASPNETCORE_URLShttp://+:8080Main ASP.NET Core listener
ALLOWED_HOSTS*ASP.NET Core host filtering
ADMIN_DATABASE_PROVIDERSqliteAdmin/control-plane database provider
ADMIN_DATABASE_CONNECTION_STRINGData Source=/app/data/hsqlagent.db儲存 accounts、roles、keys、audit records、policies 與其他 control-plane state
HMAC_KEYplaceholder保護/驗證 issued MCP keys 的 HMAC secret;至少 32 bytes
MCP_PUBLIC_ENDPOINThttp://localhost:8080/mcp產生 MCP client configuration 時使用的 absolute endpoint

MCP_PUBLIC_ENDPOINT 必須是 absolute HTTP/HTTPS URL。Production 應填入 client 真正可連線的 URL,並包含 /mcp;不要填只有 container internal network 才能解析的位址。

Admin database topology

Single-instance example 使用 SQLite;distributed example 使用 PostgreSQL:

ADMIN_DATABASE_PROVIDER=Postgres
ADMIN_DATABASE_CONNECTION_STRING=Host=postgres;Port=5432;Database=hsqlagent;Username=postgres;Password=...

當多個 hs-sql-agent instances 必須共用 identities、keys、policies 與 audit/control-plane records 時,應使用 shared Admin database。

Cache

VariableSingle-instanceDistributed用途
CACHE_PROVIDERMemoryRedisRuntime cache provider
CACHE_CONNECTION_STRINGemptyredis:6379選擇 Redis 時的 connection
CACHE_KEY_PREFIXhsqlagent:cache:相同Cache key namespace

只有在 cache state 不需要跨 application instance 共用時,process-local Memory 才適合。

Bootstrap / auto-provisioning

Variable範例用途
BOOTSTRAP_ENABLEDfalse啟用 startup provisioning/synchronization
BOOTSTRAP_DB_IDdefault-dbInitial database 的 stable bootstrap identity
BOOTSTRAP_DB_NAMEDefault DBAdmin-facing database name
BOOTSTRAP_DB_PROVIDERempty要 provision 的 provider
BOOTSTRAP_DB_HOSTlocalhostDatabase host
BOOTSTRAP_DB_PORT5432Database port
BOOTSTRAP_DB_DATABASEmydbDatabase/catalog/file value
BOOTSTRAP_DB_USERNAMEmyuserDatabase username
BOOTSTRAP_DB_PASSWORDmypasswordDatabase password
BOOTSTRAP_DB_EXTRA_SETTINGSemptyProvider-specific connection settings
BOOTSTRAP_MCP_KEY_IDdefault-keyInitial MCP key 的 stable bootstrap identity
BOOTSTRAP_MCP_KEY_NAMEDefault MCP KeyAdmin-facing key name
BOOTSTRAP_MCP_KEYplaceholderInitial raw key value
BOOTSTRAP_MCP_ALLOWED_TOOLSemptyBootstrap key 的 tool restriction

Bootstrap-managed MCP key 不走一般 key lifecycle;不能透過正常 UI 流程 edit、rotate 或 revoke。要修改時應改其 source configuration。

Admin authentication

Variable範例用途
JWT_KEYplaceholderJWT signing secret;至少 32 bytes
JWT_ISSHS-AgentJWT issuer
JWT_AUDHS-Agent-UsersJWT audience
JWT_ACCESS_TOKEN_EXPIRATION_MINUTES10Access-token lifetime
JWT_REFRESH_TOKEN_EXPIRATION_DAYS1Refresh-token lifetime
AUTH_LOCKOUT_THRESHOLD5暫時 lockout 前允許的 failed sign-ins;小於 1 會視為 1
AUTH_LOCKOUT_MINUTES15Temporary lockout duration

這組設定管理的是 Admin authentication,不是 MCP-key authentication。

Password reset 與 SMTP

若 SMTP host 或 sender 為空,password-reset mail 實際上不會送出。

Variable範例用途
PASSWORD_RESET_BASE_URLhttp://localhost:3000/reset-password對外可到達的 reset page;server 會附加 ?token=...
PASSWORD_RESET_EXPIRATION_MINUTES30One-time reset-token lifetime
SMTP_HOSTsmtp.example.comSMTP host
SMTP_PORT587SMTP port
SMTP_ENABLE_SSLtrueMail sender 使用的 SSL/STARTTLS behavior
SMTP_USERNAMEexampleSMTP credential
SMTP_PASSWORDexampleSMTP credential
SMTP_FROMno-reply@example.comSMTP provider 接受的 sender address

OIDC / SSO 與 MFA

Variable範例用途
OIDC_ENABLEDfalse啟用 OIDC authentication
OIDC_AUTHORITYemptyIdentity-provider authority
OIDC_CLIENT_IDemptyOIDC client ID
OIDC_CLIENT_SECRETemptyOIDC client secret
OIDC_REQUIRE_HTTPS_METADATAtrue要求 HTTPS discovery metadata
OIDC_EMAIL_CLAIMemailEmail claim name
OIDC_NAME_CLAIMnameDisplay-name claim
OIDC_ROLE_CLAIMrolesRole claim
OIDC_EMAIL_VERIFIED_CLAIMemail_verifiedVerified-email claim
OIDC_REQUIRE_VERIFIED_EMAILtrue依設定 claim 拒絕未驗證 email 的 identity
OIDC_SCOPE_0..2openid, profile, emailDefault scopes
OIDC_ROLE_MAPPING_SQL_ADMINSSuperUserExternal-role → local-role mapping 範例
OIDC_AUTO_PROVISIONtrueExternal identity 成功解析後自動 provision user
OIDC_FRONTEND_CALLBACK_URL/sso-callbackFrontend completion route
OIDC_LOGIN_CODE_EXPIRATION_MINUTES2Short-lived login-code lifetime
OIDC_TOTP_ISSUERHS SQL AgentTOTP issuer label
DATA_PROTECTION_KEY_PATH/app/data/data-protection-keysPersistent ASP.NET Core data-protection key directory

請參考 OIDC 與 MFA

Health、slow query、delivery 與 audit retention

Variable範例用途
HEALTH_PROBE_ENABLEDfalse啟用 background DB health probing
HEALTH_PROBE_INTERVAL_SECONDS60Probe cadence
HEALTH_PROBE_TIMEOUT_SECONDS10Per-probe timeout
HEALTH_PROBE_MAX_CONCURRENCY4限制 concurrent probe work
SLOW_QUERY_THRESHOLD_MS1000Duration 大於等於此值的 query 會記錄為 slow
ALERT_WEBHOOK_URLemptyOptional signed alert destination
ALERT_WEBHOOK_SECRETemptyHMAC/signing secret;URL 啟用時至少 32 bytes
SIEM_WEBHOOK_URLemptyOptional signed SIEM destination
SIEM_WEBHOOK_SECRETemptyHMAC/signing secret;URL 啟用時至少 32 bytes
DELIVERY_MAX_ATTEMPTS6Outbound delivery retry bound
DELIVERY_MAX_CONCURRENCY4限制 concurrent outbound deliveries
AUDIT_RETENTION_DAYS90Retention period;0 代表停用 automatic retention
AUDIT_RETENTION_MODEArchiveRuntime 合法值:ArchivePurge
AUDIT_ARCHIVE_PATH/app/data/audit-archiveArchive mode 的 destination
AUDIT_FALLBACK_PATH/app/data/audit-fallback.jsonlAudit fallback path;startup validation 要求存在設定
AUDIT_RETENTION_RUN_HOUR_UTC2Scheduled UTC hour;runtime 會 clamp 到 0–23

Archive 會先將過期 audit rows 寫入 JSONL archive,再從 Admin database 刪除;Purge 則直接刪除符合 retention 條件的 records,不建立該 archive。

Global 與 per-key rate limiting

VariableSingle-instanceDistributed用途
RATE_LIMITING_PERMIT_LIMIT00Global IP permit limit;limit/window 都為 0 時代表 unlimited
RATE_LIMITING_WINDOW_SECONDS00Global IP window
RATE_LIMITER_PROVIDERMemoryRedisShared limiter implementation
RATE_LIMITER_CONNECTION_STRINGemptyredis:6379Redis connection
RATE_LIMITER_FAILURE_MODEFailClosedFailClosedDistributed limiter unavailable 時的 behavior
RATE_LIMITER_KEY_PREFIXhsqlagent:ratelimit:相同Redis key namespace

MCP key 另外可以 inherit、override 或 disable 自己的 per-key limit。請參考 MCP Keys

Runtime policy synchronization

VariableSingle-instanceDistributed用途
SECURITY_POLICY_SYNC_PROVIDERMemoryRedisRuntime policy synchronization provider
SECURITY_POLICY_SYNC_CONNECTION_STRINGemptyredis:6379Redis connection
SECURITY_POLICY_SYNC_KEY_PREFIXhsqlagent:security-policy:相同Key namespace
SECURITY_POLICY_SYNC_REFRESH_INTERVAL_SECONDS3030Refresh interval

當 policy changes 必須跨多個 hs-sql-agent instances 傳播時,請使用 Redis。

Outbound-delivery synchronization

VariableSingle-instanceDistributed用途
OUTBOUND_DELIVERY_SYNC_PROVIDERMemoryRedisDelivery signal coordination
OUTBOUND_DELIVERY_SYNC_CONNECTION_STRINGemptyredis:6379Redis connection
OUTBOUND_DELIVERY_SYNC_KEY_PREFIXhsqlagent:outbound-delivery:相同Key namespace

SQL concurrency coordination

VariableSingle-instanceDistributed用途
SQL_CONCURRENCY_PROVIDERMemoryRedisSQL concurrency limiter provider
SQL_CONCURRENCY_CONNECTION_STRINGemptyredis:6379Redis connection
SQL_CONCURRENCY_FAILURE_MODEFailClosedFailClosedDistributed coordination 失敗時的 behavior
SQL_CONCURRENCY_KEYhsqlagent:sql-concurrency相同Shared coordination key
SQL_CONCURRENCY_LEASE_SECONDS3030Lease duration

Metadata discovery、query、DML planning/execution 與 health-related SQL work 都會走 bounded runtime paths。若 concurrency limit 必須跨整個 cluster 生效,而不是各 process 分別計算,就應使用 distributed SQL concurrency。

Observability

Variable範例用途
PROMETHEUS_ENABLEDfalse啟用 Prometheus HTTP listener
PROMETHEUS_HOST0.0.0.0Metrics listener bind host
PROMETHEUS_PORT9000獨立 metrics listener port;啟用時需介於 1–65535
OTLP_ENDPOINTemptyAbsolute HTTP(S) OTLP collector endpoint
OTEL_SERVICE_NAMEhs-sql-agentOpenTelemetry service name;不可為 blank

Prometheus 刻意使用 獨立 listener,不與 Admin/MCP application port 共用。當 OTLP_ENDPOINT 有設定時,v2.0.2 會匯出 telemetry,包含 SQL compile-evidence tracing/log integration。

請參考 Observability

Docker environment 與 embedded .NET capability options

Docker/ToolBox environment 是完整 standalone-server configuration surface。新的 NuGet integration 不同:AddHsSqlAgentCore() 本身沒有 options,每個被選到的 capability 只擁有自己的設定。

例如:

  • HsSqlAgentAdminStoreOptions:Admin database provider 與 connection string;
  • HsSqlAgentRuntimeOptions:cache、rate limiting、synchronization、SQL concurrency、DML approval storage、bootstrap、operability;
  • HsSqlAgentBuiltInAuthOptions:JWT、password reset/SMTP、enterprise identity/OIDC;
  • McpOptions:public MCP endpoint 與 HMAC secret;
  • TelemetryOptions:Prometheus 與 OTLP settings。

HsSqlAgentServiceOptions 只保留成 legacy aggregate compatibility DTO。沒有選到的 capability 不會建立或驗證它的 options,因此使用 AddHsSqlAgentHostAuthorization(...) 的 embedded host 不需要 HsSqlAgent JWT、SMTP、password-reset 或 OIDC settings。

Modular API 保留原有 code defaults;.env.example 仍是 standalone ToolBox deployment example,不代表每個 embedded host 都必須設定每個 capability。

請參考 ASP.NET Core 整合