Skip to content

sign-kms · 配置

配置 schema

来源:internal/conf/conf.protomake configMakefile:38)生成对应 Go struct。

Message字段行号
BootstrapServerDataHSMObservability8-13
Servernetworkaddrtimeouthttp_addrweb_dist_pathtlshttps55-66
TLSenablecert_filekey_fileca_file68-78
Datadatabasedriversource80-86
HSMproviders(repeated HSMProvider51-53
HSMProvideridnametypelibraryenabledpool_size39-49
Observabilityotlp_endpointinsecuremetricstracinglogging15-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.gop11client/kms_so.cinternal/data/init_user.go

变量用途出处
KMS_AUTH_SECRETJWT 签名密钥。GetAuthSecret() 未设置时 panicpkg/auth/config.go:38, 44
KMS_AUTH_COOKIE自定义 cookie 名,默认 access_tokenpkg/auth/config.go:15
DEFAULT_ADMIN_PWD首次启动管理员账号密码internal/data/init_user.go
SIGN_KMS_ENDPOINTlibkms_pkcs11.so 连接地址p11client/kms_so.c:202
KMS_SO_DEBUGlibkms_pkcs11.so 调试日志p11client/kms_so.c:39
SOFTHSM_LIBSoftHSM 库路径README.md:27-34

鉴权常量

来源:pkg/auth/config.go

行号
Cookie 名env KMS_AUTH_COOKIEaccess_token15
SecureCookie由服务器设置19
CookiePath/52
DefaultExpiry(管理后台 cookie)24 小时55
DefaultTokenExpiry(KMS access token)365 天58
MaxTokenExpiry730 天 hard cap60

SessionPool 常量

来源:pkg/pkcs11/session_pool.go

行号
DefaultPoolSize518
MaxPoolSize3019
HealthCheckInterval30 秒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

实体关键约束
Namespaceid Unique/Immutable;nametoken_label Unique;user_pinso_pin Sensitive
Keypairid Unique/Immutable(SKI hex,服务器计算);tag MaxLen 128;索引 tag+namespace_id
Userusername Unique
AccessTokenid Unique/Immutable (JTI);status enum (active/disabled);keys 是 DB 权威源

TLS 与 mTLS

来源:internal/conf/conf.proto:68-78internal/server/grpc.go:44-51, 82

TLS message 字段:enablecert_filekey_fileca_file

Tls.Enable=true && CaFile 非空时启用 gRPC 客户端证书验证(grpc.go:44-51, 82)。

多 provider 配置

HSMProviderconf.proto:39-49)字段:idnametypelibraryenabledpool_size

NewProviderRegistrypkg/pkcs11/registry.go:68)遍历 HSM.Providers;至少 1 个可用才能继续(:89-92)。