Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli) SSL auto-generation + dnsmasq for new CLI #1299

Merged
merged 31 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
68a0c29
Auto-Generating SSL certificates
subnetmarco Jun 8, 2016
ce34062
dnsmasq signals
subnetmarco Jun 9, 2016
0cb4036
Adding dnsmasq
subnetmarco Jun 9, 2016
338f72b
in progress
subnetmarco Jun 10, 2016
d5b55aa
fixing messages
subnetmarco Jun 10, 2016
161ec68
better test
subnetmarco Jun 10, 2016
11e41e1
Disabling dnsmasq for tests
subnetmarco Jun 10, 2016
2b8b04d
Adding missing serf commands and cluster CLI
subnetmarco Jun 13, 2016
9e41cf9
Continuing serf implementation
subnetmarco Jun 14, 2016
fb3f276
fixing log
subnetmarco Jun 14, 2016
771b2ec
Organizing pids, logs and serf files respectively in a "pids", "logs"…
subnetmarco Jun 15, 2016
b377a57
log message
subnetmarco Jun 15, 2016
01e50df
Starting to work on hooks test
subnetmarco Jun 15, 2016
f2f62fc
Hooks core test
subnetmarco Jun 15, 2016
1abeffa
cluster test
subnetmarco Jun 16, 2016
995e3db
ACL plugin wip
subnetmarco Jun 16, 2016
cd4c855
ACL
subnetmarco Jun 16, 2016
8f60c28
ACL done
subnetmarco Jun 17, 2016
8cc4aa2
rate-limiting wip
subnetmarco Jun 18, 2016
378b851
rate-limiting
subnetmarco Jun 21, 2016
0547c09
response ratelimiting tests
subnetmarco Jun 22, 2016
1f4f758
fixing some specs
subnetmarco Jun 22, 2016
9702ede
feat(conf) now dump compiled conf in prefix
thibaultcha Jun 16, 2016
12e91ad
fix(cli) correct support for prefix/conf in CLI and fix tests
thibaultcha Jun 22, 2016
320ad22
refactor(cli) use assert() instead of error()
thibaultcha Jun 23, 2016
42329af
docs(cli) correct help messages for --prefix arg
thibaultcha Jun 23, 2016
a9d7287
refactor(cli) polishing SSL generation
thibaultcha Jun 23, 2016
417ae6a
oauth2 wip
subnetmarco Jun 23, 2016
998b8e5
Merge branch 'refactor/ssl-autogen' of github.com:Mashape/kong into r…
subnetmarco Jun 23, 2016
4ceb221
oauth2
subnetmarco Jun 24, 2016
4eb34b0
oauth2
subnetmarco Jun 24, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions kong-0.8.2-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,29 @@ build = {
["kong.singletons"] = "kong/singletons.lua",
["kong.conf_loader"] = "kong/conf_loader.lua",

["kong.templates.kong_defaults"] = "kong/templates/kong_defaults.lua",
["kong.templates.nginx"] = "kong/templates/nginx.lua",
["kong.templates.nginx_kong"] = "kong/templates/nginx_kong.lua",
["kong.templates.kong_defaults"] = "kong/templates/kong_defaults.lua",

["kong.vendor.classic"] = "kong/vendor/classic.lua",

["kong.cmd.roar"] = "kong/cmd/roar.lua",
["kong.cmd.init"] = "kong/cmd/init.lua",
["kong.cmd.stop"] = "kong/cmd/stop.lua",
["kong.cmd.start"] = "kong/cmd/start.lua",
["kong.cmd.check"] = "kong/cmd/check.lua",
["kong.cmd.reload"] = "kong/cmd/reload.lua",
["kong.cmd.cluster"] = "kong/cmd/cluster.lua",
["kong.cmd.compile"] = "kong/cmd/compile.lua",
["kong.cmd.init"] = "kong/cmd/init.lua",
["kong.cmd.migrations"] = "kong/cmd/migrations.lua",
["kong.cmd.reload"] = "kong/cmd/reload.lua",
["kong.cmd.roar"] = "kong/cmd/roar.lua",
["kong.cmd.start"] = "kong/cmd/start.lua",
["kong.cmd.stop"] = "kong/cmd/stop.lua",
["kong.cmd.version"] = "kong/cmd/version.lua",
["kong.cmd.utils.kill"] = "kong/cmd/utils/kill.lua",
["kong.cmd.utils.log"] = "kong/cmd/utils/log.lua",
["kong.cmd.utils.nginx_conf_compiler"] = "kong/cmd/utils/nginx_conf_compiler.lua",
["kong.cmd.utils.nginx_signals"] = "kong/cmd/utils/nginx_signals.lua",
["kong.cmd.utils.ssl"] = "kong/cmd/utils/ssl.lua",
["kong.cmd.utils.kill"] = "kong/cmd/utils/kill.lua",
["kong.cmd.utils.serf_signals"] = "kong/cmd/utils/serf_signals.lua",
["kong.cmd.utils.nginx_signals"] = "kong/cmd/utils/nginx_signals.lua",
["kong.cmd.utils.prefix_handler"] = "kong/cmd/utils/prefix_handler.lua",
["kong.cmd.utils.dnsmasq_signals"] = "kong/cmd/utils/dnsmasq_signals.lua",

["kong.api.init"] = "kong/api/init.lua",
["kong.api.api_helpers"] = "kong/api/api_helpers.lua",
Expand Down
62 changes: 31 additions & 31 deletions kong.conf.default
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kong configuration file.
#
# All commented values are default values. Uncomment and update a property to
# All commented values are default values. Uncomment and update a property to
# configure it.

# The Kong working directory. The directory will contain Kong process files and
Expand All @@ -12,26 +12,26 @@
# This section determines the network settings for Kong. By default Kong listens
# for connections from all the network interfaces available on the server.

# Address and port on which the server will accept HTTP requests, consumers will
# Address and port on which the server will accept HTTP requests, consumers will
# make requests on this port.
# proxy_listen = 0.0.0.0:8000

# Same as proxy_listen, but for HTTPS requests.
# proxy_listen_ssl = 0.0.0.0:8443

# Address and port on which the admin API will listen to. The admin API is a
# private API which lets you manage your Kong infrastructure. It needs to be
# Address and port on which the admin API will listen to. The admin API is a
# private API which lets you manage your Kong infrastructure. It needs to be
# secured appropriately.
# admin_listen = 0.0.0.0:8001

# Address and port used by the node to communicate with other Kong nodes in the
# cluster with both UDP and TCP messages. All the nodes in the cluster must be
# able to communicate with this node on this address. Only IPv4 addresses are
# Address and port used by the node to communicate with other Kong nodes in the
# cluster with both UDP and TCP messages. All the nodes in the cluster must be
# able to communicate with this node on this address. Only IPv4 addresses are
# allowed (no hostnames).
# cluster_listen = 0.0.0.0:7946

# Address and port used by the node to communicate with the local clustering
# agent (TCP only, and local only). Used internally by this Kong node. Only
# Address and port used by the node to communicate with the local clustering
# agent (TCP only, and local only). Used internally by this Kong node. Only
# IPv4 addresses are allowed (no hostnames).
# cluster_listen_rpc = 127.0.0.1:7373

Expand Down Expand Up @@ -78,43 +78,43 @@
# cassandra_ssl_verify = off
# cassandra_ssl_trusted_cert = NONE

# Cluster authentication options. Provide a user and a password here if your
# Cluster authentication options. Provide a user and a password here if your
# cluster uses the "PasswordAuthenticator" scheme.
# cassandra_username = kong
# cassandra_password = kong

################################## CLUSTER #####################################

# Cluster settings for Kong nodes. Every Kong node that points to the same
# Cluster settings for Kong nodes. Every Kong node that points to the same
# database MUST join together to form a Kong Cluster, in both single or multi-DC
# setups. Kong works on the IP layer (hostnames are not supported, only IPs are
# allowed) and it expects a flat network topology without any NAT between the
# datacenters. A common setup is having a VPN between the two datacenters such
# setups. Kong works on the IP layer (hostnames are not supported, only IPs are
# allowed) and it expects a flat network topology without any NAT between the
# datacenters. A common setup is having a VPN between the two datacenters such
# that the "flat" network assumption of Kong is not violated.

# By default, the cluster_listen address is advertised. If the cluster_listen
# host is "0.0.0.0", then the first local, non-loopback, IPv4 address will be
# advertised to the other nodes. However, in some cases (specifically NAT
# By default, the cluster_listen address is advertised. If the cluster_listen
# host is "0.0.0.0", then the first local, non-loopback, IPv4 address will be
# advertised to the other nodes. However, in some cases (specifically NAT
# traversal), there may be a routable address that cannot be bound to. This flag
# enables gossiping a different address to support this.
# cluster_advertise = NONE

# Key for encrypting network traffic within Kong. Must be a base64-encoded
# Key for encrypting network traffic within Kong. Must be a base64-encoded
# 16-byte key.
# cluster_encrypt = NONE

# The TTL (time to live), in seconds, of a node in the cluster when it stops
# sending healthcheck pings, possibly caused by a node or network failure. If
# the node is not able to send a new healthcheck ping before the expiration,
# then new nodes in the cluster will stop attempting to connect to it on
# The TTL (time to live), in seconds, of a node in the cluster when it stops
# sending healthcheck pings, possibly caused by a node or network failure. If
# the node is not able to send a new healthcheck ping before the expiration,
# then new nodes in the cluster will stop attempting to connect to it on
# startup. Should be at least 60.
# cluster_ttl_on_failure = 3600

#################################### DNS #######################################

# By default Kong leverages on dnsmasq to resolve DNS addresses to the upstream
# services by using the system settings in /etc/hosts and /etc/resolv.conf.
# dnsmasq = on
dnsmasq = off

# The port used by dnsmasq, only used locally by Kong.
# dnsmasq_port = 8053
Expand All @@ -130,21 +130,21 @@
# proxy_listen and proxy_listen_ssl properties. You can optionally enable or
# disable SSL support (note that this may break plugins that are leveraging it).

ssl = on
ssl_cert = NONE
ssl_cert_key = NONE
#ssl = on
#ssl_cert = NONE
#ssl_cert_key = NONE

################################## GENERAL #####################################

# The log level for the events returned by Kong and its services.
# log_level = error

# Comma separated list of additional plugins names to load on this node, used to
# Comma separated list of additional plugins names to load on this node, used to
# load custom plugins that are not already bundled with Kong.
# Plugins will be loaded from the kong.plugins.{name}.* namespace.
# custom_plugins = NONE

# The path to the SSL certificate and key that Kong will use when listening on
# The path to the SSL certificate and key that Kong will use when listening on
# the proxy_listen_ssl port.
# ssl_cert = NONE
# ssl_cert_key = NONE
Expand All @@ -160,7 +160,7 @@ ssl_cert_key = NONE
# Allows Kong to set specific connection and proxying settings in Nginx.
# nginx_optimizations = on

# The size in MB of the internal preallocated in-memory cache for database
# entities. The default value is `128`, and the potential maximum value is the
# The size in MB of the internal preallocated in-memory cache for database
# entities. The default value is `128`, and the potential maximum value is the
# total size of the datastore.
# mem_cache_size = 128m
# mem_cache_size = 128m
51 changes: 51 additions & 0 deletions kong/cmd/cluster.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local conf_loader = require "kong.conf_loader"
local DAOFactory = require "kong.dao.factory"
local Serf = require "kong.serf"
local log = require "kong.cmd.utils.log"

local function execute(args)
local conf = assert(conf_loader(args.conf))
local dao = DAOFactory(conf)
local serf = Serf.new(conf, conf.prefix, dao)

if args.command == "members" then
local members = assert(serf:members(true))
for _, v in ipairs(members) do
print(string.format("%s\t%s\t%s", v.name, v.addr, v.status))
end
elseif args.command == "keygen" then
print(assert(serf:keygen()))
elseif args.command == "reachability" then
print(assert(serf:reachability()))
elseif args.command == "force-leave" then
local node_name = args[1]
assert(node_name ~= nil, "must specify the name of the node to leave")
log("force-leaving %s", node_name)
assert(serf:force_leave(node_name))
log("left node %s", node_name)
end
end

local lapp = [[
Usage: kong cluster COMMAND [OPTIONS]

The available commands are:
members
force-leave <node_name>
keygen
reachability

Options:
-c,--conf (optional string) configuration file
]]

return {
lapp = lapp,
execute = execute,
sub_commands = {
keygen = true,
members = true,
reachability = true,
["force-leave"] = true
}
}
4 changes: 2 additions & 2 deletions kong/cmd/compile.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local nginx_conf_compiler = require "kong.cmd.utils.nginx_conf_compiler"
local prefix_handler = require "kong.cmd.utils.prefix_handler"
local conf_loader = require "kong.conf_loader"

local function execute(args)
local conf = assert(conf_loader(args.conf))
local kong_nginx_conf = assert(nginx_conf_compiler.compile_kong_conf(conf))
local kong_nginx_conf = assert(prefix_handler.compile_kong_conf(conf))
print(kong_nginx_conf)
end

Expand Down
4 changes: 3 additions & 1 deletion kong/cmd/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ The available commands are:
stop
reload
check
migrations
compile
migrations
cluster
version

Options:
Expand All @@ -29,6 +30,7 @@ local cmds = {
check = "check",
compile = "compile",
migrations = "migrations",
cluster = "cluster",
version = "version",
roar = "roar"
}
Expand Down
19 changes: 13 additions & 6 deletions kong/cmd/reload.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
local nginx_conf_compiler = require "kong.cmd.utils.nginx_conf_compiler"
local dnsmasq_signals = require "kong.cmd.utils.dnsmasq_signals"
local prefix_handler = require "kong.cmd.utils.prefix_handler"
local nginx_signals = require "kong.cmd.utils.nginx_signals"
local serf_signals = require "kong.cmd.utils.serf_signals"
local conf_loader = require "kong.conf_loader"
local DAOFactory = require "kong.dao.factory"
local pl_path = require "pl.path"
local log = require "kong.cmd.utils.log"

local function execute(args)
local conf = assert(conf_loader(args.conf, {
prefix = args.prefix
local default_conf = assert(conf_loader()) -- just retrieve default prefix
local prefix = args.prefix or default_conf.prefix
assert(pl_path.exists(prefix), "no such prefix: "..prefix)

local conf_path = pl_path.join(prefix, "kong.conf")
local conf = assert(conf_loader(conf_path, {
prefix = prefix
}))

assert(nginx_conf_compiler.prepare_prefix(conf, conf.prefix))
assert(prefix_handler.prepare_prefix(conf, conf.prefix))
assert(dnsmasq_signals.start(conf, conf.prefix))
assert(serf_signals.start(conf, conf.prefix, DAOFactory(conf)))
assert(nginx_signals.reload(conf.prefix))
log("Reloaded")
Expand All @@ -20,8 +28,7 @@ local lapp = [[
Usage: kong reload [OPTIONS]

Options:
-c,--conf (optional string) configuration file
--prefix (optional string) Nginx prefix path
--prefix (optional string) prefix Kong is running at
]]

return {
Expand Down
17 changes: 7 additions & 10 deletions kong/cmd/start.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
local nginx_conf_compiler = require "kong.cmd.utils.nginx_conf_compiler"
local dnsmasq_signals = require "kong.cmd.utils.dnsmasq_signals"
local prefix_handler = require "kong.cmd.utils.prefix_handler"
local nginx_signals = require "kong.cmd.utils.nginx_signals"
local serf_signals = require "kong.cmd.utils.serf_signals"
local conf_loader = require "kong.conf_loader"
local DAOFactory = require "kong.dao.factory"
local log = require "kong.cmd.utils.log"

--[[
Start Kong.

Kong being a bundle of several applications and services, start acts
as follows:
--]]

local function execute(args)
local conf = assert(conf_loader(args.conf, {
prefix = args.prefix
}))

local dao = DAOFactory(conf)
assert(dao:run_migrations())
assert(nginx_conf_compiler.prepare_prefix(conf, conf.prefix))
assert(prefix_handler.prepare_prefix(conf, conf.prefix))
if conf.dnsmasq then
assert(dnsmasq_signals.start(conf, conf.prefix))
end
assert(serf_signals.start(conf, conf.prefix, dao))
assert(nginx_signals.start(conf.prefix))
log("Started")
Expand All @@ -30,7 +27,7 @@ Usage: kong start [OPTIONS]

Options:
-c,--conf (optional string) configuration file
--prefix (optional string) Nginx prefix path
--prefix (optional string) override prefix directory
]]

return {
Expand Down
22 changes: 16 additions & 6 deletions kong/cmd/stop.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
local dnsmasq_signals = require "kong.cmd.utils.dnsmasq_signals"
local nginx_signals = require "kong.cmd.utils.nginx_signals"
local serf_signals = require "kong.cmd.utils.serf_signals"
local conf_loader = require "kong.conf_loader"
local DAOFactory = require "kong.dao.factory"
local pl_path = require "pl.path"
local log = require "kong.cmd.utils.log"

local function execute(args)
-- no conf file loaded, we just want the prefix,
-- potentially overriden by the argument
local conf = assert(conf_loader(nil, {
prefix = args.prefix
local default_conf = assert(conf_loader()) -- just retrieve default prefix
local prefix = args.prefix or default_conf.prefix
assert(pl_path.exists(prefix), "no such prefix: "..prefix)

local conf_path = pl_path.join(prefix, "kong.conf")
local conf = assert(conf_loader(conf_path, {
prefix = prefix
}))

local dao = DAOFactory(conf)
assert(nginx_signals.stop(conf.prefix))
assert(serf_signals.stop(conf.prefix))
assert(serf_signals.stop(conf, conf.prefix, dao))
if conf.dnsmasq then
assert(dnsmasq_signals.stop(conf.prefix))
end
log("Stopped")
end

local lapp = [[
Usage: kong stop [OPTIONS]

Options:
--prefix (optional string) Nginx prefix path
--prefix (optional string) prefix Kong is running at
]]

return {
Expand Down
Loading