[PR #6211/9f67cbbe backport][stable-6] rhsm modules: cleanly fail when not run as root (#6218)

rhsm modules: cleanly fail when not run as root (#6211)

subscription-manager on RHEL installs a symlink in /usr/bin to
console-helper (part of usermode), which triggers an interactive prompt
for root credentials when run as user. It seems that console-helper
does not handle well non-interactive contexts (e.g. without a TTY for
input), and thus it will hang waiting for input when run as user in an
Ansible task.

Since subscription-manager requires root already anyway (and it will
fail when explicitly run as user), then apply the same logic locally on
all the modules that interact with it: redhat_subscription,
rhsm_release, and rhsm_repository.

(cherry picked from commit 9f67cbbe36)

Co-authored-by: Pino Toscano <ptoscano@redhat.com>
This commit is contained in:
patchback[bot] 2023-03-22 17:57:46 +00:00 committed by GitHub
parent e0465d1f48
commit 9c411586ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 4 deletions

View file

@ -24,6 +24,8 @@ notes:
I(server_proxy_hostname), I(server_proxy_port), I(server_proxy_user) and
I(server_proxy_password) are no longer taken from the C(/etc/rhsm/rhsm.conf)
config file and default to None.
- It is possible to interact with C(subscription-manager) only as root,
so root permissions are required to successfully run this module.
requirements:
- subscription-manager
- Optionally the C(dbus) Python library; this is usually included in the OS
@ -291,7 +293,7 @@ subscribed_pool_ids:
'''
from os.path import isfile
from os import unlink
from os import getuid, unlink
import re
import shutil
import tempfile
@ -1074,6 +1076,11 @@ def main():
required_if=[['state', 'present', ['username', 'activationkey', 'token'], True]],
)
if getuid() != 0:
module.fail_json(
msg="Interacting with subscription-manager requires root permissions ('become: true')"
)
rhsm.module = module
state = module.params['state']
username = module.params['username']