Skip to content

Commit ceeb0c5

Browse files
tfheendanielsdeleo
authored andcommitted
Limit the validation key to creating non-admin clients
This allows us to make the validation key a non-admin key.
1 parent 9470d29 commit ceeb0c5

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

chef-server-api/app/controllers/application.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ def is_admin
8888
end
8989
end
9090

91+
def is_admin_or_validator
92+
if @auth_user.admin || @auth_user.name == Chef::Config[:validation_client_name]
93+
true
94+
else
95+
raise Unauthorized, "You are not allowed to take this action."
96+
end
97+
end
98+
9199
def is_correct_node
92100
if @auth_user.admin || @auth_user.name == params[:id]
93101
true

chef-server-api/app/controllers/clients.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class ChefServerApi::Clients < ChefServerApi::Application
2323
provides :json
2424

2525
before :authenticate_every
26-
before :is_admin, :only => [ :index, :create, :update, :destroy ]
26+
before :is_admin, :only => [ :index, :update, :destroy ]
27+
before :is_admin_or_validator, :only => [ :create ]
2728
before :is_correct_node, :only => [ :show ]
2829

2930
# GET /clients
@@ -48,7 +49,13 @@ def create
4849
exists = true
4950
if params.has_key?(:inflated_object)
5051
params[:name] ||= params[:inflated_object].name
51-
params[:admin] ||= params[:inflated_object].admin
52+
# We can only get here if we're admin or the validator. Only
53+
# allow creating admin clients if we're already an admin.
54+
if @client.admin
55+
params[:admin] ||= params[:inflated_object].admin
56+
else
57+
params[:admin] = false
58+
end
5259
end
5360

5461
begin

0 commit comments

Comments
 (0)