secret

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package secret provides pluggable credential sources for run-as operations.

The whole point of this package is one small seam:

type Provider interface { Credential() (Credential, error) }

In the old days, the run-as account's password was a plaintext constant hardcoded into every script. That worked — and it was the single biggest liability in the codebase. Here, the call site that needs a credential depends only on the Provider interface; *where* the secret actually lives is a configuration decision, not a code change.

Providers, weakest to strongest:

Plaintext  - literal password in source. Possible, but it announces itself.
Env        - read from environment variables (out of the binary).
DPAPI      - Windows DPAPI-encrypted blob on disk (no key to ship). [windows]
CredMan    - Windows Credential Manager entry (binary carries no secret). [windows]

The lesson worth keeping: make the insecure path possible but obvious, and make the secure path the easy default.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedPlatform = errors.New("winadmin/secret: provider not supported on this platform")

ErrUnsupportedPlatform is returned by OS-specific providers (DPAPI, CredMan) when built for a non-Windows target.

Functions

func EncryptDPAPI

func EncryptDPAPI(string, bool) ([]byte, error)

EncryptDPAPI is a non-functional stub off Windows.

func WriteDPAPIBlob

func WriteDPAPIBlob(string, string, bool) error

WriteDPAPIBlob is a non-functional stub off Windows.

Types

type CredMan

type CredMan struct {
	TargetName string
	Domain     string
	User       string
}

CredMan is a non-functional stub off Windows.

func (CredMan) Credential

func (CredMan) Credential() (Credential, error)

Credential implements Provider; always returns ErrUnsupportedPlatform here.

type Credential

type Credential struct {
	User     string
	Domain   string
	Password string
}

Credential is a resolved set of logon values.

Domain may be a real domain ("ACME") or a machine name for a local account. An empty Domain is interpreted as "." (the local machine) by the runas package.

func (Credential) IsZero

func (c Credential) IsZero() bool

IsZero reports whether the credential carries no user and no password.

func (Credential) String

func (c Credential) String() string

String redacts the password so credentials never leak into logs.

type DPAPI

type DPAPI struct {
	User     string
	Domain   string
	BlobPath string
}

DPAPI is a non-functional stub off Windows.

func (DPAPI) Credential

func (DPAPI) Credential() (Credential, error)

Credential implements Provider; always returns ErrUnsupportedPlatform here.

type Env

type Env struct {
	UserVar     string
	DomainVar   string
	PasswordVar string
}

Env reads a credential from environment variables. This gets the secret out of the binary and into the deployment surface (a systemd unit, a CI secret, a launchd plist, etc.) — the first meaningful step up from Plaintext.

Zero-value field names fall back to sane defaults:

UserVar     -> WINADMIN_USER
DomainVar   -> WINADMIN_DOMAIN
PasswordVar -> WINADMIN_PASSWORD

func (Env) Credential

func (e Env) Credential() (Credential, error)

Credential implements Provider.

type Plaintext

type Plaintext struct {
	User     string
	Domain   string
	Password string
}

Plaintext is the deliberately-insecure option: a literal credential compiled into the program. It exists on purpose — for bootstrapping, for parity with the old scripts, and so the insecure choice is a deliberate, visible one.

Reach for Env, DPAPI, or CredMan the moment you can. Swapping is a one-line change because everything downstream only sees Provider.

func (Plaintext) Credential

func (p Plaintext) Credential() (Credential, error)

Credential implements Provider.

type Provider

type Provider interface {
	Credential() (Credential, error)
}

Provider yields a Credential at runtime. Implementations decide where the secret physically lives.

Jump to

Keyboard shortcuts

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