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

Refs #5217: Merging roles branch to master. #4073

Merged
merged 57 commits into from
May 15, 2014
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
fb142fd
Refs #5217: Initial location to declare and load permissions.
ehelms Apr 16, 2014
f091273
Fixes #5230: Adds CRUD permissions for GPG Keys.
ehelms Apr 17, 2014
ddd1631
Merge pull request #3985 from ehelms/fixes-5230
ehelms Apr 22, 2014
6f3e415
Merge remote-tracking branch 'upstream/master' into roles
Apr 23, 2014
5334474
Fixes #5260 - adding CRUD permissions for Sync Plans.
Apr 22, 2014
309c968
Merge pull request #3997 from waldenraines/sync-plan-roles
Apr 23, 2014
6fc170e
Merge pull request #4000 from waldenraines/roles
Apr 23, 2014
5e09f6f
Merge remote-tracking branch 'upstream/master' into roles
Apr 28, 2014
8e2c12d
Merge pull request #4012 from waldenraines/roles
Apr 28, 2014
537da25
Fixes # 5437 - Env controller cleanup
parthaa Apr 24, 2014
d453fe1
Fixes #5416 - adding CRUD permissions for activation keys.
Apr 23, 2014
fdfc0ae
Merge pull request #4003 from waldenraines/activation-keys-roles
Apr 29, 2014
bf04f12
Merge pull request #4014 from parthaa/env-cleanup
parthaa Apr 29, 2014
f2f640b
Merge remote-tracking branch 'upstream/master' into roles
May 1, 2014
4af5e43
Merge branch 'master' of https://github.com/Katello/katello into roles
May 1, 2014
14a4246
Merge pull request #4027 from waldenraines/roles
May 1, 2014
70a7645
Fixes #5261: Adds CRUD permissions for Products and Repositories.
ehelms Apr 28, 2014
a587444
Merge pull request #4017 from ehelms/fixes-5261
ehelms May 1, 2014
69e9e1e
Fixes #5536: Wraps Organization APIs in authorization protections.
ehelms May 1, 2014
da0552d
Merge pull request #4033 from ehelms/fixes-5536
ehelms May 2, 2014
cb0db9c
Fixes #5521: Adding permissions for managing subscriptions and manife…
ehelms May 1, 2014
ad368d6
Merge pull request #4042 from ehelms/fixes-5521
ehelms May 5, 2014
c319eac
Fixes #5531: Wrapping sync controllers in with new permissions.
ehelms May 3, 2014
283108d
Merge pull request #4044 from ehelms/fixes-5531
ehelms May 5, 2014
a0270f1
Fixes #5434, adding permissions for Content Views
Apr 24, 2014
738c8cd
Merge pull request #4043 from waldenraines/content-view-roles
May 6, 2014
676ff5d
Fixes #5530 - CRUD perms for Environments
parthaa Apr 30, 2014
1ad2a3c
Refs #5217: Adjusts product organization_id migration to account for …
ehelms May 7, 2014
13bf35e
Merge pull request #4058 from ehelms/refs-5217
ehelms May 7, 2014
dcc4819
Fixes #5593, display authorized menu items post single page app.
May 6, 2014
fe48da2
Merge pull request #4053 from waldenraines/5593
May 8, 2014
5bd4204
Merge pull request #4035 from parthaa/env-perms
parthaa May 8, 2014
ccf93f4
Fixes #5591, adding authorization for Red Hat Repositories.
May 7, 2014
cc80c81
Fixes #5635, displaying bastion unauthorized error message on 403.
May 8, 2014
8e917f1
Merge pull request #4057 from waldenraines/rh-repo-roles
May 8, 2014
b594e0b
Merge pull request #4060 from waldenraines/5635
May 8, 2014
e83a6f1
Merge remote-tracking branch 'upstream/master' into roles
May 8, 2014
c6a8807
Merge pull request #4062 from waldenraines/roles
May 8, 2014
b0ec04b
Fixes #5533: Adding Content Host permissions.
ehelms May 10, 2014
c66ca3b
Merge pull request #4055 from ehelms/fixes-5533
ehelms May 12, 2014
6d176b0
Merge branch 'master' of https://github.com/Katello/katello into mast…
ehelms May 13, 2014
990817c
Fixes #5698, specify absolute URLs instead of relative in menu.
May 13, 2014
becc032
Merge remote branch 'origin/master' into master-to-roles
ehelms May 13, 2014
b331f87
Merge pull request #4077 from waldenraines/5698
May 13, 2014
3346934
Merge pull request #4072 from ehelms/master-to-roles
ehelms May 13, 2014
4422005
Fixes #5702 - CV index call now respects environment_id correctly
parthaa May 13, 2014
996a1ed
Merge pull request #4079 from parthaa/cv-index
parthaa May 13, 2014
5788e19
Refs #5217: Adding check that the consumer cert matches the passed in
ehelms May 14, 2014
d8fe46f
Merge pull request #4085 from ehelms/refs-5217
ehelms May 14, 2014
3526da5
Refs #5217: Moving permissions into lib/katello directory.
ehelms May 14, 2014
c7efcfb
Merge pull request #4087 from ehelms/refs-5217
ehelms May 14, 2014
2735ea0
Refs #5217: Fix activation key destroy.
ehelms May 14, 2014
875633d
Refs #5217: Fix content host menu item and add organization scoping.
ehelms May 15, 2014
ec9aae7
Merge pull request #4088 from ehelms/refs-5217
ehelms May 15, 2014
3193025
Merge branch 'master' of https://github.com/Katello/katello into mast…
ehelms May 15, 2014
af2dd40
Merge pull request #4093 from ehelms/master-to-roles
ehelms May 15, 2014
bd4c802
Merge pull request #4092 from ehelms/refs-5217
ehelms May 15, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 45 additions & 1 deletion app/controllers/katello/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,38 @@ def load_search_service(service = nil)

