~ubuntu-branches/ubuntu/precise/puppet/precise-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-02-08 00:28:43 UTC
  • mfrom: (1.1.22 upstream) (3.1.19 sid)
  • Revision ID: james.westby@ubuntu.com-20110208002843-1xrv7w3vqblrn15m
Tags: 2.6.4-2ubuntu1
* 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
      # this one will allow all file access, and thus delegate
 
12
      # to fileserver.conf
 
13
      { :acl => "/file" },
 
14
      { :acl => "/certificate_revocation_list/ca", :method => :find, :authenticated => true },
 
15
      { :acl => "/report", :method => :save, :authenticated => true },
 
16
      { :acl => "/certificate/ca", :method => :find, :authenticated => false },
 
17
      { :acl => "/certificate/", :method => :find, :authenticated => false },
 
18
      { :acl => "/certificate_request", :method => [:find, :save], :authenticated => false },
 
19
      { :acl => "/status", :method => [:find], :authenticated => true },
 
20
    ]
 
21
 
 
22
    def self.main
 
23
      synchronize do
 
24
        add_acl = @main.nil?
 
25
        super
 
26
        @main.insert_default_acl if add_acl and !@main.exists?
 
27
      end
 
28
      @main
 
29
    end
 
30
 
 
31
    # check wether this request is allowed in our ACL
 
32
    # raise an Puppet::Network::AuthorizedError if the request
 
33
    # is denied.
 
34
    def allowed?(request)
 
35
      read
 
36
 
 
37
      # we're splitting the request in part because
 
38
      # fail_on_deny could as well be called in the XMLRPC context
 
39
      # with a ClientRequest.
 
40
 
 
41
            @rights.fail_on_deny(
 
42
        build_uri(request),
 
43
        
 
44
                  :node => request.node,
 
45
                  :ip => request.ip,
 
46
                  :method => request.method,
 
47
                  :environment => request.environment,
 
48
                  :authenticated => request.authenticated)
 
49
    end
 
50
 
 
51
    def initialize(file = nil, parsenow = true)
 
52
      super(file || Puppet[:rest_authconfig], parsenow)
 
53
 
 
54
      # if we didn't read a file (ie it doesn't exist)
 
55
      # make sure we can create some default rights
 
56
      @rights ||= Puppet::Network::Rights.new
 
57
    end
 
58
 
 
59
    def parse
 
60
      super()
 
61
      insert_default_acl
 
62
    end
 
63
 
 
64
    # force regular ACLs to be present
 
65
    def insert_default_acl
 
66
      DEFAULT_ACL.each do |acl|
 
67
        unless rights[acl[:acl]]
 
68
          Puppet.info "Inserting default '#{acl[:acl]}'(#{acl[:authenticated] ? "auth" : "non-auth"}) acl because #{( !exists? ? "#{Puppet[:rest_authconfig]} doesn't exist" : "none where found in '#{@file}'")}"
 
69
          mk_acl(acl)
 
70
        end
 
71
      end
 
72
      # queue an empty (ie deny all) right for every other path
 
73
      # actually this is not strictly necessary as the rights system
 
74
      # denies not explicitely allowed paths
 
75
      unless rights["/"]
 
76
        rights.newright("/")
 
77
        rights.restrict_authenticated("/", :any)
 
78
      end
 
79
    end
 
80
 
 
81
    def mk_acl(acl)
 
82
      @rights.newright(acl[:acl])
 
83
      @rights.allow(acl[:acl], acl[:allow] || "*")
 
84
 
 
85
      if method = acl[:method]
 
86
        method = [method] unless method.is_a?(Array)
 
87
        method.each { |m| @rights.restrict_method(acl[:acl], m) }
 
88
      end
 
89
      @rights.restrict_authenticated(acl[:acl], acl[:authenticated]) unless acl[:authenticated].nil?
 
90
    end
 
91
 
 
92
    def build_uri(request)
 
93
      "/#{request.indirection_name}/#{request.key}"
 
94
    end
 
95
  end
 
96
end