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 ExecAsUser ¶
ExecAsUser executes a subprocess as a given user inside a security context.
func GetDefaultRunAsUser ¶
GetDefaultRunAsUser returns default run as user for CLI args based on current user.
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 Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager implements security manager.
func NewManager ¶
NewManager returns a new instance of security manager.
func (*Manager) DeleteACLEntries ¶
DeleteACLEntries removes any ACL added entries. Even after deletion there can be stable mask entry left because of the bootstraping (https://github.com/steiler/acls/blob/4ab4fd13906d754855a374a0cb0e0a41124efa54/acls.go#L69-L74) made the ACL lib when no ACLs found on the path. We can technically remove this mask entry as well but if dont know if that entry is added by us or already exists In order to keep the logic simpler, we leave the mask entry as such as it does not have any effect without any valid ACL entry.
func (*Manager) DropPrivileges ¶
DropPrivileges will change `root` user to run as user 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.
type SecurityContext ¶
type SecurityContext struct {
Name string
// contains filtered or unexported fields
}
SecurityContext implements a security context where functions can be safely executed with required privileges on a thread locked to OS.
func NewSecurityContext ¶
func NewSecurityContext(c *SCConfig) (*SecurityContext, error)
NewSecurityContext returns a new instance of SecurityContext.
func (*SecurityContext) Exec ¶
func (s *SecurityContext) Exec(data any) error
Exec executes the function inside the security context and returns error if any.