check

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 25 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 check compares a committed application stack with what the code declares: it renders the stack afresh and reports every owned file whose committed content differs, which is the drift between the code and the infrastructure.

Index

Constants

View Source
const (
	GoModulesStage   = "go-modules"
	WebPackagesStage = "web-packages"
)

The reserved stages of the seeded Dockerfile: the Go module download and the browser package install, which the image build caches per commit.

Variables

ReservedStages lists the two, in the order the image build builds them.

Functions

func Migrations

func Migrations(appDir string, m *derive.Model) (findings []MigrationFinding, spans []MigrationSpan, err error)

Migrations reads the application's migration directories, the schema migrations and the seed beside them, by the sequence rule (migration.Sequence) and answers every problem and each directory's span. It is bedrock check's reading of the migrations, which bedrock render applies before the first push and bedrock migration check in the CI migrations job, over the whole directory rather than a pull request's changes.

func MigrationsFix

func MigrationsFix(ctx context.Context, appDir string) string

MigrationsFix is the line that names the fix for the sequence rule's findings while the checkout has no release tag: until the first release a committed migration may still change, and bedrock migration renumber packs the whole sequence from 000001. Empty once a release tag is in the checkout, or outside a git work tree, where git says nothing.

func Sees

func Sees(stages []Stage, name string, args []string) []string

Sees lists the build arguments among args that the named stage can see, in the order args gives them: those it declares with ARG, those its FROM line reads (an ARG before the first FROM reaches the FROM lines alone), and those any stage it is built on can see, the stage its FROM names and every stage it copies from (COPY --from), since what such a stage holds depends on their values. None for a stage the Dockerfile lacks.

Types

type Authoritative

type Authoritative struct {
	// Path is the file's path relative to the stack directory.
	Path string
	// Line is the resource block's line (1-based).
	Line int
	// Address is the resource's type.name.
	Address string
}

Authoritative is an authoritative IAM resource (a *_iam_binding or *_iam_policy) declared in one of the stack's files, other than a file store's bucket policy. The stack refuses them: such a resource replaces every member of its role or policy on each apply, so a pull-request stack applying one would remove the environment's members, and two pull requests each other's. A *_iam_member adds one member and removes only that one. The file stores' bucket policies (google_storage_bucket_iam_policy.<store>, as storage.tf declares them) are admitted by address: the stack sets each bucket's whole permission list on purpose, so that Cloud Storage's default grants to the project's basic roles are gone from it, and a pull-request stack makes buckets of its own, so its policies remove nobody else's members. A policy on any other bucket, and a binding on a file store's bucket, stay refused.

func ScanAuthoritative

func ScanAuthoritative(dir string, admitted []string) ([]Authoritative, error)

ScanAuthoritative finds the authoritative IAM resources in every .tf file of the directory, a person's files included, other than the ones at the admitted addresses (the file stores' bucket policies): what check refuses, and what the pipeline's test of a stack's plan refuses before the apply.

type BinaryFinding

type BinaryFinding struct {
	// Process is the program's name (migrate, jobs, hooks), Dir its main package, Binary
	// the path in the image, and Runs what runs it (the migration steps, the job, the
	// hook steps).
	Process string
	Dir     string
	Binary  string
	Runs    string
}

BinaryFinding is a program whose binary the Dockerfile does not build.

type BuildArgumentFinding

type BuildArgumentFinding struct {
	// Name is the argument's name, Value the catalog's value it carries.
	Name  string
	Value string
}

BuildArgumentFinding is a build argument the placement declares that no stage of the Dockerfile declares with ARG.

type BuildSecretFinding

type BuildSecretFinding struct {
	// ID is the mount's id, the secret's name.
	ID string
	// Missing lists the environments whose build_secrets declare no such secret, in
	// promotion order.
	Missing []string
}

BuildSecretFinding is a build secret the Dockerfile mounts as required that some environment does not declare.

type BundleFinding

type BundleFinding struct {
	// Var is the site's variable, Path the bundle it names (web/dist/console).
	Var  string
	Path string
}

BundleFinding is a browser bundle the Dockerfile does not set the site's variable for: the site would serve the bundle from the code's default, a path the image does not hold.

type CloudArmorFinding

