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

secrets

package
v3.50.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package secrets provides authenticated encryption (AES-256-GCM) for user-scoped secrets stored in the database — here, each user's GitLab personal access token. The master key (KEK) lives only in the server config/env (secrets.key), never in the database or git.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoKey = errors.New("no encryption key configured (set secrets.key)")

ErrNoKey is returned when a seal/open is attempted without a configured KEK.

Functions

This section is empty.

Types

type SealedValue

type SealedValue struct {
	KeyVersion int    `json:"keyVersion"`
	Nonce      []byte `json:"nonce"`
	Ciphertext []byte `json:"ciphertext"`
}

SealedValue is an encrypted secret as stored in the database. It carries everything needed to decrypt except the key: the key version, the per-value random nonce and the GCM ciphertext (which already includes the authentication tag).

type Sealer

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

Sealer seals and opens secrets with a fixed KEK. A nil *Sealer means "no key configured" and every operation fails closed with ErrNoKey.

func NewSealer

func NewSealer(keyB64 string) (*Sealer, error)

NewSealer builds a Sealer from a base64-encoded 32-byte (AES-256) key. An empty key returns (nil, nil): the caller treats "no KEK configured" as a soft state and fails closed only when a secret operation is actually attempted. A malformed key is an error.

func (*Sealer) Open

func (s *Sealer) Open(v SealedValue) (string, error)

Open decrypts a SealedValue back to plaintext. It fails when the key is wrong or the data was tampered with (GCM authentication) — there is no plaintext fallback.

func (*Sealer) Seal

func (s *Sealer) Seal(plaintext string) (SealedValue, error)

Seal encrypts plaintext with a fresh random nonce.

Jump to

Keyboard shortcuts

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