dbmask

package
v1.5.20 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dbmask validates declarative masking rules and applies them to a throwaway database copy.

Index

Constants

View Source
const (
	Null      = "null"
	Hash      = "hash"
	FakeEmail = "fake_email"
	FakeName  = "fake_name"
	Fixed     = "fixed"
)

Transforms a rule can apply to one column.

Variables

View Source
var ErrInvalidRule = errors.New("dbmask: invalid rule")

ErrInvalidRule marks a rule that is refused before it reaches a database.

View Source
var ErrUnsupportedEngine = errors.New("dbmask: masking is only available for postgres")

ErrUnsupportedEngine marks an engine that has no masking implementation.

Functions

func Supported

func Supported(engine string) bool

Supported reports whether an engine can be masked.

func ToStored

func ToStored(rules []Rule, newID func() (string, error)) ([]store.MaskingRule, error)

ToStored maps validated rules to their rows; newID names each row.

func Weakens

func Weakens(prev, next []Rule) bool

Weakens reports whether next drops or changes any rule of prev.

Types

type Applied

type Applied struct {
	Target    string `json:"target"`
	Transform string `json:"transform"`
	Rows      int64  `json:"rows"`
}

Applied is what one rule changed. It never holds a value.

type Container

type Container struct{ Runtime InputExecer }

Container runs scripts with psql inside a Postgres container, fed on stdin so no text reaches a shell.

func (Container) SQL

func (c Container) SQL(ctx context.Context, containerName, script string) (string, error)

SQL implements Executor.

type Executor

type Executor interface {
	SQL(ctx context.Context, containerName, script string) (string, error)
}

Executor runs a SQL script inside the database container and returns its unaligned output. It must stop at the first failing statement.

type InputExecer

type InputExecer interface {
	ExecWithInput(ctx context.Context, containerName string, cmd []string, input io.Reader) (io.ReadCloser, error)
}

InputExecer is the container runtime surface masking needs.

type Report

type Report []Applied

Report lists what was masked, in rule order.

func Apply

func Apply(ctx context.Context, ex Executor, engine, containerName string, rules []Rule) (Report, error)

Apply masks the database in containerName. The caller must keep that copy unreachable until Apply returns nil and must destroy it on any error. It must never be pointed at a source database.

func (Report) Summary

func (r Report) Summary() string

Summary is a short value free sentence for the branch record.

type Rule

type Rule struct {
	Schema    string `json:"schema,omitempty"`
	Table     string `json:"table"`
	Column    string `json:"column"`
	Transform string `json:"transform"`
	Value     string `json:"value,omitempty"`
}

Rule masks one column. Value is used by the fixed transform only.

func FromStored

func FromStored(rows []store.MaskingRule) ([]Rule, error)

FromStored reads rows back and refuses any row it does not fully understand.

func Validate

func Validate(rules []Rule) ([]Rule, error)

Validate normalizes the schema and refuses anything that cannot be applied safely.

func (Rule) Target

func (r Rule) Target() string

Target names the column a rule covers.

type SafeError

type SafeError struct {
	Reason string
	// contains filtered or unexported fields
}

SafeError carries a reason built from identifiers and fixed text only, safe to store and show.

func (*SafeError) Error

func (e *SafeError) Error() string

func (*SafeError) Unwrap

func (e *SafeError) Unwrap() error

Jump to

Keyboard shortcuts

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