type CloudArmorFinding struct {
	// Environment is the environment, the entry's key in cloud_armor.
	Environment string
	// Mode is the entry's value on the branch: "preview" or "enforce".
	Mode string
	// Ref is where the branch's copy was read: the default branch's ref by hand
	// (origin/<branch>, or the local branch), the base branch's name in the pipeline.
	Ref string
}

CloudArmorFinding is one environment whose Cloud Armor entry the working tree removes while the branch it merges into has the policy on.

func CompareCloudArmor

func CompareCloudArmor(now, committed []byte, nowFile, committedRef string) ([]CloudArmorFinding, error)

CompareCloudArmor compares two copies of the stack's terraform.tfvars for a Cloud Armor policy removed in one step: now is the working tree's (named for a message by nowFile; empty when the tree has no file, which holds no map), committed the copy on the branch the change merges into, read at committedRef (empty when there is no copy to compare with). An environment on there ("preview" or "enforce") and absent here is a finding, in the committed copy's order; an environment at "off" there may go. A map that is not written out ({ ... }), a key that is not a string and a value that is not a literal string are refused on either side. bedrock check calls it with the default branch's copy read through git, and the check trigger's plan step with the base branch's read through GitHub, so the one rule holds by hand and in the pipeline.

func (*CloudArmorFinding) Problem

func (f *CloudArmorFinding) Problem() string

Problem says what removing the entry in one step does and the two steps that take it out: the check's refused line and the pipeline guard's, so the sentence lives once.

type Finding

type Finding struct {
	// Path is the file's path relative to the stack directory, or to the application
	// root when Root is set.
	Path string
	// Root is true for a file at the application root (the pipeline files).
	Root bool
	// Missing reports a file the render produces that the directory lacks.
	Missing bool
	// Line is the first differing line (1-based), 0 when Missing.
	Line int
	// Want and Got are that line as rendered and as committed.
	Want string
	Got  string
}

Finding is one file that is not as the render says it should be.

type GeneratedFinding

type GeneratedFinding struct {
	// Environment is the environment, and Variable the environment variable the secret
	// feeds, its key in secret_versions.<environment>.
	Environment string
	Variable    string
	// Problem says what the entry is and what to write.
	Problem string
}

GeneratedFinding is one disagreement between a secret's tag in the code and its entry in an environment's secret_versions.

type ImageStart

type ImageStart struct {
	// Found says what the Dockerfile sets, as written: `ENTRYPOINT ["/app"]`,
	// `CMD ["/console"]`, the two joined, or that it sets neither.
	Found string
	// Multi reports the sites layout, whose contract the start is held to.
	Multi bool
	// Binary is the binary the image starts on its own, and in the sites layout Site
	// the site it serves; both empty when Problem is set, and Site in the flat layout.
	Binary string
	Site   string
	// Problem is what is wrong with a sites-layout image's start, empty when it
	// passes.
	Problem string
	// Lines are the lines a sites-layout image ends with, the comment and the CMD
	// naming the first site's binary, as the seeded Dockerfile has them; empty in the
	// flat layout.
	Lines string
}

ImageStart is how the image starts, read from the ENTRYPOINT and CMD of the Dockerfile's last stage, the one the image is: a line of the report when the start follows the layout's contract, a refusal when a sites-layout image breaks it (Problem set).

func ScanStart

func ScanStart(appDir string, m *derive.Model) (*ImageStart, error)

