Skip to content

Commit

Permalink
feat(conf) support for the nginx 'user' directive
Browse files Browse the repository at this point in the history
Support user directive of Nginx.

From #2180
  • Loading branch information
depay authored and thibaultcha committed Mar 29, 2017
1 parent 82a6951 commit f3572ac
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
# HTTPS requests to the admin API, if
# `admin_ssl` is enabled.

#nginx_user = nobody # Defines user and group credentials used by
# worker processes. If group is omitted, a
# group whose name equals that of user is
# used. Ex: [user] [group].

This comment has been minimized.

Copy link
@Tieske

Tieske Mar 30, 2017

Member

from the text I get that the default is nobody nobody as group == name if omitted, I think that the comment line should be updated like that eg.

#nginx_user = nobody nobody

#nginx_worker_processes = auto # Determines the number of worker processes
# spawned by Nginx.

Expand Down
1 change: 1 addition & 0 deletions kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ local CONF_INFERENCES = {
cluster_listen = {typ = "string"},
cluster_listen_rpc = {typ = "string"},
cluster_advertise = {typ = "string"},
nginx_user = {typ = "string"},
nginx_worker_processes = {typ = "string"},
upstream_keepalive = {typ = "number"},

Expand Down
1 change: 1 addition & 0 deletions kong/templates/kong_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ proxy_listen = 0.0.0.0:8000
proxy_listen_ssl = 0.0.0.0:8443
admin_listen = 0.0.0.0:8001
admin_listen_ssl = 0.0.0.0:8444
nginx_user = nobody

This comment has been minimized.

Copy link
@depay

depay Mar 31, 2017

Author Contributor

@Tieske did you mean that here the nginx_user = nobody should also be nginx_user = nobody nobody ?

This comment has been minimized.

Copy link
@Tieske

Tieske Mar 31, 2017

Member

Actually both. This one as it is the actual default, the one in kong.conf.default because it communicates to users what the defaults are.

This comment has been minimized.

Copy link
@depay

depay Mar 31, 2017

Author Contributor

#2311 fixed here

nginx_worker_processes = auto
nginx_optimizations = on
nginx_daemon = on
Expand Down
1 change: 1 addition & 0 deletions kong/templates/nginx.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
return [[
user ${{NGINX_USER}};
worker_processes ${{NGINX_WORKER_PROCESSES}};
daemon ${{NGINX_DAEMON}};
Expand Down
3 changes: 3 additions & 0 deletions spec/01-unit/02-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe("Configuration loader", function()
it("loads the defaults", function()
local conf = assert(conf_loader())
assert.is_string(conf.lua_package_path)
assert.equal("nobody", conf.nginx_user)
assert.equal("auto", conf.nginx_worker_processes)
assert.equal("0.0.0.0:8001", conf.admin_listen)
assert.equal("0.0.0.0:8000", conf.proxy_listen)
Expand All @@ -21,6 +22,7 @@ describe("Configuration loader", function()
-- defaults
assert.equal("on", conf.nginx_daemon)
-- overrides
assert.equal("nobody", conf.nginx_user)
assert.equal("1", conf.nginx_worker_processes)
assert.equal("0.0.0.0:9001", conf.admin_listen)
assert.equal("0.0.0.0:9000", conf.proxy_listen)
Expand All @@ -39,6 +41,7 @@ describe("Configuration loader", function()
-- defaults
assert.equal("on", conf.nginx_daemon)
-- overrides
assert.equal("nobody", conf.nginx_user)
assert.equal("auto", conf.nginx_worker_processes)
assert.equal("127.0.0.1:9001", conf.admin_listen)
assert.equal("0.0.0.0:9000", conf.proxy_listen)
Expand Down
1 change: 1 addition & 0 deletions spec/01-unit/03-prefix_handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe("NGINX conf compiler", function()
describe("compile_nginx_conf()", function()
it("compiles a main NGINX conf", function()
local nginx_conf = prefix_handler.compile_nginx_conf(helpers.test_conf)
assert.matches("user nobody;", nginx_conf, nil, true))

This comment has been minimized.

Copy link
@subnetmarco

subnetmarco Mar 30, 2017

Member

@depay this line has an error, you have added one more ) at the end.

assert.matches("worker_processes 1;", nginx_conf, nil, true)
assert.matches("daemon on;", nginx_conf, nil, true)
end)
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/custom_nginx.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This is a custom nginx configuration template for Kong specs

user ${{NGINX_USER}};
worker_processes ${{NGINX_WORKER_PROCESSES}};
daemon ${{NGINX_DAEMON}};

Expand Down

1 comment on commit f3572ac

@thibaultcha
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since nobody defaults to nobody nobody I don't really think this is a must have. It's also documented in the comment that this is the behavior. Fine with adding it though.

Please sign in to comment.