Documentation
¶
Overview ¶
Package sudo provides support for various methods of running commands with elevated privileges.
Index ¶
- Variables
- func Doas(cmd string) string
- func Noop(cmd string) string
- func RegisterDoas(repository *Registry)
- func RegisterSudo(repository *Registry)
- func RegisterUID0Noop(repository *Registry)
- func RegisterWindowsNoop(repository *Registry)
- func Sudo(cmd string) string
- type Factory
- type Provider
- type Registry
- type RunnerProvider
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoSudo is returned when no supported sudo method is found. ErrNoSudo = errors.New("no supported sudo method found") // DefaultRegistry is the default sudo repository. DefaultRegistry = sync.OnceValue(func() *Registry { provider := NewRegistry() RegisterWindowsNoop(provider) RegisterUID0Noop(provider) RegisterSudo(provider) RegisterDoas(provider) return provider }) )
Functions ¶
func RegisterDoas ¶
func RegisterDoas(repository *Registry)
RegisterDoas registers a doas DecorateFunc with the given repository.
func RegisterSudo ¶
func RegisterSudo(repository *Registry)
RegisterSudo registers a sudo DecorateFunc with the given repository.
func RegisterUID0Noop ¶
func RegisterUID0Noop(repository *Registry)
RegisterUID0Noop registers a noop DecorateFunc with the given repository which can be used when the user is root.
func RegisterWindowsNoop ¶
func RegisterWindowsNoop(repository *Registry)
RegisterWindowsNoop registers a noop DecorateFunc with the given repository if the current session has effective administrator privileges. IsInRole uses CheckTokenMembership, which returns true only when the Administrators SID is present and not marked deny-only — the correct signal for an effectively elevated token. SSH sessions on Windows always provide a full elevated token for Administrators group members regardless of UAC; WinRM does too for domain accounts or when LocalAccountTokenFilterPolicy=1 is set.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider provides a unified interface to interact with different sudo methods. It ensures that a suitable sudo runner is lazily initialized and made available for privileged command execution.
func NewSudoProvider ¶
func NewSudoProvider(get RunnerProvider, runner cmd.Runner) *Provider
NewSudoProvider creates a new instance of Provider with the provided RunnerProvider function and runner.