Skip to content

Conversation

willmafh
Copy link
Contributor

@willmafh willmafh commented Jul 21, 2025

proxy_ssl_verify_by_lua directives

  • proxy_ssl_verify_by_lua directives are working after receiving server certificates, allowing us to control upstream ssl handshake dynamically with Lua

  • a series of related PRs

  • some of the docs hasn't finished yet, since the PR has not been merged, and some release infos can't be added, please review the codes first and docs may be updated later

@HanadaLee
Copy link

Should this pr be prepared for grpc and uwsgi module as well? They also support upstream SSL related configurations.

grpc_ssl_verify_by_lua
uwsgi_ssl_verify_by_lua

@willmafh
Copy link
Contributor Author

Should this pr be prepared for grpc and uwsgi module as well? They also support upstream SSL related configurations.

grpc_ssl_verify_by_lua uwsgi_ssl_verify_by_lua

Let's first focus on proxy_ssl_verify_by_lua, since grpc/uwsgi are not that commonly used

@willmafh
Copy link
Contributor Author

willmafh commented Jul 29, 2025

@agentzh @zhuizhuhaomeng ping for review...sorry to bother, but please take some time to review the PR, thanks!


**phase:** *right-after-server-certificate-message-was-processed*

Equivalent to [proxy_ssl_verify_by_lua_block](#proxy_ssl_verify_by_lua_block), except that the file specified by `<path-to-lua-script-file>` contains the Lua code, or, as from the `v0.5.0rc32` release, the [LuaJIT bytecode](#luajit-bytecode-support) to be executed.
Copy link
Contributor

Choose a reason for hiding this comment

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

why is v0.5.0rc32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from other places in this README.markdown, please search it!

cctx->original_request_count = r->main->count;
cctx->done = 0;
cctx->entered_proxy_ssl_verify_handler = 1;
cctx->pool = ngx_create_pool(128, c->log);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use c->pool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope! c is upstream connection and we will destroy the pool when calling ngx_http_lua_proxy_ssl_verify_done for proxy ssl verify to reenter, but the connection to upstream need to maintain, so we create a new pool specially for proxy ssl.


c->log->action = "loading proxy ssl verify by lua";

if (llcf->proxy_ssl_verify_handler == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? Do you have test case to cover this code path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original code structure was copied from ngx_http_lua_ssl_certby.c, but it seems unnecessary, so I will delete it.



int
ngx_http_lua_ffi_ssl_get_verify_result(ngx_http_request_t *r, char **err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ngx_http_lua_ffi_ssl_get_verify_result(ngx_http_request_t *r, char **err)
ngx_http_lua_ffi_get_upstream_ssl_verify_result(ngx_http_request_t *r, char **err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These functions will be used in lua file proxysslverify.lua like this proxy_ssl_vfy.get_verify_result(23), it seems redundant to add upstream in the function name, or change it to ngx_http_lua_ffi_proxy_ssl_get_verify_result seems more reasonable?



void
ngx_http_lua_ffi_ssl_free_verify_cert(void *cdata)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ngx_http_lua_ffi_ssl_free_verify_cert(void *cdata)
ngx_http_lua_ffi_free_upstream_ssl_free_verify_cert(void *cdata)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above



void *
ngx_http_lua_ffi_ssl_get_verify_cert(ngx_http_request_t *r, char **err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ngx_http_lua_ffi_ssl_get_verify_cert(ngx_http_request_t *r, char **err)
ngx_http_lua_ffi_get_upstream_ssl_verify_cert(ngx_http_request_t *r, char **err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

--- request
GET /t
--- response_body
lua_upstream_skip_openssl_default_verify default off
Copy link
Contributor

Choose a reason for hiding this comment

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

should be on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The directive is lua_upstream_skip_openssl_default_verify, the default behavior is NOT to bypass openssl's default verify process, otherwise security problems maybe introduced, notice the semantic!

plan tests => repeat_each() * (blocks() * 6 + 6);
} else {
plan tests => repeat_each() * (blocks() * 5 + 10);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a test to test the client abort during the upstream ssl verify.

conf->proxy_ssl_verify_chunkname = prev->proxy_ssl_verify_chunkname;
}

if (conf->proxy_ssl_verify_src.len) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a macro in th patch to test if the patch has been applied.

@willmafh willmafh force-pushed the proxy_ssl_verify_by_lua branch from 143af2b to c4888f8 Compare September 15, 2025 03:09
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.

3 participants