-
Notifications
You must be signed in to change notification settings - Fork 170
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
Support HTTPS and introduce ssl_certificate policy phase #622
Changes from all commits
7e86746
ca8e23a
82f0d35
08e81e5
90c06af
20989fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDBjCCAe4CCQDF1mZcWyPgwTANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJB | ||
VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0 | ||
cyBQdHkgTHRkMB4XDTE2MTExNzA4NDcxOVoXDTE3MTExNzA4NDcxOVowRTELMAkG | ||
A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0 | ||
IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB | ||
AKvwk7TsVwW/0KSpZMU4LU7PE5rJGGyy0EJY/Y22uAuqzAYDyyuShW3IfUqS0hr5 | ||
nOLZWSMjntcHbbLsYy6J6ZcmxfwlpS8FGOq2zhQvHZCmxMTRSTK+5EfgLe0al556 | ||
k2RoEcsGgK4jTH09+Fig3dMBL/1ly+s/z7JBzFkCX03y6BA26CjrHl2aVJjyJWRs | ||
Z1/9qndjCzZzVCsdJ7NJi/km3ugAJFRPggxucBeyCToHkQQacXYL4X8S8fS6oP7w | ||
XNMttBdENl1iGT1uD4mxjy1i8L3v8OhK6qxE+dxGLcakECbuGDGBGi/Cyn4sPKfs | ||
fghFfboSPm60OfeXcyS1n+sCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAWcctiXNI | ||
Je80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IBAQBkyiygZOJKkxSuMQ9pQ5CldPIloCd+LV0MLmzMztH5NF0/ | ||
Zr4hiUB4vMPIt5a2Ay5Og3C04wVoFBbNuMs/70nwBkxqQ0+7c8qmlgLk9OTvjkOC | ||
MEN4bd4MK2WNRw6340bm13nOaBcqsQW//0jhJaWFKEIBddXNwawP1Ua8/B1hXJKz | ||
vSmCWM7XZ2A/LoB69eSwyse1D75BpYOZ5WdBRBKnZO45cc0eRcbGYvK0KOeXXjNw | ||
LCqdMZav74dfB4LM/b6CnHyrZC6FFtJbsBLLJ7UCcRNeR6UF0tTdUel95LdscA5j | ||
sMqFt3bnE9U+IIy3BoxorviPdlbInLXBzynqqyl3 | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpQIBAAKCAQEAq/CTtOxXBb/QpKlkxTgtTs8TmskYbLLQQlj9jba4C6rMBgPL | ||
K5KFbch9SpLSGvmc4tlZIyOe1wdtsuxjLonplybF/CWlLwUY6rbOFC8dkKbExNFJ | ||
Mr7kR+At7RqXnnqTZGgRywaAriNMfT34WKDd0wEv/WXL6z/PskHMWQJfTfLoEDbo | ||
KOseXZpUmPIlZGxnX/2qd2MLNnNUKx0ns0mL+Sbe6AAkVE+CDG5wF7IJOgeRBBpx | ||
dgvhfxLx9Lqg/vBc0y20F0Q2XWIZPW4PibGPLWLwve/w6ErqrET53EYtxqQQJu4Y | ||
MYEaL8LKfiw8p+x+CEV9uhI+brQ595dzJLWf6wIDAQABAoIBAAYuW+EBLg+y2ZlR | ||
zaGZZ2eR4i6KVCp0MzBvao4Rp4Qj27nLoR4r4kgUEQ0BQjReDNnK3n145ljsl3D7 | ||
NoWRx6f7aNqrr8iE8mRdtgLbvsBYfnJk47DDVAmRcZU4g4La/Tl61EjsLuwTsMg/ | ||
1hG5lr/jJwqBAleur5TE8MeyYiK3LajeisCO7GMp3ubrWqX1JenpxPidr4V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tu5bd+trUnMaF/iEvpg0K6ycP1EbdTqWpuWAOCH972oxDm/B47by/oky+ZS | ||
cBXPGKTg9kin1WCdBgjB+l/U1RIXWOkymPp+pqHvAoGAUDwpY9OqVubSAJ0XP0PD | ||
n/r/Xh2QxHvdViKn2tQWk8GVZiPEKRQt9qRd/FvvfK2EyNidjVNdo3+1zBXPvhhZ | ||
0S24R3cTBg5E0u7VP/fSxGATA0iWFpBwJAsSO0A0mTOqkSlbusc/A91mm7yPRUze | ||
0D052HvLm/jwu3jtspYnXk0CgYBM6NxhEPuMKpeHHlEzyUwPitYcDCF6Iw85sf+r | ||
1S7/L22K0H6T9GppvmLGNBvTX70ByZLidlkfz5vj559bIb7/5Ur9Fv2Nr8ilbZeo | ||
wW+CKkN6o4VSJYCU7Qeq1g0Taqx0H1H8TuQ15E/N/Q9Lzlpoh1M1RfWVg+3Ii+nD | ||
gcNShwKBgAJtZi3Ux51ycxjNWj/dLHTOy7grzvODybsvjxG7vvzg/OfhWtCSbCK3 | ||
fdB2fGFGI8RogAvPFqpsl/t5AbOfQoQ/WofElw2tSt6ya+LP2iRKjeXyq6G5Oo9b | ||
KGyTLDlqoBYaKAivmRUZcR/7dBVhNd9hzgLdcnZREw+0nhtYhytu | ||
-----END RSA PRIVATE KEY----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,7 +122,32 @@ http { | |
|
||
access_log {{ access_log_file | default: "/dev/stdout" }} time; | ||
|
||
listen {{ port.apicast | default: 8080 }}; | ||
{%- assign http_port = port.apicast | default: 8080 %} | ||
{%- assign https_port = env.APICAST_HTTPS_PORT %} | ||
|
||
{% if http_port != https_port -%} | ||
listen {{ http_port }}; | ||
{% endif %} | ||
|
||
{% if https_port -%} | ||
listen {{ https_port }} ssl; | ||
|
||
{%- assign https_certificate = env.APICAST_HTTPS_CERTIFICATE -%} | ||
ssl_certificate {% if https_certificate -%} | ||
{{ https_certificate }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one does not need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is path that was given by user in ENV, so we should not need to do any transformations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it does not really work. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
{%- else -%} | ||
{{ "conf/server.crt" | filesystem | first }} | ||
{%- endif %}; | ||
|
||
{%- assign https_certificate_key = env.APICAST_HTTPS_CERTIFICATE_KEY -%} | ||
ssl_certificate_key {% if https_certificate_key -%} | ||
{{ https_certificate_key }} | ||
{%- else -%} | ||
{{ "conf/server.key" | filesystem | first }} | ||
{%- endif %}; | ||
|
||
ssl_certificate_by_lua_block { require('apicast.executor'):ssl_certificate() } | ||
{%- endif %} | ||
|
||
server_name _; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIBTzCB9gIJAJ/Hbl7Rg8UpMAoGCCqGSM49BAMCMDAxEDAOBgNVBAoMB0FQSWNh | ||
c3QxHDAaBgNVBAsME0RlZmF1bHQgY2VydGlmaWNhdGUwHhcNMTgwNjA1MTAxNjAx | ||
WhcNMjgwNjAyMTAxNjAxWjAwMRAwDgYDVQQKDAdBUEljYXN0MRwwGgYDVQQLDBNE | ||
ZWZhdWx0IGNlcnRpZmljYXRlMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEVUiV | ||
WRQcAve1ssYN0qaFWP33pYRLSV4SM6G0BB3SLiYnQKan8K0I7DtvOAoT8HOm0UyM | ||
+6vNyedReg5PXHOuPjAKBggqhkjOPQQDAgNIADBFAiEAoSKLhFHcwFGSu1N4NxSq | ||
p0bGI5J8WYfrdvWVZgWsV9MCIBeJzCEsegLdVBf/mn+4m7GNitMNzLj4CxTCnpqq | ||
S1m1 | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-----BEGIN EC PARAMETERS----- | ||
BggqhkjOPQMBBw== | ||
-----END EC PARAMETERS----- | ||
-----BEGIN EC PRIVATE KEY----- | ||
MHcCAQEEIK9vyuYjAXWiI6QwoBwMs2BPKyY/46Qdd8ZFgTCA2YNRoAoGCCqGSM49 | ||
AwEHoUQDQgAEVUiVWRQcAve1ssYN0qaFWP33pYRLSV4SM6G0BB3SLiYnQKan8K0I | ||
7DtvOAoT8HOm0UyM+6vNyedReg5PXHOuPg== | ||
-----END EC PRIVATE KEY----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ local PHASES = { | |
'content', 'balancer', | ||
'header_filter', 'body_filter', | ||
'post_action', 'log', 'metrics', | ||
|
||
'ssl_certificate', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add this new phase to the list that we have in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. |
||
} | ||
|
||
local setmetatable = setmetatable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
local _M = require('apicast.policy').new('HTTPS', '1.0.0') | ||
local ssl = require('ngx.ssl') | ||
local new = _M.new | ||
|
||
function _M.new(configuration) | ||
local policy = new(configuration) | ||
|
||
if configuration then | ||
policy.certificate_chain = assert(ssl.parse_pem_cert(configuration.certificate)) | ||
policy.priv_key = assert(ssl.parse_pem_priv_key(configuration.key)) | ||
end | ||
|
||
return policy | ||
end | ||
|
||
function _M:ssl_certificate() | ||
assert(ssl.clear_certs()) | ||
|
||
assert(ssl.set_cert(self.certificate_chain)) | ||
assert(ssl.set_priv_key(self.priv_key)) | ||
end | ||
|
||
return _M |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried this with
https_port = nil
?I remember problems when comparing nils in Liquid, but maybe it was a different issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a new test case in
t/listen-https.t
just to be sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So like the variable not set at all? That works - normal blackbox tests run with https_port not set.
The issue was that
{% if env.somevar %}
would be true even if it is empty.This works just fine because
http_port
always has value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right 👍