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

Update Zypper auth check #1270

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Update Zypper auth check #1270

wants to merge 4 commits into from

Conversation

jesusbv
Copy link
Collaborator

@jesusbv jesusbv commented Jan 9, 2025

Description

When a hybrid system runs zypper command, the check
needs to take care of the subscription verification

Currently, the check lacks paid extension ID, resulting in
an unsuccessful verification

This change fixes that

If system is hybrid, and the path being accessed belongs to a paid extension,
we check that the paid extension subscription is active

if the repository path belongs to a free repository or no matches with paid extensions,
no need to check the subscription

if ZypperAuth handle_scc_subscription method gets called without a product id,
the method will check all non free products suscriptions to be active, if any

This fixes bsc#1230157

How to test

Start an Azure instance, register LTSS, wait > 20 min for the cache to get expired
run zypper ref should work

Change Type

Please select the correct option.

  • Bug Fix (a non-breaking change which fixes an issue)
  • New Feature (a non-breaking change which adds new functionality)
  • Documentation Update (a change which only updates documentation)

Checklist

Please check off each item if the requirement is met.

  • I have reviewed my own code and believe that it's ready for an external review.
  • I have provided comments for any hard-to-understand code.
  • I have documented the MANUAL.md file with any changes to the user experience.
  • If my changes are non-trivial, I have added a changelog entry to notify users at package/obs/rmt-server.changes.

Review

Please check out our review guidelines
and get in touch with the author to get a shared understanding of the change.

@jesusbv jesusbv self-assigned this Jan 9, 2025
@jesusbv jesusbv requested review from digitaltom and rjschwei January 9, 2025 16:49
@jesusbv jesusbv added the 2.21 label Jan 9, 2025
@jesusbv jesusbv marked this pull request as draft January 9, 2025 20:00
When a hybrid system runs zypper command, the check
needs to take care of the subscription verification

Currently, the check lacks paid extension ID, resulting in
an unsuccessful verification

This change fixes that

If system is hybrid, and the path being accessed belongs to a paid extension,
we check that the paid extension subscription is active

if the repository path belongs to a free repository or no matches with paid extensions,
no need to check the subscription

if ZypperAuth handle_scc_subscription method gets called without a product id,
the method will check _all_ non free products suscriptions to be active, if any

This fixes bsc#1230157
@jesusbv jesusbv changed the title Fix the check for allowing repositories Update Zypper auth check Jan 10, 2025
repos_paths.each do |repo_path|
if headers.fetch('X-Original-URI', '').include? repo_path
logger.info "verifying paid extension #{paid_extension.identifier}"
return ZypperAuth.verify_instance(request, logger, @system, paid_extension.id)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could call handle_scc_subscription from path_allowed? or all_allowed_paths in the same file

I think adjusting the logic for ZypperAuth's path_allowed? (as in this PR) split the responsibilities clearer

Copy link
Member

Choose a reason for hiding this comment

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

This creates a loop ZypperAuth.verify_instance calls handle_scc_subscription in 2 places. In one of those places we have if is_valid && system.hybrid? && !handle_scc_subscription(request, system, verification_provider, params_product_id) So if the instance verification passed and the system is hybrid we end up in handle_scc_subscription and then here, since the system is a hybrid system we turn around and call verify_instance again. I do not understand how this is going to end well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and then here, since the system is a hybrid system we turn around and call verify_instance again

I do not know what you mean, if you mean that we call ZypperAuth.verify_instance twice,

  • one in line 166 (which we return the returned value of that call)
  • one in line 173

the call in line 173 happens if the system is not hybrid (and I would add byos) or if it is hybrid/byos and the path trying to be accessed was not found in that system products

is that what you meant, @rjschwei ?

Copy link
Collaborator Author

@jesusbv jesusbv Jan 10, 2025

Choose a reason for hiding this comment

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

my comment of moving the handle_scc_subscription (in ZypperAuth engine) call to path_allowed? (in strict_authentication engine) is more of "whose responsibility is it ?"

For example, if zypper is trying to access path A, it makes sense that the method checking if it is allowed
path_allowed? checks that the path is a non free repo and then checks that the subscription is valid/not expired

while verify_instance maybe should verify that the instance metadata is valid

It was just an open question than a suggestion

Copy link
Collaborator Author

@jesusbv jesusbv Jan 13, 2025

Choose a reason for hiding this comment

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

@rjschwei can you explain what you mean with

and then here, since the system is a hybrid system we turn around and call verify_instance again

?

@jesusbv
Copy link
Collaborator Author

jesusbv commented Jan 10, 2025

I will add the tests and coverage but it can be reviewed in the meantime

@jesusbv jesusbv marked this pull request as ready for review January 10, 2025 10:24
@jesusbv jesusbv requested a review from rjschwei January 10, 2025 10:33
@@ -51,9 +51,22 @@ def verify_instance(request, logger, system, params_product_id = nil)
end

def handle_scc_subscription(request, system, verification_provider, params_product_id = nil)
Copy link
Member

@digitaltom digitaltom Jan 10, 2025

Choose a reason for hiding this comment

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

Would such name describe that method intent better?

Suggested change
def handle_scc_subscription(request, system, verification_provider, params_product_id = nil)
def has_active_subscription?(request, system, verification_provider, params_product_id = nil)

def path_allowed?(path)
return false unless original_path_allowed?(path)
def path_allowed?(headers)
return false unless original_path_allowed?(headers)
Copy link
Member

Choose a reason for hiding this comment

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

What's going on here, original_path_allowed? is an alias for path_allowed?, and then we call original_path_allowed? from inside path_allowed??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct

def path_allowed?(headers)
return false unless original_path_allowed?(headers)

if @system.hybrid?
Copy link
Member

Choose a reason for hiding this comment

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

But shouldn't this apply to proxy systems as well? A BYOS system that uses RMT as a proxy to SCC should have the same verification right? OR do we not hit this code path for proxy clients?

Copy link
Collaborator Author

@jesusbv jesusbv Jan 10, 2025

Choose a reason for hiding this comment

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

we do, and I think byos? system should be included, unless there are BYOS subscriptions to register the system that include LTSS, meaning one regcode including system + LTSS instead of two regcodes (something I wanted to check here before including it)

I think the workflow is two reg codes

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

Successfully merging this pull request may close these issues.

3 participants