# Override Foreman authorized method to call the Katello authorize check
def authorized
authorize_katello
if converted_controllers.include?(request.params['controller'])
super
else
authorize_katello
end
end

def converted_controllers
[
'katello/api/v2/activation_keys',
'katello/api/v2/content_views',
'katello/api/v2/content_view_filters',
'katello/api/v2/content_view_filter_rules',
'katello/api/v2/content_view_puppet_modules',
'katello/api/v2/content_view_versions',
'katello/api/v2/gpg_keys',
'katello/api/v2/sync_plans',
'katello/api/v2/products',
'katello/api/v2/repositories',
'katello/api/v2/products_bulk_actions',
'katello/api/v2/repositories_bulk_actions',
'katello/api/v2/content_uploads',
'katello/api/v2/organizations',
'katello/api/v2/subscriptions',
'katello/api/v2/sync',
'katello/api/v2/environments',
'katello/api/v2/systems',
'katello/api/v2/system_packages',
'katello/api/v2/system_errata',
'katello/api/v2/systems_bulk_actions',
'katello/api/v1/candlepin_proxies'
]
end

def verify_ldap
Expand Down Expand Up @@ -104,5 +135,18 @@ def respond(options = {})
return send(method_name, options)
end

def format_bulk_action_messages(args = {})
models = args.fetch(:models)
authorized = args.fetch(:authorized)
messages = []

unauthorized = models - authorized

messages << args.fetch(:success) % authorized.length if authorized.present?
messages << args.fetch(:error) % unauthorized if unauthorized.present?

messages
end

end
end
132 changes: 17 additions & 115 deletions app/controllers/katello/api/v1/candlepin_proxies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Api::V1::CandlepinProxiesController < Api::V1::ApiController

include Katello::Authentication::ClientAuthentication

skip_before_filter :authorize, :except => [:consumer_create, :rhsm_index]
before_filter :authenticate, :only => [:list_owners]
before_filter :authenticate_client, :except => [:list_owners, :consumer_create, :rhsm_index, :consumer_activate]

before_filter :add_candlepin_version_header

before_filter :proxy_request_path, :proxy_request_body
Expand All @@ -29,95 +33,6 @@ class Api::V1::CandlepinProxiesController < Api::V1::ApiController
before_filter :find_hypervisor_environment_and_content_view, :only => [:hypervisors_update]
before_filter :find_system, :only => [:consumer_show, :consumer_destroy, :consumer_checkin,
:upload_package_profile, :regenerate_identity_certificates, :facts]
before_filter :find_user_by_login, :only => [:list_owners]
before_filter :authorize, :except => [:consumer_activate]

# TODO: break up method
# rubocop:disable MethodLength
def rules

proxy_test = lambda do
route, _, params = Engine.routes.router.recognize(request) do |rte, match, parameters|
break rte, match, parameters if rte.name
end

