canary

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: GPL-3.0 Imports: 15 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 canary plants fake credentials and watches for them leaving.

A canary is a value that looks exactly like a real secret — an AWS key pair, a GitHub token, a database password — and is worth nothing. Put it where an agent could read it (a decoy .env, a fake credentials file) and nothing legitimate will ever send it anywhere. So when a tool call carries it out, in plain text or base64 or hex or URL-encoded, that call is an exfiltration attempt, and agentgate stops it.

Index

Constants

This section is empty.

Variables

View Source
var Kinds = []string{"aws", "github", "openai", "stripe", "password"}

Kinds of canary, each shaped like the real thing.

Functions

func Strings

func Strings(v any) string

Strings flattens a decoded JSON value into its strings, keys included, one per line. Searching those rather than the raw JSON undoes the escapes (\u0041 for A) a value could otherwise hide behind.

Types

type Canary

type Canary struct {
	ID    string `json:"id"`
	Label string `json:"label,omitempty"`
	Kind  string `json:"kind"`
	// Values are the strings that must never leave: an access key id and
	// its secret, a token, a password.
	Values []string `json:"values"`
	// File is the decoy written for it, if any.
	File      string    `json:"file,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

Canary is one planted fake secret.

func Generate

func Generate(kind, label string) (Canary, error)

Generate makes a new canary of a kind.

func (Canary) Decoy

func (c Canary) Decoy() string

Decoy renders the canary as the file an agent would expect to find it in.

func (Canary) DecoyFor

func (c Canary) DecoyFor(path string) string

DecoyFor renders the canary for a file at path: as dotenv lines when the file is a .env file, and otherwise in the format the real secret usually lives in. A decoy that looks out of place is one an agent might not use.

type Detector

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

Detector finds canary values in arbitrary text, including the common ways of dressing a secret up to get it past a filter.

func (*Detector) Empty

func (d *Detector) Empty() bool

Empty reports whether there is nothing to look for.

func (*Detector) Find

func (d *Detector) Find(text string) (Hit, bool)

Find reports the first canary in text.

func (*Detector) Values

func (d *Detector) Values() []string

Values returns every canary value, for callers that must leave them alone (the result redaction, for one).

type Hit

type Hit struct {
	Canary Canary
	// Encoding is how it was dressed up: plain, base64, hex, url, reversed.
	Encoding string
}

Hit is a canary found in a call.

type Store

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

Store is the canaries file: canaries.json next to the audit database, so every agentgate process that shares a config shares its canaries.

func Open

func Open(path string) (*Store, error)

Open reads the store; a missing file is an empty store.

func (*Store) Add

func (s *Store) Add(c Canary) error

Add stores a canary.

func (*Store) Detector

func (s *Store) Detector() *Detector

Detector returns a detector for the current canaries, picking up changes another process made to the file at most once a second.

func (*Store) List

func (s *Store) List() []Canary

List returns the canaries, oldest first.

func (*Store) Path

func (s *Store) Path() string

Path is where the store lives.

func (*Store) Remove

func (s *Store) Remove(idOrLabel string) ([]Canary, error)

Remove deletes the canaries with this id or label and returns them.

Jump to

Keyboard shortcuts

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