Documentation
¶
Index ¶
- Variables
- func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, error)
- func GetAdditionalGroupsPath(additionalGroups []string, groupPath string) ([]int, error)
- func MkdirAllAndChown(path string, mode os.FileMode, uid, gid int, opts ...MkdirOpt) error
- func MkdirAndChown(path string, mode os.FileMode, uid, gid int, opts ...MkdirOpt) error
- func WithOnlyNew(o *mkdirOptions)
- type ExecUser
- type Group
- type IDMap
- type IdentityMapping
- type MkdirOpt
- type SubID
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoPasswdEntries is returned if no matching entries were found in /etc/group. ErrNoPasswdEntries = errors.New("no matching entries in passwd file") // ErrNoGroupEntries is returned if no matching entries were found in /etc/passwd. ErrNoGroupEntries = errors.New("no matching entries in group file") // ErrRange is returned if a UID or GID is outside of the valid range. ErrRange = fmt.Errorf("uids and gids must be in range %d-%d", minID, maxID) )
Functions ¶
func GetAdditionalGroups ¶
GetAdditionalGroups looks up a list of groups by name or group id against the given /etc/group formatted data. If a group name cannot be found, an error will be returned. If a group id cannot be found, or the given group data is nil, the id will be returned as-is provided it is in the legal range.
func GetAdditionalGroupsPath ¶
GetAdditionalGroupsPath is a wrapper around GetAdditionalGroups that opens the groupPath given and gives it as an argument to GetAdditionalGroups.
func MkdirAllAndChown ¶ added in v0.4.0
MkdirAllAndChown creates a directory (include any along the path) and then modifies ownership to the requested uid/gid. By default, if the directory already exists, this function will still change ownership and permissions. If WithOnlyNew is passed as an option, then only the newly created directories will have ownership and permissions changed.
func MkdirAndChown ¶ added in v0.4.0
MkdirAndChown creates a directory and then modifies ownership to the requested uid/gid. By default, if the directory already exists, this function still changes ownership and permissions. If WithOnlyNew is passed as an option, then only the newly created directory will have ownership and permissions changed. Note that unlike os.Mkdir(), this function does not return IsExist error in case path already exists.
func WithOnlyNew ¶ added in v0.4.0
func WithOnlyNew(o *mkdirOptions)
WithOnlyNew is an option for MkdirAllAndChown that will only change ownership and permissions on newly created directories. If the directory already exists, it will not be modified
Types ¶
type ExecUser ¶
func GetExecUser ¶
GetExecUser parses a user specification string (using the passwd and group readers as sources for /etc/passwd and /etc/group data, respectively). In the case of blank fields or missing data from the sources, the values in defaults is used.
GetExecUser will return an error if a user or group literal could not be found in any entry in passwd and group respectively.
Examples of valid user specifications are:
- ""
- "user"
- "uid"
- "user:group"
- "uid:gid
- "user:gid"
- "uid:group"
It should be noted that if you specify a numeric user or group id, they will not be evaluated as usernames (only the metadata will be filled). So attempting to parse a user with user.Name = "1337" will produce the user with a UID of 1337.
func GetExecUserPath ¶
func GetExecUserPath(userSpec string, defaults *ExecUser, passwdPath, groupPath string) (*ExecUser, error)
GetExecUserPath is a wrapper for GetExecUser. It reads data from each of the given file paths and uses that data as the arguments to GetExecUser. If the files cannot be opened for any reason, the error is ignored and a nil io.Reader is passed instead.
type IDMap ¶
IDMap represents an entry in /proc/PID/{u,g}id_map
func ParseIDMapFile ¶
func ParseIDMapFileFilter ¶
type IdentityMapping ¶ added in v0.4.0
IdentityMapping contains a mappings of UIDs and GIDs. The zero value represents an empty mapping.
func LoadIdentityMapping ¶ added in v0.4.0
func LoadIdentityMapping(name string) (IdentityMapping, error)
LoadIdentityMapping takes a requested username and using the data from /etc/sub{uid,gid} ranges, creates the proper uid and gid remapping ranges for that user/group pair
func (IdentityMapping) Empty ¶ added in v0.4.0
func (i IdentityMapping) Empty() bool
Empty returns true if there are no id mappings
func (IdentityMapping) RootPair ¶ added in v0.4.0
func (i IdentityMapping) RootPair() (int, int)
RootPair returns a uid and gid pair for the root user. The error is ignored because a root user always exists, and the defaults are correct when the uid and gid maps are empty.
func (IdentityMapping) ToContainer ¶ added in v0.4.0
func (i IdentityMapping) ToContainer(uid, gid int) (int, int, error)
ToContainer returns the container UID and GID for the host uid and gid
type MkdirOpt ¶ added in v0.4.0
type MkdirOpt func(*mkdirOptions)
MkdirOpt is a type for options to pass to Mkdir calls
type SubID ¶
SubID represents an entry in /etc/sub{u,g}id