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

Fixes #15490 - adding view_host filter and improving error messages #2428

Closed
wants to merge 1 commit into from

Conversation

lzap
Copy link
Member

@lzap lzap commented Jun 3, 2015

Fixing both missing permissions and incorrect error message.

@@ -317,7 +317,7 @@
:externalNodes, :pxe_config, :storeconfig_klasses, :auto_complete_search, :bmc,
:runtime, :resources, :templates, :overview, :nics],
:dashboard => [:OutOfSync, :errors, :active],
:unattended => [:template, :provision],
:unattended => [:template, :provision] + TemplateKind.all.map(&:name).map(&:to_sym),
Copy link
Member

Choose a reason for hiding this comment

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

avoid double map, TemplateKind.all.map { |kind| kind.name.to_sym }

Copy link
Member

Choose a reason for hiding this comment

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

also I'd prefer using some hard list (maybe just put this into constant https://github.com/theforeman/foreman/blob/develop/db/seeds.d/07-config_templates.rb#L9),

@ares
Copy link
Member

ares commented Jun 3, 2015

In redmine issue you've mentioned review_templates permissions, did you change your mind?

@lzap
Copy link
Member Author

lzap commented Jun 4, 2015

Yeah, changed my mind because it looks like unattended with provision already works okay. Unattended does not have permission checks enabled, it's only reviews what need it. I don't see any security risk there. Let me change the AR to static list. AFAIK the only plugin that adds a template kind is bootdisk currently, but there is no way of previewing bootdisk templates therefore we don't need to add the permission symbol there?

@lzap
Copy link
Member Author

lzap commented Jun 4, 2015

Fixed, what you think?

@lzap
Copy link
Member Author

lzap commented Jun 4, 2015

Fixed failing tests. FYI these were expecting incorrect behavior. If you test this, the controller errors out with "Undefined method: layout" error because actually layout is not usable with this particular controller.

@@ -312,12 +312,13 @@
pc_ajax_actions = [:parameters]
subnets_ajax_actions = [:freeip]
tasks_ajax_actions = [:show]
template_kinds = [:PXELinux, :PXEGrub, :iPXE, :provision, :finish, :script, :user_data, :ZTP]
Copy link
Member

Choose a reason for hiding this comment

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

could you deduplicate this list? https://github.com/theforeman/foreman/blob/develop/db/seeds.d/07-config_templates.rb#L9

just put it into a constant somewhere in TemplateKind and use it in both places?

@ares
Copy link
Member

ares commented Jun 4, 2015

Other than the duplication issue seems all right, I'll continue with testing when it's resolved.

@ohadlevy
Copy link
Member

@lzap bump?

@lzap
Copy link
Member Author

lzap commented Jun 16, 2015

Done!

diff --git a/app/models/template_kind.rb b/app/models/template_kind.rb
index 7c1e5a9..d647c1c 100644
--- a/app/models/template_kind.rb
+++ b/app/models/template_kind.rb
@@ -6,4 +6,8 @@ class TemplateKind < ActiveRecord::Base
   has_many :os_default_templates
   validates :name, :presence => true, :uniqueness => true
   scoped_search :on => :name
+
+  def self.predefined
+    [:PXELinux, :PXEGrub, :iPXE, :provision, :finish, :script, :user_data, :ZTP]
+  end
 end
diff --git a/app/services/foreman/access_permissions.rb b/app/services/foreman/access_permissions.rb
index a732de6..9b4488a 100644
--- a/app/services/foreman/access_permissions.rb
+++ b/app/services/foreman/access_permissions.rb
@@ -318,13 +318,12 @@ Foreman::AccessControl.map do |permission_set|
     pc_ajax_actions = [:parameters]
     subnets_ajax_actions = [:freeip]
     tasks_ajax_actions = [:show]
-    template_kinds =  [:PXELinux, :PXEGrub, :iPXE, :provision, :finish, :script, :user_data, :ZTP]

     map.permission :view_hosts,    {:hosts => [:index, :show, :errors, :active, :out_of_sync, :disabled, :pending, :vm,
                                       :externalNodes, :pxe_config, :storeconfig_klasses, :auto_complete_search, :bmc,
                                       :runtime, :resources, :templates, :overview, :nics],
                                     :dashboard => [:OutOfSync, :errors, :active],
-                                    :unattended => [:template, :provision] + template_kinds,
+                                    :unattended => [:template, :provision] + TemplateKind.predefined,
                                      :"api/v1/hosts" => [:index, :show, :status],
                                      :"api/v2/hosts" => [:index, :show, :status, :vm_compute_attributes],
                                      :"api/v2/interfaces" => [:index, :show],

@ares
Copy link
Member

ares commented Jun 16, 2015

Could you please also use TemplateKind.predefined in https://github.com/theforeman/foreman/blob/develop/db/seeds.d/07-provisioning_templates.rb (that's why I wanted you to extract it)

@ares
Copy link
Member

ares commented Jun 16, 2015

Why did you choose to use class method instead of constant? This will be harder to extend if we need it (only with alias_method_chain), if it was an array in constant, one could push to that array.

@lzap
Copy link
Member Author

lzap commented Jun 15, 2016

Right, added and rebased on top of develop.

@domcleal
Copy link
Contributor

On re-reviewing this, it seems the issue has already been fixed in b1997f5 when I refactored the controller in the same way that was suggested in the #10689 comments. Previewing templates as a non-admin user works fine.

It does though mean we're vulnerable in develop to the security issue I mentioned at #2428 (comment), so this needs addressing. I've filed this as http://projects.theforeman.org/issues/15490, and updated foreman-security + requested a CVE.

What I'd like to do is:

  1. Close #10689 as a resolved or a dupe of #13039, which fixes the issue.
  2. Update this PR to reference #15490, as it contains the authorisation fixes and fixes the error handling on 403s.
  3. Update this PR to fix some review comments which I'll add shortly.

Sorry for the ticket change, but I'd like to be absolutely clear about what this is fixing.

@@ -351,7 +351,7 @@
:externalNodes, :pxe_config, :storeconfig_klasses, :auto_complete_search, :bmc,
:runtime, :resources, :templates, :overview, :nics],
:dashboard => [:OutOfSync, :errors, :active],
:unattended => [:host_template, :hostgroup_template],
:unattended => [:host_template, :hostgroup_template] + TemplateKind.default_template_labels.keys.collect(&:to_sym),
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be necessary now, since the action is always going to be either :host_template or :hostgroup_template - the routing changed in b1997f5 to route the template kinds to a single action.

@domcleal
Copy link
Contributor

I'd like to add, that given the security issue, please let me know if you don't plan to update this PR to fix it and instead, I'll patch it myself - rather than leave it months again.

@domcleal
Copy link
Contributor

@lzap if you could please update this soon to fix the security issue, or let me know if you don't plan to.

@lzap
Copy link
Member Author

lzap commented Jul 11, 2016

@domcleal had a huge github backlog and noticed just now. I can start tomorrow with this.

@lzap lzap changed the title Fixes #10689 - template preview permissions fixed Fixes #15490 - adding view_host filter and improving error messages Jul 12, 2016
@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • commit message for cd5ab4d is not wrapped at 72nd column
  • commit message for cd5ab4d is not wrapped at 72nd column
  • commit message for cd5ab4d is not wrapped at 72nd column

If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@lzap
Copy link
Member Author

lzap commented Jul 12, 2016

Amended all your last comments, rebased and pushed.

Users who are logged in with permissions to view some hosts are able to
preview provisioning templates for any host by specifying its hostname
in the URL, as the specific view_hosts permissions and filters aren't
checked. If the organization or location features are enabled, the user
will still be restricted to their associated orgs/locs.

This can disclose configuration information about the host, including
root password hashes if used in preseed/kickstart templates.
@domcleal
Copy link
Contributor

Merged as c3c186d, thanks @lzap!

@domcleal domcleal closed this Jul 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants