Skip to content

Commit

Permalink
feat(RBAC): RHINENG-13334 allow reading SSG with any read permission
Browse files Browse the repository at this point in the history
  • Loading branch information
romanblanco committed Oct 1, 2024
1 parent 66a61ea commit dd087f0
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/controllers/v1/benchmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class BenchmarksController < ApplicationController
def index
render_json benchmarks
end
permission_for_action :index, Rbac::COMPLIANCE_VIEWER
permission_for_action :index, Rbac::V1_COMPLIANCE_VIEWER

def show
render_json benchmark
end
permission_for_action :show, Rbac::COMPLIANCE_VIEWER
permission_for_action :show, Rbac::V1_COMPLIANCE_VIEWER

private

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/v1/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def index
permitted_params[:sort_by] ||= 'score'
render_json resolve_collection
end
permission_for_action :index, Rbac::COMPLIANCE_VIEWER
permission_for_action :index, Rbac::V1_COMPLIANCE_VIEWER

def show
render_json profile
end
permission_for_action :show, Rbac::COMPLIANCE_VIEWER
permission_for_action :show, Rbac::V1_COMPLIANCE_VIEWER

def create
Policy.transaction do
Expand Down Expand Up @@ -65,7 +65,7 @@ def tailoring_file

audit_tailoring_file
end
permission_for_action :tailoring_file, Rbac::COMPLIANCE_VIEWER
permission_for_action :tailoring_file, Rbac::V1_COMPLIANCE_VIEWER
permitted_params_for_action :tailoring_file, id: ID_TYPE.required

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/v1/rules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RulesController < ApplicationController
def index
render_json resolve_collection
end
permission_for_action :index, Rbac::COMPLIANCE_VIEWER
permission_for_action :index, Rbac::V1_COMPLIANCE_VIEWER
permitted_params_for_action :index, policy_id: ID_TYPE

def show
Expand All @@ -20,7 +20,7 @@ def show

render_json rule
end
permission_for_action :show, Rbac::COMPLIANCE_VIEWER
permission_for_action :show, Rbac::V1_COMPLIANCE_VIEWER

private

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v1/supported_ssgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SupportedSsgsController < ApplicationController
def index
render_json supported_ssgs
end
permission_for_action :index, Rbac::COMPLIANCE_VIEWER
permission_for_action :index, Rbac::V1_COMPLIANCE_VIEWER

private

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v1/value_definitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ValueDefinitionsController < ApplicationController
def index
render_json resolve_collection
end
permission_for_action :index, Rbac::COMPLIANCE_VIEWER
permission_for_action :index, Rbac::V1_COMPLIANCE_VIEWER

private

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Benchmark < Types::BaseObject
cached_static_field :value_definitions, [::Types::ValueDefinition], null: true
cached_static_field :rule_tree, GraphQL::Types::JSON, null: true

enforce_rbac Rbac::COMPLIANCE_VIEWER
enforce_rbac Rbac::V1_COMPLIANCE_VIEWER

def profiles
object.profiles.canonical
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/operating_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class OperatingSystem < Types::BaseObject
field :major, Int, null: false
field :minor, Int, null: false

enforce_rbac Rbac::COMPLIANCE_VIEWER
enforce_rbac Rbac::V1_COMPLIANCE_VIEWER
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/os_major_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class OsMajorVersion < Types::BaseObject
field :os_major_version, Int, null: false
cached_static_field :profiles, [::Types::Profile], null: true

enforce_rbac Rbac::COMPLIANCE_VIEWER
enforce_rbac Rbac::V1_COMPLIANCE_VIEWER
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Query < Types::BaseObject
description 'All business objectives visible by the user'
end

enforce_rbac Rbac::COMPLIANCE_VIEWER
enforce_rbac Rbac::V1_COMPLIANCE_VIEWER

def system(id:)
Pundit.authorize(context[:current_user], ::Host.find(id), :show?)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Rule < Types::BaseObject
field :failed_count, Int, null: true
field :compliant, Boolean, null: false

enforce_rbac Rbac::COMPLIANCE_VIEWER
enforce_rbac Rbac::V1_COMPLIANCE_VIEWER

def compliant
system_id && profile_id && %w[pass notapplicable notselected].include?(
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/value_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class ValueDefinition < Types::BaseObject
field :description, String, null: true
field :default_value, String, null: false

enforce_rbac Rbac::COMPLIANCE_VIEWER
enforce_rbac Rbac::V1_COMPLIANCE_VIEWER
end
end
3 changes: 2 additions & 1 deletion app/services/rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Rbac

INVENTORY_UNGROUPED_ENTRIES = [].freeze
INVENTORY_HOSTS_READ = 'inventory:hosts:read'
COMPLIANCE_VIEWER = 'compliance:policy:read' # universal read permission accross all roles
V1_COMPLIANCE_VIEWER = 'compliance:policy:read'
COMPLIANCE_VIEWER = 'compliance:*:read'
COMPLIANCE_ADMIN = 'compliance:*:*'
POLICY_READ = 'compliance:policy:read'
POLICY_CREATE = 'compliance:policy:create'
Expand Down

0 comments on commit dd087f0

Please sign in to comment.