Documentation
¶
Overview ¶
Package hieraeyaml is a pure-Go (no cgo) adapter mirroring the Ruby hiera-eyaml gem: it reads eyaml YAML data, decrypts the ENC[...] scalars it contains, and exposes an "eyaml" data_hash backend for the github.com/go-hiera/hiera engine.
The cryptography lives entirely in github.com/go-eyaml/eyaml; this package is the thin, hiera-facing layer on top of it:
- a Config/New pair that builds a Backend from PEM key material, supplied either inline (PublicKeyPEM/PrivateKeyPEM) or by path through an injectable FS seam (PublicKeyPath/PrivateKeyPath) so callers and tests never need real files;
- Backend.EncryptString / Backend.DecryptString for single scalars, and Backend.DecryptValue to walk a decoded value tree decrypting every ENC[...] token it finds (block and inline string forms alike);
- Backend.DataHash, a func(data []byte, path string) (map[string]any, error) that YAML-parses a data file and decrypts it, matching the signature go-hiera's Hiera.RegisterDataHash expects;
- Backend.Register, which registers DataHash under the name "eyaml" on a *hiera.Hiera so a hierarchy level can select "data_hash: eyaml".
Only the pkcs7 scheme is supported, inherited from go-eyaml; the hiera-eyaml gpg encryptor is deferred there and therefore here too.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend decrypts and encrypts eyaml data. Construct one with New.
func New ¶
New builds a Backend from cfg. It errors if a configured path cannot be read, if the PEM material is invalid, or if no key material is supplied at all.
func (*Backend) DataHash ¶
DataHash is the go-hiera data_hash backend seam: it YAML-parses data and decrypts every ENC[...] scalar, returning the resulting hash. path is used only for error context. Its signature matches the argument gohiera.Hiera.RegisterDataHash expects.
func (*Backend) DecryptString ¶
DecryptString decrypts s when it is an ENC[...] token and returns it verbatim otherwise, so plaintext scalars pass through unchanged.
func (*Backend) DecryptValue ¶
DecryptValue walks a decoded value tree (as produced by YAML parsing) and decrypts every ENC[...] scalar, leaving other scalars untouched. Maps and slices are copied; the input is not mutated.
func (*Backend) EncryptString ¶
EncryptString seals s into an ENC[PKCS7,...] token.
type Config ¶
type Config struct {
// PublicKeyPEM / PrivateKeyPEM are inline PEM blocks.
PublicKeyPEM []byte
PrivateKeyPEM []byte
// PublicKeyPath / PrivateKeyPath are read through FS when the matching
// inline field is empty.
PublicKeyPath string
PrivateKeyPath string
// FS overrides the file-access seam (defaults to the OS filesystem).
FS FS
}
Config configures a Backend. Key material is the RSA private key and the matching X.509 certificate (hiera-eyaml's "public key"). Supply either the inline PEM fields or the *Path fields; inline PEM wins when both are set. Provide only the certificate for an encrypt-only backend, only the private key for a decrypt-only backend, or both for round trips.