user

package
v0.0.0-...-01aaff4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package user provides user and group management operations.

Password and SSH key operations accept values inline in the request body rather than via Object Store + file.Deployer (which cron and certificate providers use). These are small values attached to a user account, not file deployments — Object Store would add unnecessary ceremony. SSH key fingerprints serve as the natural identity, so no SHA state tracking is needed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateGroupOpts

type CreateGroupOpts struct {
	Name   string `json:"name"`
	GID    int    `json:"gid,omitempty"`
	System bool   `json:"system,omitempty"`
}

CreateGroupOpts contains options for creating a new group.

type CreateUserOpts

type CreateUserOpts struct {
	Name     string   `json:"name"`
	UID      int      `json:"uid,omitempty"`
	GID      int      `json:"gid,omitempty"`
	Home     string   `json:"home,omitempty"`
	Shell    string   `json:"shell,omitempty"`
	Groups   []string `json:"groups,omitempty"`
	Password string   `json:"password,omitempty"`
	System   bool     `json:"system,omitempty"`
}

CreateUserOpts contains options for creating a new user.

type Darwin

type Darwin struct{}

Darwin implements the Provider interface for Darwin (macOS). All methods return ErrUnsupported as user/group management is not available on macOS.

func NewDarwinProvider

func NewDarwinProvider() *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) AddKey

func (d *Darwin) AddKey(
	_ context.Context,
	_ string,
	_ SSHKey,
) (*SSHKeyResult, error)

AddKey returns ErrUnsupported on Darwin.

func (*Darwin) ChangePassword

func (d *Darwin) ChangePassword(
	_ context.Context,
	_ string,
	_ string,
) (*Result, error)

ChangePassword returns ErrUnsupported on Darwin.

func (*Darwin) CreateGroup

func (d *Darwin) CreateGroup(
	_ context.Context,
	_ CreateGroupOpts,
) (*GroupResult, error)

CreateGroup returns ErrUnsupported on Darwin.

func (*Darwin) CreateUser

func (d *Darwin) CreateUser(
	_ context.Context,
	_ CreateUserOpts,
) (*Result, error)

CreateUser returns ErrUnsupported on Darwin.

func (*Darwin) DeleteGroup

func (d *Darwin) DeleteGroup(
	_ context.Context,
	_ string,
) (*GroupResult, error)

DeleteGroup returns ErrUnsupported on Darwin.

func (*Darwin) DeleteUser

func (d *Darwin) DeleteUser(
	_ context.Context,
	_ string,
) (*Result, error)

DeleteUser returns ErrUnsupported on Darwin.

func (*Darwin) GetGroup

func (d *Darwin) GetGroup(
	_ context.Context,
	_ string,
) (*Group, error)

GetGroup returns ErrUnsupported on Darwin.

func (*Darwin) GetUser

func (d *Darwin) GetUser(
	_ context.Context,
	_ string,
) (*User, error)

GetUser returns ErrUnsupported on Darwin.

func (*Darwin) ListGroups

func (d *Darwin) ListGroups(
	_ context.Context,
) ([]Group, error)

ListGroups returns ErrUnsupported on Darwin.

func (*Darwin) ListKeys

func (d *Darwin) ListKeys(
	_ context.Context,
	_ string,
) ([]SSHKey, error)

ListKeys returns ErrUnsupported on Darwin.

func (*Darwin) ListUsers

func (d *Darwin) ListUsers(
	_ context.Context,
) ([]User, error)

ListUsers returns ErrUnsupported on Darwin.

func (*Darwin) RemoveKey

func (d *Darwin) RemoveKey(
	_ context.Context,
	_ string,
	_ string,
) (*SSHKeyResult, error)

RemoveKey returns ErrUnsupported on Darwin.

func (*Darwin) UpdateGroup

func (d *Darwin) UpdateGroup(
	_ context.Context,
	_ string,
	_ UpdateGroupOpts,
) (*GroupResult, error)

UpdateGroup returns ErrUnsupported on Darwin.

func (*Darwin) UpdateUser

func (d *Darwin) UpdateUser(
	_ context.Context,
	_ string,
	_ UpdateUserOpts,
) (*Result, error)

UpdateUser returns ErrUnsupported on Darwin.

type Debian

type Debian struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Debian implements the Provider interface for Debian-family systems.

func NewDebianProvider

