Documentation
¶
Index ¶
- Variables
- func SecurityTagGlob(snapName string) string
- func ValidateName(name string) error
- type BadInterfacesError
- type Interface
- type Interfaces
- type Plug
- type PlugRef
- type Repository
- func (r *Repository) AddInterface(i Interface) error
- func (r *Repository) AddPlug(plug *Plug) error
- func (r *Repository) AddSlot(slot *Slot) error
- func (r *Repository) AddSnap(snapInfo *snap.Info) error
- func (r *Repository) AllPlugs(interfaceName string) []*Plug
- func (r *Repository) AllSlots(interfaceName string) []*Slot
- func (r *Repository) AutoConnectBlacklist(snapName string) map[string]bool
- func (r *Repository) AutoConnectCandidates(plugSnapName, plugName string) []*Slot
- func (r *Repository) Connect(plugSnapName, plugName, slotSnapName, slotName string) error
- func (r *Repository) Disconnect(plugSnapName, plugName, slotSnapName, slotName string) error
- func (r *Repository) DisconnectSnap(snapName string) ([]string, error)
- func (r *Repository) Interface(interfaceName string) Interface
- func (r *Repository) Interfaces() *Interfaces
- func (r *Repository) Plug(snapName, plugName string) *Plug
- func (r *Repository) Plugs(snapName string) []*Plug
- func (r *Repository) RemovePlug(snapName, plugName string) error
- func (r *Repository) RemoveSlot(snapName, slotName string) error
- func (r *Repository) RemoveSnap(snapName string) error
- func (r *Repository) SecuritySnippetsForSnap(snapName string, securitySystem SecuritySystem) (map[string][][]byte, error)
- func (r *Repository) Slot(snapName, slotName string) *Slot
- func (r *Repository) Slots(snapName string) []*Slot
- type SecurityBackend
- type SecuritySystem
- type Slot
- type SlotRef
- type TestInterface
- func (t *TestInterface) AutoConnect() bool
- func (t *TestInterface) ConnectedPlugSnippet(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error)
- func (t *TestInterface) ConnectedSlotSnippet(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error)
- func (t *TestInterface) Name() string
- func (t *TestInterface) PermanentPlugSnippet(plug *Plug, securitySystem SecuritySystem) ([]byte, error)
- func (t *TestInterface) PermanentSlotSnippet(slot *Slot, securitySystem SecuritySystem) ([]byte, error)
- func (t *TestInterface) SanitizePlug(plug *Plug) error
- func (t *TestInterface) SanitizeSlot(slot *Slot) error
- func (t *TestInterface) String() string
- type TestSecurityBackend
- type TestSetupCall
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownSecurity is reported when a interface is unable to deal with a given security system. ErrUnknownSecurity = errors.New("unknown security system") )
Functions ¶
func SecurityTagGlob ¶
SecurityTagGlob returns a pattern that matches all security tags belonging to the same snap as the given app.
func ValidateName ¶
ValidateName checks if a string can be used as a plug or slot name.
Types ¶
type BadInterfacesError ¶
type BadInterfacesError struct {
// contains filtered or unexported fields
}
BadInterfacesError is returned when some snap interfaces could not be registered. Those interfaces not mentioned in the error were successfully registered.
func (*BadInterfacesError) Error ¶
func (e *BadInterfacesError) Error() string
type Interface ¶
type Interface interface { // Unique and public name of this interface. Name() string // SanitizePlug checks if a plug is correct, altering if necessary. SanitizePlug(plug *Plug) error // SanitizeSlot checks if a slot is correct, altering if necessary. SanitizeSlot(slot *Slot) error // PermanentPlugSnippet returns the snippet of text for the given security // system that is used during the whole lifetime of affected applications, // whether the plug is connected or not. // // Permanent security snippet can be used to grant permissions to a snap that // has a plug of a given interface even before the plug is connected to a // slot. // // An empty snippet is returned when there are no additional permissions // that are required to implement this interface. ErrUnknownSecurity error // is returned when the plug cannot deal with the requested security // system. PermanentPlugSnippet(plug *Plug, securitySystem SecuritySystem) ([]byte, error) // ConnectedPlugSnippet returns the snippet of text for the given security // system that is used by affected application, while a specific connection // between a plug and a slot exists. // // Connection-specific security snippet can be used to grant permission to // a snap that has a plug of a given interface connected to a slot in // another snap. // // The snippet should be specific to both the plug and the slot. If the // slot is not necessary then consider using PermanentPlugSnippet() // instead. // // An empty snippet is returned when there are no additional permissions // that are required to implement this interface. ErrUnknownSecurity error // is returned when the plug cannot deal with the requested security // system. ConnectedPlugSnippet(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error) // PermanentSlotSnippet returns the snippet of text for the given security // system that is used during the whole lifetime of affected applications, // whether the slot is connected or not. // // Permanent security snippet can be used to grant permissions to a snap that // has a slot of a given interface even before the first connection to that // slot is made. // // An empty snippet is returned when there are no additional permissions // that are required to implement this interface. ErrUnknownSecurity error // is returned when the plug cannot deal with the requested security // system. PermanentSlotSnippet(slot *Slot, securitySystem SecuritySystem) ([]byte, error) // ConnectedSlotSnippet returns the snippet of text for the given security // system that is used by affected application, while a specific connection // between a plug and a slot exists. // // Connection-specific security snippet can be used to grant permission to // a snap that has a slot of a given interface connected to a plug in // another snap. // // The snippet should be specific to both the plug and the slot, if the // plug is not necessary then consider using PermanentSlotSnippet() // instead. // // An empty snippet is returned when there are no additional permissions // that are required to implement this interface. ErrUnknownSecurity error // is returned when the plug cannot deal with the requested security // system. ConnectedSlotSnippet(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error) // AutoConnect returns whether plugs and slots should be implicitly // auto-connected when an unambiguous connection candidate is available in // the OS snap. AutoConnect() bool }
Interface describes a group of interchangeable capabilities with common features. Interfaces act as a contract between system builders, application developers and end users.
type Interfaces ¶
Interfaces holds information about a list of plugs and slots, and their connections.
type Plug ¶
Plug represents the potential of a given snap to connect to a slot.
func (*Plug) MarshalJSON ¶
MarshalJSON returns the JSON encoding of plug.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository stores all known snappy plugs and slots and ifaces.
func NewRepository ¶
func NewRepository() *Repository
NewRepository creates an empty plug repository.
func (*Repository) AddInterface ¶
func (r *Repository) AddInterface(i Interface) error
AddInterface adds the provided interface to the repository.
func (*Repository) AddPlug ¶
func (r *Repository) AddPlug(plug *Plug) error
AddPlug adds a plug to the repository. Plug names must be valid snap names, as defined by ValidateName. Plug name must be unique within a particular snap.
func (*Repository) AddSlot ¶
func (r *Repository) AddSlot(slot *Slot) error
AddSlot adds a new slot to the repository. Adding a slot with invalid name returns an error. Adding a slot that has the same name and snap name as another slot returns an error.
func (*Repository) AddSnap ¶
func (r *Repository) AddSnap(snapInfo *snap.Info) error
AddSnap adds plugs and slots declared by the given snap to the repository.
This function can be used to implement snap install or, when used along with RemoveSnap, snap upgrade.
AddSnap doesn't change existing plugs/slots. The caller is responsible for ensuring that the snap is not present in the repository in any way prior to calling this function. If this constraint is violated then no changes are made and an error is returned.
Each added plug/slot is validated according to the corresponding interface. Unknown interfaces and plugs/slots that don't validate are not added. Information about those failures are returned to the caller.
func (*Repository) AllPlugs ¶
func (r *Repository) AllPlugs(interfaceName string) []*Plug
AllPlugs returns all plugs of the given interface. If interfaceName is the empty string, all plugs are returned.
func (*Repository) AllSlots ¶
func (r *Repository) AllSlots(interfaceName string) []*Slot
AllSlots returns all slots of the given interface. If interfaceName is the empty string, all slots are returned.
func (*Repository) AutoConnectBlacklist ¶
func (r *Repository) AutoConnectBlacklist(snapName string) map[string]bool
AutoConnectBlacklist returns plug names that should not be auto-connected.
Plug is blacklisted if it has no connections despite using an auto-connected interface. That implies it was manually disconnected.
func (*Repository) AutoConnectCandidates ¶
func (r *Repository) AutoConnectCandidates(plugSnapName, plugName string) []*Slot
AutoConnectCandidates finds and returns viable auto-connection candidates for a given plug.
func (*Repository) Connect ¶
func (r *Repository) Connect(plugSnapName, plugName, slotSnapName, slotName string) error
Connect establishes a connection between a plug and a slot. The plug and the slot must have the same interface.
func (*Repository) Disconnect ¶
func (r *Repository) Disconnect(plugSnapName, plugName, slotSnapName, slotName string) error
Disconnect disconnects the named plug from the slot of the given snap.
Disconnect has three modes of operation that depend on the passed arguments:
- If all the arguments are specified then Disconnect() finds a specific slot and a specific plug and disconnects that plug from that slot. It is an error if plug or slot cannot be found or if the connect does not exist.
- If plugSnapName and plugName are empty then Disconnect() finds the specified slot and disconnects all the plugs connected there. It is not an error if there are no such plugs but it is still an error if the slot does not exist.
- If plugSnapName, plugName and slotName are all empty then Disconnect finds the specified snap (designated by slotSnapName) and disconnects all the plugs from all the slots found therein. It is not an error if there are no such plugs but it is still an error if the snap does not exist or has no slots at all.
func (*Repository) DisconnectSnap ¶
func (r *Repository) DisconnectSnap(snapName string) ([]string, error)
DisconnectSnap disconnects all the connections to and from a given snap.
The return value is a list of names that were affected.
func (*Repository) Interface ¶
func (r *Repository) Interface(interfaceName string) Interface
Interface returns an interface with a given name.
func (*Repository) Interfaces ¶
func (r *Repository) Interfaces() *Interfaces
Interfaces returns object holding a lists of all the plugs and slots and their connections.
func (*Repository) Plug ¶
func (r *Repository) Plug(snapName, plugName string) *Plug
Plug returns the specified plug from the named snap.
func (*Repository) Plugs ¶
func (r *Repository) Plugs(snapName string) []*Plug
Plugs returns the plugs offered by the named snap.
func (*Repository) RemovePlug ¶
func (r *Repository) RemovePlug(snapName, plugName string) error
RemovePlug removes the named plug provided by a given snap. The removed plug must exist and must not be used anywhere.
func (*Repository) RemoveSlot ¶
func (r *Repository) RemoveSlot(snapName, slotName string) error
RemoveSlot removes a named slot from the given snap. Removing a slot that doesn't exist returns an error. Removing a slot that is connected to a plug returns an error.
func (*Repository) RemoveSnap ¶
func (r *Repository) RemoveSnap(snapName string) error
RemoveSnap removes all the plugs and slots associated with a given snap.
This function can be used to implement snap removal or, when used along with AddSnap, snap upgrade.
RemoveSnap does not remove connections. The caller is responsible for ensuring that connections are broken before calling this method. If this constraint is violated then no changes are made and an error is returned.
func (*Repository) SecuritySnippetsForSnap ¶
func (r *Repository) SecuritySnippetsForSnap(snapName string, securitySystem SecuritySystem) (map[string][][]byte, error)
SecuritySnippetsForSnap collects all of the snippets of a given security system that affect a given snap. The return value is indexed by app/hook security tag within that snap.
func (*Repository) Slot ¶
func (r *Repository) Slot(snapName, slotName string) *Slot
Slot returns the specified slot from the named snap.
func (*Repository) Slots ¶
func (r *Repository) Slots(snapName string) []*Slot
Slots returns the slots offered by the named snap.
type SecurityBackend ¶
type SecurityBackend interface { // Name returns the name of the backend. // This is intended for diagnostic messages. Name() string // Setup creates and loads security artefacts specific to a given snap. // The snap can be in developer mode to make security violations non-fatal // to the offending application process. // // This method should be called after changing plug, slots, connections // between them or application present in the snap. Setup(snapInfo *snap.Info, devMode bool, repo *Repository) error // Remove removes and unloads security artefacts of a given snap. // // This method should be called during the process of removing a snap. Remove(snapName string) error }
SecurityBackend abstracts interactions between the interface system and the needs of a particular security system.
type SecuritySystem ¶
type SecuritySystem string
SecuritySystem is a name of a security system.
const ( // SecurityAppArmor identifies the apparmor security system. SecurityAppArmor SecuritySystem = "apparmor" // SecuritySecComp identifies the seccomp security system. SecuritySecComp SecuritySystem = "seccomp" // SecurityDBus identifies the DBus security system. SecurityDBus SecuritySystem = "dbus" // SecurityUDev identifies the UDev security system. SecurityUDev SecuritySystem = "udev" // SecurityMount identifies the mount security system. SecurityMount SecuritySystem = "mount" )
type Slot ¶
Slot represents a capacity offered by a snap.
func (*Slot) MarshalJSON ¶
MarshalJSON returns the JSON encoding of slot.
type TestInterface ¶
type TestInterface struct { // InterfaceName is the name of this interface InterfaceName string // AutoConnectFlag indicates whether plugs and slots should be implicitly // auto-connected. AutoConnectFlag bool // SanitizePlugCallback is the callback invoked inside SanitizePlug() SanitizePlugCallback func(plug *Plug) error // SanitizeSlotCallback is the callback invoked inside SanitizeSlot() SanitizeSlotCallback func(slot *Slot) error // SlotSnippetCallback is the callback invoked inside ConnectedSlotSnippet() SlotSnippetCallback func(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error) // PermanentSlotSnippetCallback is the callback invoked inside PermanentSlotSnippet() PermanentSlotSnippetCallback func(slot *Slot, securitySystem SecuritySystem) ([]byte, error) // PlugSnippetCallback is the callback invoked inside ConnectedPlugSnippet() PlugSnippetCallback func(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error) // PermanentPlugSnippetCallback is the callback invoked inside PermanentPlugSnippet() PermanentPlugSnippetCallback func(plug *Plug, securitySystem SecuritySystem) ([]byte, error) }
TestInterface is a interface for various kind of tests. It is public so that it can be consumed from other packages.
func (*TestInterface) AutoConnect ¶
func (t *TestInterface) AutoConnect() bool
AutoConnect returns whether plugs and slots should be implicitly auto-connected when an unambiguous connection candidate is available in the OS snap.
func (*TestInterface) ConnectedPlugSnippet ¶
func (t *TestInterface) ConnectedPlugSnippet(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error)
ConnectedPlugSnippet returns the configuration snippet "required" to offer a test plug. Providers don't gain any extra permissions.
func (*TestInterface) ConnectedSlotSnippet ¶
func (t *TestInterface) ConnectedSlotSnippet(plug *Plug, slot *Slot, securitySystem SecuritySystem) ([]byte, error)
ConnectedSlotSnippet returns the configuration snippet "required" to use a test plug. Consumers don't gain any extra permissions.
func (*TestInterface) Name ¶
func (t *TestInterface) Name() string
Name returns the name of the test interface.
func (*TestInterface) PermanentPlugSnippet ¶
func (t *TestInterface) PermanentPlugSnippet(plug *Plug, securitySystem SecuritySystem) ([]byte, error)
PermanentPlugSnippet returns the configuration snippet "required" to offer a test plug. Providers don't gain any extra permissions.
func (*TestInterface) PermanentSlotSnippet ¶
func (t *TestInterface) PermanentSlotSnippet(slot *Slot, securitySystem SecuritySystem) ([]byte, error)
PermanentSlotSnippet returns the configuration snippet "required" to use a test plug. Consumers don't gain any extra permissions.
func (*TestInterface) SanitizePlug ¶
func (t *TestInterface) SanitizePlug(plug *Plug) error
SanitizePlug checks and possibly modifies a plug.
func (*TestInterface) SanitizeSlot ¶
func (t *TestInterface) SanitizeSlot(slot *Slot) error
SanitizeSlot checks and possibly modifies a slot.
func (*TestInterface) String ¶
func (t *TestInterface) String() string
String() returns the same value as Name().
type TestSecurityBackend ¶
type TestSecurityBackend struct { // SetupCalls stores information about all calls to Setup SetupCalls []TestSetupCall // RemoveCalls stores information about all calls to Remove RemoveCalls []string // SetupCallback is an callback that is optionally called in Setup SetupCallback func(snapInfo *snap.Info, developerMode bool, repo *Repository) error // RemoveCallback is a callback that is optionally called in Remove RemoveCallback func(snapName string) error }
TestSecurityBackend is a security backend intended for testing.
func (*TestSecurityBackend) Name ¶
func (b *TestSecurityBackend) Name() string
Name returns the name of the security backend.
func (*TestSecurityBackend) Remove ¶
func (b *TestSecurityBackend) Remove(snapName string) error
Remove records information about the call and calls the remove callback if one is defined
func (*TestSecurityBackend) Setup ¶
func (b *TestSecurityBackend) Setup(snapInfo *snap.Info, devMode bool, repo *Repository) error
Setup records information about the call and calls the setup callback if one is defined.
type TestSetupCall ¶
type TestSetupCall struct { // SnapInfo is a copy of the snapInfo argument to a particular call to Setup SnapInfo *snap.Info // DevMode is a copy of the developerMode argument to a particular call to Setup DevMode bool }
TestSetupCall stores details about calls to TestSecurityBackend.Setup
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package apparmor contains primitives for working with apparmor.
|
Package apparmor contains primitives for working with apparmor. |
package backendtest contains common code for testing backends
|
package backendtest contains common code for testing backends |
Package dbus implements interaction between snappy and dbus.
|
Package dbus implements interaction between snappy and dbus. |
Package mount implements mounts that get mapped into the snap Snappy creates fstab like configuration files that describe what directories from the system or from other snaps should get mapped into the snap.
|
Package mount implements mounts that get mapped into the snap Snappy creates fstab like configuration files that describe what directories from the system or from other snaps should get mapped into the snap. |
Package seccomp implements integration between snappy and ubuntu-core-launcher around seccomp.
|
Package seccomp implements integration between snappy and ubuntu-core-launcher around seccomp. |
Package udev implements integration between snappy, udev and ubuntu-core-laucher around tagging character and block devices so that they can be accessed by applications.
|
Package udev implements integration between snappy, udev and ubuntu-core-laucher around tagging character and block devices so that they can be accessed by applications. |