-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageCustomizer: Add Support for Configuring User Sudoers File #11196
base: 3.0-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ const ( | |
defaultFilePermissions = 0o755 | ||
) | ||
|
||
func copyAdditionalFiles(baseConfigPath string, additionalFiles imagecustomizerapi.AdditionalFileList, | ||
imageChroot *safechroot.Chroot, | ||
func CopyAdditionalFiles(baseConfigPath string, additionalFiles imagecustomizerapi.AdditionalFileList, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to make a function public if you are accessing it from the same package/directory. |
||
imageChroot safechroot.ChrootInterface, | ||
) error { | ||
for _, additionalFile := range additionalFiles { | ||
logger.Log.Infof("Copying: %s", additionalFile.Destination) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,5 +137,40 @@ func addOrUpdateUser(user imagecustomizerapi.User, baseConfigPath string, imageC | |
return err | ||
} | ||
|
||
// Set user's sudo access. | ||
err = UpdateSudoAccess(imageChroot, user.Name, user.Sudo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func UpdateSudoAccess(installChroot safechroot.ChrootInterface, username string, enableSudo bool) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was trying to put this function inside userutils.py but will create cyclic dependency issue. |
||
if enableSudo { | ||
|
||
// Define the sudo configuration file path for the user | ||
sudoersFile := fmt.Sprintf("/etc/sudoers.d/%s", username) | ||
|
||
// Content for sudo configuration | ||
content := fmt.Sprintf("%s ALL=(ALL) NOPASSWD:ALL", username) | ||
|
||
// Permissions for the sudoers file (read-only for root) | ||
permissions := imagecustomizerapi.FilePermissions(0440) | ||
|
||
// Create the AdditionalFile object | ||
additionalFiles := imagecustomizerapi.AdditionalFileList{ | ||
imagecustomizerapi.AdditionalFile{ | ||
Destination: fmt.Sprintf("/etc/sudoers.d/%s", username), | ||
Content: &content, | ||
Permissions: &permissions, | ||
}, | ||
} | ||
|
||
err := CopyAdditionalFiles(sudoersFile, additionalFiles, installChroot) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to use |
||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this setting specifically enabling no-password sudo? If that's the case, then could we make the setting name appropriately specific to that? Given that this is a security-impacting setting, I think we should be as clear as we can about what the image owner is opening up.