Documentation
¶
Index ¶
- Constants
- func NewProviderHCLogger(logger *types.Logger, serviceType string) hclog.Logger
- func ProviderSecureConfig(sha256Hex string) (*plugin.SecureConfig, error)
- func RegisterRemoteBinding(providerName, serviceType, execPath, sha256Hex string) error
- func RegisterServiceBinding(name string, serviceBindingBuilder ServiceBindingBuilder)
- func ReplaceProviderBindings(providerName string, serviceTypes []string, execPath, sha256Hex string) error
- func SetServiceBinding(name string, builder ServiceBindingBuilder)
- func SqliteAccountForDir(dir string) map[string]string
- func SqliteBindingDir(bindingConfig map[string]string) (string, error)
- func SqliteBindingPattern(bindingConfig map[string]string) (string, error)
- func UnregisterProviderBindings(providerName string)
- type Artifact
- type ArtifactType
- type GrantApplyResult
- type MysqlServiceBinding
- func (b *MysqlServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, ...) (GrantApplyResult, error)
- func (b *MysqlServiceBinding) CloseService(ctx context.Context) error
- func (b *MysqlServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error
- func (b *MysqlServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, ...) (map[string]string, []Artifact, error)
- func (b *MysqlServiceBinding) GetAccountEnv(ctx context.Context) ([]string, []string, error)
- func (b *MysqlServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, ...) error
- func (b *MysqlServiceBinding) RevokeGrants(ctx context.Context, account map[string]string, _ types.BindingMetadata, ...) error
- func (b *MysqlServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
- type PostgresServiceBinding
- func (b *PostgresServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, ...) (GrantApplyResult, error)
- func (b *PostgresServiceBinding) CloseService(ctx context.Context) error
- func (b *PostgresServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error
- func (b *PostgresServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, ...) (map[string]string, []Artifact, error)
- func (b *PostgresServiceBinding) GetAccountEnv(ctx context.Context) ([]string, []string, error)
- func (b *PostgresServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, ...) error
- func (b *PostgresServiceBinding) RevokeGrants(ctx context.Context, account map[string]string, ...) error
- func (b *PostgresServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
- type RedisServiceBinding
- func (b *RedisServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, ...) (GrantApplyResult, error)
- func (b *RedisServiceBinding) CloseService(ctx context.Context) error
- func (b *RedisServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error
- func (b *RedisServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, ...) (map[string]string, []Artifact, error)
- func (b *RedisServiceBinding) GetAccountEnv(ctx context.Context) ([]string, []string, error)
- func (b *RedisServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, ...) error
- func (b *RedisServiceBinding) RevokeGrants(ctx context.Context, account map[string]string, ...) error
- func (b *RedisServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
- type ServiceBinding
- type ServiceBindingBuilder
- type ServiceBindingRuntime
- type SqliteServiceBinding
- func (b *SqliteServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, ...) (GrantApplyResult, error)
- func (b *SqliteServiceBinding) CloseService(ctx context.Context) error
- func (b *SqliteServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error
- func (b *SqliteServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, ...) (map[string]string, []Artifact, error)
- func (b *SqliteServiceBinding) GetAccountEnv(ctx context.Context) ([]string, []string, error)
- func (b *SqliteServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, ...) error
- func (b *SqliteServiceBinding) RevokeGrants(ctx context.Context, account map[string]string, ...) error
- func (b *SqliteServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
Constants ¶
const ( // SqliteDefaultDir is the default in-container mount directory for the // app's sqlite binding (an app has at most one sqlite binding), // overridable per binding with the "path" binding config key. SqliteDefaultDir = "/data" // SqliteDBFile is the default database file inside the binding directory. // With litestream enabled every file matching the replication pattern // (default *.db, overridable with the "pattern" binding config key) is // replicated; this is just the conventional main database name. SqliteDBFile = "data.db" // SqliteDefaultPattern is the default litestream replication file pattern // for the binding directory. SqliteDefaultPattern = "*.db" )
const ( SqliteConfigLitestream = "litestream_config" SqliteConfigPathPrefix = "path_prefix" SqliteConfigVolumeSize = "volume_size" )
Sqlite service config keys
const BindingHostnameDisable = "disable"
const SqliteBindingConfigPath = "path"
SqliteBindingConfigPath is the binding config key overriding the mount directory, e.g. binding create --config path=/mydata sqlite /apps/b1 or an auto binding source "sqlite;path=/mydata".
const SqliteBindingConfigPattern = "pattern"
SqliteBindingConfigPattern is the binding config key overriding the litestream replication file pattern (default SqliteDefaultPattern), e.g. binding create --config pattern=*.sqlite3 sqlite /apps/b1.
const SqliteServiceType = "sqlite"
SqliteServiceType is the service type name for the sqlite binding. Unlike postgres/mysql there is no external endpoint: a binding provides the app a persistent named volume (docker) or PVC (kubernetes) holding sqlite database files, with optional litestream replication configured on the service.
Variables ¶
This section is empty.
Functions ¶
func NewProviderHCLogger ¶ added in v0.18.7
NewProviderHCLogger builds the hclog.Logger go-plugin uses on the host side: provider log lines (hclog JSON on the provider's stderr) and go-plugin lifecycle messages are routed into the server's zerolog log.
func ProviderSecureConfig ¶ added in v0.18.7
func ProviderSecureConfig(sha256Hex string) (*plugin.SecureConfig, error)
ProviderSecureConfig builds the go-plugin SecureConfig that verifies the executable's sha256 before launch; nil when no checksum is available.
func RegisterRemoteBinding ¶ added in v0.18.7
RegisterRemoteBinding registers a service type served by an out-of-process binding provider executable. The builder is cheap: the provider process is launched lazily by InitializeService and killed by CloseService, so dry runs (which build binding instances but open no connections) spawn nothing. Compiled-in bindings always win: registering a service type they serve is an error, as is a type already registered by a different provider. sha256Hex is the expected checksum of the executable, verified by go-plugin before every launch; empty (dev providers) disables the check.
func RegisterServiceBinding ¶
func RegisterServiceBinding(name string, serviceBindingBuilder ServiceBindingBuilder)
RegisterServiceBinding registers a service binding
func ReplaceProviderBindings ¶ added in v0.18.7
func ReplaceProviderBindings(providerName string, serviceTypes []string, execPath, sha256Hex string) error
ReplaceProviderBindings atomically replaces the named provider's registrations: service types no longer served are removed, the given types are registered with the new executable and checksum, all under one lock so no caller ever observes a half-registered provider. Conflicts (built-in types, types owned by another provider) fail the whole call before any change is made.
func SetServiceBinding ¶ added in v0.18.7
func SetServiceBinding(name string, builder ServiceBindingBuilder)
SetServiceBinding registers a builder for a service type, removing the registration when builder is nil. Used by tests to install fakes and restore the previous state.
func SqliteAccountForDir ¶ added in v0.18.15
SqliteAccountForDir returns the account map for a sqlite binding mounted at dir: the directory the volume is mounted at, the default database path in it and the file url. The values are deterministic; the volume itself is created lazily by the container layer at app start.
func SqliteBindingDir ¶ added in v0.18.15
SqliteBindingDir resolves the in-container data directory for a sqlite binding from its binding config: the "path" key when set (validated as an absolute clean path), SqliteDefaultDir otherwise.
func SqliteBindingPattern ¶ added in v0.18.15
SqliteBindingPattern resolves the litestream replication file pattern for a sqlite binding from its binding config: the "pattern" key when set (validated as a file glob relative to the binding directory), SqliteDefaultPattern otherwise.
func UnregisterProviderBindings ¶ added in v0.18.7
func UnregisterProviderBindings(providerName string)
UnregisterProviderBindings removes all service types registered by the named provider. Compiled-in bindings are never unregistered.
Types ¶
type Artifact ¶ added in v0.18.0
type Artifact struct {
Type ArtifactType
Name string
}
Artifact identifies one object created on the service by GenerateAccount, such as a role/schema (postgres) or user/database (mysql). The caller tracks the created artifacts and passes them back to DeleteArtifact to undo the creation on rollback.
type ArtifactType ¶ added in v0.18.0
type ArtifactType string
const ( ArtifactRole ArtifactType = "role" ArtifactSchema ArtifactType = "schema" ArtifactUser ArtifactType = "user" ArtifactDatabase ArtifactType = "database" ArtifactLogin ArtifactType = "login" // SQL Server server-level login backing a database user )
type GrantApplyResult ¶ added in v0.18.5
type GrantApplyResult struct {
// GrantsApplied is the set of grants now in effect on the service for the
// account, to be recorded in the binding metadata. Grants pending revoke are
// still included; the caller removes them from the metadata after RevokeGrants
// succeeds.
GrantsApplied []types.BindingGrant
// Granted lists the grants newly applied on the service by this call. If the
// caller's metadata transaction is rolled back, these are the grants to
// compensate via RevokeGrants.
Granted []types.BindingGrant
// PendingRevokes lists grants that are applied on the service but no longer
// desired. The caller executes them via RevokeGrants after its metadata
// transaction commits.
PendingRevokes []types.BindingGrant
}
GrantApplyResult is the outcome of ApplyGrants. ApplyGrants only executes the additive part of a grant change; revokes are computed but not executed, so a caller can defer them until after its metadata transaction commits (a running app may see extra grants during the operation, but never loses a grant from an operation that is later rolled back).
type MysqlServiceBinding ¶ added in v0.17.5
func (*MysqlServiceBinding) ApplyGrants ¶ added in v0.17.5
func (b *MysqlServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, bindingMetadata types.BindingMetadata, derivedFromMetadata types.BindingMetadata, reapplyAll bool) (GrantApplyResult, error)
func (*MysqlServiceBinding) CloseService ¶ added in v0.17.5
func (b *MysqlServiceBinding) CloseService(ctx context.Context) error
func (*MysqlServiceBinding) DeleteArtifact ¶ added in v0.18.0
func (b *MysqlServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error
DeleteArtifact drops one user or database previously reported as created by GenerateAccount. The caller only passes back artifacts created during the current operation; pre-existing databases are never reported as created and so are never dropped here.
func (*MysqlServiceBinding) GenerateAccount ¶ added in v0.17.5
func (b *MysqlServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, bindingMetadata types.BindingMetadata, derivedFromMetadata *types.BindingMetadata, isStaging bool) (map[string]string, []Artifact, error)
func (*MysqlServiceBinding) GetAccountEnv ¶ added in v0.18.7
func (*MysqlServiceBinding) InitializeService ¶ added in v0.17.5
func (b *MysqlServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, runtime ServiceBindingRuntime) error
func (*MysqlServiceBinding) RevokeGrants ¶ added in v0.18.5
func (b *MysqlServiceBinding) RevokeGrants(ctx context.Context, account map[string]string, _ types.BindingMetadata, revokes, regrants []types.BindingGrant) error
func (*MysqlServiceBinding) RunCommand ¶ added in v0.17.5
func (b *MysqlServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
type PostgresServiceBinding ¶
func (*PostgresServiceBinding) ApplyGrants ¶ added in v0.17.3
func (b *PostgresServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, bindingMetadata types.BindingMetadata, derivedFromMetadata types.BindingMetadata, reapplyAll bool) (GrantApplyResult, error)
func (*PostgresServiceBinding) CloseService ¶ added in v0.17.4
func (b *PostgresServiceBinding) CloseService(ctx context.Context) error
func (*PostgresServiceBinding) DeleteArtifact ¶ added in v0.18.0
func (b *PostgresServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error
DeleteArtifact drops one role or schema previously reported as created by GenerateAccount. The caller only passes back artifacts created during the current operation, so a newly created role cannot own pre-existing objects and a schema drop only removes objects created since the schema itself was created.
func (*PostgresServiceBinding) GenerateAccount ¶
func (b *PostgresServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, bindingMetadata types.BindingMetadata, derivedFromMetadata *types.BindingMetadata, isStaging bool) (map[string]string, []Artifact, error)
func (*PostgresServiceBinding) GetAccountEnv ¶ added in v0.18.7
func (*PostgresServiceBinding) InitializeService ¶ added in v0.17.3
func (b *PostgresServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, runtime ServiceBindingRuntime) error
func (*PostgresServiceBinding) RevokeGrants ¶ added in v0.18.5
func (b *PostgresServiceBinding) RevokeGrants(ctx context.Context, account map[string]string, derivedFromMetadata types.BindingMetadata, revokes, regrants []types.BindingGrant) error
func (*PostgresServiceBinding) RunCommand ¶ added in v0.17.4
func (b *PostgresServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
type RedisServiceBinding ¶ added in v0.18.18
func (*RedisServiceBinding) ApplyGrants ¶ added in v0.18.18
func (b *RedisServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, bindingMetadata types.BindingMetadata, derivedFromMetadata types.BindingMetadata, reapplyAll bool) (GrantApplyResult, error)
ApplyGrants rebuilds the derived user's complete ACL rule set in one atomic ACL SETUSER, from the union of the currently applied and the desired grants. The union keeps this additive, per the interface contract: grants that are no longer desired are reported in PendingRevokes but stay in effect until the caller runs RevokeGrants after its metadata transaction commits. Since ACL SETUSER creates missing users, this also restores a derived user lost to a server restart without an aclfile (via `binding update --reapply-all`). The full rule set is applied every time, so reapplyAll needs no special handling and nothing is ever deferred (a grant target is just a key pattern, it does not need to exist).
func (*RedisServiceBinding) CloseService ¶ added in v0.18.18
func (b *RedisServiceBinding) CloseService(ctx context.Context) error
func (*RedisServiceBinding) DeleteArtifact ¶ added in v0.18.18
func (b *RedisServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error
DeleteArtifact deletes one ACL user previously reported as created by GenerateAccount. Keys under the binding's prefix are not touched; like the other bindings, data outlives the account.
func (*RedisServiceBinding) GenerateAccount ¶ added in v0.18.18
func (b *RedisServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, bindingMetadata types.BindingMetadata, derivedFromMetadata *types.BindingMetadata, isStaging bool) (map[string]string, []Artifact, error)
func (*RedisServiceBinding) GetAccountEnv ¶ added in v0.18.18
func (*RedisServiceBinding) InitializeService ¶ added in v0.18.18
func (b *RedisServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, runtime ServiceBindingRuntime) error
func (*RedisServiceBinding) RevokeGrants ¶ added in v0.18.18
func (b *RedisServiceBinding) RevokeGrants(ctx context.Context, account map[string]string, derivedFromMetadata types.BindingMetadata, revokes, regrants []types.BindingGrant) error
RevokeGrants removes grants that are no longer desired. Every caller path maintains the invariant that the account's remaining grants after the revoke equal exactly the regrants list (the revokes are a subset of what is applied, and everything else applied is in regrants), so the rule set is rebuilt from regrants in one atomic ACL SETUSER. Kept grants are never transiently revoked, and revoking a grant that was never applied is naturally harmless.
func (*RedisServiceBinding) RunCommand ¶ added in v0.18.18
func (b *RedisServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
type ServiceBinding ¶
type ServiceBinding interface {
// GetAccountEnv returns the names of the env values included in the
// account info for this binding: the always-present params first, then the
// optional params. This is static info: it must be callable on an
// uninitialized instance, before InitializeService.
GetAccountEnv(ctx context.Context) ([]string, []string, error)
// Initialize the service with the given config. This is called when the service binding is created.
InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, runtime ServiceBindingRuntime) error
// Close the service connection. This is called when the service binding is no longer needed.
CloseService(ctx context.Context) error
// Generate the account based on the binding config. This is called once when the binding is created, after the service is initialized.
// The account and its backing artifacts (role/schema, user/database) are created on the endpoint specified in the service config
// and are persisted immediately. The artifacts that were created are returned in creation order; pre-existing objects that the
// account merely references (like the base binding's schema for a derived binding) must not be included. If creation fails
// partway and already-created artifacts cannot be rolled back internally, they are returned along with the error so the
// caller can clean them up.
GenerateAccount(ctx context.Context, bindingId, bindingPath string, bindingMetadata types.BindingMetadata,
derivedFromMetadata *types.BindingMetadata, isStaging bool) (map[string]string, []Artifact, error)
// Delete one artifact previously reported as created by GenerateAccount. The caller only passes back artifacts
// created during the current operation; the implementation must delete only the named artifact.
DeleteArtifact(ctx context.Context, artifact Artifact) error
// Apply the grants to the account. This is called when the binding is created, after the account is generated.
// It can be called again if the grants are changed. Only new grants are executed (and persisted immediately);
// grants that need to be removed are returned in PendingRevokes without being executed, for the caller to run
// via RevokeGrants once its metadata transaction commits.
ApplyGrants(ctx context.Context, account map[string]string,
bindingMetadata, derivedFromMetadata types.BindingMetadata, reapplyAll bool) (GrantApplyResult, error)
// Revoke the given grants from the account, then re-apply the regrants. Called with the PendingRevokes of an
// earlier ApplyGrants after the caller's metadata transaction commits (regrants = the grants that remain
// desired), or with the Granted list to compensate when the transaction is rolled back (regrants = the grants
// that were applied before the operation). The regrants restore privileges that an overlapping revoke removes
// (e.g. revoking read:t1 while read:* remains would otherwise drop SELECT on t1). Revoking a grant that is not
// currently applied must be harmless.
RevokeGrants(ctx context.Context, account map[string]string,
derivedFromMetadata types.BindingMetadata, revokes, regrants []types.BindingGrant) error
// Run a command on the endpoint specified in the service config as the binding account.
RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
}
func NewMysqlServiceBinding ¶ added in v0.17.5
func NewMysqlServiceBinding() ServiceBinding
func NewPostgresServiceBinding ¶
func NewPostgresServiceBinding() ServiceBinding
func NewRedisServiceBinding ¶ added in v0.18.18
func NewRedisServiceBinding() ServiceBinding
func NewSqliteServiceBinding ¶ added in v0.18.15
func NewSqliteServiceBinding() ServiceBinding
type ServiceBindingBuilder ¶
type ServiceBindingBuilder func() ServiceBinding
func GetServiceBinding ¶ added in v0.18.7
func GetServiceBinding(name string) (ServiceBindingBuilder, bool)
GetServiceBinding returns the builder registered for a service type.
type ServiceBindingRuntime ¶ added in v0.18.0
type ServiceBindingRuntime struct {
LocalhostBindingHostname string
// LitestreamConfigNames are the [litestream.<name>] config names defined in
// the server config, used by the sqlite binding to validate its
// litestream_config service config key.
LitestreamConfigNames []string
// LitestreamFileConfigNames are the subset of LitestreamConfigNames using
// the file replica type (a host-local directory). They are valid for
// metadata replication but unusable from app containers, so the sqlite
// binding rejects them.
LitestreamFileConfigNames []string
}
type SqliteServiceBinding ¶ added in v0.18.15
func (*SqliteServiceBinding) ApplyGrants ¶ added in v0.18.15
func (b *SqliteServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, bindingMetadata, derivedFromMetadata types.BindingMetadata, reapplyAll bool) (GrantApplyResult, error)
func (*SqliteServiceBinding) CloseService ¶ added in v0.18.15
func (b *SqliteServiceBinding) CloseService(ctx context.Context) error
func (*SqliteServiceBinding) DeleteArtifact ¶ added in v0.18.15
func (b *SqliteServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error
func (*SqliteServiceBinding) GenerateAccount ¶ added in v0.18.15
func (b *SqliteServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, bindingMetadata types.BindingMetadata, derivedFromMetadata *types.BindingMetadata, isStaging bool) (map[string]string, []Artifact, error)
func (*SqliteServiceBinding) GetAccountEnv ¶ added in v0.18.15
func (*SqliteServiceBinding) InitializeService ¶ added in v0.18.15
func (b *SqliteServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, runtime ServiceBindingRuntime) error
func (*SqliteServiceBinding) RevokeGrants ¶ added in v0.18.15
func (b *SqliteServiceBinding) RevokeGrants(ctx context.Context, account map[string]string, derivedFromMetadata types.BindingMetadata, revokes, regrants []types.BindingGrant) error
func (*SqliteServiceBinding) RunCommand ¶ added in v0.18.15
func (b *SqliteServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)