RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2174887 - Environment module does not accept values with white-space when registering system in interactive mode
Summary: Environment module does not accept values with white-space when registering s...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: subscription-manager
Version: 8.8
Hardware: Unspecified
OS: Unspecified
medium
high
Target Milestone: rc
: 8.9
Assignee: Pino Toscano
QA Contact: Red Hat subscription-manager QE Team
URL:
Whiteboard:
Depends On: 2174297
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-03-02 14:42 UTC by Rehana
Modified: 2023-11-14 17:58 UTC (History)
6 users (show)

Fixed In Version: subscription-manager-1.28.37-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 2174297
Environment:
Last Closed: 2023-11-14 15:47:57 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github candlepin subscription-manager pull 3241 0 None Merged [1.28] 2174887: register: do a simple `strip()` on environment(s) input 2023-04-04 08:40:13 UTC
Red Hat Issue Tracker RHELPLAN-150466 0 None None None 2023-03-02 14:45:05 UTC
Red Hat Product Errata RHBA-2023:7092 0 None None None 2023-11-14 15:48:15 UTC

Description Rehana 2023-03-02 14:42:34 UTC
+++ This bug was initially created as a clone of Bug #2174297 +++

Description of problem: when registering the system in interactive mode to a server with multi-environment capability, environment module does not accept values with spaces


Version-Release number of selected component (if applicable):
[root@kvm-03-guest14 ~]# rpm -qa subscription-manager
subscription-manager-1.29.33-1.el9.x86_64

How reproducible:
Below is demonstration of the issue-
[root@kvm-03-guest14 ~]# subscription-manager version
server type: This system is currently not registered.
subscription management server: 4.2.15-1
subscription management rules: 5.43
subscription-manager: 1.29.33-1.el9
[root@kvm-03-guest14 ~]#

[root@kvm-03-guest14 ~]# subscription-manager register --username testuser1 --password ***** --org *******
Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
Hint: Organization "******" contains following environments: DevEnv, Test Env1
Environments: Test Env1
No such environment: TestEnv1   <<<<  it simply removes the space from value provided
[root@kvm-03-guest14 ~]# 
[root@kvm-03-guest14 ~]# subscription-manager register --username testuser1 --password ****** --org ****
Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
Hint: Organization "*******" contains following environments: DevEnv, Test Env1
Environments: "Test\ Env1"
No such environment: "Test\Env1"    <<<<  it simply removes the space from value provided
[root@kvm-03-guest14 ~]



Actual results:
spaces in the environment value is getting removed and hence registration fails for wrong value

Expected results:
only preceding and ending whitespaces should be removed

Additional info:

it works fine for cli non interactive mode-
[root@kvm-03-guest14 ~]# subscription-manager register --username testuser1 --password ****** --org **** --environments "Test Env1"
Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
The system has been registered with ID: 75aa3d13-7af1-4a3f-8c7d-f6ad602a258e
The registered system name is: kvm-03-guest14.hv2.lab.eng.bos.redhat.com

--- Additional comment from Pino Toscano on 2023-03-02 10:50:00 UTC ---

