Skip to content

fix: Make lua-resty-openssl optional again - #354

Open
sriemer wants to merge 2 commits into
masterfrom
fix-lua-resty-openssl-depend
Open

sriemer wants to merge 2 commits into
masterfrom
fix-lua-resty-openssl-depend

Conversation

@sriemer

@sriemer sriemer commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

lua-resty-openssl is only needed for mTLS (client certificate) connections, but since #307 (310e78dd829c) a [warn] line was logged at module load time whenever it was missing. Every worker logged it, even for users who never use mTLS. The README also claimed the package is "a prerequisite for all HTTP connections", which is wrong.

Changes

  • lib/resty/http_connect.lua: do not log at module load time. Log the warning only when mTLS is requested (ssl_client_cert and ssl_client_priv_key set) and resty.openssl.* is not available, and only once per worker (module-level openssl_warned flag), so a misconfigured deployment cannot flood the error log. The traceback of the failed require lists all searched package paths and can be several KB. The error return for that case is unchanged, so every mTLS attempt still fails with the same error. The load-time res variable is renamed to openssl_err, since it is now used further from where it is defined.
  • README.md: drop lua-resty-openssl from the install command and document that it is optional and only required for mTLS. The warning is documented as logged once per worker.
  • t/20-mtls.t: add two tests that simulate a missing lua-resty-openssl (failing require plus reload of resty.http_connect). TEST 5 requests mTLS three times and expects the error each time but exactly one warning. TEST 6 does a non-mTLS connect and expects no [warn] and no [error].

The rockspec intentionally does not list lua-resty-openssl, because LuaRocks has no optional dependencies.

Validation

Using the Docker setup from DOCKER_BUILD.md:

Run Result
luacheck lib && make coverage 0 warnings / 0 errors, 21 test files, 434 tests, all passed (before the once-per-worker fix and the two new tests)
luacheck lib && make test (after the once-per-worker fix) 0 warnings / 0 errors, 21 test files, 442 tests, all passed
New TEST 5 with the openssl_warned guard disabled fails, since the warning is logged more than once
Without resty.openssl (rock removed and the copy bundled with OpenResty hidden) Everything passes except t/20-mtls.t TEST 3 and TEST 4, which send a real client cert and cannot work without the module

Before this change, nearly every test file failed in the "without resty.openssl" setup because of the load-time [warn], which the tests assert against (no_error_log [warn]).

Follow-up to #353 (lua-resty-string dependency).

@sriemer
sriemer force-pushed the fix-lua-resty-openssl-depend branch from a529d55 to 5da8d1a Compare November 17, 2026 10:32
@sriemer sriemer changed the title Make lua-resty-openssl optional again fix: Make lua-resty-openssl optional again Nov 17, 2026
@sriemer sriemer self-assigned this Nov 17, 2026
@sriemer sriemer added the bugfix label Nov 17, 2026
@sriemer

sriemer commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Built and tested with the help of IBM Bob Shell 2.1.0.

Requesting reviews by @catbro666, @tzssangglass, @chronolaw, @pintsized, @Tieske, @piotrp. TIA

AFAICS, only @catbro666 was requesting the hard lua-resty-openssl requirement.
The issue is that the rockspec is not reflecting this. So either we make this optional again like in this PR or we add the hard lua-resty-openssl requirement to the rockspec. My vote is for keeping it optional like in this PR.
Please tell me your opinions. TIA

lua-resty-openssl is only needed for mTLS (client certificate)
connections. Everything else works without it, but a warning was logged
at module load time whenever it was missing. This made every worker log
a `[warn]` line for users who do not use mTLS.

Only log the warning when mTLS is requested and the module is not
available. The error return for that case is unchanged.

Also fix the README: lua-resty-openssl is not a prerequisite for all
HTTP connections. Drop it from the install command and document that it
is only required for mTLS.
@sriemer
sriemer force-pushed the fix-lua-resty-openssl-depend branch from 5da8d1a to 1ae158e Compare November 17, 2026 11:21
@sriemer

sriemer commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Rebased for OpenResty 1.31.8.1 testing in CI.

When mTLS is requested and lua-resty-openssl is not available, the
warning including the traceback of the failed require was logged on
every connect() call. The traceback lists all searched package paths,
so a misconfigured deployment could flood the error log.

Log the warning only once per worker. The error return is unchanged,
so every mTLS attempt still fails with the same error.

Add tests that verify the warning is logged exactly once when mTLS is
requested without lua-resty-openssl and not at all without mTLS.
@sriemer

sriemer commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Added a second commit to fix the log spam issue and updated the PR description accordingly with the help of IBM Bob.
Prompts:

  • Please review the latest commit in this branch against https://github.com/ledgetech/lua-resty-http/pull/354 for security, safety, edge cases, performance and not spamming the error logs too much in production environments.
  • Yes, please do what you mean with "I can apply the log-once change and the README tweak, and add the test, if you want.".
  • Please commit this change.
  • Please update the first comment of https://github.com/ledgetech/lua-resty-http/pull/354 with the fix applied.

Another Bob Shell PR review is happy now with the latest code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant