postgres

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package postgres implements the dynamic-secret Provider seam over a PostgreSQL engine. It mints a login role IN ROLE the operator's grant role, VALID UNTIL the lease expiry (the engine refuses NEW password logins after the deadline even if Hikyo is down; it does not end sessions already open, see createRoleSQL), extends, drops (idempotently), and probes role status. Every outbound connection is TLS verify-full and dials only a policy-approved public address (or an operator-allowed CIDR); there is no arbitrary-SQL entry point and no statement ever reads a secret back out.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Origin       string
	Password     string
	AllowedCIDRs []netip.Prefix
	RootCAs      *x509.CertPool
	Deadline     time.Duration
}

Config constructs a provider. Origin is a postgres URL carrying the admin user and target database but NOT the password (postgres://user@host:port/db); Password is the sealed admin credential, held only for the provider's lifetime. AllowedCIDRs are operator egress exceptions; RootCAs overrides the system trust store when set. Deadline bounds every operation and MUST be shorter than the caller's row-claim lease.

type Provider

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

Provider is one configured PostgreSQL target. It opens a fresh connection per operation (operator provider actions are rare and a lease mint is one request each), so there is no pool to leak; Close forgets the admin credential.

func New

func New(cfg Config) (*Provider, error)

New validates the config and builds the base connection template. It does not connect: the first connection happens on the first operation, under that operation's deadline.

func (*Provider) Close

func (p *Provider) Close()

Close forgets the admin credential. There is no pooled connection to release (each operation opens and closes its own).

func (*Provider) CreateRole

func (p *Provider) CreateRole(ctx context.Context, req dynamic.CreateRoleRequest) error

CreateRole mints the lease role. The role name and grant role are sanitized identifiers; the password is validated to the generator charset before it is placed in the (engine-escaped) literal, so no value can break out of the DDL.

func (*Provider) DropRole

func (p *Provider) DropRole(ctx context.Context, name string) error

DropRole removes the lease role. It is idempotent: a role that is already gone is a success, which is what makes revoke safe to retry.

Dropping the role prevents any further login as it. It does NOT terminate backends already connected as the role: PostgreSQL refuses DROP ROLE only while the role owns objects or holds privileges, not while it has open sessions, and those sessions keep running until they disconnect or the database's own session controls (pg_terminate_backend, idle/statement timeouts, a proxy's connection lifetime) end them. Revocation is therefore a login deadline, not an access deadline.

func (*Provider) ExtendRole

func (p *Provider) ExtendRole(ctx context.Context, name string, validUntil time.Time) error

ExtendRole moves VALID UNTIL forward (or back). An absent role is a definite failure the caller settles by reconcile.

func (*Provider) RoleStatus

func (p *Provider) RoleStatus(ctx context.Context, name string) (dynamic.RoleStatus, error)

RoleStatus probes pg_roles so reconcile can settle any transition, including a renew (it reads back VALID UNTIL), not just a mint or drop.

Jump to

Keyboard shortcuts

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