-
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
[THREESCALE-328] Allow to set a client SSL cert for upstream #610
Conversation
gateway/conf.d/apicast.conf
Outdated
|
||
# {% if proxy_ssl_certificate and proxy_ssl_certificate_key %} | ||
# {% capture proxy_ssl_session_reuse %} | ||
# proxy_ssl_session_reuse off; |
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.
Maybe we should expose this as a config option with a default value so it can be customized.
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.
Maybe, but I couldn't make this work properly with proxy_ssl_session_reuse on;
gateway/conf.d/apicast.conf
Outdated
# proxy_ssl_certificate {{ proxy_ssl_certificate }}; | ||
# {% endcapture %} | ||
# {% capture ssl_certificate_key %} | ||
# proxy_ssl_certificate_key {{ proxy_ssl_certificate_key }}; |
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.
Lets not forget proxy_ssl_password_file.
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.
Yes. Otherwise, we'll need to type the password when Apicast boots.
-- @tfield ?policy_chain policy_chain @{policy_chain} instance | ||
-- @tfield ?{string,...} nameservers list of nameservers | ||
-- @tfield ?string package.path path to load Lua files | ||
-- @tfield ?string package.cpath path to load libraries | ||
-- @table environment.default_config default configuration | ||
_M.default_config = { | ||
ca_bundle = resty_env.value('SSL_CERT_FILE'), | ||
proxy_ssl_certificate = resty_env.value('SSL_PROXY_CERTIFICATE'), |
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.
We probably should covert them to absolute paths because it fails with relative ones as it changes nginx workdir/prefix with:
nginx: [emerg] BIO_new_file("/tmp/public.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/tmp/public.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
But we also should support engine:name:id
format which would load the key from OpenSSL.
gateway/conf.d/apicast.conf
Outdated
# {% endcapture %} | ||
# {{ proxy_ssl_session_reuse | replace: "#", "" }} | ||
# {{ ssl_certificate | replace: "#", "" }} | ||
# {{ ssl_certificate_key | replace: "#", "" }} |
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 find this working quite well:
# {% if proxy_ssl_certificate and proxy_ssl_certificate_key %}
# {% capture proxy_ssl %}
#{#} proxy_ssl_session_reuse off;
#{#} proxy_ssl_certificate {{ proxy_ssl_certificate }};
#{#} proxy_ssl_certificate_key {{ proxy_ssl_certificate_key }};
# {% endcapture %}
# {{ proxy_ssl | replace: "#{#}", "" }}
# {% endif %}
This makes it obvious that it should strip only the first part of the comment and allows commenting lines within comments.
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.
Good idea 👍
-- @tfield ?policy_chain policy_chain @{policy_chain} instance | ||
-- @tfield ?{string,...} nameservers list of nameservers | ||
-- @tfield ?string package.path path to load Lua files | ||
-- @tfield ?string package.cpath path to load libraries | ||
-- @table environment.default_config default configuration | ||
_M.default_config = { | ||
ca_bundle = resty_env.value('SSL_CERT_FILE'), | ||
proxy_ssl_certificate = resty_env.value('SSL_PROXY_CERTIFICATE'), | ||
proxy_ssl_certificate_key = resty_env.value('SSL_PROXY_CERTIFICATE_KEY'), |
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.
We probably could name these like APICAST_PROXY_*
(APICAST_PROXY_CERTIFICATE
and APICAST_PROXY_CERTIFICATE_KEY
).
APICAST_PROXY
is not the best name. Maybe APICAST_UPSTREAM_HTTPS
?
gateway/conf.d/apicast.conf
Outdated
|
||
# {% if proxy_ssl_certificate and proxy_ssl_certificate_key %} | ||
# {% capture proxy_ssl %} | ||
#{#} # proxy_ssl_session_reuse off; |
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.
We'll need to set this one according to APICAST_PROXY_SESSION_REUSE
.
t/mutual-ssl.t
Outdated
use Test::APIcast::Blackbox 'no_plan'; | ||
|
||
env_to_apicast( | ||
'APICAST_PROXY_CERTIFICATE' => '../html/server.crt', |
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.
These should be client.crt
and client.key
.
t/mutual-ssl.t
Outdated
ssl_certificate $TEST_NGINX_SERVROOT/html/server.crt; | ||
ssl_certificate_key $TEST_NGINX_SERVROOT/html/server.key; | ||
|
||
ssl_client_certificate $TEST_NGINX_SERVROOT/html/server.crt; |
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.
client.crt
e267984
to
e9e237f
Compare
"proxy": { | ||
"api_backend": "https://client.badssl.com", | ||
"backend": { | ||
"endpoint": "https://echo-api.3scale.net" |
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.
?
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.
Yep. But I could not figure it out from the debug logs. Haven't done wireshark yet.
e9e237f
to
5da2d65
Compare
* so they are read at the very last moment * this allows updating them in between loadng config and rendering the template * depends on 3scale/liquid-lua#4, 3scale/liquid-lua#5
8288105
to
cc4dbfb
Compare
cc4dbfb
to
66f77bb
Compare
a3cce31
to
850a2a5
Compare
…ERTIFICATE_KEY [THREESCALE-328]
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.
👍
This PR introduces 2 new ENVs (
APICAST_PROXY_HTTPS_CERTIFICATE_KEY
andAPICAST_PROXY_HTTPS_CERTIFICATE
), they are used to set a client SSL certificate using theproxy_ssl_certificate
and theproxy_ssl_certificate_key
NGINX directives.As a limitation, this certificate needs to be valid for all the services configured.
Closes THREESCALE-328.