-
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-5105] Adding support for mtls when using proxy policy #1499
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4d32f50
Introduce tls module
tkan145 26c408d
[upstream_mtls] refactor to use tls module
tkan145 09c1c25
[upstream-mtls] Move certificate logic inside APIcast policy
tkan145 d0c557a
[proxy] Add support to set client certificate/key when sending reques…
tkan145 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
local base = require "resty.core.base" | ||
|
||
local type = type | ||
local tostring = tostring | ||
|
||
local get_request = base.get_request | ||
local ffi = require "ffi" | ||
local C = ffi.C | ||
|
||
local _M = {} | ||
|
||
local NGX_OK = ngx.OK | ||
|
||
local ngx_http_apicast_ffi_set_proxy_cert_key; | ||
local ngx_http_apicast_ffi_set_proxy_ca_cert; | ||
local ngx_http_apicast_ffi_set_ssl_verify | ||
|
||
ffi.cdef([[ | ||
int ngx_http_apicast_ffi_set_proxy_cert_key( | ||
ngx_http_request_t *r, void *cdata_chain, void *cdata_key); | ||
int ngx_http_apicast_ffi_set_proxy_ca_cert( | ||
ngx_http_request_t *r, void *cdata_ca); | ||
int ngx_http_apicast_ffi_set_ssl_verify( | ||
ngx_http_request_t *r, int verify, int verify_deph); | ||
]]) | ||
|
||
ngx_http_apicast_ffi_set_proxy_cert_key = C.ngx_http_apicast_ffi_set_proxy_cert_key | ||
ngx_http_apicast_ffi_set_proxy_ca_cert = C.ngx_http_apicast_ffi_set_proxy_ca_cert | ||
ngx_http_apicast_ffi_set_ssl_verify = C.ngx_http_apicast_ffi_set_ssl_verify | ||
|
||
-- Set the certs for the upstream connection. Need to receive the pointers from | ||
-- parse_* functions. | ||
function _M.set_upstream_cert_and_key(cert, key) | ||
local r = get_request() | ||
if not r then | ||
error("no request found") | ||
end | ||
|
||
if not cert or not key then | ||
return nil, "cert and key must not be nil" | ||
end | ||
|
||
local ret = ngx_http_apicast_ffi_set_proxy_cert_key(r, cert, key) | ||
if ret ~= NGX_OK then | ||
return nil, "error while setting upstream client certificate and key" | ||
end | ||
end | ||
|
||
-- Set the trusted store for the upstream connection. | ||
function _M.set_upstream_ca_cert(store) | ||
local r = get_request() | ||
if not r then | ||
error("no request found") | ||
end | ||
|
||
if not store then | ||
return nil, "trusted store must not be nil" | ||
end | ||
|
||
local ret = ngx_http_apicast_ffi_set_proxy_ca_cert(r, store) | ||
if ret ~= NGX_OK then | ||
return nil, "error while setting upstream trusted CA store" | ||
end | ||
end | ||
|
||
-- Verify upstream connection | ||
function _M.set_upstream_ssl_verify(verify, verify_deph) | ||
local r = get_request() | ||
if not r then | ||
error("no request found") | ||
end | ||
|
||
if type(verify) ~= 'boolean' then | ||
return nil, "verify expects a boolean but found " .. type(verify) | ||
end | ||
|
||
if type(verify_deph) ~= 'number' then | ||
return nil, "verify depth expects a number but found " .. type(verify) | ||
end | ||
|
||
if verify_deph < 0 then | ||
return nil, "verify_deph expects a non-negative interger but found" .. tostring(verify_deph) | ||
end | ||
|
||
local val = ngx_http_apicast_ffi_set_ssl_verify(r, verify, verify_deph) | ||
if val ~= NGX_OK then | ||
return nil, "error while setting upstream verify" | ||
end | ||
end | ||
|
||
return _M |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we plan to move this file (and content) to the apicast-nginx-module??
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, I'm planing to replace https://github.com/3scale/apicast-nginx-module/blob/master/lib/resty/mtls.lua with the content of this
tls.lua
file. This makes it easier to test for patches, memory leaks...etc.