Documentation
¶
Overview ¶
Package dbmask validates declarative masking rules and applies them to a throwaway database copy.
Index ¶
Constants ¶
const ( Null = "null" Hash = "hash" FakeEmail = "fake_email" FakeName = "fake_name" Fixed = "fixed" )
Transforms a rule can apply to one column.
Variables ¶
var ErrInvalidRule = errors.New("dbmask: invalid rule")
ErrInvalidRule marks a rule that is refused before it reaches a database.
var ErrUnsupportedEngine = errors.New("dbmask: masking is only available for postgres")
ErrUnsupportedEngine marks an engine that has no masking implementation.
Functions ¶
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.
type Executor ¶
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.
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.