-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
lxd_connection: Allow non-root users to connect to an instance #9659
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
@yeetypete this PR contains the following merge commits: Please rebase your branch to remove these commits. |
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.
Thanks for your contribution! Please add a changelog fragment. I've also added some first comments below.
This comment was marked as outdated.
This comment was marked as outdated.
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.
Other than the already existing comments, LGTM
Co-authored-by: Felix Fontein <[email protected]>
fyi I've also replicated this functionality in the incus plugin: #9743 |
Backport to stable-10: 💚 backport PR created✅ Backport PR branch: Backported as #9751 🤖 @patchback |
* fix: add support for non-root user * fix: show correct info for connection * fix: use build_exec_command to execute as nonroot * unset default user * feat: add options for setting remote user and become method * fix: add root as default remote_user * fix: remove ansible_ssh_user from remote_user vars * fix: use single quotes inside f-string * fix: ensure lxc exec comes first * fix: line length * fix: use -c flag with su * Update plugins/connection/lxd.py Co-authored-by: Felix Fontein <[email protected]> * Update plugins/connection/lxd.py Co-authored-by: Felix Fontein <[email protected]> * Update plugins/connection/lxd.py Co-authored-by: Felix Fontein <[email protected]> * doc: add changelog fragment * fix: use underscore for module name in fragment * Update 9659-lxd_connection-nonroot-user.yml Co-authored-by: Felix Fontein <[email protected]> * fix: add put command * feat: add get_remote_uid_gid placeholder function * feat: complete placeholder _get_remote_uid_gid function * fix: better logging * fix: ensure default values are of type str * fix: use ints for uid and gid * fix: print put command * fix: format * fix: display msg for PUT * fix: add comment about defaults * fix: format * fix: use os module to get uid and gid * Revert "fix: use os module to get uid and gid" This reverts commit bb2ba14. * Update plugins/connection/lxd.py Co-authored-by: Felix Fontein <[email protected]> * fix: omit uid, gid args in lxd file push if root --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 06df717)
@yeetypete thanks for your contribution! |
@russoz thanks for reviewing! |
…t users to connect to an instance (#9751) lxd_connection: Allow non-root users to connect to an instance (#9659) * fix: add support for non-root user * fix: show correct info for connection * fix: use build_exec_command to execute as nonroot * unset default user * feat: add options for setting remote user and become method * fix: add root as default remote_user * fix: remove ansible_ssh_user from remote_user vars * fix: use single quotes inside f-string * fix: ensure lxc exec comes first * fix: line length * fix: use -c flag with su * Update plugins/connection/lxd.py Co-authored-by: Felix Fontein <[email protected]> * Update plugins/connection/lxd.py Co-authored-by: Felix Fontein <[email protected]> * Update plugins/connection/lxd.py Co-authored-by: Felix Fontein <[email protected]> * doc: add changelog fragment * fix: use underscore for module name in fragment * Update 9659-lxd_connection-nonroot-user.yml Co-authored-by: Felix Fontein <[email protected]> * fix: add put command * feat: add get_remote_uid_gid placeholder function * feat: complete placeholder _get_remote_uid_gid function * fix: better logging * fix: ensure default values are of type str * fix: use ints for uid and gid * fix: print put command * fix: format * fix: display msg for PUT * fix: add comment about defaults * fix: format * fix: use os module to get uid and gid * Revert "fix: use os module to get uid and gid" This reverts commit bb2ba14. * Update plugins/connection/lxd.py Co-authored-by: Felix Fontein <[email protected]> * fix: omit uid, gid args in lxd file push if root --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 06df717) Co-authored-by: Peter Siegel <[email protected]>
SUMMARY
Currently the
lxd_connection
only supports connecting to an instance as root. This PR extends the plugin to allow a non-root user, configurable via theansible_user
var to connect to the instance. The optionlxd_become_method
controls the command used to switch users, (su
by default but could also besudo -u
). The defaults ensure the old behavior so this should be a non-breaking change.ISSUE TYPE
COMPONENT NAME
lxd_connection
ADDITIONAL INFORMATION
If it is beneficial I would also be happy to add this functionality to the
incus_connection
andlxc_connection
plugins.