主题
sign-kms · 配置
配置 schema
来源:internal/conf/conf.proto。make config(Makefile:38)生成对应 Go struct。
| Message | 字段 | 行号 |
|---|---|---|
Bootstrap | Server、Data、HSM、Observability | 8-13 |
Server | network、addr、timeout、http_addr、web_dist_path、tls、https | 55-66 |
TLS | enable、cert_file、key_file、ca_file | 68-78 |
Data | database(driver、source) | 80-86 |
HSM | providers(repeated HSMProvider) | 51-53 |
HSMProvider | id、name、type、library、enabled、pool_size | 39-49 |
Observability | otlp_endpoint、insecure、metrics、tracing、logging | 15-24 |
core.yaml
来源:conf/core.yaml(样例值)。顶层 key 同 Bootstrap 字段:
yaml
server:
addr: 0.0.0.0:9200
http_addr: 0.0.0.0:9201
timeout: 60s
https: false
web_dist_path: ../../web/dist
# tls: # 注释默认关闭;ca_file 非空时启用 mTLS
# enable: true
# cert_file: ...
# key_file: ...
# ca_file: ...
data:
database:
driver: sqlite3
source: file:./kms.db?cache=shared&_fk=1
observability:
otlp_endpoint: "localhost:4317"
insecure: true
metrics:
enable: true
tracing:
enable: true
sample_ratio: 1.0
logging:
enable: true
hsm:
providers:
- id: 'softhsm-dev'
name: 'SoftHSM (Dev)'
type: 'soft'
library: '/usr/lib/softhsm/libsofthsm2.so'
enabled: true
pool_size: 5
- id: 'hardware-dev'
name: 'Hardware HSM - Mock'
type: 'hardware'
library: '/usr/lib/softhsm/libsofthsm2.so'
enabled: true环境变量
来源:pkg/auth/config.go、p11client/kms_so.c、internal/data/init_user.go。
| 变量 | 用途 | 出处 |
|---|---|---|
KMS_AUTH_SECRET | JWT 签名密钥。GetAuthSecret() 未设置时 panic | pkg/auth/config.go:38, 44 |
KMS_AUTH_COOKIE | 自定义 cookie 名,默认 access_token | pkg/auth/config.go:15 |
DEFAULT_ADMIN_PWD | 首次启动管理员账号密码 | internal/data/init_user.go |
SIGN_KMS_ENDPOINT | libkms_pkcs11.so 连接地址 | p11client/kms_so.c:202 |
KMS_SO_DEBUG | libkms_pkcs11.so 调试日志 | p11client/kms_so.c:39 |
SOFTHSM_LIB | SoftHSM 库路径 | README.md:27-34 |
鉴权常量
来源:pkg/auth/config.go。
| 项 | 值 | 行号 |
|---|---|---|
| Cookie 名 | env KMS_AUTH_COOKIE 或 access_token | 15 |
SecureCookie | 由服务器设置 | 19 |
CookiePath | / | 52 |
DefaultExpiry(管理后台 cookie) | 24 小时 | 55 |
DefaultTokenExpiry(KMS access token) | 365 天 | 58 |
MaxTokenExpiry | 730 天 hard cap | 60 |
SessionPool 常量
来源:pkg/pkcs11/session_pool.go。
| 项 | 值 | 行号 |
|---|---|---|
DefaultPoolSize | 5 | 18 |
MaxPoolSize | 30 | 19 |
HealthCheckInterval | 30 秒 | 20 |
角色与权限
来源:pkg/auth/claims.go:42-46。
readonly → {get_public_key, verify}
readwrite → {sign, verify, get_public_key}
admin → {sign, verify, get_public_key, gen_keypair, sign_cert, sign_crl}DB 实体(Ent schema)
来源:internal/data/ent/schema/。完整字段列表见 04-modules · DB schema。
| 实体 | 关键约束 |
|---|---|
Namespace | id Unique/Immutable;name、token_label Unique;user_pin、so_pin Sensitive |
Keypair | id Unique/Immutable(SKI hex,服务器计算);tag MaxLen 128;索引 tag+namespace_id |
User | username Unique |
AccessToken | id Unique/Immutable (JTI);status enum (active/disabled);keys 是 DB 权威源 |
TLS 与 mTLS
来源:internal/conf/conf.proto:68-78、internal/server/grpc.go:44-51, 82。
TLS message 字段:enable、cert_file、key_file、ca_file。
Tls.Enable=true && CaFile 非空时启用 gRPC 客户端证书验证(grpc.go:44-51, 82)。
多 provider 配置
HSMProvider(conf.proto:39-49)字段:id、name、type、library、enabled、pool_size。
NewProviderRegistry(pkg/pkcs11/registry.go:68)遍历 HSM.Providers;至少 1 个可用才能继续(:89-92)。