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

feat: Added levels of connectivity to connect command #179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jirihnidek
Copy link
Contributor

@jirihnidek jirihnidek commented Dec 9, 2024

  • Card ID: CCT-1005
  • First step of levels of connectivity
  • When connect command is used, then it is possible to
    enabled or disable three features using command line
    options --enable-feature or --disable-feature. Following
    features are supported
    • content
    • analytics
    • remote-management
  • Added checks for allowed combination of CLI options
  • Modified UI little bit to be able to visualize that
    feature was not started
  • Output to JSON format is still supported
  • When machine readable format is used, then add information
    about enabled/disabled content to generated JSON file
  • When machine readable output is used, then list of
    enabled/disable features is added to the generated JSON doc
  • Unified UI for colorful and not colorful mode
  • Changed UI for disconnect command to looks similar to connect command
  • Connecting looks like this in interactive mode:
Connecting localhost to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [✓]analytics, [✓]remote-management

 [✓] This system is already connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [✓] Analytics ... Connected to Red Hat Insights
  [✓] Remote Management ... Activated the yggdrasil service

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector

@jirihnidek
Copy link
Contributor Author

jirihnidek commented Dec 9, 2024

Open question:

  • How should we list enabled/disabled features in generated JSON document?
  • Current output looks like this:
{
    "hostname": "localhost",
    "uid": 0,
    "enabled_features": [
        "analytics",
        "remote-management"
    ],
    "disabled_features": [
        "content"
    ],
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

Another possible solution could be following:

{
    "hostname": "localhost",
    "uid": 0,
    "features": {
        "enabled": [
            "analytics",
            "remote-management"
        ],
        "disabled": [
            "content"
        ],
    },
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

Or we can introduce something like this. This has potential to add there more attributes in the future:

{
    "hostname": "localhost",
    "uid": 0,
    "features": {
        "content": {
            "enabled": false,
        },
        "analytics": {
            "enabled": true,
        },
        "remote-management": {
            "enabled": true,
        },
    },
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

TODO:

  • Allow to enabled/disable features in interactive mode, when user has to input username & password (this should be part of another PR)

Copy link
Contributor

@m-horky m-horky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch seems solid. I won't comment much on the code itself; we'll likely see further changes done in near future as we stabilize it before new features come.

The output seems to jump around, were the two spaces intentional?

$ rhc connect --disable-feature analytics
...
 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
 [ ] Analytics ... Connecting to Red Hat Insights disabled
  [✓] Remote Management ... Activated the yggdrasil service

When disconnecting, Insights reported status 1 even though we should have detected we're (already) unregistered:

 [✓] Deactivated the yggdrasil service
 [𐄂] Cannot disconnect from Red Hat Insights: exit status 1
 [✓] Disconnected from Red Hat Subscription Management

The same goes for disconnection: with nothing connected in the first place, the output doesn't say yggdrasil wasn't enabled in the first place. That's a non-blocking note, but it feels strange.

$ rhc connect --enable-feature remote-management --disable-feature remote-management
cannot enable feature: "remote-management": feature "remote-management" explicitly disabled

Are we able to display something prettier and more human-understandable? Non-blocking note, may be addressed later.

if uiSettings.isMachineReadable {
connectResult.EnabledFeatures = append(connectResult.EnabledFeatures, feature.ID)
}
featuresStr = append(featuresStr, "["+symbolOK+"]"+feature.ID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a space between the checkbox and the text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to have some white space between checkbox and the text too, but standard "space" is IMHO too long and final line could be confusing at the first glance:

Current behavior:

Features preferences: [✓]content, [ ]analytics, [ ]remote-management

Proposed behavior:

Features preferences: [✓] content, [ ] analytics, [ ] remote-management

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks fine to me, I wouldn't worry too much.

if uiSettings.isMachineReadable {
connectResult.DisabledFeatures = append(connectResult.EnabledFeatures, feature.ID)
}
featuresStr = append(featuresStr, "[ ]"+feature.ID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a space between the checkbox and the text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

@m-horky
Copy link
Contributor

m-horky commented Dec 17, 2024

Or we can introduce something like this. This has potential to add there more attributes in the future:

{
    "hostname": "localhost",
    "uid": 0,
    "features": {
        "content": {
            "enabled": false,
        },
        "analytics": {
            "enabled": true,
        },
        "remote-management": {
            "enabled": true,
        },
    },
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

I like the nested approach. Would it make sense to move the _connected, _enabled keys into the features map?

"features": {
  "content": {
    "enabled": true,
    "connected": true,
  },
  "analytics": {
    "enabled": true,
    "connected": false,
  },
  ...
}

Copy link
Collaborator

@subpop subpop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small change I think we can make. I will test the behavior of this branch and follow up with another review.

rhsm.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
rhsm.go Outdated
if err := privConn.Object(
"com.redhat.RHSM1",
"/com/redhat/RHSM1/Register").Call(
"com.redhat.RHSM1.Register.RegisterWithActivationKeys",
dbus.Flags(0),
orgID,
activationKeys,
map[string]string{},
map[string]string{"enable_content": enabledContentStr},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try to register with my activation key, I get the following error:

[link@lima-rhel-10 rhc]$ sudo ./builddir/rhc connect -o 12671438 -a developer
Connecting lima-rhel-10 to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [✓]analytics, [✓]remote-management

 [𐄂] Cannot connect to Red Hat Subscription Management
  [𐄂] Skipping generation of Red Hat repository file
  [𐄂] Skipping connection to Red Hat Insights
  [𐄂] Skipping activation of yggdrasil service

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector

The following errors were encountered during connect:

TYPE   STEP  ERROR
ERROR  rhsm  cannot connect to Red Hat Subscription Management: error: Unknown arguments: dict_keys(['enable_content'])

Does the D-Bus method RegisterWithActivationKeys not accept 'enable_content' as
a parameter option? If so, does this mean that we cannot opt out of content if
registering with an activation key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@subpop Good point. I am working on the fix fix for rhsm.service. It should be simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR for subscription-manager created: candlepin/subscription-manager#3488

connect_cmd.go Outdated Show resolved Hide resolved
connect_cmd.go Outdated Show resolved Hide resolved
@subpop
Copy link
Collaborator

subpop commented Jan 7, 2025

Or we can introduce something like this. This has potential to add there more attributes in the future:

{
    "hostname": "localhost",
    "uid": 0,
    "features": {
        "content": {
            "enabled": false,
        },
        "analytics": {
            "enabled": true,
        },
        "remote-management": {
            "enabled": true,
        },
    },
    "rhsm_connected": true,
    "content_enabled": false,
    "insights_connected": true,
    "yggdrasil_started": true
}

I like the nested approach. Would it make sense to move the _connected, _enabled keys into the features map?

"features": {
  "content": {
    "enabled": true,
    "connected": true,
  },
  "analytics": {
    "enabled": true,
    "connected": false,
  },
  ...
}

I like this as well. Putting both "connected" and "enabled" inside the JSON object seems like the most scalable approach.

@jirihnidek
Copy link
Contributor Author

jirihnidek commented Jan 7, 2025

@m-horky @subpop OK, it seems we have consensus that we will use the third variant of proposed JSON format.

BTW: We can do big changes of JSON format ATM, because it hasn't been shipped in any official release. We can drop content_enabled, insights_connected and yggdrasil_started and move all information to features, because insights_connected would be duplicate of features["analytics"].connected. I'm also proposing to not use connected keyword, but I would use word successful, because word connected does not make much sense e.g. for feature content

{
    "hostname": "localhost",
    "uid": 0,
    "rhsm_connected": true,
    "features": {
        "content": {
            "enabled": false,
            "successful": true,
        },
        "analytics": {
            "enabled": true,
            "successful": false,
        },
        "remote_management": {
            "enabled": true,
            "successful": true,
        },
    },
}

@jirihnidek jirihnidek force-pushed the jhnidek/connect_levels_of_connectivity branch from 170304e to bd93706 Compare January 7, 2025 22:23
@Archana-PandeyM
Copy link

Archana-PandeyM commented Jan 9, 2025

Hi, this is my first attempt to get hands on for this feature. When I am trying to enable only one feature I still see everything getting enabled, for example I am trying to enable only content but all three feature are enabled. This should not happen, I should not need to mention disable-feature explicitly-

`[root@kvm-01-guest13 ~]# rhc connect --username ******* --password ******* --enable-feature content
Connecting kvm-01-guest13.lab.eng.brq2.redhat.com to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [✓]analytics, [✓]remote-management

 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [✓] Analytics ... Connected to Red Hat Insights
  [✓] Remote Management ... Activated the yggdrasil service

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector
[root@kvm-01-guest13 ~]#`

@jirihnidek
Copy link
Contributor Author

Hi, this is my first attempt to get hands on for this feature. When I am trying to enable only one feature I still see everything getting enabled, for example I am trying to enable only content but all three feature are enabled. This should not happen, I should not need to mention disable-feature explicitly-

[root@kvm-01-guest13 ~]# rhc connect --username ******* --password ******* --enable-feature content
Connecting kvm-01-guest13.lab.eng.brq2.redhat.com to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [✓]analytics, [✓]remote-management

 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [✓] Analytics ... Connected to Red Hat Insights
  [✓] Remote Management ... Activated the yggdrasil service

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector

The intention of --enable-feature FEATURE was originally little bit different. By default some features could be disabled and this CLI option would only enable one specific FEATURE.

In theory we can change behavior of --enable-feature, but your proposed behavior could be also considered confusing in some situation. @subpop What do you thing?

@Archana-PandeyM
Copy link

@subpop @jirihnidek I have one more concern, when rhc connect is run without --enable-feature or --disable-feature then by default connectivity level should be “level 2: analytics” (Did this requirement change overtime, not sure so I am just highlighting )

`[root@kvm-01-guest13 ~]# rhc connect --username ********  --password *******
Connecting ******************* to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [✓]analytics, [✓]remote-management

 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [✓] Analytics ... Connected to Red Hat Insights
  [✓] Remote Management ... Activated the yggdrasil service

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector

`

@subpop
Copy link
Collaborator

subpop commented Jan 9, 2025

The intention of --enable-feature FEATURE was originally little bit different. By default some features could be disabled and this CLI option would only enable one specific FEATURE.

In theory we can change behavior of --enable-feature, but your proposed behavior could be also considered confusing in some situation. @subpop What do you thing?

I don't like the idea of --enable-feature implicitly disabling all features except for the named one. That is not intuitive. --enable-feature should only enable a feature that is not enabled. If it is passed, naming a feature that is already enabled (by default or via dependency resolution), it should be a no-op. In the current circumstances, where all features are enabled by default, it's a meaningless flag, but if we change the defaults (as a result of the comment above) or add new features that are not enabled by default, it will become a more meaningful flag.

@Archana-PandeyM In the current design, to accomplish what you were trying to do, you would need to disable the features you don't want: --disable-feature analytics --disable-feature management.

@subpop
Copy link
Collaborator

subpop commented Jan 9, 2025

@subpop @jirihnidek I have one more concern, when rhc connect is run without --enable-feature or --disable-feature then by default connectivity level should be “level 2: analytics” (Did this requirement change overtime, not sure so I am just highlighting )

rhc today enables all three levels by default, so the design here maintains that. I'll check with Christian if he has any expectation around changing the default enabled features.

@Archana-PandeyM Archana-PandeyM self-requested a review January 13, 2025 09:46
@Archana-PandeyM
Copy link

Archana-PandeyM commented Jan 13, 2025

@jirihnidek With current implementation if 'Analytics' is disabled then 'remote-management' should be disabled too. but looks like there is issue-:

[root@kvm-01-guest13 ~]# rhc connect --username ********* --password *********  --disable-feature analytics
Connecting kvm-01-guest13.lab.eng.brq2.redhat.com to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [ ]analytics, [✓]remote-management

 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [ ] Analytics ... Connecting to Red Hat Insights disabled
  [✓] Remote Management ... Activated the yggdrasil service

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector

In the command output above 'analytics' is disabled but 'remote-management' is enabled. We should throw error instead or disable both.

@jirihnidek jirihnidek force-pushed the jhnidek/connect_levels_of_connectivity branch 2 times, most recently from dfbefe4 to eda17d4 Compare January 14, 2025 16:11
@jirihnidek
Copy link
Contributor Author

jirihnidek commented Jan 14, 2025

@Archana-PandeyM you are right. I forgot to consider this case. I altered behavior a little bit, when analytics is disabled, then remote-management is also disabled. I also added reason to the output, why the feature was disabled:

root@localhost:/# rhc connect --username admin --password admin --organization donaldduck \
    --disable-feature analytics
Connecting localhost to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [ ]analytics, [ ]remote-management

 [✓] Connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [ ] Analytics ... Connecting to Red Hat Insights disabled
  [ ] Management .... Starting yggdrasil service disabled (required feature "analytics" is disabled)

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector

@jirihnidek jirihnidek requested a review from subpop January 15, 2025 13:47
Copy link
Collaborator

@subpop subpop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One tiny consideration about the location of smallIndent and mediumIndent. Otherwise, this looks good to me from a code perspective.

I tested the behavior too and it works as expected with username and password. Activation keys still don't work due to candlepin/subscription-manager#3488.

constants.go Outdated Show resolved Hide resolved
@Archana-PandeyM
Copy link

@jirihnidek One last observation for this round of testing, I noticed that even though I requested to disable 'content' and the rhc connect says the file was not generated, Still redhat.repo file has repository details. Is the change in subman build(Do I need to install a seperate build)? Here are the reproducer steps:

`[root@kvm-01-guest13 ~]# ll /etc/yum.repos.d/redhat.repo
ls: cannot access '/etc/yum.repos.d/redhat.repo': No such file or directory
[root@kvm-01-guest13 ~]# 
[root@kvm-01-guest13 ~]# rhc connect --username *********** --password **********  --disable-feature content
Connecting kvm-01-guest13.lab.eng.brq2.redhat.com to Red Hat.
This might take a few seconds.

Features preferences: [ ]content, [✓]analytics, [ ]remote-management

 [✓] Connected to Red Hat Subscription Management
  [ ] Content ... Red Hat repository file not generated                       <<<<< file not generated
  [✓] Analytics ... Connected to Red Hat Insights
  [ ] Management .... Starting yggdrasil service disabled (required feature "content" is disabled)

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector
[root@kvm-01-guest13 ~]# ll /etc/yum.repos.d/redhat.repo
-rw-r--r--. 1 root root 48261 Jan 15 17:02 /etc/yum.repos.d/redhat.repo          <<<< file is still generated and content enabled
[root@kvm-01-guest13 ~]# yum repolist | grep rhel
rhel-10-for-x86_64-appstream-rpms                                         Red Hat Enterprise Linux 10 for x86_64 - AppStream (RPMs)
rhel-10-for-x86_64-baseos-rpms                                            Red Hat Enterprise Linux 10 for x86_64 - BaseOS (RPMs)
[root@kvm-01-guest13 ~]# 

`

@jirihnidek
Copy link
Contributor Author

@Archana-PandeyM yeah, you also need to use build of subscription-manager from this PR: candlepin/subscription-manager#3488 (do not forget to restart rhsm.service) Otherwise, the content is not disabled due to bug in subscription-manager (nonempty value including "false" is represented as a true).

* Card ID: CCT-1005
* First step of levels of connectivity
* When connect command is used, then it is possible to
  enabled or disable three features using command line
  options --enable-feature or --disable-feature. Following
  features are supported
  - content
  - analytics
  - remote-management
* Added checks for allowed combination of CLI options
* Modified UI little bit to be able to visualize that
  feature was not started
* Output to JSON format is still supported, but it was
  modified.
* When machine readable format is used, then information
  about features could be following:

{
    "hostname": "localhost",
    "uid": 0,
    "rhsm_connected": true,
    "features": {
        "content": {
            "enabled": true,
            "successful": true
        },
        "analytics": {
            "enabled": true,
            "successful": false,
            "error": "some error message"
        },
        "remote_management": {
            "enabled": false,
            "successful": false
        }
    }
}
@jirihnidek jirihnidek force-pushed the jhnidek/connect_levels_of_connectivity branch from eda17d4 to 73d3974 Compare January 20, 2025 10:25
@Archana-PandeyM
Copy link

@jirihnidek Thanks!
I tried with the mentioned rhel build and could reproduce the issue.


[root@kvm-01-guest13 ~]# rpm -qa | grep subscription-manager
subscription-manager-rhsm-certificates-20220623-6.el10.noarch
python3-subscription-manager-rhsm-1.30.3-1.20250106164229731439.pr3488.5.gcb97911fd.el10.x86_64
subscription-manager-1.30.3-1.20250106164229731439.pr3488.5.gcb97911fd.el10.x86_64
libdnf-plugin-subscription-manager-1.30.3-1.20250106164229731439.pr3488.5.gcb97911fd.el10.x86_64
[root@kvm-01-guest13 ~]# 
[root@kvm-01-guest13 ~]# 
[root@kvm-01-guest13 ~]# 
[root@kvm-01-guest13 ~]# systemctl restart rhsm.service
[root@kvm-01-guest13 ~]# rhc connect --username ********** --password ************* --disable-feature content
Connecting ****************** to Red Hat.
This might take a few seconds.

Features preferences: [ ]content, [✓]analytics, [ ]remote-management

 [✓] Connected to Red Hat Subscription Management
  [ ] Content ... Red Hat repository file not generated
  [✓] Analytics ... Connected to Red Hat Insights
  [ ] Management .... Starting yggdrasil service disabled (required feature "content" is disabled)

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector
[root@kvm-01-guest13 ~]# 

[root@kvm-01-guest13 ~]# ll /etc/yum.repos.d/redhat.repo 
-rw-r--r--. 1 root root 48261 Jan 21 08:31 /etc/yum.repos.d/redhat.repo
[root@kvm-01-guest13 ~]# yum repolist | grep rhel
rhel-10-for-x86_64-appstream-rpms                                         Red Hat Enterprise Linux 10 for x86_64 - AppStream (RPMs)
rhel-10-for-x86_64-baseos-rpms                                            Red Hat Enterprise Linux 10 for x86_64 - BaseOS (RPMs)
[root@kvm-01-guest13 ~]#

@jirihnidek
Copy link
Contributor Author

OK, I have result of investigation. It seems that insights-client --register calls subscription-manager refresh. Thus, content is enabled despite rhsm.service itself does not install any content.

When D-Bus methods Register*() are called with option enable_content: false, then the content is installed later by rhsmcertd.service during periodical certificate check-in despite /etc/pki/entitlement is empty.

If we really want to disable content, then we probably have to disable managing content in /etc/rhsm/rhsm.conf (manage_repos = 1).

@jirihnidek
Copy link
Contributor Author

User can run rhc connect multiple times with different set of levels of connectivity. It seems that it can enable/disable some feature, but it has no effect as you can see here:

[root@localhost ~]# rhc connect --username ********** --password ********** --disable-feature content
Connecting localhost to Red Hat.
This might take a few seconds.

Features preferences: [ ]content, [✓]analytics, [ ]remote-management

 [✓] Connected to Red Hat Subscription Management
  [ ] Content ... Red Hat repository file not generated
  [✓] Analytics ... Connected to Red Hat Insights
  [ ] Management .... Starting yggdrasil service disabled (required feature "content" is disabled)

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector


[root@localhost ~]# rhc status
Connection status for localhost:

✓ Connected to Red Hat Subscription Management
✓ Connected to Red Hat Insights
● The yggdrasil service is inactive

Manage your connected systems: https://red.ht/connector


[root@localhost ~]# rhc connect --username ********** --password ********** --disable-feature analytics
Connecting localhost to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [ ]analytics, [ ]remote-management

 [✓] This system is already connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [ ] Analytics ... Connecting to Red Hat Insights disabled
  [ ] Management .... Starting yggdrasil service disabled (required feature "analytics" is disabled)

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector


[root@localhost ~]# rhc status
Connection status for localhost:

✓ Connected to Red Hat Subscription Management
✓ Connected to Red Hat Insights
● The yggdrasil service is inactive

Manage your connected systems: https://red.ht/connector

I think that rhc connect should return some error on already connected system and non-zero exit code.

@jirihnidek
Copy link
Contributor Author

The rhc status should also print some information about enabled/disabled content, but it should be part of another PR.

@subpop
Copy link
Collaborator

subpop commented Jan 22, 2025

The rhc status should also print some information about enabled/disabled content, but it should be part of another PR.

Agreed.

@subpop
Copy link
Collaborator

subpop commented Jan 22, 2025

User can run rhc connect multiple times with different set of levels of connectivity. It seems that it can enable/disable some feature, but it has no effect as you can see here:

[root@localhost ~]# rhc connect --username ********** --password ********** --disable-feature content
Connecting localhost to Red Hat.
This might take a few seconds.

Features preferences: [ ]content, [✓]analytics, [ ]remote-management

 [✓] Connected to Red Hat Subscription Management
  [ ] Content ... Red Hat repository file not generated
  [✓] Analytics ... Connected to Red Hat Insights
  [ ] Management .... Starting yggdrasil service disabled (required feature "content" is disabled)

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector


[root@localhost ~]# rhc status
Connection status for localhost:

✓ Connected to Red Hat Subscription Management
✓ Connected to Red Hat Insights
● The yggdrasil service is inactive

Manage your connected systems: https://red.ht/connector


[root@localhost ~]# rhc connect --username ********** --password ********** --disable-feature analytics
Connecting localhost to Red Hat.
This might take a few seconds.

Features preferences: [✓]content, [ ]analytics, [ ]remote-management

 [✓] This system is already connected to Red Hat Subscription Management
  [✓] Content ... Red Hat repository file generated
  [ ] Analytics ... Connecting to Red Hat Insights disabled
  [ ] Management .... Starting yggdrasil service disabled (required feature "analytics" is disabled)

Successfully connected to Red Hat!

Manage your connected systems: https://red.ht/connector


[root@localhost ~]# rhc status
Connection status for localhost:

✓ Connected to Red Hat Subscription Management
✓ Connected to Red Hat Insights
● The yggdrasil service is inactive

Manage your connected systems: https://red.ht/connector

I think that rhc connect should return some error on already connected system and non-zero exit code.

This makes sense. The first run of rhc connect enables insights-client. The second one doesn't disable it because --disable-feature=analytics doesn't actively disable a feature; it just skips activating a feature. Maybe we need to implement the two EnableFunc and DisableFunc handler functions for the features and make sure that they (a) act idempotently; and (b) are invoked first DisableFunc and then conditionally EnableFunc if the flag is requested.

The original design intent of rhc connect is to be idempotent. This way it can be run multiple times (as part of scripts and other tooling). I can see there being a design flaw in that design intent though; if you run rhc connect using one set of credentials, and then run it again using a different set of credentials, it might attempt to register with the newer credentials without first unregistering the first set of credentials. We should probably revisit this design.

@jirihnidek
Copy link
Contributor Author

@Archana-PandeyM @subpop the issue of not disabled content is fixed in the PR for subscription-manager: candlepin/subscription-manager#3500

@jirihnidek
Copy link
Contributor Author

jirihnidek commented Jan 23, 2025

The original design intent of rhc connect is to be idempotent. This way it can be run multiple times (as part of scripts and other tooling). I can see there being a design flaw in that design intent though; if you run rhc connect using one set of credentials, and then run it again using a different set of credentials, it might attempt to register with the newer credentials without first unregistering the first set of credentials. We should probably revisit this design.

The current behavior of rhc connect is that it can be called multiple times with different username, password and organization, when system is already registered. The organization can influence set of available content. Thus, we should not ignore it. We do not store credential on the system for security reasons.

This is the reason, why subscription-manager does not allow to call subscription-manager register, when system is already registered. And it is also reason, why register command has CLI option --force. What "force" CLI option does? It unregisters and then it registers system again with given username & password or organization & activation key?

Question is: Shouldn't we also introduce --force CLI option to connect command?

@subpop
Copy link
Collaborator

subpop commented Jan 24, 2025

Shouldn't we also introduce --force CLI option to connect command?

No. Introducing a --force flag becomes ambiguous; what does it mean to "force a connection"? Will it register the system somehow anyway, if the credentials are invalid? "Force" does not clearly or explicitly communicate "first the system will be unregistered before attempting to be registered with the credentials".

If it is an error to run "register/connect" on a system that is already registered/connected, then the connect command should exit, reporting that error. The user should be expected to first unregistered the system by running disconnect. Then they follow up that command with connect again.

Now, that means that we probably do need to make changes to this PR so that rhc connect will exit with an error if the system is already registered. That will work around the issue of features previously enabled not being correctly disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants