Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorEventLogger(errorLog, eventLog Logger) func(*event.Event, error)
- func ErrorLogger(errorLog Logger) func(*event.Event, error)
- func MultiMonitor(monitors ...func(*event.Event, error)) func(*event.Event, error)
- func PermissionDenied(internalDetails string) error
- func RetryAfter(t time.Time) error
- func Unauthenticated(publicReason string) error
- func Unavailable(internal error) error
- type AccessConfig
- type Authorizer
- type Config
- type Instance
- func (inst *Instance) Connect(ctx context.Context, r io.Reader, w io.WriteCloser) error
- func (inst *Instance) ID() string
- func (inst *Instance) Kill(ctx context.Context) error
- func (inst *Instance) Status(ctx context.Context) *api.Status
- func (inst *Instance) Suspend(ctx context.Context) error
- func (inst *Instance) Wait(ctx context.Context) (status *api.Status)
- type InstanceConnector
- type InstancePolicy
- type InstanceServices
- type Inventory
- type Logger
- type NoAccess
- func (NoAccess) Authorize(ctx context.Context) (context.Context, error)
- func (NoAccess) AuthorizeInstance(ctx context.Context, _ *ResourcePolicy, _ *InstancePolicy) (context.Context, error)
- func (NoAccess) AuthorizeProgram(ctx context.Context, _ *ResourcePolicy, _ *ProgramPolicy) (context.Context, error)
- func (NoAccess) AuthorizeProgramInstance(ctx context.Context, _ *ResourcePolicy, _ *ProgramPolicy, _ *InstancePolicy) (context.Context, error)
- func (NoAccess) AuthorizeProgramInstanceSource(ctx context.Context, _ *ResourcePolicy, _ *ProgramPolicy, _ *InstancePolicy, ...) (context.Context, error)
- func (NoAccess) AuthorizeProgramSource(ctx context.Context, _ *ResourcePolicy, _ *ProgramPolicy, _ string) (context.Context, error)
- type ProgramPolicy
- type PublicAccess
- func (*PublicAccess) Authorize(ctx context.Context) (context.Context, error)
- func (a *PublicAccess) AuthorizeInstance(ctx context.Context, res *ResourcePolicy, inst *InstancePolicy) (context.Context, error)
- func (a *PublicAccess) AuthorizeProgram(ctx context.Context, res *ResourcePolicy, prog *ProgramPolicy) (context.Context, error)
- func (a *PublicAccess) AuthorizeProgramInstance(ctx context.Context, res *ResourcePolicy, prog *ProgramPolicy, ...) (context.Context, error)
- func (a *PublicAccess) AuthorizeProgramInstanceSource(ctx context.Context, res *ResourcePolicy, prog *ProgramPolicy, ...) (context.Context, error)
- func (a *PublicAccess) AuthorizeProgramSource(ctx context.Context, res *ResourcePolicy, prog *ProgramPolicy, _ string) (context.Context, error)
- type ResourcePolicy
- type Server
- func (s *Server) DebugInstance(ctx context.Context, instance string, req *api.DebugRequest) (_ *api.DebugResponse, err error)
- func (s *Server) DeleteInstance(ctx context.Context, instance string) (err error)
- func (s *Server) Features() *api.Features
- func (s *Server) InstanceConnection(ctx context.Context, instance string) (_ api.Instance, _ func(context.Context, io.Reader, io.WriteCloser) error, ...)
- func (s *Server) InstanceInfo(ctx context.Context, instance string) (_ *api.InstanceInfo, err error)
- func (s *Server) Instances(ctx context.Context) (_ *api.Instances, err error)
- func (s *Server) KillInstance(ctx context.Context, instance string) (_ api.Instance, err error)
- func (s *Server) ModuleContent(ctx context.Context, module string) (stream io.ReadCloser, length int64, err error)
- func (s *Server) ModuleInfo(ctx context.Context, module string) (_ *api.ModuleInfo, err error)
- func (s *Server) Modules(ctx context.Context) (_ *api.Modules, err error)
- func (s *Server) NewInstance(ctx context.Context, module string, launch *api.LaunchOptions) (_ api.Instance, err error)
- func (s *Server) PinModule(ctx context.Context, module string, know *api.ModuleOptions) (err error)
- func (s *Server) ResumeInstance(ctx context.Context, instance string, resume *api.ResumeOptions) (_ api.Instance, err error)
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Snapshot(ctx context.Context, instance string, know *api.ModuleOptions) (module string, err error)
- func (s *Server) SourceModule(ctx context.Context, uri string, know *api.ModuleOptions) (module string, err error)
- func (s *Server) SourceModuleInstance(ctx context.Context, uri string, know *api.ModuleOptions, ...) (module string, _ api.Instance, err error)
- func (s *Server) SuspendInstance(ctx context.Context, instance string) (_ api.Instance, err error)
- func (s *Server) UnpinModule(ctx context.Context, module string) (err error)
- func (s *Server) UpdateInstance(ctx context.Context, instance string, update *api.InstanceUpdate) (_ *api.InstanceInfo, err error)
- func (s *Server) UploadModule(ctx context.Context, upload *api.ModuleUpload, know *api.ModuleOptions) (module string, err error)
- func (s *Server) UploadModuleInstance(ctx context.Context, upload *api.ModuleUpload, know *api.ModuleOptions, ...) (_ string, _ api.Instance, err error)
- func (s *Server) WaitInstance(ctx context.Context, instID string) (_ *api.Status, err error)
- type Source
Constants ¶
const ( DefaultMaxModules = 64 DefaultMaxProcs = 4 DefaultTotalStorageSize = 256 * 1024 * 1024 DefaultTotalResidentSize = 64 * 1024 * 1024 DefaultMaxModuleSize = 32 * 1024 * 1024 DefaultMaxTextSize = 16 * 1024 * 1024 DefaultMaxMemorySize = 32 * 1024 * 1024 DefaultStackSize = wa.PageSize DefaultTimeResolution = time.Second / 100 )
Variables ¶
var DefaultAccessConfig = AccessConfig{ ResourcePolicy{ DefaultMaxModules, DefaultMaxProcs, DefaultTotalStorageSize, DefaultTotalResidentSize, }, ProgramPolicy{ DefaultMaxModuleSize, DefaultMaxTextSize, DefaultStackSize, }, InstancePolicy{ DefaultMaxMemorySize, DefaultStackSize, DefaultTimeResolution, nil, }, }
var ErrServerClosed = errors.New("server closed")
Functions ¶
func ErrorEventLogger ¶
ErrorEventLogger creates an event monitor which prints log messages. Internal errors are printed to errorLog and other events to eventLog.
func ErrorLogger ¶
ErrorLogger creates an event monitor which prints log messages. Internal errors are printed to errorLog and other events are ignored.
func MultiMonitor ¶
MultiMonitor combines multiple event monitors.
func PermissionDenied ¶
PermissionDenied error. The details are not exposed to the client.
func RetryAfter ¶
RetryAfter creates a TooManyRequests error with the earliest time when the request should be retried.
func Unauthenticated ¶
Unauthenticated error. The reason will be shown to the client.
func Unavailable ¶
Unavailable service error. The details are not exposed to the client.
Types ¶
type AccessConfig ¶
type AccessConfig struct { ResourcePolicy ProgramPolicy InstancePolicy }
AccessConfig utility for Authorizer implementations. InstancePolicy.Services must be set explicitly, other fields have defaults.
func (*AccessConfig) ConfigureInstance ¶
func (config *AccessConfig) ConfigureInstance(p *InstancePolicy)
func (*AccessConfig) ConfigureProgram ¶
func (config *AccessConfig) ConfigureProgram(p *ProgramPolicy)
func (*AccessConfig) ConfigureResource ¶
func (config *AccessConfig) ConfigureResource(p *ResourcePolicy)
type Authorizer ¶
type Authorizer interface { Authorize(context.Context) (context.Context, error) AuthorizeProgram(context.Context, *ResourcePolicy, *ProgramPolicy) (context.Context, error) AuthorizeProgramSource(context.Context, *ResourcePolicy, *ProgramPolicy, string) (context.Context, error) AuthorizeInstance(context.Context, *ResourcePolicy, *InstancePolicy) (context.Context, error) AuthorizeProgramInstance(context.Context, *ResourcePolicy, *ProgramPolicy, *InstancePolicy) (context.Context, error) AuthorizeProgramInstanceSource(context.Context, *ResourcePolicy, *ProgramPolicy, *InstancePolicy, string) (context.Context, error) // contains filtered or unexported methods }
Authorizer and moderator of server access.
The methods should return Unauthenticated, PermissionDenied or Unavailable errors to signal successful prevention of access. Other types of errors are interpreted as failures of the authorization mechanism. Returning a nil error grants access.
An implementation should adjust the ResourcePolicy, ProgramPolicy and InstancePolicy objects' fields. The limits are enforced automatically by the server, which may also lead to denial of access.
Principal id can be obtained using the principal.ContextID(context.Context) function. If it is nil, the request didn't contain credentials, and the access should be denied unless the policy allows anonymous access. If the principal id is non-nil, it should be checked unless the policy allows access to everyone.
An implementation may choose to discriminate based on server operation type. It can be obtained using the ContextOp(context.Context) function.
Authorizer may be expanded with new methods (prefixed with the Authorize namespace) also between major releases. Implementations must inherit methods from a concrete access authorization type, and must not add unrelated methods with the Authorize prefix to avoid breakage. The conservative choice is to inherit from NoAccess. That way, new functionality will be effectively disabled.
type Config ¶
type Config struct { ImageStorage image.Storage Inventory Inventory ProcessFactory runtime.ProcessFactory AccessPolicy Authorizer ModuleSources map[string]Source Monitor func(*event.Event, error) OpenDebugLog func(string) io.WriteCloser }
func (*Config) Configured ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
func (*Instance) Connect ¶
Connect to a running instance. Disconnection happens when context is canceled, the instance stops running, or the program closes the connection.
type InstanceConnector ¶
type InstanceConnector interface { // Connect allocates a new I/O stream. The returned function is to be used // to transfer data between a network connection and the instance. If it's // non-nil, a connection was established. Connect(context.Context) func(context.Context, io.Reader, io.WriteCloser) error // Close causes currently blocked and future Connect calls to return nil. // Established connections will not be closed. Close() error }
type InstancePolicy ¶
type InstancePolicy struct { MaxMemorySize int // Linear memory growth limit. StackSize int // Including system/runtime overhead. TimeResolution time.Duration // Granularity of time functions. // Services function defines which services are discoverable by the // instance. Services func(context.Context) InstanceServices }
type InstanceServices ¶
type InstanceServices interface { InstanceConnector runtime.ServiceRegistry }
func NewInstanceServices ¶
func NewInstanceServices(c InstanceConnector, r runtime.ServiceRegistry) InstanceServices
type NoAccess ¶
type NoAccess struct{}
NoAccess permitted to any resource.
func (NoAccess) AuthorizeInstance ¶
func (NoAccess) AuthorizeInstance(ctx context.Context, _ *ResourcePolicy, _ *InstancePolicy) (context.Context, error)
func (NoAccess) AuthorizeProgram ¶
func (NoAccess) AuthorizeProgram(ctx context.Context, _ *ResourcePolicy, _ *ProgramPolicy) (context.Context, error)
func (NoAccess) AuthorizeProgramInstance ¶
func (NoAccess) AuthorizeProgramInstance(ctx context.Context, _ *ResourcePolicy, _ *ProgramPolicy, _ *InstancePolicy) (context.Context, error)
func (NoAccess) AuthorizeProgramInstanceSource ¶
func (NoAccess) AuthorizeProgramInstanceSource(ctx context.Context, _ *ResourcePolicy, _ *ProgramPolicy, _ *InstancePolicy, _ string) (context.Context, error)
func (NoAccess) AuthorizeProgramSource ¶
func (NoAccess) AuthorizeProgramSource(ctx context.Context, _ *ResourcePolicy, _ *ProgramPolicy, _ string) (context.Context, error)
type ProgramPolicy ¶
type PublicAccess ¶
type PublicAccess struct {
AccessConfig
}
PublicAccess authorization for everyone, including anonymous requests. Configurable resource limits.
func NewPublicAccess ¶
func NewPublicAccess(services func(context.Context) InstanceServices) *PublicAccess
func (*PublicAccess) AuthorizeInstance ¶
func (a *PublicAccess) AuthorizeInstance(ctx context.Context, res *ResourcePolicy, inst *InstancePolicy) (context.Context, error)
func (*PublicAccess) AuthorizeProgram ¶
func (a *PublicAccess) AuthorizeProgram(ctx context.Context, res *ResourcePolicy, prog *ProgramPolicy) (context.Context, error)
func (*PublicAccess) AuthorizeProgramInstance ¶
func (a *PublicAccess) AuthorizeProgramInstance(ctx context.Context, res *ResourcePolicy, prog *ProgramPolicy, inst *InstancePolicy) (context.Context, error)
func (*PublicAccess) AuthorizeProgramInstanceSource ¶
func (a *PublicAccess) AuthorizeProgramInstanceSource(ctx context.Context, res *ResourcePolicy, prog *ProgramPolicy, inst *InstancePolicy, _ string) (context.Context, error)
func (*PublicAccess) AuthorizeProgramSource ¶
func (a *PublicAccess) AuthorizeProgramSource(ctx context.Context, res *ResourcePolicy, prog *ProgramPolicy, _ string) (context.Context, error)
type ResourcePolicy ¶
type ResourcePolicy struct { MaxModules int // Pinned module limit. MaxProcs int // Active instance limit. TotalStorageSize int // Sum of pinned module and metadata sizes. TotalResidentSize int // Sum of all memory mapping and buffer sizes. }
TODO: ResourcePolicy is not yet enforced by server
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) DebugInstance ¶
func (s *Server) DebugInstance(ctx context.Context, instance string, req *api.DebugRequest) (_ *api.DebugResponse, err error)
func (*Server) DeleteInstance ¶
func (*Server) InstanceConnection ¶
func (*Server) InstanceInfo ¶
func (*Server) KillInstance ¶
func (*Server) ModuleContent ¶
func (*Server) ModuleInfo ¶
func (*Server) NewInstance ¶
func (*Server) ResumeInstance ¶
func (*Server) SourceModule ¶
func (*Server) SourceModuleInstance ¶
func (*Server) SuspendInstance ¶
func (*Server) UnpinModule ¶
func (*Server) UpdateInstance ¶
func (s *Server) UpdateInstance(ctx context.Context, instance string, update *api.InstanceUpdate) (_ *api.InstanceInfo, err error)
func (*Server) UploadModule ¶
func (s *Server) UploadModule(ctx context.Context, upload *api.ModuleUpload, know *api.ModuleOptions) (module string, err error)
func (*Server) UploadModuleInstance ¶
func (s *Server) UploadModuleInstance(ctx context.Context, upload *api.ModuleUpload, know *api.ModuleOptions, launch *api.LaunchOptions) (_ string, _ api.Instance, err error)
type Source ¶
type Source interface { // CanonicalURI converts a source URI to its canonical form. The result // should be byte-wise identical to all other canonicalized URIs which // refer to the same location. // // CanonicalURI is called with an absolute URI which doesn't contain // successive slashes. It starts with the source name (e.g. "/foo/..."). // // If the URI is know to be invalid, an error should be returned. CanonicalURI(uri string) (string, error) // OpenURI for reading an object. The argument is a URI returned by // CanonicalizeURI. // // If the object's size exceeds maxSize, the object is not to be opened. // The reader is not necessarily drained, but it will be closed. The // reader must produce exactly contentLength's worth of bytes when read in // full. // // Not-found condition can be signaled by returning nil content with zero // length. Content-too-long condition can be signaled by returning nil // content with nonzero length (doesn't have to be actual content length). OpenURI( ctx context.Context, uri string, maxSize int, ) ( content io.ReadCloser, contentLength int64, err error, ) }
Source of immutable data.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
sql
Package sql implements Inventory and NonceChecker backed by SQL database.
|
Package sql implements Inventory and NonceChecker backed by SQL database. |
api
Package api contains definitions useful for accessing the HTTP and websocket APIs.
|
Package api contains definitions useful for accessing the HTTP and websocket APIs. |
api/debug
Package debug contains functionality useful for accessing the instance debugging API via HTTP.
|
Package debug contains functionality useful for accessing the instance debugging API via HTTP. |