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

Check for SLE Micro and SUMa headers to grant access #1246

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ class AuthenticationController < ::ApplicationController
# This is the endpoint for nginx subrequest auth check
def check
request_uri = request.headers['X-Original-URI']
auth_result = path_allowed?(request.headers['X-Original-URI'])
auth_result = path_allowed?(request.headers)
logger.info "Authentication subrequest for #{request_uri} -- #{auth_result ? 'allowed' : 'denied'}"
head auth_result ? :ok : :forbidden
end

protected

def path_allowed?(path)
def path_allowed?(headers)
path = headers['X-Original-URI']
return false if path.blank?

return true if path =~ %r{/product\.license/}

path = '/' + path.gsub(/^#{RMT::DEFAULT_MIRROR_URL_PREFIX}/, '')

# Allow access to SLES 12 and 12-SP1 repos for systems migrating from SLES 11
has_sles11 = @system.products.where(identifier: 'SUSE_SLES').first
return true if (has_sles11 && (path =~ %r{/12/} || path =~ %r{/12-SP1/}))

all_allowed_paths.find { |allowed_path| path =~ /^#{Regexp.escape(allowed_path)}/ }
all_allowed_paths(headers).find { |allowed_path| path =~ /^#{Regexp.escape(allowed_path)}/ }
end

def all_allowed_paths
def all_allowed_paths(headers)
# return all versions of the same product and arch
# (that the system has available with that subscription)
# in order to validate access not only for current product but others
Expand All @@ -39,7 +40,14 @@ def all_allowed_paths
# for the SUMa PAYG offers, RMT access verification code allows access
# to the SUMa Client Tools channels and SUMa Proxy channels
# when product is SUMA_Server and PAYG or SUMA_Server and used as SCC proxy
manager_prod = @system.products.any? { |p| p.identifier.downcase.include?('manager-server') }
manager_prod = @system.products.any? do |p|
manager = p.identifier.downcase.include?('manager-server')
# SUMA 5.0 must have access to SUMA 4.3, 4.2 and so on
micro = p.identifier.downcase.include?('sle-micro')
instance_id_header = headers.fetch('X-Instance-Identifier', '').casecmp('suse-manager-server').zero?
instance_version_header = headers.fetch('X-Instance-Version', '') == '5.0'
Copy link
Member

Choose a reason for hiding this comment

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

@rjmateus will SUMa always send the 5.0 version identifier even when we move to 5.1, 5.2 etc.?

Copy link
Member

Choose a reason for hiding this comment

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

I think we should/will send in future the real suma version. So yes, 5.1, 5.2, ... might be there.

Copy link
Member

Choose a reason for hiding this comment

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

As Michael said, that is the goal. I even change the version to 5.1 in our upstream project.

Copy link
Member

Choose a reason for hiding this comment

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

@jesusbv per comment from SUMa team the version check needs to be different, could be a > check.

manager || (micro && instance_id_header && instance_version_header)
end

if manager_prod
# add all SUMA products paths
Expand Down