Compare commits
3 Commits
95e85e8b45
...
c89dde186a
Author | SHA1 | Date | |
---|---|---|---|
c89dde186a | |||
18a64de0de | |||
99c622b69f |
3
.changes/unreleased/Added-20250311-152028.yaml
Normal file
3
.changes/unreleased/Added-20250311-152028.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
kind: Added
|
||||
body: 'UserCommands: add ssh public keys when running locally'
|
||||
time: 2025-03-11T15:20:28.487596157-05:00
|
3
.changes/unreleased/Added-20250311-153026.yaml
Normal file
3
.changes/unreleased/Added-20250311-153026.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
kind: Added
|
||||
body: 'UserCommands: add field CreateUserHome'
|
||||
time: 2025-03-11T15:30:26.824884876-05:00
|
3
.changes/unreleased/Changed-20250311-153619.yaml
Normal file
3
.changes/unreleased/Changed-20250311-153619.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
kind: Changed
|
||||
body: 'UserCommands: change field name'
|
||||
time: 2025-03-11T15:36:19.802011559-05:00
|
@ -12,6 +12,8 @@ This is dedicated to `user` commands. The command `type` field must be `user`. U
|
||||
| `userOperation` | The type of operation to perform. | `string` | yes | no |
|
||||
| `userID` | The user ID to use. | `string` | no | no |
|
||||
| `userGroups` | The groups the user should be added to. | `[]string` | no | no |
|
||||
| `systemUser` | Create a system user. | `bool` | no | no |
|
||||
| `userCreateHome`| Create the home directory. | `bool` | no | no |
|
||||
| `userSshPubKeys`| The keys to add to the user's authorized keys. | `[]string` | no | yes |
|
||||
| `userShell` | The shell for the user. | `string` | no | no |
|
||||
| `userHome` | The user's home directory. | `string` | no | no |
|
||||
|
@ -223,11 +223,8 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
||||
if err != nil {
|
||||
return collectOutput(&cmdOutBuf, command.Name, cmdCtxLogger, command.OutputToLog), fmt.Errorf("error creating file %s/authorized_keys: %v", userSshDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
return collectOutput(&cmdOutBuf, command.Name, cmdCtxLogger, command.OutputToLog), fmt.Errorf("error opening file %s/authorized_keys: %v", userSshDir, err)
|
||||
}
|
||||
f, err = os.OpenFile(fmt.Sprintf("%s/authorized_keys", userSshDir), 0700, os.ModeAppend)
|
||||
if err != nil {
|
||||
return collectOutput(&cmdOutBuf, command.Name, cmdCtxLogger, command.OutputToLog), fmt.Errorf("error opening file %s/authorized_keys: %v", userSshDir, err)
|
||||
|
@ -115,7 +115,9 @@ type (
|
||||
|
||||
UserShell string `yaml:"userShell,omitempty"`
|
||||
|
||||
SystemUser bool `yaml:"systemUser,omitempty"`
|
||||
UserCreateHome bool `yaml:"userCreateHome,omitempty"`
|
||||
|
||||
UserIsSystem bool `yaml:"userIsSystem,omitempty"`
|
||||
|
||||
UserPassword string `yaml:"userPassword,omitempty"`
|
||||
|
||||
|
@ -293,7 +293,8 @@ func getCommandTypeAndSetCommandInfo(command *Command) *Command {
|
||||
command.Username,
|
||||
command.UserHome,
|
||||
command.UserShell,
|
||||
command.SystemUser,
|
||||
command.UserIsSystem,
|
||||
command.UserCreateHome,
|
||||
command.UserGroups,
|
||||
command.Args)
|
||||
case "modify":
|
||||
|
@ -15,7 +15,7 @@ func (l LinuxUserManager) NewLinuxManager() *LinuxUserManager {
|
||||
}
|
||||
|
||||
// AddUser adds a new user to the system.
|
||||
func (l LinuxUserManager) AddUser(username, homeDir, shell string, isSystem bool, groups, args []string) (string, []string) {
|
||||
func (l LinuxUserManager) AddUser(username, homeDir, shell string, createHome, isSystem bool, groups, args []string) (string, []string) {
|
||||
baseArgs := []string{}
|
||||
|
||||
if isSystem {
|
||||
@ -38,6 +38,11 @@ func (l LinuxUserManager) AddUser(username, homeDir, shell string, isSystem bool
|
||||
baseArgs = append(baseArgs, args...)
|
||||
}
|
||||
|
||||
if createHome {
|
||||
baseArgs = append(baseArgs, "-m")
|
||||
|
||||
}
|
||||
|
||||
args = append(baseArgs, username)
|
||||
|
||||
cmd := "useradd"
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
// UserManager defines the interface for user management operations.
|
||||
// All functions but one return a string for the command and any args.
|
||||
type UserManager interface {
|
||||
AddUser(username, homeDir, shell string, isSystem bool, groups, args []string) (string, []string)
|
||||
AddUser(username, homeDir, shell string, createHome, isSystem bool, groups, args []string) (string, []string)
|
||||
RemoveUser(username string) (string, []string)
|
||||
ModifyUser(username, homeDir, shell string, groups []string) (string, []string)
|
||||
// Modify password uses chpasswd for Linux systems to build the command to change the password
|
||||
|
Loading…
x
Reference in New Issue
Block a user