# route names are defined in routes.rb (:as => :name)
case route.name
when "api_proxy_consumer_deletionrecord_delete_path"
User.consumer? || Organization.all_editable?
when "api_proxy_owner_pools_path"
find_optional_organization
if params[:consumer]
(User.consumer? || @organization.readable?) && current_user.uuid == params[:consumer]
else
(User.consumer? || @organization.readable?)
end
when "api_proxy_owner_servicelevels_path"
find_optional_organization
(User.consumer? || @organization.readable?)
when "api_proxy_consumer_certificates_path", "api_proxy_consumer_releases_path", "api_proxy_certificate_serials_path",
"api_proxy_consumer_entitlements_path", "api_proxy_consumer_entitlements_post_path", "api_proxy_consumer_entitlements_delete_path",
"api_proxy_consumer_dryrun_path", "api_proxy_consumer_owners_path", "api_proxy_consumer_compliance_path"
User.consumer? && current_user.uuid == params[:id]
when "api_proxy_consumer_certificates_delete_path"
User.consumer? && current_user.uuid == params[:consumer_id]
when "api_proxy_pools_path"
User.consumer? && current_user.uuid == params[:consumer]
when "api_proxy_entitlements_path"
User.consumer?
when "api_proxy_subscriptions_post_path"
User.consumer? && current_user.uuid == params[:consumer_uuid]
when "api_proxy_consumer_content_overrides_path", "api_proxy_consumer_content_overrides_put_path",
"api_proxy_consumer_content_overrides_delete_path"
# These queries are restricted in Candlepin
User.consumer?
when "api_proxy_consumer_guestids_path", "api_proxy_consumer_guestids_get_guestid_path",
"api_proxy_consumer_guestids_put_path", "api_proxy_consumer_guestids_put_guestid_path",
"api_proxy_consumer_guestids_delete_guestid_path"
# These queries are restricted in Candlepin
User.consumer?
when "api_proxy_deleted_consumers_path"
current_user.has_superadmin_role?
else
Rails.logger.warn "Unknown proxy route #{request.method} #{request.fullpath}, access denied"
false
end
end
# After a system registers, it immediately uploads its packages. Although newer subscription-managers send
# certificate (User.consumer? == true), some do not. In this case, confirm that the user has permission to
# register systems in the system's organization and environment.
upload_system_packages = lambda do
@system.editable? ||
System.registerable?(@system.environment, @system.organization) ||
User.consumer?
end
consumer_only = lambda { User.consumer? }
list_owners_test = lambda { @user.id == User.current.id } #user can see only his/her owners
register_system = lambda { System.registerable?(@environment, @organization, @content_view) }
index_systems = lambda { System.any_readable?(@organization) }
edit_system = lambda do
subscribable = @content_view ? @content_view.subscribable? : true
subscribable && (@system.editable? || User.consumer?)
end

{
:get => proxy_test,
:post => proxy_test,
:put => proxy_test,
:delete => proxy_test,
:upload_package_profile => upload_system_packages,
:consumer_checkin => consumer_only,
:regenerate_identity_certificates => consumer_only,
:consumer_create => register_system,
:consumer_destroy => consumer_only,
:consumer_show => consumer_only,
:index => index_systems,
:hypervisors_update => consumer_only,
:list_owners => list_owners_test,
:rhsm_index => lambda {true},
:facts => edit_system
}
end

rescue_from RestClient::Exception do |e|
Rails.logger.error pp_exception(e)
Expand Down Expand Up @@ -203,19 +118,13 @@ def consumer_checkin
#api :PUT, "/consumers/:id/profile", "Update installed packages"
#param :id, String, :desc => "UUID of the consumer", :required => true
def upload_package_profile
allowed = rules[:upload_package_profile].call
if allowed
fail HttpErrors::BadRequest, _("No package profile received for %s") % @system.name unless params.key?(:_json)
@system.upload_package_profile(params[:_json])
render :json => Resources::Candlepin::Consumer.get(@system.uuid)
else
Rails.logger.warn(_("Consumer %s not allowed to upload package profile.") % params[:id])
respond_for_update :resource => {}
end
fail HttpErrors::BadRequest, _("No package profile received for %s") % @system.name unless params.key?(:_json)
@system.upload_package_profile(params[:_json])
render :json => Resources::Candlepin::Consumer.get(@system.uuid)
end

def list_owners
orgs = @user.allowed_organizations
orgs = User.current.organizations
# rhsm expects owner (Candlepin format)
# rubocop:disable SymbolName
respond_for_index :collection => orgs.map { |o| { :key => o.label, :displayName => o.name } }
Expand Down Expand Up @@ -275,13 +184,6 @@ def facts
render :json => {:content => _("Facts successfully updated.")}, :status => 200
end

protected

# to support rhsm client authentication
def authenticate
set_client_user || super
end

private

def get_organization(org_id)
Expand All @@ -302,12 +204,6 @@ def find_system
@system
end

def find_user_by_login
@user = User.find_by_login(params[:login])
fail HttpErrors::NotFound, _("Couldn't find user '%s'") % params[:login] if @user.nil?
@user
end

def find_default_organization_and_or_environment
# This has to grab the first default org associated with this user AND
# the environment that goes with him.
Expand Down Expand Up @@ -424,12 +320,14 @@ def get_content_view_environments(label = nil)
where("#{Organization.table_name}.id = ?", @organization.id)
environments = environments.where("#{Katello::ContentViewEnvironment.table_name}.label = ?", label) if label

# remove any content view environments that aren't readable
unless @organization.readable?
environments.delete_if do |env|
environments.delete_if do |env|
if env.content_view.default
!env.environment.readable?
else
!env.content_view.readable?
end
end

environments
end

Expand All @@ -449,5 +347,9 @@ def logger
::Logging.logger['cp_proxy']
end

def add_candlepin_version_header
response.headers["X-CANDLEPIN-VERSION"] = "katello/#{Katello.config.katello_version}"
end

end
end
98 changes: 0 additions & 98 deletions app/controllers/katello/api/v1/content_uploads_controller.rb

This file was deleted.