Documentation
¶
Overview ¶
Package registry builds, signs, fetches and verifies registry indexes.
A registry is a git repo of service definitions. CI turns it into a single index.json plus index.json.sig, an Ed25519 signature over the exact bytes of index.json. Clients only trust an index whose signature checks out against a public key they already have, so a compromised web host can't push definitions to users.
Index ¶
- Constants
- Variables
- func EmbeddedBytes() (index, sig []byte)
- func Fetch(ctx context.Context, src Source) (index, sig []byte, err error)
- func GenerateKey() (privSeed, pub string, err error)
- func ParsePublicKey(s string) (ed25519.PublicKey, error)
- func PrivateKeyFromSeed(s string) (ed25519.PrivateKey, error)
- func PublicKeyString(sk ed25519.PrivateKey) string
- func Sign(index []byte, sk ed25519.PrivateKey) []byte
- func Verify(index, sigFile []byte, pub ed25519.PublicKey) error
- type Cache
- type Index
- type Skipped
- type Source
Constants ¶
const IndexSchema = 1
IndexSchema is the index format version.
const KeyPrefix = "anyserve-ed25519:"
KeyPrefix marks an Anyserve public key string.
const MainName = "main"
MainName is the name of the built-in registry.
const MainPublicKey = "anyserve-ed25519:6dJrvi7OZIf0qcvUcX0ZoPv6b+RyRSFWjTtOLRrMYOE="
MainPublicKey is the pinned key the main registry is signed with. Rotating it requires a new Anyserve release.
const MainURL = "https://jonsjava.github.io/anyserve-registry/index.json"
MainURL is where the main registry index is published: GitHub Pages for github.com/jonsjava/anyserve-registry, updated with `make publish-registry`.
Variables ¶
var ErrBadSignature = errors.New("registry index signature does not match the trusted key; refusing to use it")
ErrBadSignature means the index was not signed by a trusted key.
Functions ¶
func EmbeddedBytes ¶
func EmbeddedBytes() (index, sig []byte)
EmbeddedBytes returns the raw snapshot, for seeding the cache.
func Fetch ¶
Fetch downloads and verifies a source's index, returning the raw verified bytes and signature so the caller can cache them.
func GenerateKey ¶
GenerateKey creates a signing key pair. The private key is returned as a base64 seed for storing in a file or CI secret; the public key in the "anyserve-ed25519:..." form clients pin.
func ParsePublicKey ¶
ParsePublicKey decodes an "anyserve-ed25519:..." public key.
func PrivateKeyFromSeed ¶
func PrivateKeyFromSeed(s string) (ed25519.PrivateKey, error)
PrivateKeyFromSeed decodes a base64 seed produced by GenerateKey.
func PublicKeyString ¶
func PublicKeyString(sk ed25519.PrivateKey) string
PublicKeyString renders a private key's public half for pinning.
Types ¶
type Cache ¶
type Cache struct{ Dir string }
Cache stores verified indexes on disk, one directory per registry.
type Index ¶
type Index struct {
Schema int `json:"schema"`
Name string `json:"name"`
Generated time.Time `json:"generated"`
Services []*spec.Definition `json:"services"`
// Skipped lists definitions in a downloaded index that this version of
// Anyserve can't use. Not part of the published format.
Skipped []Skipped `json:"-"`
}
Index is the published registry index.
func Build ¶
Build reads every *.yaml definition in dir, validates them all and returns the index. It reports every invalid file, not just the first.
func ParseIndex ¶
ParseIndex decodes and checks an index. Call it only on verified bytes.
Each definition is decoded on its own. One that uses fields this version of Anyserve doesn't know (a feature added later), fails its checks, or requires a newer Anyserve is skipped and listed in Skipped, so a registry that has moved ahead still offers everything else.
func VerifyAndParse ¶
VerifyAndParse verifies index bytes for a source and decodes them.