func NewDebianProvider(
	logger *slog.Logger,
	fs avfs.VFS,
	execManager exec.Manager,
) *Debian

NewDebianProvider factory to create a new Debian instance.

func (*Debian) AddKey

func (d *Debian) AddKey(
	ctx context.Context,
	username string,
	key SSHKey,
) (*SSHKeyResult, error)

AddKey adds an SSH public key to the user's authorized_keys file.

func (*Debian) ChangePassword

func (d *Debian) ChangePassword(
	ctx context.Context,
	name string,
	password string,
) (*Result, error)

ChangePassword changes a user's password.

func (*Debian) CreateGroup

func (d *Debian) CreateGroup(
	ctx context.Context,
	opts CreateGroupOpts,
) (*GroupResult, error)

CreateGroup creates a new system group.

func (*Debian) CreateUser

func (d *Debian) CreateUser(
	ctx context.Context,
	opts CreateUserOpts,
) (*Result, error)

CreateUser creates a new user account.

func (*Debian) DeleteGroup

func (d *Debian) DeleteGroup(
	ctx context.Context,
	name string,
) (*GroupResult, error)

DeleteGroup removes a system group.

func (*Debian) DeleteUser

func (d *Debian) DeleteUser(
	ctx context.Context,
	name string,
) (*Result, error)

DeleteUser removes a user account and its home directory.

func (*Debian) GetGroup

func (d *Debian) GetGroup(
	ctx context.Context,
	name string,
) (*Group, error)

GetGroup returns a single group by name.

func (*Debian) GetUser

func (d *Debian) GetUser(
	ctx context.Context,
	name string,
) (*User, error)

GetUser returns a single user account by name.

func (*Debian) ListGroups

func (d *Debian) ListGroups(
	ctx context.Context,
) ([]Group, error)

ListGroups returns all system groups.

func (*Debian) ListKeys

func (d *Debian) ListKeys(
	ctx context.Context,
	username string,
) ([]SSHKey, error)

ListKeys returns the SSH authorized keys for the given user.

func (*Debian) ListUsers

func (d *Debian) ListUsers(
	ctx context.Context,
) ([]User, error)

ListUsers returns all user accounts from /etc/passwd.

func (*Debian) RemoveKey

func (d *Debian) RemoveKey(
	ctx context.Context,
	username string,
	fingerprint string,
) (*SSHKeyResult, error)

RemoveKey removes an SSH public key by fingerprint from the user's authorized_keys file.

func (*Debian) UpdateGroup

func (d *Debian) UpdateGroup(
	ctx context.Context,
	name string,
	opts UpdateGroupOpts,
) (*GroupResult, error)

UpdateGroup updates group membership.

func (*Debian) UpdateUser

func (d *Debian) UpdateUser(
	ctx context.Context,
	name string,
	opts UpdateUserOpts,
) (*Result, error)

UpdateUser modifies an existing user account.

type Group

type Group struct {
	Name    string   `json:"name"`
	GID     int      `json:"gid"`
	Members []string `json:"members,omitempty"`
}

Group represents a system group.

type GroupResult

type GroupResult struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

GroupResult represents the result of a group mutation operation.

type Linux

type Linux struct{}

Linux implements the Provider interface for generic Linux. All methods return ErrUnsupported; use the Debian provider for Debian-family systems.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) AddKey

func (l *Linux) AddKey(
	_ context.Context,
	_ string,
	_ SSHKey,
) (*SSHKeyResult, error)

AddKey returns ErrUnsupported on generic Linux.

func (*Linux) ChangePassword

func (l *Linux) ChangePassword(
	_ context.Context,
	_ string,
	_ string,
) (*Result, error)

ChangePassword returns ErrUnsupported on generic Linux.

func (*Linux) CreateGroup

func (l *Linux) CreateGroup(
	_ context.Context,
	_ CreateGroupOpts,
) (*GroupResult, error)

CreateGroup returns ErrUnsupported on generic Linux.

func (*Linux) CreateUser

func (l *Linux) CreateUser(
	_ context.Context,
	_ CreateUserOpts,
) (*Result, error)

CreateUser returns ErrUnsupported on generic Linux.

func (*Linux) DeleteGroup

func (l *Linux) DeleteGroup(
	_ context.Context,
	_ string,
) (*GroupResult, error)

DeleteGroup returns ErrUnsupported on generic Linux.

func (*Linux) DeleteUser

