Help us shape the future of Go! Take the 2026 Go Developer Survey

secrets

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package secrets 是平台密钥方案的 envelope 加密实现(architecture §2.3 密钥方案 + §2.4 密钥行):

  • envelope 加密 = age(filippo.io/age,依赖复核选定——密钥即文件, 与「主密钥存控制面主机文件、权限保护、与备份分离」形态天然契合);
  • 主密钥 = age X25519 identity,首次启动生成、文件权限保护(POSIX 下要求 owner 独占;Windows 无同语义位,检查降级为文件存在+可解析);
  • env 密文入 env_vars 表(state 层不解释密文);secret 值永不进 事件/审计/日志(state-model §2.9——负面测试钉死);
  • Swarm secret 引用 `fleetly-<app>-<name>-<hash8>`:值轮换即换名 换引用(hash8 = 内容 sha256 前 8)。

Index

Constants

View Source
const DefaultKeyPath = "./fleetly.key"

DefaultKeyPath 是主密钥文件缺省路径(可经配置 secrets.key_path 覆盖)。

Variables

View Source
var ErrWeakPermissions = errors.New("secrets: master key file permissions too open")

ErrWeakPermissions 表示主密钥文件权限过宽(POSIX:group/other 有任何 访问位)。密钥与备份分离、文件权限保护是架构 §2.3 的硬要求——fail-fast 拒绝加载,不静默降级。

Functions

This section is empty.

Types

type Box

type Box struct {
	// contains filtered or unexported fields
}

Box 是 envelope 加解密器:持主密钥(age identity),Encrypt/Decrypt 对称 使用。零值不可用;经 EnsureKey/LoadKey 构造。

func EnsureKey

func EnsureKey(path string) (*Box, bool, error)

EnsureKey 加载主密钥;文件不存在时生成新密钥并落盘(首次启动生成 + 返回 created=true,调用方必须提示用户妥善保存——密钥丢失 = 全部 env 密文不可解,与备份分离保存)。路径权限检查失败 → ErrWeakPermissions。

func LoadKey

func LoadKey(path string) (*Box, error)

LoadKey 从文件加载既有主密钥(不自动生成——CLI 等只读消费方显式加载)。

func (*Box) CheckHealth

func (b *Box) CheckHealth() error

CheckHealth 报告密钥就绪(fleetlyd secrets 服务结构性 Checker: 密钥已加载即可用——解密能力由 Encrypt/Decrypt 自证,健康检查不做额外 加解密自旋)。

func (*Box) Decrypt

func (b *Box) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt 以主密钥解 envelope。错误信息不含密文/明文材料(age 库错误本身 不回显内容;本包不把输入拼进错误——负面测试钉死)。

func (*Box) Encrypt

func (b *Box) Encrypt(plaintext []byte) ([]byte, error)

Encrypt 以主公钥 envelope 加密(输出 = age 标准密文,ASCII armored 的 二进制流形态)。

func (*Box) Path

func (b *Box) Path() string

Path 返回主密钥文件路径。

func (*Box) Recipient

func (b *Box) Recipient() (string, error)

Recipient 返回主公钥(age recipient 字符串)。指纹/展示用:备份台账与 恢复校验用它对齐「密钥指纹」(state-model §2.7 恢复顺序②),不承载 解密能力。

type SwarmSecretRef

type SwarmSecretRef struct {
	// Name 是 Swarm secret 名 `fleetly-<app>-<name>-<hash8>`。
	Name string
	// Hash8 是内容 sha256 前 8(hex)。
	Hash8 string
}

SwarmSecretRef 是一个 Swarm secret 的平台引用:名字 = naming.SecretName (值轮换即换名),hash8 随值绑定——引用参与 desired-hash(state-model §2.5 平台覆盖层「secret 引用」),轮换天然触发重部署。

func SecretRef

func SecretRef(app, name, value string) (SwarmSecretRef, error)

SecretRef 由平台密钥库条目构造 Swarm secret 引用。value 是明文——本函数 只取其哈希,明文不落到任何返回值/错误(负面测试钉死)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL