credsync

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 10 Imported by: ? 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 credsync is what the control server's SyncCredentials RPC (EDGE_CREDENTIAL_SYNC=full on an edge) is built from in every edition: the hook its handler registers through, what a handler reads from the control server (Source), and the read of credential rows with their Apps.

SyncCredentials streams the App credentials an edge's namespace may serve, as hashes, so the edge can validate keys without asking the hub. It is an Enterprise feature: the handler is registered by the Enterprise module (Register), and without one, in the Community edition, the RPC answers Unimplemented, which an edge takes to mean "stay on demand".

The package is separate from the control server (package grpc) so that the Enterprise handler depends on this, the proto and the models, and not on the control server and everything it imports. Like every streaming RPC of the control server, SyncCredentials runs behind its stream authentication: a handler is only reached by a caller that presented the edge token.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEdgeEncryptionKey = errors.New("MICROGATEWAY_ENCRYPTION_KEY is not set or too short to hash credentials for edges")

ErrNoEdgeEncryptionKey: the control server has no usable MICROGATEWAY_ENCRYPTION_KEY, so it cannot make the hashes edges hold.

Functions

func Register

func Register(h Handler)

Register installs the handler of SyncCredentials for every control server in the process. Nil removes it.

Types

type Handler

Handler serves one SyncCredentials call for the control server src.

func Registered

func Registered() Handler

Registered returns the installed handler, or nil.

type Row

type Row struct {
	// Credential, soft-deleted ones included (DeletedAt is then set). Its
	// Secret is the plaintext, or secrets.RefusedCredential when it does
	// not decrypt on this hub (Hashable is then false).
	Credential models.Credential
	// App is the live (not soft-deleted) App whose key this is, with what
	// AppConfig needs loaded, or nil when there is none.
	App *models.App
}

Row is one credential and the App that uses it.

func Rows

func Rows(ctx context.Context, db *gorm.DB, afterID uint, limit int, changedSince *time.Time) ([]Row, error)

Rows reads the next page of credentials by id, after afterID, at most limit of them, with their Apps. With changedSince nil it reads every credential (soft-deleted ones included); otherwise only those that changed at or after that time: the credential's or its App's updated_at or deleted_at. The App counts whether or not it is soft-deleted, so that deleting or deactivating an App brings its credential up again.

It reads through the models, so secrets come back decrypted, and it is the same on SQLite and Postgres. A page is bounded by limit: a caller streaming every credential holds one page at a time.

func (Row) Hashable

func (r Row) Hashable() bool

Hashable reports whether the credential's secret can be hashed for edges.

type Source

type Source interface {
	// RegisteredNamespace is the namespace an edge's requests are
	// answered for: the one the edge registered in, whatever the request
	// names. registered is false for an empty edge ID and for one with no
	// registration, which get nothing; err is a failed lookup.
	RegisteredNamespace(edgeID string) (namespace string, registered bool, err error)
	// NamespaceLicensed reports whether the namespace holds a licensed
	// slot (or is the default namespace).
	NamespaceLicensed(namespace string) bool
	// ServesNamespace reports whether an App of appNamespace is served by
	// edges of edgeNamespace.
	ServesNamespace(appNamespace, edgeNamespace string) bool
	// AppConfig is an App as an edge receives it for a credential. app
	// needs what Rows loads.
	AppConfig(app *models.App) *pb.AppConfig
	// NodeID is the replica's cluster node ID.
	NodeID() string
	// DatabaseFailovers is how many times the replica has seen the
	// writable database server change since it started.
	DatabaseFailovers() int64
	// DatabaseTime is the database server's clock.
	DatabaseTime(ctx context.Context) (time.Time, error)
	// EdgeCredentialHasher makes the hash an edge holds for a credential,
	// or fails with ErrNoEdgeEncryptionKey.
	EdgeCredentialHasher() (*credhash.Hasher, error)
	// CredentialSyncRows is Rows on the control server's database.
	CredentialSyncRows(ctx context.Context, afterID uint, limit int, changedSince *time.Time) ([]Row, error)
}

Source is what a handler reads from the control server it serves for.

Jump to

Keyboard shortcuts

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