Skip to content
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

[PR #9659/06df717b backport][stable-10] lxd_connection: Allow non-root users to connect to an instance #9751

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Feb 15, 2025

This is a backport of PR #9659 as merged into main (06df717).

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 the ansible_user var to connect to the instance. The option lxd_become_method controls the command used to switch users, (su by default but could also be sudo -u). The defaults ensure the old behavior so this should be a non-breaking change.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

lxd_connection

ADDITIONAL INFORMATION

If it is beneficial I would also be happy to add this functionality to the incus_connection and lxc_connection plugins.

* 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)
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added backport connection connection plugin feature This issue/PR relates to a feature request new_contributor Help guide this first time contributor plugins plugin (any type) labels Feb 15, 2025
@felixfontein felixfontein merged commit 75e35bf into stable-10 Feb 15, 2025
138 checks passed
@felixfontein felixfontein deleted the patchback/backports/stable-10/06df717bc62fe3371acb2462b7694828b8e8196e/pr-9659 branch February 15, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport connection connection plugin feature This issue/PR relates to a feature request new_contributor Help guide this first time contributor plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants