~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to .pc/debian-changes/lib/puppet/network/rest_authconfig.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'puppet/network/authconfig'
2
 
 
3
 
module Puppet
4
 
  class Network::RestAuthConfig < Network::AuthConfig
5
 
 
6
 
    extend MonitorMixin
7
 
    attr_accessor :rights
8
 
 
9
 
    DEFAULT_ACL = [
10
 
      { :acl => "~ ^\/catalog\/([^\/]+)$", :method => :find, :allow => '$1', :authenticated => true },
11
 
      { :acl => "~ ^\/node\/([^\/]+)$", :method => :find, :allow => '$1', :authenticated => true },
12
 
      # this one will allow all file access, and thus delegate
13
 
      # to fileserver.conf
14
 
      { :acl => "/file" },
15
 
      { :acl => "/certificate_revocation_list/ca", :method => :find, :authenticated => true },
16
 
      { :acl => "/report", :method => :save, :authenticated => true },
17
 
      { :acl => "/certificate/ca", :method => :find, :authenticated => false },
18
 
      { :acl => "/certificate/", :method => :find, :authenticated => false },
19
 
      { :acl => "/certificate_request", :method => [:find, :save], :authenticated => false },
20
 
      { :acl => "/status", :method => [:find], :authenticated => true },
21
 
    ]
22
 
 
23
 
    def self.main
24
 
      synchronize do
25
 
        add_acl = @main.nil?
26
 
        super
27
 
        @main.insert_default_acl if add_acl and !@main.exists?
28
 
      end
29
 
      @main
30
 
    end
31
 
 
32
 
    # check wether this request is allowed in our ACL
33
 
    # raise an Puppet::Network::AuthorizedError if the request
34
 
    # is denied.
35
 
    def allowed?(indirection, method, key, params)
36
 
      read
37
 
 
38
 
      # we're splitting the request in part because
39
 
      # fail_on_deny could as well be called in the XMLRPC context
40
 
      # with a ClientRequest.
41
 
 
42
 
      if authorization_failure_exception = @rights.is_request_forbidden_and_why?(indirection, method, key, params)
43
 
        Puppet.warning("Denying access: #{authorization_failure_exception}")
44
 
        raise authorization_failure_exception
45
 
      end
46
 
    end
47
 
 
48
 
    def initialize(file = nil, parsenow = true)
49
 
      super(file || Puppet[:rest_authconfig], parsenow)
50
 
 
51
 
      # if we didn't read a file (ie it doesn't exist)
52
 
      # make sure we can create some default rights
53
 
      @rights ||= Puppet::Network::Rights.new
54
 
    end
55
 
 
56
 
    def parse
57
 
      super()
58
 
      insert_default_acl
59
 
    end
60
 
 
61
 
    # force regular ACLs to be present
62
 
    def insert_default_acl
63
 
      DEFAULT_ACL.each do |acl|
64
 
        unless rights[acl[:acl]]
65
 
          Puppet.info "Inserting default '#{acl[:acl]}'(#{acl[:authenticated] ? "auth" : "non-auth"}) ACL because #{( !exists? ? "#{Puppet[:rest_authconfig]} doesn't exist" : "none were found in '#{@file}'")}"
66
 
          mk_acl(acl)
67
 
        end
68
 
      end
69
 
      # queue an empty (ie deny all) right for every other path
70
 
      # actually this is not strictly necessary as the rights system
71
 
      # denies not explicitely allowed paths
72
 
      unless rights["/"]
73
 
        rights.newright("/")
74
 
        rights.restrict_authenticated("/", :any)
75
 
      end
76
 
    end
77
 
 
78
 
    def mk_acl(acl)
79
 
      @rights.newright(acl[:acl])
80
 
      @rights.allow(acl[:acl], acl[:allow] || "*")
81
 
 
82
 
      if method = acl[:method]
83
 
        method = [method] unless method.is_a?(Array)
84
 
        method.each { |m| @rights.restrict_method(acl[:acl], m) }
85
 
      end
86
 
      @rights.restrict_authenticated(acl[:acl], acl[:authenticated]) unless acl[:authenticated].nil?
87
 
    end
88
 
  end
89
 
end