~racb/ubuntu/saucy/puppet/dep8-hiera

« back to all changes in this revision

Viewing changes to .pc/security-mar-2013.patch/lib/puppet/network/rest_authconfig.rb

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-03-11 11:16:08 UTC
  • Revision ID: package-import@ubuntu.com-20130311111608-6gtkc65hikm0p07r
Tags: 2.7.18-1ubuntu2
* SECURITY UPDATE: Multiple security issues
  - debian/patches/security-mar-2013.patch: upstream patch to fix
    multiple security issues.
  - CVE-2013-1640 - Remote code execution on master from authenticated clients
  - CVE-2013-1652 - Insufficient input validation
  - CVE-2013-1653 - Remote code execution
  - CVE-2013-1654 - Protocol downgrade
  - CVE-2013-1655 - Unauthenticated remote code execution risk
  - CVE-2013-2275 - Incorrect default report ACL

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
      # These allow `auth any`, because if you can do them anonymously you
 
18
      # should probably also be able to do them when trusted.
 
19
      { :acl => "/certificate/ca", :method => :find, :authenticated => :any },
 
20
      { :acl => "/certificate/", :method => :find, :authenticated => :any },
 
21
      { :acl => "/certificate_request", :method => [:find, :save], :authenticated => :any },
 
22
      { :acl => "/status", :method => [:find], :authenticated => true },
 
23
    ]
 
24
 
 
25
    def self.main
 
26
      synchronize do
 
27
        add_acl = @main.nil?
 
28
        super
 
29
        @main.insert_default_acl if add_acl and !@main.exists?
 
30
      end
 
31
      @main
 
32
    end
 
33
 
 
34
    def allowed?(request)
 
35
      Puppet.deprecation_warning "allowed? should not be called for REST authorization - use check_authorization instead"
 
36
      check_authorization(request)
 
37
    end
 
38
 
 
39
    # check wether this request is allowed in our ACL
 
40
    # raise an Puppet::Network::AuthorizedError if the request
 
41
    # is denied.
 
42
    def check_authorization(indirection, method, key, params)
 
43
      read
 
44
 
 
45
      # we're splitting the request in part because
 
46
      # fail_on_deny could as well be called in the XMLRPC context
 
47
      # with a ClientRequest.
 
48
 
 
49
      if authorization_failure_exception = @rights.is_request_forbidden_and_why?(indirection, method, key, params)
 
50
        Puppet.warning("Denying access: #{authorization_failure_exception}")
 
51
        raise authorization_failure_exception
 
52
      end
 
53
    end
 
54
 
 
55
    def initialize(file = nil, parsenow = true)
 
56
      super(file || Puppet[:rest_authconfig], parsenow)
 
57
 
 
58
      # if we didn't read a file (ie it doesn't exist)
 
59
      # make sure we can create some default rights
 
60
      @rights ||= Puppet::Network::Rights.new
 
61
    end
 
62
 
 
63
    def parse
 
64
      super()
 
65
      insert_default_acl
 
66
    end
 
67
 
 
68
    # force regular ACLs to be present
 
69
    def insert_default_acl
 
70
      if exists? then
 
71
        reason = "none were found in '#{@file}'"
 
72
      else
 
73
        reason = "#{Puppet[:rest_authconfig]} doesn't exist"
 
74
      end
 
75
 
 
76
      DEFAULT_ACL.each do |acl|
 
77
        unless rights[acl[:acl]]
 
78
          Puppet.info "Inserting default '#{acl[:acl]}' (auth #{acl[:authenticated]}) ACL because #{reason}"
 
79
          mk_acl(acl)
 
80
        end
 
81
      end
 
82
      # queue an empty (ie deny all) right for every other path
 
83
      # actually this is not strictly necessary as the rights system
 
84
      # denies not explicitely allowed paths
 
85
      unless rights["/"]
 
86
        rights.newright("/")
 
87
        rights.restrict_authenticated("/", :any)
 
88
      end
 
89
    end
 
90
 
 
91
    def mk_acl(acl)
 
92
      @rights.newright(acl[:acl])
 
93
      @rights.allow(acl[:acl], acl[:allow] || "*")
 
94
 
 
95
      if method = acl[:method]
 
96
        method = [method] unless method.is_a?(Array)
 
97
        method.each { |m| @rights.restrict_method(acl[:acl], m) }
 
98
      end
 
99
      @rights.restrict_authenticated(acl[:acl], acl[:authenticated]) unless acl[:authenticated].nil?
 
100
    end
 
101
  end
 
102
end