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

[THREESCALE-328] Allow to set a client SSL cert for upstream #610

Merged
merged 5 commits into from
Feb 20, 2018

Conversation

davidor
Copy link
Contributor

@davidor davidor commented Feb 19, 2018

This PR introduces 2 new ENVs (APICAST_PROXY_HTTPS_CERTIFICATE_KEY and APICAST_PROXY_HTTPS_CERTIFICATE), they are used to set a client SSL certificate using the proxy_ssl_certificate and the proxy_ssl_certificate_key NGINX directives.

As a limitation, this certificate needs to be valid for all the services configured.

Closes THREESCALE-328.


# {% if proxy_ssl_certificate and proxy_ssl_certificate_key %}
# {% capture proxy_ssl_session_reuse %}
# proxy_ssl_session_reuse off;
Copy link
Contributor

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.

Copy link
Contributor Author

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;

# proxy_ssl_certificate {{ proxy_ssl_certificate }};
# {% endcapture %}
# {% capture ssl_certificate_key %}
# proxy_ssl_certificate_key {{ proxy_ssl_certificate_key }};
Copy link
Contributor

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.

Copy link
Contributor Author

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'),
Copy link
Contributor

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.

# {% endcapture %}
# {{ proxy_ssl_session_reuse | replace: "#", "" }}
# {{ ssl_certificate | replace: "#", "" }}
# {{ ssl_certificate_key | replace: "#", "" }}
Copy link
Contributor

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.

Copy link
Contributor Author

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'),
Copy link
Contributor

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 ?


# {% if proxy_ssl_certificate and proxy_ssl_certificate_key %}
# {% capture proxy_ssl %}
#{#} # proxy_ssl_session_reuse off;
Copy link
Contributor Author

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',
Copy link
Contributor Author

@davidor davidor Feb 19, 2018

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;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

client.crt

@mikz mikz force-pushed the configurable-proxy-ssl-cert branch 6 times, most recently from e267984 to e9e237f Compare February 20, 2018 09:25
"proxy": {
"api_backend": "https://client.badssl.com",
"backend": {
"endpoint": "https://echo-api.3scale.net"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

?

Copy link
Contributor

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.

@mikz mikz force-pushed the configurable-proxy-ssl-cert branch from e9e237f to 5da2d65 Compare February 20, 2018 09:40
mikz added 2 commits February 20, 2018 11:52
* 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
@mikz mikz force-pushed the configurable-proxy-ssl-cert branch from 8288105 to cc4dbfb Compare February 20, 2018 10:57
@mikz mikz force-pushed the configurable-proxy-ssl-cert branch from cc4dbfb to 66f77bb Compare February 20, 2018 11:13
@davidor davidor force-pushed the configurable-proxy-ssl-cert branch from a3cce31 to 850a2a5 Compare February 20, 2018 11:54
@mikz mikz changed the title [WIP] Allow to set a client SSL cert for upstream [THREESCALE-328] Allow to set a client SSL cert for upstream Feb 20, 2018
Copy link
Contributor

@mikz mikz left a comment

Choose a reason for hiding this comment

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

👍

@mikz mikz merged commit dab3c18 into master Feb 20, 2018
@mikz mikz deleted the configurable-proxy-ssl-cert branch February 20, 2018 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants