Documentation
¶
Overview ¶
Package sysuser provisions the kukeon system user/group and applies kukeon-managed file ownership during `kuke init`. The package is invoked from the init command so that a non-root user added to the kukeon group can dial the kukeond socket without sudo while writes under /opt/kukeon still require root (they go through the daemon).
Index ¶
- func ChownAndChmod(path string, uid, gid int, mode os.FileMode) error
- func ChownTreeAndChmod(root string, uid, gid int, dirMode, fileMode os.FileMode) error
- func ChownTreeAndChmodSkip(root string, uid, gid int, dirMode, fileMode os.FileMode, ...) error
- type CommandRunner
- type EnsureOptions
- type EnsureResult
- type ExecRunner
- type LookupGroupFunc
- type LookupUserFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChownAndChmod ¶
ChownAndChmod sets ownership and mode on a single path. Use this for the kukeond socket and for the /run/kukeon top-level directory.
func ChownTreeAndChmod ¶
ChownTreeAndChmod walks a directory tree and applies the requested owner to every entry, dirMode to directories, and fileMode to regular files. Splitting the modes keeps the recursive descent from making JSON metadata files executable when the caller wants 0o750-style group-traverse on dirs.
Symlinks are lchowned but not chmoded — Linux stores no mode bits on symlinks, and os.Chmod follows the link, which would mutate the wrong file.
func ChownTreeAndChmodSkip ¶ added in v0.6.0
func ChownTreeAndChmodSkip( root string, uid, gid int, dirMode, fileMode os.FileMode, skip func(path string, info os.FileInfo) bool, ) error
ChownTreeAndChmodSkip is ChownTreeAndChmod with an optional skip predicate. When skip is non-nil and returns true for an entry, that entry is left untouched — its owner and mode are preserved. Returning true for a directory prunes the entire subtree (filepath.SkipDir), so live state that a different code path owns is never re-chowned/chmodded by a tree-wide sweep. `kuke init` uses this to keep its idempotent ownership pass out of per-container kuketty tty directories, whose socket the daemon binds at 0o660 owned by the container's runtime uid (issue #1207).
Types ¶
type CommandRunner ¶
CommandRunner runs system commands. The default implementation shells out via os/exec; tests can substitute a fake to avoid mutating the host.
type EnsureOptions ¶
type EnsureOptions struct {
Runner CommandRunner
LookupGroup LookupGroupFunc
LookupUser LookupUserFunc
// NoLoginShell overrides the picked nologin shell. If empty, the helper
// chooses /usr/sbin/nologin or /sbin/nologin based on what exists.
NoLoginShell string
}
EnsureOptions configures EnsureUserGroup. Zero-valued fields fall back to the production lookups and the default runner.
type EnsureResult ¶
EnsureResult reports the outcome of EnsureUserGroup.
func EnsureUserGroup ¶
func EnsureUserGroup(ctx context.Context, username, groupname string, opts EnsureOptions) (EnsureResult, error)
EnsureUserGroup creates the named system group and user if they don't already exist, then returns the resolved UID/GID. Idempotent — re-running after a prior init is a no-op aside from the lookups.
Requires CAP_SYS_ADMIN (effectively, root) when creation is needed because it shells out to groupadd/useradd. The caller (kuke init) is already root, so this is fine in the production path.
type ExecRunner ¶
type ExecRunner struct{}
ExecRunner shells out via os/exec. It is the production CommandRunner.
type LookupGroupFunc ¶
LookupGroupFunc lets tests stub user.LookupGroup without populating /etc/group. Production callers should leave it nil to fall back to the stdlib lookup.