ScanStart reads the Dockerfile at the application root for how the image starts and holds it to the layout's contract: in the sites layout no ENTRYPOINT and a CMD in the exec form naming one site's binary (the first site's is the default the seeded Dockerfile writes); in the flat layout whatever the image sets, described and never refused. It answers nil without a Dockerfile (the unseeded finding covers it) and for a flat image that sets neither instruction. It is bedrock check's reading, and the one bedrock render repeats for the Dockerfile it keeps.

func (*ImageStart) Passed

func (s *ImageStart) Passed() string

Passed is the report's line for a start that follows the contract: in the sites layout the image sets no entrypoint and its default command is a site's binary; in the flat layout the image starts the site as it says, and its service runs it as written.

func (*ImageStart) Refusal

func (s *ImageStart) Refusal(dockerfile string) []string

Refusal is the refusal's text, for the report's refused line and bedrock render's note: the first line names the Dockerfile as given, says what it sets and why the stack's services cannot start with it, and the lines after it are the ones to end the image with.

type Instruction

type Instruction struct {
	Line    int
	Keyword string
	Args    string
}

Instruction is one Dockerfile instruction: its line, its keyword in upper case, and its arguments with continuation lines joined.

func (Instruction) Copies

func (in Instruction) Copies() (from string, sources []string)

Copies reads a COPY or ADD instruction: the stage or image it copies from (--from, empty for the build context) and its sources, the destination left off. Another instruction answers nothing.

type LatestSecret

type LatestSecret struct {
	// Environment is the environment, and Variable the environment variable the secret
	// feeds, its key in secret_versions.<environment>.
	Environment string
	Variable    string
}

LatestSecret is one secret an environment runs at whatever version is added next.

type MaintenanceFinding

type MaintenanceFinding struct {
	// Problem says what is missing or over, and the fix.
	Problem string
}

MaintenanceFinding is one warning about the maintenance windows.

type MigrationFinding

type MigrationFinding struct {
	// Path is the file, or the directory for a problem of the sequence as a whole.
	Path string
	// Problem says what is wrong, the way a person reads it.
	Problem string
}

MigrationFinding is one problem with the migrations directory.

type MigrationSpan

type MigrationSpan struct {
	Dir string
	migration.Span
}

MigrationSpan is what one migration directory holds as the sequence rule reads it: the directory as the application names it, and the count and the lowest and highest index.

type ProgramsFinding

type ProgramsFinding struct {
	// Programs are the application's shipped programs, by directory.
	Programs []derive.ReleaseProgram
}

ProgramsFinding is the shipped programs the release files declare where no stage of the Dockerfile declares the PROGRAMS build argument.

func (*ProgramsFinding) Refusal

func (f *ProgramsFinding) Refusal(dockerfile string) []string

Refusal is the refusal's text, for the report's refused line: the first line names the Dockerfile as given, the programs the release files ship and why the image would carry none, and the lines after it are the ones to add, the compile and then the copy.

type ReleaseLineFinding

type ReleaseLineFinding struct {
	// Path is the configuration file, relative to the application root.
	Path string
	// Problem says what is wrong, the way a person reads it.
	Problem string
}

ReleaseLineFinding is a release-please setting under which a feature release does not open a new patch line.

type ReleaseSectionFinding

type ReleaseSectionFinding struct {
	// Path is the configuration file, relative to the application root.
	Path string
	// Package is the package whose own changelog-sections lacks the types, empty for the
	// top level.
	Package string
	// Missing are the accepted types without a section, in the title check's order.
	Missing []string
}

ReleaseSectionFinding is a release-please changelog-sections list that lacks a type the title check accepts.

func (ReleaseSectionFinding) Problem

func (f ReleaseSectionFinding) Problem() string

Problem says what is wrong, the way a person reads it: the level, the types and the fix.

type Report

type Report struct {
	// Dir is the stack directory checked, and AppDir the application root its pipeline
	// files were checked at.
	Dir    string
	AppDir string
	// Checked counts the owned files compared.
	Checked int
	// Findings are the owned files that differ or are missing, in path order.
	Findings []Finding
	// Unseeded lists the seeded files the directory lacks: not drift, since the tool
	// writes them once and a person keeps them, but worth a line.
	Unseeded []string
	// Authoritative lists the authoritative IAM resources declared anywhere in the
	// stack, owned files and a person's alike, in path then line order, the file
	// stores' bucket policies excepted.
	Authoritative []Authoritative
	// Undeclared lists the input variables the stack's .tf files read (var.<name>),
	// owned files and a person's alike, that no variable block among them declares, in
	// path then line order: tofu refuses the plan at its first step over any one of
	// them, with nothing else in the stack read.
	Undeclared []render.UndeclaredVariable
	// Migrations are the problems with the schema migrations directory: a file that
	// is not a migration, an index with two up files, a gap in the sequence.
	// MigrationsFix names their fix when the checkout has no release tag: the renumber
	// packs the whole sequence until the first release (MigrationsFix).
	Migrations    []MigrationFinding
	MigrationsFix string
	// BuildSecrets are the build secrets the Dockerfile mounts as required that some
	// environment's placement does not declare.
	BuildSecrets []BuildSecretFinding
	// Binaries are the jobs whose command the Dockerfile does not build, and Bundles the
	// browser bundles whose variable it does not set.
	Binaries []BinaryFinding
	Bundles  []BundleFinding
	// SiteBundles are the sites' bundles in the sites layout, each held to one directory
	// across development and the stack: a line of the report when the Procfile's
	// directory is the one the workspace's build writes, refused when the Procfile sets
	// none or one the build does not write (SiteBundle.Problem). Empty in the flat
	// layout.
	SiteBundles []SiteBundle
	// Start is how the image starts, read from the Dockerfile's ENTRYPOINT and CMD: a
	// line of the report when it follows the layout's contract, and refused when a
	// sites-layout image sets an entrypoint or no default command naming a site's
	// binary (Start.Problem), since each site's service passes its binary as the
	// container's arguments, which replace only a default command. Nil without a
	// Dockerfile, and for a flat image that sets neither instruction.
	Start *ImageStart
	// Stages are the instructions the Dockerfile's reserved stages hold beyond their
	// install, which the image build would export to the registry's cache for every
	// environment; MissingStages are the reserved stages the Dockerfile lacks, whose
	// downloads the image build then caches nothing of (a warning, not drift).
	Stages        []StageFinding
	MissingStages []string
	// BuildArguments are the build arguments the placement declares (buildArguments) that
	// no stage of the Dockerfile declares with ARG.
	BuildArguments []BuildArgumentFinding
	// Programs are the shipped programs the release files declare when no stage of the
	// Dockerfile declares the PROGRAMS build argument, under which the image build
	// compiles none of them; nil when the code ships none, or a stage declares it.
	Programs *ProgramsFinding
	// Retired lists the files an earlier bedrock rendered at the application root that
	// are still committed (render.Retired); bedrock render removes them.
	Retired []string
	// ReleaseLines are the release-please settings under which a feature release would
	// not open a new patch line (a feature on the patch below 1.0).
	ReleaseLines []ReleaseLineFinding
	// ReleaseSections are the release-please changelog-sections lists that lack a type
	// the CI's title check accepts, under which a merge of only such titles would never
	// release.
	ReleaseSections []ReleaseSectionFinding
	// ReleaseFiles are release-please's files the application root lacks (its
	// configuration, its manifest): seeded files like the Dockerfile, but without them
	// the release workflow cuts no release and nothing reaches an environment, so their
	// absence is refused where another seeded file's is a line of the report.
	ReleaseFiles []string
	// Maintenance are the warnings about the maintenance windows: production without a
	// setting, a release file the checkout lacks, a dated slot that has passed. Warnings,
	// not drift: the check stays clean, so the refusal at run start is never the first
	// sign.
	Maintenance []MaintenanceFinding
	// CloudArmor are the environments whose Cloud Armor entry in terraform.tfvars the
	// working tree removes while the default branch has the policy on ("preview" or
	// "enforce"): removing the entry detaches the policy and destroys it in one apply,
	// which fails while the policy is attached, so the entry goes to "off" first.
	CloudArmor []CloudArmorFinding
	// SignInThreshold are the sign-in throttle's variables in terraform.tfvars
	// (cloud_armor_sign_in_count, cloud_armor_sign_in_interval) whose value is not a
	// positive whole number: the policy could not take it, and the stack's own
	// validation refuses the same at plan.
	SignInThreshold []SignInThresholdFinding
	// Latest are the secrets an environment's secret_versions in terraform.tfvars lets
	// track the newest version (the word latest in place of a version number), in
	// promotion order and then by name. Information, not drift: pinning is the default and
	// latest the exception a secret with a real need takes, and the check names each one
	// so the exception stays visible.
	Latest []LatestSecret
	// Generated are the entries of secret_versions in terraform.tfvars that disagree with
	// the code's secret tags, per environment: a secret the tooling makes
	// (secret:"generated" or secret:"versioned", whose versions the pipeline derives at
	// each build) with a version number, latest, the other tag's word or no entry, where
	// its own tag's word belongs; and a secret someone puts in place carrying either
	// word. Refused: the stack's own precondition refuses the same.
	Generated []GeneratedFinding
	// Retirements are the entries of retired in terraform.tfvars, the variables a
	// release retires: each a line of the report naming what the variable declares (a
	// secret, a build secret, a file store, the Firestore database), whose protection
	// against a destroy the release's apply lifts in every environment so that the next
	// release can remove the declaration; and refused when nothing declares the variable
	// (Retirement.Problem), since the release that removes a declaration takes its name
	// out of the list with it.
	Retirements []Retirement
}

Report is the outcome of one check.

func Run

func Run(ctx context.Context, m *derive.Model, dir, appDir string) (*Report, error)

Run renders the model and compares the owned files with the directory's, and the owned files at the application root with appDir's. It also reads the schema migrations directory and the seed directory beside it for a sequence the migrate command could not apply in order, and the stack's placement against the default branch's for a Cloud Armor policy removed in one step.

func (*Report) Clean

func (r *Report) Clean() bool

Clean reports no drift, no refused resource, every variable read declared, a sound migration sequence, every required build secret declared, every job's binary built, an image that starts as the layout's contract says, reserved stages holding their install alone, every declared build argument declared by the Dockerfile, the shipped programs' build argument declared when the code ships any, release lines that a feature release opens, a changelog section for every accepted title type, release-please's files in place, no Cloud Armor policy removed in one step, and a sign-in throttle threshold the policy can take, and no retired variable that nothing declares.

func (*Report) Write

func (r *Report) Write(w io.Writer)

Write prints the report the way a person reads it: one line per file, the first differing line under each.

type Retirement

type Retirement struct {
	// Variable is the entry, the variable a secret, a build secret, a file store or the
	// Firestore database is declared by.
	Variable string
	// What says what the variable declares, and where; empty when nothing does.
	What string
	// Problem says why the entry is refused: nothing declares the variable.
	Problem string
}

Retirement is one entry of retired in terraform.tfvars.

type SignInThresholdFinding

type SignInThresholdFinding struct {
	// Variable is the variable, cloud_armor_sign_in_count or cloud_armor_sign_in_interval.
	Variable string
	// Value is the value as the file writes it, for the message.
	Value string
}

SignInThresholdFinding is one sign-in throttle variable in terraform.tfvars whose value the policy could not take: not a number, not whole, or not above zero.

func (*SignInThresholdFinding) Problem

func (f *SignInThresholdFinding) Problem() string

Problem says what the variable is and what a value of it is.

type SiteBundle

type SiteBundle struct {
	// Site is the site's name, Variable its bundle variable (APP_DIST).
	Site     string
	Variable string
	// Procfile is the directory the site's process line in the Procfile sets the
	// variable to, as written there, root-relative; empty when no line sets it.
	Procfile string
	// Output is the root-relative directory the workspace's build writes the bundle to
	// (angular.json's outputPath); empty when angular.json names no single application
	// project to read it from.
	Output string
	// Served is the directory the stack sets the service's variable to, under the
	// image's working directory.
	Served string
	// Problem is what is wrong, empty when the site passes.
	Problem string
}

SiteBundle is one site's bundle as the check reads it: the directory the Procfile sets for development, the one the workspace's build writes, and the one the stack's service serves; a line of the report when the Procfile's is the build's, a refusal when the Procfile sets none or one the build does not write (Problem set).

func (*SiteBundle) Passed

func (b *SiteBundle) Passed() string

Passed is the report's line for a site whose bundle is one directory throughout: where the service serves it from, as the Procfile sets it and, when angular.json could be read, as the build writes it.

type Stage

type Stage struct {
	Name         string
	Line         int
	Base         string
	Instructions []Instruction
}

Stage is one build stage of a Dockerfile: its name (empty for a stage without AS), the line of its FROM, the image or earlier stage its FROM names (Base), and the instructions after it.

func Named

func Named(stages []Stage, name string) *Stage

Named is the stage of the name, or nil.

func Stages

func Stages(src []byte) []Stage

Stages reads the Dockerfile's stages: comment lines are dropped, a line ending in a backslash continues on the next, and a keyword is read whatever its case.

func (*Stage) Args

func (s *Stage) Args() []string

Args are the build arguments the stage declares with ARG, in order: each name of an ARG instruction, with or without a default (ARG NAME, ARG NAME=value, several on one line). A build argument reaches a stage's instructions only once the stage declares it.

type StageFinding

type StageFinding struct {
	// Stage is the reserved stage, Line the instruction's line, Instruction the
	// instruction as written (its first line), and Problem what is wrong with it.
	Stage       string
	Line        int
	Instruction string
	Problem     string
}

StageFinding is an instruction a reserved stage holds that it must not.

Jump to

Keyboard shortcuts

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