Skip to content

Commit

Permalink
Merge pull request #5940 from camlow325/task/master/PUP-6359-fail-fs-…
Browse files Browse the repository at this point in the history
…mount-auth-for-non-global-allow-directives

(PUP-6359) Fail fileserver auth for mounts with non-global allow
  • Loading branch information
joshcooper committed Jun 7, 2017
2 parents 70af0de + 183c661 commit 233975d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/puppet/indirector/file_server.rb
Expand Up @@ -15,7 +15,15 @@ def authorized?(request)

# If we're not serving this mount, then access is denied.
return false unless mount
mount.allowed?(request.node, request.ip)

# If there are no auth directives or there is an 'allow *' directive, then
# access is allowed.
if mount.empty? || mount.globalallow?
return true
end

Puppet.err _("Denying %{method} request for %{desc} on fileserver mount '%{mount_name}'. Use of auth directives for 'fileserver.conf' mount points is no longer supported. Remove these directives and use the 'auth.conf' file instead for access control.") % { method: request.method, desc: request.description, mount_name: mount.name }
return false
end

# Find our key using the fileserver.
Expand Down
Expand Up @@ -70,6 +70,7 @@

# Use a real mount, so the integration is a bit deeper.
mount1 = Puppet::FileServing::Configuration::Mount::File.new("one")
mount1.stubs(:globalallow?).returns true
mount1.stubs(:allowed?).returns true
mount1.path = File.join(path, "%h")

Expand Down
Expand Up @@ -50,6 +50,7 @@

# Use a real mount, so the integration is a bit deeper.
mount1 = Puppet::FileServing::Configuration::Mount::File.new("one")
mount1.stubs(:globalallow?).returns true
mount1.stubs(:allowed?).returns true
mount1.path = File.join(env_path, "%h")

Expand Down
19 changes: 17 additions & 2 deletions spec/unit/indirector/file_server_spec.rb
Expand Up @@ -249,6 +249,7 @@ module Testing; end
@configuration.stubs(:split_path).with(@request).returns([@mount, "rel/path"])
@request.stubs(:node).returns("mynode")
@request.stubs(:ip).returns("myip")
@mount.stubs(:name).returns "myname"
@mount.stubs(:allowed?).with("mynode", "myip").returns "something"
end

Expand All @@ -274,8 +275,22 @@ module Testing; end
expect(@file_server).not_to be_authorized(@request)
end

it "should return the results of asking the mount whether the node and IP are authorized" do
expect(@file_server.authorized?(@request)).to eq("something")
it "should return true when no auth directives are defined for the mount point" do
@mount.stubs(:empty?).returns true
@mount.stubs(:globalallow?).returns nil
expect(@file_server).to be_authorized(@request)
end

it "should return true when a global allow directive is defined for the mount point" do
@mount.stubs(:empty?).returns false
@mount.stubs(:globalallow?).returns true
expect(@file_server).to be_authorized(@request)
end

it "should return false when a non-global allow directive is defined for the mount point" do
@mount.stubs(:empty?).returns false
@mount.stubs(:globalallow?).returns false
expect(@file_server).not_to be_authorized(@request)
end
end
end

0 comments on commit 233975d

Please sign in to comment.