Documentation
¶
Overview ¶
Package rules derives the map (schema cernly.map/v1) from a scan's facts: links from services to their code, and which stack is production. Facts in, map out: no file, network or clock access, so the same facts and settings give the same map. See https://cernly.dev/how/map/.
Index ¶
- Constants
- Variables
- func LicenceDenied(expr string, deny []string) (hit []string, ok bool)
- func NameSegments(name string) []string
- func SensitiveWord(name, typ string) string
- func Transitive(f fact.Fact) bool
- func ValidConfirmation(kind, subject, value string) bool
- type AITool
- type Attached
- type CIBuild
- type CIImage
- type Catalogue
- type ConfirmRef
- type Confirmation
- type ConfirmationUse
- type Coupling
- type Declarant
- type Dismissed
- type Entry
- type Finding
- type GateFinding
- type GatePolicy
- type GateResult
- type Image
- type ImportCycle
- type ImportEdge
- type InternalUse
- type Items
- type JobRef
- type LanguageSize
- type Link
- type Map
- type Metrics
- type ModuleGraph
- type OwnHost
- type Package
- type Party
- type Pin
- type Push
- type Reason
- type RouteEdge
- type SDK
- type ScanRef
- type SensitiveColumn
- type ServiceItems
- type ServiceMetrics
- type ServiceModules
- type Settings
- type Signal
- type Size
- type StackRole
- type Surface
- type Table
- type TestJob
- type TestPresence
- type UnknownHost
Constants ¶
const ( ConfirmStackRole = "stack_role" ConfirmParty = "party" ConfirmHost = "host" ConfirmDriver = "driver" // subject a dependency key; value store:<the store it talks to> or not_used ValueApproved = "approved" ValueNotSupplier = "not_supplier" ValueOwn = "own" ValueNotUsed = "not_used" ValueStorePrefix = "store:" )
Confirmation kinds and values.
const ( StatusApplied = "applied" StatusOverridden = "overridden" // a declaration in the scan says otherwise, and wins StatusNoSubject = "no_subject" // this scan has no such stack, party or host StatusIgnored = "ignored" // a kind or value these rules do not know )
Confirmation statuses in the map.
const ( GradeConfirmed = "confirmed" // two or more signal kinds agree, from two or more facts GradeSingle = "single" // one signal kind, or one fact )
Party grades.
const ( SchemaID = "cernly.map/v1" // Bump on any change to the map output; see CHANGELOG.md. Version = "0.15.0" )
const ( RoleProduction = "production" RoleUnconfirmed = "production (unconfirmed)" RoleNone = "none" )
Stack roles.
const ( FindingNoCodeLink = "no_code_link" FindingLinkConflict = "link_conflict" FindingProductionUnconfirmed = "production_unconfirmed" FindingImagePinning = "image_pinning" )
Finding rules.
const DeploymentNotSeen = "not_seen"
DeploymentNotSeen: no deployment of the image is in the repo. Kubernetes, Helm or Terraform adapters may later show where an image runs; until then this is the only value.
const FindingDriverWithoutStore = "driver_without_store"
FindingDriverWithoutStore: a service ships a database driver, but the repo describes no data store of that engine. A driver never becomes a data store: a service can ship one it does not use. A person confirms which store it talks to, or dismisses it, through a driver confirmation.
const FindingPartyUnconfirmed = "party_unconfirmed"
const GateSchemaID = "cernly.gate/v1"
const RendersOnly = "renders only, does not deploy"
RendersOnly is the reason of a job that reaches a stack but never starts it: helm template or lint, kustomize build, compose config, --dry-run.
Variables ¶
var SensitiveWords = []string{
"password", "passwd", "pwd", "passphrase",
"secret", "token", "api_key", "apikey", "access_key", "private_key",
"iban", "bic", "card", "cvv", "cvc",
"ssn", "national_id",
"email", "phone",
"birth", "birthdate", "dob",
"salary",
}
SensitiveWords is the fixed list. An entry of two segments matches two consecutive segments of the name.
Functions ¶
func LicenceDenied ¶
LicenceDenied reads a declared licence as an SPDX expression and reports the ids on the deny list that every way of meeting it needs: OR needs one branch, AND needs both, "X WITH exception" counts as X, a trailing + is ignored. Ids compare without regard to case. ok is false when the expression does not parse; such a licence never matches (no guessing).
func NameSegments ¶
NameSegments splits a column name on anything not a letter or digit and on camelCase boundaries, lowercased: "apiKeyHash" and "api_key_hash" are both [api key hash]; "HTTPToken" is [http token]; digits stay with the letters before them ("card_last4" is [card last4]).
func SensitiveWord ¶
SensitiveWord returns the list entry a column name matches, or "". The type exception: a boolean column holds no such value (email_verified).
func Transitive ¶
Transitive reports a dependency from a lockfile that no manifest declares. The rules read direct dependencies only: the attach rule, the provider catalogue's SDK signal and the gate's new_dependency. The SBOM reads both.
func ValidConfirmation ¶
ValidConfirmation reports whether the rules know this kind and value, and the subject has the kind's form.
Types ¶
type AITool ¶
type AITool struct {
Tool string `json:"tool"`
Name string `json:"name"`
Files int `json:"files"`
From []string `json:"from"`
}
AITool is an AI coding tool the repo is set up for (agent_config facts): repo-level proof, not proof of which change it wrote.
type Attached ¶
type Attached struct {
Service string `json:"service"`
Fact string `json:"fact"`
Kind string `json:"kind"`
Scope string `json:"scope,omitempty"`
Internal string `json:"internal,omitempty"` // repo folder, when the dependency is an internal package
Source string `json:"source"` // the link source the evidence lies in
From []string `json:"from"`
}
Attached puts a fact that lives in a service's code on that service: a dependency whose manifest, an env var or outbound host whose file, lies in the sources of a recipe the service is linked to. Nothing is filtered; scope is shown as the fact has it. Service is a service key, or a ci_image key for an image built in CI.
type CIBuild ¶
type CIBuild struct {
Build string `json:"build"` // image_build fact key
Workflow string `json:"workflow"`
Job string `json:"job"`
JobName string `json:"job_name,omitempty"`
JobLine int `json:"job_line,omitempty"`
Line int `json:"line,omitempty"` // the step that builds it, or reaches the script that does
Events []string `json:"events"`
Branches []string `json:"branches"`
TestJob *TestJob `json:"test_job,omitempty"`
}
CIBuild is one CI job that builds the image.
type CIImage ¶
type CIImage struct {
Image string `json:"image"` // ci_image:<dockerfile>:<stage>, the subject in attached[] and parties
Recipe string `json:"recipe"`
Dockerfile string `json:"dockerfile"`
Target string `json:"target"` // the stage built: the named target, or the final stage's name
ImageRepos []string `json:"image_repos"`
Builds []CIBuild `json:"builds"`
Pushes []Push `json:"pushes"`
Contexts []string `json:"contexts"`
Sources []string `json:"sources"`
Precision string `json:"precision"`
TestOnly bool `json:"test_only"` // every CI job that builds it is a test job
Deployment string `json:"deployment"` // not_seen: nothing in this repo shows where it runs
Detail string `json:"detail"`
From []string `json:"from"`
}
CIImage is an image a CI job builds that no Compose service of the repo runs. It is a box of its own on the map, so the application a repo ships is not missing when its deployment lives elsewhere. It is never production: where it runs is not in this repo.
type ConfirmRef ¶
type ConfirmRef struct {
ID int64 `json:"id"`
Value string `json:"value"`
By string `json:"by"`
At string `json:"at"`
Overridden bool `json:"overridden,omitempty"` // a declaration in the scan wins
}
ConfirmRef marks an item a confirmation is about.
type Confirmation ¶
type Confirmation struct {
ID int64 `json:"id"` // the entry in the instance's trail
Kind string `json:"kind"` // stack_role, party or host
Subject string `json:"subject"` // a stack key, party:<id> or host:<host>
Value string `json:"value"` // stack_role: production or none; party: approved or not_supplier; host: also own
Reason string `json:"reason"`
By string `json:"by"` // display name
Issuer string `json:"issuer,omitempty"` // who, as the sign-in provider knows them
Person string `json:"person,omitempty"` // the provider's subject for them
At string `json:"at"` // when it was made, RFC 3339
}
Confirmation is a decision a person made outside the repo: a stack's role, or what an outside party or host is. It is an input to the rules, like the default branch, recorded in the map's settings; it never changes a fact. A declaration in the scan (.cernly.yml or the operator's file) wins over it.
type ConfirmationUse ¶
type ConfirmationUse struct {
Confirmation
Status string `json:"status"`
}
ConfirmationUse is what one confirmation did to this map.
type Coupling ¶
type Coupling struct {
Packages int `json:"packages"`
Imports int `json:"imports"` // edges between them
MaxFanIn int `json:"max_fan_in"`
MaxFanOut int `json:"max_fan_out"`
Cycles int `json:"cycles"`
Depth int `json:"depth"`
}
Coupling is the coupling of a set of packages: a service's, or all.
type Declarant ¶
type Declarant struct {
By string `json:"by"` // repo (.cernly.yml) or operator
Line int `json:"line,omitempty"`
}
Declarant is who declared something and where.
type Dismissed ¶
type Dismissed struct {
Subject string `json:"subject"`
Kind string `json:"kind"` // party or host
Name string `json:"name"`
Confirmed ConfirmRef `json:"confirmed"`
From []string `json:"from"`
}
Dismissed is a party or host a person said is not a supplier: moved here from parties or unknown, so a reader can tell it from one never found.
type Entry ¶
type Entry struct {
ID string `json:"id"`
Name string `json:"name"`
Category string `json:"category"`
Kind string `json:"kind"` // provider or protocol
SDKs []SDK `json:"sdks"`
EnvPrefixes []string `json:"env_prefixes"`
Hosts []string `json:"hosts"`
Images []string `json:"images"`
InternalEngines []string `json:"internal_engines,omitempty"` // protocol: a data store of this engine in the stack serves it
ResolvedBy []string `json:"resolved_by,omitempty"` // protocol: a provider whose match on the same service names it
Sources []string `json:"sources"`
Checked string `json:"checked"`
Review string `json:"review"`
}
type Finding ¶
type Finding struct {
Rule string `json:"rule"`
Subject string `json:"subject"`
Grade string `json:"grade,omitempty"` // image_pinning: floating, unknown or exact
Image string `json:"image,omitempty"` // image_pinning: registry/repository, no tag
Detail string `json:"detail"`
From []string `json:"from"`
}
type GateFinding ¶
type GateFinding struct {
Rule string `json:"rule"`
Level string `json:"level"`
Subject string `json:"subject"`
Detail string `json:"detail"`
From []string `json:"from"`
Evidence []fact.Evidence `json:"evidence"`
}
GateFinding is one thing the head adds that the policy watches. Evidence is the head scan's file and line for the facts in From.
type GatePolicy ¶
type GatePolicy struct {
Rule string `json:"rule"`
Level string `json:"level"`
By string `json:"by"`
Line int `json:"line,omitempty"`
// Licences: licence_not_allowed only, the ids from both sides (a deny
// list is stricter the longer it is).
Licences []string `json:"licences,omitempty"`
}
GatePolicy is one rule's level in effect, and who set it. By is default when neither side declared the rule.
func Policy ¶
func Policy(s *fact.Scan) []GatePolicy
Policy is the level per rule a scan's config section sets: the stricter of the repo's and the operator's, or the rule's default (config.GateDefault) when neither names it. Without an operator entry the repo may also set off; the gate shows that as gate_loosened when the base was stricter.
type GateResult ¶
type GateResult struct {
Schema string `json:"schema"`
Base ScanRef `json:"base"`
Head ScanRef `json:"head"`
RulesVersion string `json:"rules_version"`
Policy []GatePolicy `json:"policy"`
Findings []GateFinding `json:"findings"`
Blocked bool `json:"blocked"` // a finding at level block
}
GateResult is the outcome of one comparison.
type ImportCycle ¶
ImportCycle is a set of packages that import each other, directly or through one another (a strongly connected component of more than one).
type ImportEdge ¶
type InternalUse ¶
type InternalUse struct {
ID string `json:"id"`
Service string `json:"service"`
Datastore string `json:"datastore"`
From []string `json:"from"`
}
InternalUse is a protocol served inside the stack (S3 by a MinIO data store), so it is left off the outside parties.
type Items ¶
type Items struct {
ServiceItems
ProductionStacks []string `json:"production_stacks"`
}
Items are what each count counts (rules 0.10.0), so a reader can trace a number to its facts: party ids (each party lists its signal facts), data store keys, columns as table.column (the table lists its facts), the image_pinning findings by subject and image, production stack keys and route keys. Each list is as long as its count.
type LanguageSize ¶
type Link ¶
type Link struct {
Service string `json:"service"`
Recipe string `json:"recipe"`
Contexts []string `json:"contexts"`
Sources []string `json:"sources"` // repo paths: the recipe's sources inside each build context
Precision string `json:"precision"`
Via []string `json:"via"`
From []string `json:"from"`
}
type Map ¶
type Map struct {
Schema string `json:"schema"`
Scan ScanRef `json:"scan"`
RulesVersion string `json:"rules_version"`
CatalogueVersion string `json:"catalogue_version"`
Settings Settings `json:"settings"`
Stacks []StackRole `json:"stacks"`
Links []Link `json:"links"`
Images []Image `json:"images"`
CIImages []CIImage `json:"ci_images"`
Attached []Attached `json:"attached"`
Parties []Party `json:"parties"`
Internal []InternalUse `json:"internal"`
Unknown []UnknownHost `json:"unknown"`
Own []OwnHost `json:"own"`
Routes []RouteEdge `json:"routes"`
AITools []AITool `json:"ai_tools"`
Findings []Finding `json:"findings"`
// Database tables merged across schema sources, with the columns to
// check. Absent when the scan has no db_table facts.
Tables []Table `json:"tables,omitempty"`
// Test suites per service and the commands that run them. Absent
// without test_suite facts.
Tests []TestPresence `json:"tests,omitempty"`
// What each confirmation in settings did, and the parties and hosts a
// person dismissed. Absent without confirmations.
Confirmations []ConfirmationUse `json:"confirmations,omitempty"`
Dismissed []Dismissed `json:"dismissed,omitempty"`
// The import graph of the repo's own packages. Absent when the scan has
// no import facts.
Modules *ModuleGraph `json:"modules,omitempty"`
// Surface metrics in total, in production and per service, with size
// and coupling as context.
Metrics *Metrics `json:"metrics"`
}
type Metrics ¶
type Metrics struct {
Total Surface `json:"total"`
Production Surface `json:"production"` // stacks whose role is production or production (unconfirmed)
Services []ServiceMetrics `json:"services"`
}
Metrics are the surface metrics: what can go wrong and where, counted from the map itself, for the whole repo, for its production stacks and per service. Size (files, lines, languages) is context next to them, never the headline. Coupling comes from the module graph.
type ModuleGraph ¶
type ModuleGraph struct {
Packages []Package `json:"packages"`
Edges []ImportEdge `json:"edges"`
Cycles []ImportCycle `json:"cycles"`
// What each service reaches: from its Go entrypoints when its recipe
// records resolved ones, else every package in its sources.
Services []ServiceModules `json:"services"`
}
ModuleGraph is the import graph of the repo's own packages: import facts as edges, the packages they name as nodes, with coupling per package. Absent when the scan has no import facts.
type OwnHost ¶
type OwnHost struct {
Host string `json:"host"`
Domain string `json:"domain"`
Declared *Declarant `json:"declared,omitempty"`
ServedBy []string `json:"served_by,omitempty"`
Confirmed *ConfirmRef `json:"confirmed,omitempty"` // claimed as own by a confirmation
From []string `json:"from"`
}
OwnHost is a host on one of the organisation's own declared domains: never an outside party, never unknown. OwnHost is a host of the organisation's own: on a declared own domain, or served by a route of the repo (proof), or both. Domain is the declared domain, or the host itself when it is only served.
type Package ¶
type Package struct {
Package string `json:"package"`
Language string `json:"language"`
Dir string `json:"dir"`
Module string `json:"module,omitempty"`
FanIn int `json:"fan_in"` // packages of the repo that import it
FanOut int `json:"fan_out"` // packages of the repo it imports
// Depth is the longest chain of imports below it, in packages; a cycle
// counts as one step.
Depth int `json:"depth"`
Cycle bool `json:"cycle,omitempty"`
}
type Party ¶
type Party struct {
ID string `json:"id"`
Name string `json:"name"`
Category string `json:"category"`
Kind string `json:"kind"`
Grade string `json:"grade"`
Services []string `json:"services"` // empty: matched only by facts on no service
Signals []Signal `json:"signals"`
Confirmed *ConfirmRef `json:"confirmed,omitempty"` // approved by a confirmation
}
type Push ¶
type Push struct {
Target string `json:"target"`
By string `json:"by"` // push or docker_push
Build string `json:"build"`
Workflow string `json:"workflow,omitempty"`
Job string `json:"job,omitempty"`
Line int `json:"line,omitempty"`
}
Push is a registry repository the image is pushed to, as written, tag stripped. By push the build command pushes all its tags (build-push-action push: true, --push); by docker_push a later step of the same job runs docker push with that name (line is that step's).
type Reason ¶
type Reason struct {
Workflow string `json:"workflow"`
Job string `json:"job"`
Role string `json:"role"`
Detail string `json:"detail"`
Unreadable []string `json:"unreadable,omitempty"`
TestJob *TestJob `json:"test_job,omitempty"`
}
Reason is the verdict on one workflow job that starts the stack.
type RouteEdge ¶
type RouteEdge struct {
Route string `json:"route"`
Stack string `json:"stack,omitempty"` // empty: no compose service mounts the file
Via string `json:"via,omitempty"` // the service that mounts the file
Sites []string `json:"sites"`
Match string `json:"match"`
Action string `json:"action"`
Upstream string `json:"upstream,omitempty"`
To string `json:"to,omitempty"`
From []string `json:"from"`
}
RouteEdge is one route of a web server config: the stack it runs in, through the service that mounts the config file, and the service it sends the request to. An upstream that names a service of the same stack becomes that edge; any other upstream (host.docker.internal, an outside address) stays as written, with no target.
type SDK ¶
SDK is a Go module (prefix up to a path boundary, so major versions and subpackages match) or an npm package (exact, or a scope when it ends in /).
type SensitiveColumn ¶
type SensitiveColumn struct {
Column string `json:"column"`
Word string `json:"word"` // the list entry that matched
From []string `json:"from"` // db_column fact keys, one per source
}
SensitiveColumn is a column whose name matches the word list: something to check (encryption and access), never a verdict. The name is all the rule reads; the facts cannot say how the value is stored or who reads it.
type ServiceItems ¶
type ServiceItems struct {
OutsideParties []string `json:"outside_parties"`
DataStores []string `json:"data_stores"`
ColumnsToCheck []string `json:"columns_to_check"`
UnpinnedImages []Pin `json:"unpinned_images"`
Routes []string `json:"routes"`
}
ServiceItems are a service's items: production stacks are not counted per service.
type ServiceMetrics ¶
type ServiceMetrics struct {
Service string `json:"service"`
Role string `json:"role"` // its stack's role; none for an image built in CI
OutsideParties int `json:"outside_parties"`
DataStores int `json:"data_stores"`
ColumnsToCheck int `json:"columns_to_check"`
UnpinnedImages int `json:"unpinned_images"`
Routes int `json:"routes"`
Size Size `json:"size"`
Coupling *Coupling `json:"coupling,omitempty"`
Items ServiceItems `json:"items"`
}
ServiceMetrics is one service's, or one image built in CI's, share. DataStores are the data stores it depends on in its stack.
type ServiceModules ¶
type Settings ¶
type Settings struct {
DefaultBranch string `json:"default_branch"`
// Confirmations in effect: decisions a person made outside the repo, passed by the caller. Absent
// when there are none, so older maps keep their bytes.
Confirmations []Confirmation `json:"confirmations,omitempty"`
}
type Size ¶
type Size struct {
Files int `json:"files"`
Lines int `json:"lines"`
TestFiles int `json:"test_files"`
TestLines int `json:"test_lines"`
Languages []LanguageSize `json:"languages"`
}
Size counts every source file; the test files and lines among them (by each language's convention) are counted again on their own.
type StackRole ¶
type StackRole struct {
Stack string `json:"stack"`
Name string `json:"name,omitempty"` // declared display name
Role string `json:"role"`
DerivedRole string `json:"derived_role,omitempty"` // what the rules derived, when a declaration replaced it
Declared *Declarant `json:"declared,omitempty"`
Confirmed *ConfirmRef `json:"confirmed,omitempty"` // a confirmation from the caller
Manual bool `json:"manual"`
Reasons []Reason `json:"reasons"`
}
type Surface ¶
type Surface struct {
OutsideParties int `json:"outside_parties"`
DataStores int `json:"data_stores"`
ColumnsToCheck int `json:"columns_to_check"`
UnpinnedImages int `json:"unpinned_images"`
ProductionStacks int `json:"production_stacks"`
Routes int `json:"routes"`
Size Size `json:"size"`
Coupling *Coupling `json:"coupling,omitempty"`
Items Items `json:"items"`
}
type Table ¶
type Table struct {
Table string `json:"table"` // the qualified name, as the facts give it
Schema string `json:"schema,omitempty"` // the part before the last dot; absent when the name has none
From []string `json:"from"` // db_table fact keys, one per source
Check []SensitiveColumn `json:"check,omitempty"` // columns whose name looks sensitive
}
Table is one database table as every schema source declares it: the SQL migrations and a Prisma schema that name the same qualified table are one table with two sources. The scanner already qualifies a name by its database convention (unqualified SQL is public unless the set is MySQL-shaped; Prisma on Postgres is public), so the name is the merge key and nothing is guessed here.
type TestJob ¶
type TestJob struct {
By string `json:"by"` // job_id, job_name, step_name or runner
Match string `json:"match"` // the name, or the first test runner command, as written
Line int `json:"line"` // line of the job or step in the workflow file
}
TestJob says why a CI job is a test job. A test job never makes a stack production.
type TestPresence ¶
type TestPresence struct {
Service string `json:"service,omitempty"` // service key; absent for a suite on no service
Suite string `json:"suite"`
Language string `json:"language"`
Framework string `json:"framework"`
Files int `json:"files"`
Runs []string `json:"runs"` // test_run keys that cover the suite
Jobs []JobRef `json:"jobs,omitempty"` // CI jobs that reach one of those runs
From []string `json:"from"`
}
TestPresence says whether a service's code has tests and whether a command runs them: test_suite facts inside the service's link sources, and the test_run facts that cover each suite. No coverage: nothing is run. Whether the job ran on a change is the checks reader's.
type UnknownHost ¶
type UnknownHost struct {
Host string `json:"host"`
Usage string `json:"usage"`
Confirmed *ConfirmRef `json:"confirmed,omitempty"` // approved as a supplier by a confirmation
From []string `json:"from"`
}
UnknownHost is a host no catalogue entry claims: the unknown bucket. Usage is the strongest way it was seen: request, default (outbound), env_hint (an example env value), mention (a literal that is not shown to be called).