~lynxman/ubuntu/oneiric/puppet/lp_854899

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

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