(In reply to Archana Pandey from comment #0)
> [root@kvm-03-guest14 ~]# subscription-manager register --username testuser1
> --password ***** --org *******
> Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
> Hint: Organization "******" contains following environments: DevEnv, Test
> Env1
> Environments: Test Env1
> No such environment: TestEnv1   <<<<  it simply removes the space from value
> provided

Typing the environments like this (environment names as-they-are) is correct.

> [root@kvm-03-guest14 ~]# subscription-manager register --username testuser1
> --password ****** --org ****
> Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
> Hint: Organization "*******" contains following environments: DevEnv, Test
> Env1
> Environments: "Test\ Env1"
> No such environment: "Test\Env1"    <<<<  it simply removes the space from
> value provided

This is not correct, as there is no unquoting or unescaping done.

The problem happens only when asking the user for environments:
https://github.com/candlepin/subscription-manager/blob/82a44c368f4f83c32d1933b774d731a5c341e9ef/src/subscription_manager/cli_command/register.py#L441-L444
Tracking back the history of this code, we have (ignoring no-op commits):
- https://github.com/candlepin/subscription-manager/commit/7d0199fb9419daad10530ad87cb2ef7fdae37a62
  this re-adds support for non-multi-environments scenarios
- https://github.com/candlepin/subscription-manager/commit/19ae947ad78a517d8ba999fdc41b62dcd850dbad
  this adds support for multiple environments: note that the `strip()` for non-multi-environments (i.e. only trailing and leading whitespace characters are removed) becomes `replace(" ", "")` (i.e. every single space is removed)
(both the commit above are part of https://github.com/candlepin/subscription-manager/pull/2920 )
- https://github.com/candlepin/subscription-manager/commit/69c4921f4fd9915e19317af44c4bf72cc5bf72e1
  (part of https://github.com/candlepin/subscription-manager/pull/989 )
  this is introduces the interactive query for an environment, doing the `strip()` in the input (unlike what other `input()` prompts do)

My notes:
- I'm not sure why the input is `strip()`ed for non-multi-environment input; the original commit doesn't say that
- I think the logic in removing spaces in the multi-environment case was done to mimic the non-multi-environment one, sadly in a sub-optimal way which creates this issue

The user may type any arbitrary amount of environments to register to when prompted interactively, so I think that the logic to strip spaces is most likely still needed: an input string "Env 1, Env2,MyEnv" must result in "Env 1", "Env2", "MyEnv" (and not as "Env 1", " Env2", "MyEnv"). Looking at the code:
- the result of `RegisterCommand._prompt_for_environment()` is passed directly to `check_set_environment_names()`
- `check_set_environment_names()` does `strip()` on the split elements of an environment string:
  https://github.com/candlepin/subscription-manager/blob/82a44c368f4f83c32d1933b774d731a5c341e9ef/src/subscription_manager/cli_command/environments.py#L196-L203

Hence, I think we can safely do a single `strip()` on the input of `RegisterCommand._prompt_for_environment()`, in both multi-environments and non-multi-environments scenarios: this way, empty or whitespace-only inputs are rejected, prompting the user again.
Attempt of PR for this: https://github.com/candlepin/subscription-manager/pull/3219

Comment 1 Jan Stavel 2023-04-19 12:41:16 UTC
TASK [The First Environment] **************************************************************************************************************************************************************************************
changed: [kvm-04-guest16.hv2.lab.eng.bos.redhat.com]

TASK [The Second Environment] *************************************************************************************************************************************************************************************
changed: [kvm-04-guest16.hv2.lab.eng.bos.redhat.com]

TASK [List of the Available Environments] *************************************************************************************************************************************************************************
ok: [kvm-04-guest16.hv2.lab.eng.bos.redhat.com] => 
  msg: |-
    +-------------------------------------------+
              Environments
    +-------------------------------------------+
    Name:        JStavel Env 01
    Description: new env01
  
    Name:        JStavel Env 02
    Description: Jan Stavel Env 02

TASK [Register a system with environment having space inside a name] **********************************************************************************************************************************************
changed: [kvm-04-guest16.hv2.lab.eng.bos.redhat.com]

TASK [Output from register command] *******************************************************************************************************************************************************************************
ok: [kvm-04-guest16.hv2.lab.eng.bos.redhat.com] => 
  msg: |-
    Registering to: archana-candlepin.usersys.redhat.com:8443/candlepin
    Hint: Organization "admin" contains following environments: JStavel Env 01, JStavel Env 02
    JStavel Env 01
    Environments: JStavel Env 01
    JStavel Env 01
    The system has been registered with ID: edc3e3f5-0a60-49e5-b831-27464c16cf27
    The registered system name is: kvm-04-guest16.hv2.lab.eng.bos.redhat.com

TASK [List of enabled environments] *******************************************************************************************************************************************************************************
changed: [kvm-04-guest16.hv2.lab.eng.bos.redhat.com]

TASK [Enabled Environment should have space inside] ***************************************************************************************************************************************************************
ok: [kvm-04-guest16.hv2.lab.eng.bos.redhat.com] => 
  msg: |-
    +-------------------------------------------+
              Environments
    +-------------------------------------------+
    Name:        JStavel Env 01
    Description: new env01

TASK [Version of the package subscription-manager] ****************************************************************************************************************************************************************
ok: [kvm-04-guest16.hv2.lab.eng.bos.redhat.com] => 
  msg: |-
    server type: Red Hat Subscription Management
    subscription management server: 4.3.1-1
    subscription management rules: 5.43
    subscription-manager: 1.28.36+26.gcc438fc3e-1.git.0.729c474

Comment 7 errata-xmlrpc 2023-11-14 15:47:57 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (subscription-manager bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:7092


Note You need to log in before you can comment on or make changes to this bug.