plugin_security

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: 12 Imported by: 2 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 plugin_security provides security validation for plugins in both CE and ENT editions

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSecurityNotAvailable indicates advanced security features require Enterprise Edition
	ErrSecurityNotAvailable = errors.New("advanced plugin security features require Enterprise Edition")

	// ErrInternalNetworkBlocked indicates GRPC host targets an internal network address
	ErrInternalNetworkBlocked = errors.New("plugin command targets internal network address")

	// ErrSignatureVerificationFailed indicates the signature verification failed
	ErrSignatureVerificationFailed = errors.New("plugin signature verification failed")

	// ErrInvalidHost indicates the host is invalid or malformed
	ErrInvalidHost = errors.New("invalid or malformed host address")

	// ErrNoPublicKey indicates no public key was provided or configured
	ErrNoPublicKey = errors.New("no public key specified for signature verification")

	// ErrPublicKeyNotFound indicates the requested public key could not be found
	ErrPublicKeyNotFound = errors.New("public key not found")

	// ErrInvalidSignature indicates the signature is invalid or corrupted
	ErrInvalidSignature = errors.New("invalid or corrupted signature")
)

Functions

func CheckCommandHosts added in v2.3.0

func CheckCommandHosts(command string) error

CheckCommandHosts applies the plugin host rule (netguard.CheckPluginHost) to the host of every URL in command (grpc://, oci://, http(s)://): unless ALLOW_INTERNAL_NETWORK_ACCESS=true, a host that is, or resolves to, an internal address, or does not resolve, is refused (a host named in LLM_UPSTREAM_ALLOWED_INTERNAL_HOSTS is exempt). It is the host check of ValidateCommand for paths that have no security service at hand (service layer creates and upgrades).

func CheckCommandHostsWith added in v2.3.0

func CheckCommandHostsWith(command string, exempt netguard.Exemption) error

CheckCommandHostsWith is CheckCommandHosts with the plugin's own "Allow internal host" exemption (netguard.CommandExemption).

func IsEnterpriseAvailable

func IsEnterpriseAvailable() bool

IsEnterpriseAvailable returns true if enterprise plugin security features are available

func IsEnterpriseRequired

func IsEnterpriseRequired(err error) bool

IsEnterpriseRequired returns true if the error indicates Enterprise Edition is required

func IsSecurityError

func IsSecurityError(err error) bool

IsSecurityError returns true if the error is a security-related error

func ValidateCommand

func ValidateCommand(command string, securityService Service) error

ValidateCommand performs security validation on a plugin command string. It is shared by the API layer (create/update requests) and the plugin manager (load time), so records that enter the database without passing through the API (direct DB writes, migrations, imports, replication) are still validated before a process is spawned.

securityService is used for internal-network host validation on URL commands (enforced in ENT, and configurable in CE). A nil service skips the host check but all other checks still apply.

func ValidateCommandWith added in v2.3.0

func ValidateCommandWith(command string, securityService Service, exempt netguard.Exemption) error

ValidateCommandWith is ValidateCommand with the plugin's own "Allow internal host" exemption (netguard.CommandExemption): its hosts skip the internal-host check.

Types

type Config

type Config struct {
	// OCI configuration for signature verification
	OCIConfig *ociplugins.OCIConfig

	// Development mode settings
	AllowInternalNetworkAccess bool

	// SourcePolicy limits the plugin deployment types (oci, file, grpc) the
	// installation accepts. The zero value allows all.
	SourcePolicy SourcePolicy
}

Config holds configuration for plugin security service

type ErrPluginSourceNotAllowed added in v2.3.0

type ErrPluginSourceNotAllowed struct {
	Source  PluginSource
	Allowed []PluginSource
	// Setting is the configuration setting that changes the policy.
	Setting string
}

ErrPluginSourceNotAllowed reports a plugin whose deployment type the installation's source policy does not accept.

func (*ErrPluginSourceNotAllowed) Error added in v2.3.0

func (e *ErrPluginSourceNotAllowed) Error() string

type GRPCValidationResult

type GRPCValidationResult struct {
	Allowed bool
	Host    string
	Reason  string
}

GRPCValidationResult contains the result of GRPC host validation

type OCIReference

type OCIReference = ociplugins.OCIReference

OCIReference is re-exported from ociplugins for convenience

type PluginSource added in v2.3.0

type PluginSource string

PluginSource is a plugin deployment type, as an installation's source policy names it.

const (
	// SourceOCI is a plugin pulled from an OCI registry (oci://).
	SourceOCI PluginSource = "oci"
	// SourceFile is a local executable: a path or file:// command. Every
	// command that is neither oci:// nor grpc:// is run as one, so it is
	// this source too, including http:// and https:// commands.
	SourceFile PluginSource = "file"
	// SourceGRPC is an external plugin process reached over gRPC (grpc://).
	SourceGRPC PluginSource = "grpc"
)

func SourceOf added in v2.3.0

func SourceOf(command string) PluginSource

SourceOf classifies a plugin command exactly as the plugin managers dispatch it: a case-sensitive "oci://" prefix is oci, "grpc://" is grpc, and anything else is run as a local executable (file). The command is deliberately not trimmed, lower-cased or parsed, so " oci://x" or "OCI://x" is file, as it would be run.

type SecurityContext

type SecurityContext struct {
	Context        context.Context
	AllowOverrides bool // Allow development overrides
}

SecurityContext provides context for security operations

type Service

type Service interface {
	// ValidateGRPCHost validates that a GRPC host is not targeting internal networks
	// CE and ENT: Blocks internal IP addresses unless development override is enabled
	ValidateGRPCHost(host string) error

	// IsInternalIP checks if a host resolves to an internal/private IP address
	// CE and ENT: Checks against private IP ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, etc.)
	IsInternalIP(host string) bool

	// VerifySignature verifies the signature of an OCI artifact using a public key
	// CE: Always returns nil (no verification)
	// ENT: Performs full Cosign signature verification
	VerifySignature(ctx context.Context, ref *OCIReference, pubKeyID string) error

	// VerifyBundle verifies a signature bundle for keyless signing
	// CE: Always returns nil (no verification)
	// ENT: Verifies using certificate identity and OIDC issuer
	VerifyBundle(ctx context.Context, ref *OCIReference, issuer, subject string) error

	// VerifyWithPolicy verifies a signature using a policy file
	// CE: Always returns nil (no verification)
	// ENT: Not supported; returns an error (the in-process verifier has no
	// cosign policy engine)
	//
	// Deprecated: cosign policy files are not supported; use VerifySignature.
	VerifyWithPolicy(ctx context.Context, ref *OCIReference, policyPath string) error

	// GetPublicKeyPath retrieves the path to a public key for verification
	// CE: Always returns empty string
	// ENT: Resolves key references to file paths
	GetPublicKeyPath(pubKeyID string) (string, error)

	// ValidatePublicKey checks if a public key file exists and is accessible
	// CE: Always returns nil
	// ENT: Validates the key file
	ValidatePublicKey(keyPath string) error

	// LoadPublicKeysFromDirectory loads all public keys from a directory
	// CE: Always returns empty slice
	// ENT: Scans directory for public key files
	LoadPublicKeysFromDirectory(dir string) ([]string, error)
}

Service defines the interface for plugin security operations CE provides basic internal-network blocking; OCI signature verification is a no-op in CE ENT provides full security enforcement

func NewService

func NewService(config *Config) Service

NewService creates a new plugin security service Returns enterprise implementation if available, otherwise community stub

type ServiceFactory

type ServiceFactory func(config *Config) Service

ServiceFactory is a function that creates a Service implementation

func RegisterEnterpriseFactory

func RegisterEnterpriseFactory(factory ServiceFactory) (previous ServiceFactory)

RegisterEnterpriseFactory registers the enterprise implementation factory This is called by the enterprise package's init() function. It returns the factory it replaced, so tests can register a fake and restore the original.

type SourcePolicy added in v2.3.0

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

SourcePolicy is the set of plugin sources an installation accepts. The zero value allows every source.

func AllowAllSources added in v2.3.0

func AllowAllSources() SourcePolicy

AllowAllSources returns the policy that accepts every source.

func ParseSourcePolicy added in v2.3.0

func ParseSourcePolicy(csv string) (SourcePolicy, error)

ParseSourcePolicy parses a comma-separated list of sources ("oci", "file", "grpc"; case and spaces are ignored). An empty value allows every source. An unknown source, or a list with no sources (","), is an error: a typo must not silently allow everything or nothing.

func (SourcePolicy) Allowed added in v2.3.0

func (p SourcePolicy) Allowed() []PluginSource

Allowed returns the accepted sources, in the order oci, file, grpc.

func (SourcePolicy) AllowsAll added in v2.3.0

func (p SourcePolicy) AllowsAll() bool

AllowsAll reports whether the policy accepts every source.

func (SourcePolicy) Check added in v2.3.0

func (p SourcePolicy) Check(command string) error

Check returns an *ErrPluginSourceNotAllowed if the policy does not accept the command's source (see SourceOf).

func (SourcePolicy) String added in v2.3.0

func (p SourcePolicy) String() string

String describes the policy, e.g. "oci,file" or "all".

func (SourcePolicy) WithSetting added in v2.3.0

func (p SourcePolicy) WithSetting(name string) SourcePolicy

WithSetting returns the policy with the name of the setting that changes it (e.g. AI_STUDIO_PLUGIN_ALLOWED_SOURCES), which Check's error names.

type VerificationResult

type VerificationResult struct {
	Verified  bool
	Method    string // "cosign", "bundle", "policy"
	PublicKey string
	Error     error
}

VerificationResult contains the result of a signature verification

Jump to

Keyboard shortcuts

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