-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(healthcheck) support to mTLS in active checks (#41)
* feat(healthcheck) support to mTLS in active checks * chore(ci) install penlight in test env
- Loading branch information
Showing
6 changed files
with
207 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
use Test::Nginx::Socket::Lua; | ||
use Cwd qw(cwd); | ||
|
||
workers(1); | ||
|
||
plan tests => repeat_each() * 4; | ||
|
||
my $pwd = cwd(); | ||
|
||
our $HttpConfig = qq{ | ||
lua_package_path "$pwd/lib/?.lua;;"; | ||
lua_shared_dict test_shm 8m; | ||
lua_shared_dict my_worker_events 8m; | ||
}; | ||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: configure a MTLS probe | ||
--- http_config eval | ||
qq{ | ||
$::HttpConfig | ||
} | ||
--- config | ||
location = /t { | ||
content_by_lua_block { | ||
local we = require "resty.worker.events" | ||
assert(we.configure{ shm = "my_worker_events", interval = 0.1 }) | ||
|
||
local pl_file = require "pl.file" | ||
local cert = pl_file.read("t/util/cert.pem", true) | ||
local key = pl_file.read("t/util/key.pem", true) | ||
|
||
local healthcheck = require("resty.healthcheck") | ||
local checker = healthcheck.new({ | ||
name = "testing_mtls", | ||
shm_name = "test_shm", | ||
type = "http", | ||
ssl_cert = cert, | ||
ssl_key = key, | ||
checks = { | ||
active = { | ||
http_path = "/status", | ||
healthy = { | ||
interval = 999, -- we don't want active checks | ||
successes = 3, | ||
}, | ||
unhealthy = { | ||
interval = 999, -- we don't want active checks | ||
tcp_failures = 3, | ||
http_failures = 3, | ||
} | ||
}, | ||
passive = { | ||
healthy = { | ||
successes = 3, | ||
}, | ||
unhealthy = { | ||
tcp_failures = 3, | ||
http_failures = 3, | ||
} | ||
} | ||
} | ||
}) | ||
ngx.say(checker ~= nil) -- true | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
true | ||
|
||
|
||
=== TEST 2: configure a MTLS probe with parsed cert/key | ||
--- http_config eval | ||
qq{ | ||
$::HttpConfig | ||
} | ||
--- config | ||
location = /t { | ||
content_by_lua_block { | ||
local we = require "resty.worker.events" | ||
assert(we.configure{ shm = "my_worker_events", interval = 0.1 }) | ||
|
||
local pl_file = require "pl.file" | ||
local ssl = require "ngx.ssl" | ||
local cert = ssl.parse_pem_cert(pl_file.read("t/util/cert.pem", true)) | ||
local key = ssl.parse_pem_priv_key(pl_file.read("t/util/key.pem", true)) | ||
|
||
local healthcheck = require("resty.healthcheck") | ||
local checker = healthcheck.new({ | ||
name = "testing_mtls", | ||
shm_name = "test_shm", | ||
type = "http", | ||
ssl_cert = cert, | ||
ssl_key = key, | ||
checks = { | ||
active = { | ||
http_path = "/status", | ||
healthy = { | ||
interval = 999, -- we don't want active checks | ||
successes = 3, | ||
}, | ||
unhealthy = { | ||
interval = 999, -- we don't want active checks | ||
tcp_failures = 3, | ||
http_failures = 3, | ||
} | ||
}, | ||
passive = { | ||
healthy = { | ||
successes = 3, | ||
}, | ||
unhealthy = { | ||
tcp_failures = 3, | ||
http_failures = 3, | ||
} | ||
} | ||
} | ||
}) | ||
ngx.say(checker ~= nil) -- true | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
true |
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,19 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDCTCCAfGgAwIBAgIUWWntedJ1yLAJE2baK/Mg06osmGAwDQYJKoZIhvcNAQEL | ||
BQAwFDESMBAGA1UECgwJS29uZyBJbmMuMB4XDTIwMDQyMzIwMjcwMFoXDTMwMDQy | ||
MTIwMjcwMFowFDESMBAGA1UECgwJS29uZyBJbmMuMIIBIjANBgkqhkiG9w0BAQEF | ||
AAOCAQ8AMIIBCgKCAQEAvVBrEH34MzwKlkBapiNyXr9huSShuojy+7i/01BSFng3 | ||
1TiejXJ3pEjykZqt7ENkZ6+BTYUdb9klK221yXiSyX71x97O0WHHuhH/m4XwGiIH | ||
YPBHdg+ExdMRflXgwtlW3of2hTWxkPkPQDPhoSQVMc5DkU7EOgrTxkv1rUWVAed4 | ||
gSK4IT2AkhKwOSkewZANj2bnK5Evf71ACyJd7IQbJAIYoKBwRJAUXJMA7XAreIB+ | ||
nEr9whNYTklhB4aEa2wtOQuiQubIMJzdOryEX5nufH+tL4p1QKhRPFAqqtJ2Czgw | ||
YZY/v9IrThl19r0nL7FIvxFDNIMeOamJxDLQqsh9NwIDAQABo1MwUTAdBgNVHQ4E | ||
FgQU9t6YAdQ5mOXeqvptN5l3yYZGibEwHwYDVR0jBBgwFoAU9t6YAdQ5mOXeqvpt | ||
N5l3yYZGibEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAhi83 | ||
aXsfJGqr9Zb1guWxbI8uKoG6o88ptXjV2c6dJnxXag0A/Rj+bX2bcPkN2kvQksNl | ||
MBUQlniOydZfsBUAoC0V7yyGUv9eO2RIeFnnNpRXNu+n+Kg2bvgvu8BKNNNOASZv | ||
+Vmzvo9lbfhS9MNAxYk9eTiPNUZ3zn2RfFyT6YWWJbRjk//EAlchyud3XGug9/hw | ||
c05dtzWEYT8GdzMd+Y1/2kR5r/CapSj7GEqL5T3+zDIfjbhTokV7WBrw6og2avoZ | ||
vzrF8xWucry5/2mKQbRxMyCtKYUKTcoLzF4HrNQCETm0n9qUODrHER7Wit9fQFZX | ||
1GEA3BkX2tsbIVVaig== | ||
-----END CERTIFICATE----- |
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,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC9UGsQffgzPAqW | ||
QFqmI3Jev2G5JKG6iPL7uL/TUFIWeDfVOJ6NcnekSPKRmq3sQ2Rnr4FNhR1v2SUr | ||
bbXJeJLJfvXH3s7RYce6Ef+bhfAaIgdg8Ed2D4TF0xF+VeDC2Vbeh/aFNbGQ+Q9A | ||
M+GhJBUxzkORTsQ6CtPGS/WtRZUB53iBIrghPYCSErA5KR7BkA2PZucrkS9/vUAL | ||
Il3shBskAhigoHBEkBRckwDtcCt4gH6cSv3CE1hOSWEHhoRrbC05C6JC5sgwnN06 | ||
vIRfme58f60vinVAqFE8UCqq0nYLODBhlj+/0itOGXX2vScvsUi/EUM0gx45qYnE | ||
MtCqyH03AgMBAAECggEAA1hWa/Yt2onnDfyZHXJm5PGwwlq5WNhuorADA7LZoHgD | ||
VIspkgpBvu9jCduX0yLltUdOm5YMjRtjIr9PhP3SaikKIrv3H5AAvXLv90mIko2j | ||
X70fJiDkEbLHDlpqHEdG16vDWVs3hf5AnLvN8tD2ZujkHL8tjHEAiPJyptsh5OSw | ||
XaltCD67U940XXJ89x0zFZ/3RoRk78wX3ELz7/dY0cMnslMavON+LYTq9hQZyVmm | ||
nOhZICWerKjax4t5f9PZ/zM6IhEVrUhw2WrC31tgRo+ITCIA/nkKid8vNhkiLVdw | ||
jTyAYDLgYW7K8/zVrzmV9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