func (l *Linux) DeleteUser(
	_ context.Context,
	_ string,
) (*Result, error)

DeleteUser returns ErrUnsupported on generic Linux.

func (*Linux) GetGroup

func (l *Linux) GetGroup(
	_ context.Context,
	_ string,
) (*Group, error)

GetGroup returns ErrUnsupported on generic Linux.

func (*Linux) GetUser

func (l *Linux) GetUser(
	_ context.Context,
	_ string,
) (*User, error)

GetUser returns ErrUnsupported on generic Linux.

func (*Linux) ListGroups

func (l *Linux) ListGroups(
	_ context.Context,
) ([]Group, error)

ListGroups returns ErrUnsupported on generic Linux.

func (*Linux) ListKeys

func (l *Linux) ListKeys(
	_ context.Context,
	_ string,
) ([]SSHKey, error)

ListKeys returns ErrUnsupported on generic Linux.

func (*Linux) ListUsers

func (l *Linux) ListUsers(
	_ context.Context,
) ([]User, error)

ListUsers returns ErrUnsupported on generic Linux.

func (*Linux) RemoveKey

func (l *Linux) RemoveKey(
	_ context.Context,
	_ string,
	_ string,
) (*SSHKeyResult, error)

RemoveKey returns ErrUnsupported on generic Linux.

func (*Linux) UpdateGroup

func (l *Linux) UpdateGroup(
	_ context.Context,
	_ string,
	_ UpdateGroupOpts,
) (*GroupResult, error)

UpdateGroup returns ErrUnsupported on generic Linux.

func (*Linux) UpdateUser

func (l *Linux) UpdateUser(
	_ context.Context,
	_ string,
	_ UpdateUserOpts,
) (*Result, error)

UpdateUser returns ErrUnsupported on generic Linux.

type Provider

type Provider interface {
	ListUsers(ctx context.Context) ([]User, error)
	GetUser(ctx context.Context, name string) (*User, error)
	CreateUser(ctx context.Context, opts CreateUserOpts) (*Result, error)
	UpdateUser(ctx context.Context, name string, opts UpdateUserOpts) (*Result, error)
	DeleteUser(ctx context.Context, name string) (*Result, error)
	ChangePassword(ctx context.Context, name string, password string) (*Result, error)
	ListGroups(ctx context.Context) ([]Group, error)
	GetGroup(ctx context.Context, name string) (*Group, error)
	CreateGroup(ctx context.Context, opts CreateGroupOpts) (*GroupResult, error)
	UpdateGroup(ctx context.Context, name string, opts UpdateGroupOpts) (*GroupResult, error)
	DeleteGroup(ctx context.Context, name string) (*GroupResult, error)
	ListKeys(ctx context.Context, username string) ([]SSHKey, error)
	AddKey(ctx context.Context, username string, key SSHKey) (*SSHKeyResult, error)
	RemoveKey(ctx context.Context, username string, fingerprint string) (*SSHKeyResult, error)
}

Provider implements the methods to manage users and groups.

type Result

type Result struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

Result represents the result of a user mutation operation.

type SSHKey

type SSHKey struct {
	Type        string `json:"type"`
	Fingerprint string `json:"fingerprint"`
	Comment     string `json:"comment,omitempty"`
	RawLine     string `json:"raw_line,omitempty"`
}

SSHKey represents an SSH public key from authorized_keys.

type SSHKeyResult

type SSHKeyResult struct {
	Changed bool `json:"changed"`
}

SSHKeyResult represents the result of an SSH key mutation operation.

type UpdateGroupOpts

type UpdateGroupOpts struct {
	Members []string `json:"members,omitempty"`
}

UpdateGroupOpts contains options for updating an existing group.

type UpdateUserOpts

type UpdateUserOpts struct {
	Shell  string   `json:"shell,omitempty"`
	Home   string   `json:"home,omitempty"`
	Groups []string `json:"groups,omitempty"`
	Lock   *bool    `json:"lock,omitempty"`
}

UpdateUserOpts contains options for updating an existing user.

type User

type User struct {
	Name   string   `json:"name"`
	UID    int      `json:"uid"`
	GID    int      `json:"gid"`
	Home   string   `json:"home"`
	Shell  string   `json:"shell"`
	Groups []string `json:"groups,omitempty"`
	Locked bool     `json:"locked"`
}

User represents a system user account.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL