Documentation
¶
Overview ¶
Package security implements privilege management and execution of privileged actions in security contexts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoSecurityCtx = errors.New("security context not found") ErrSecurityCtxDataAssertion = errors.New("data type cannot be asserted") )
Custom errors.
Functions ¶
func DropCapabilities ¶
func DropCapabilities() error
DropCapabilities drops any existing capabilities on the process.
func DropPrivileges ¶
DropPrivileges will change `root` user to `nobody` and drop any unnecessary privileges only keeping the ones passed in `caps` argument. If current user is not root, this function is no-op and we expect either process or file to have necessary capabilities in the production environments.
func ExecAsUser ¶
func ExecAsUser(data interface{}) error
ExecAsUser executes a subprocess as a given user inside a security context.
Types ¶
type ExecSecurityCtxData ¶
type ExecSecurityCtxData struct { Context context.Context //nolint:containedctx Cmd []string Environ []string UID int GID int StdOut []byte Logger *slog.Logger }
ExecSecurityCtxData contains the input/output data for executing subprocess inside security context.
type SecurityContext ¶
type SecurityContext struct { Logger *slog.Logger Launcher *cap.Launcher Func func(interface{}) error Caps []cap.Value CapSet *cap.Set Name string }
SecurityContext implements a security context where functions can be safely executed with required privileges on a thread locked to OS.
func NewSecurityContext ¶
func NewSecurityContext( name string, caps []cap.Value, f func(interface{}) error, logger *slog.Logger, ) (*SecurityContext, error)
NewSecurityContext returns a new instance of SecurityContext.
func (*SecurityContext) Exec ¶
func (s *SecurityContext) Exec(data interface{}) error
Exec executes the function inside the security context and returns error if any.