guard

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 5 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 guard is the ceremony between a developer and a destructive action.

A developer holding a prod context in the same switcher as qa will eventually act on the wrong one. Every layer here exists because designing against that beats trusting attention:

  • the environment's name travels with every gate, never inferred from memory
  • the write policy comes from the environment, not from the screen
  • a confirm environment wants the resource name typed, the pattern people already know from deleting a GitHub repository
  • break-glass unlocks production for fifteen minutes with a stated reason, then re-locks itself
  • the blast radius and the equivalent kubectl travel with the gate, so nobody confirms something they have not seen
  • a gate is always about exactly one environment

One boundary, stated plainly and repeated in the docs: these layers protect against accidents, not against intent. The write policy lives in a config file the user controls and can edit in a second. RBAC is the security boundary; this is ergonomics on top of it and never a substitute for it.

Index

Constants

View Source
const (
	RequireNothing    = ""
	RequireTypedName  = "typed-name"
	RequireBreakGlass = "break-glass"
)

What the UI must collect before the action may run.

View Source
const BreakGlassWindow = 15 * time.Minute

BreakGlassWindow is how long production stays armed after an unlock. Long enough to finish an incident action, short enough that nobody leaves prod unlocked by forgetting.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Verb      string
	Resource  string
	Name      string
	Namespace string
	// Kubectl is the equivalent command. Showing it is how somebody checks the
	// tool's understanding against their own before agreeing to it.
	Kubectl string
	Blast   Blast
}

Action is the thing somebody is about to do.

type Blast

type Blast struct {
	Pods    int    `json:"pods"`
	Summary string `json:"summary,omitempty"`
	// Unknown marks a radius nobody computed. Rendering it as zero would be a
	// claim nobody made.
	Unknown bool `json:"unknown,omitempty"`
}

Blast is what an action touches.

type Clock

type Clock interface{ Now() time.Time }

Clock is injected so the window's expiry is tested without waiting.

type Gate

type Gate struct {
	Permitted   bool   `json:"permitted"`
	Require     string `json:"require,omitempty"`
	Confirm     string `json:"confirm,omitempty"`
	Environment string `json:"environment"`
	Risk        string `json:"risk"`
	Policy      string `json:"policy"`
	Reason      string `json:"reason,omitempty"`
	Kubectl     string `json:"kubectl,omitempty"`
	Blast       Blast  `json:"blast"`
	// UnlockedUntil is when a break-glass window closes, empty when locked.
	UnlockedUntil string `json:"unlockedUntil,omitempty"`
}

Gate is the answer: whether the action may proceed, and what it costs.

type Guard

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

Guard holds the break-glass windows. They live in memory and die with the process, like everything else: a tool that remembers prod was unlocked yesterday is a tool that unlocks prod tomorrow.

func New

func New(clock Clock) *Guard

New builds a guard.

func (*Guard) Check

func (g *Guard) Check(contextName string, env environments.Environment, a Action) Gate

Check answers whether one action may proceed in one environment.

func (*Guard) Lock

func (g *Guard) Lock(contextName string)

Lock closes a window early, which is what somebody does when they are done rather than waiting out the clock.

func (*Guard) Unlock

func (g *Guard) Unlock(contextName, reason string) (Unlock, error)

Unlock arms one environment for the break-glass window.

The reason is required and kept. Somebody arming production should have to say why, and the record is what makes that legible afterwards.

type Unlock

type Unlock struct {
	Context string    `json:"context"`
	Reason  string    `json:"reason"`
	At      time.Time `json:"at"`
	Until   time.Time `json:"until"`
}

Unlock is the record of somebody arming an environment. It belongs on the session timeline: arming production is an event, not a setting.

Jump to

Keyboard shortcuts

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