Skip to content

Conversation

@suryaparua-official
Copy link

Description

This PR fixes an issue where $ENV:// and $secret:// certificate references
were not resolved in Stream TLS mode.

While the same configuration works correctly in HTTP, Stream TLS was passing
the raw reference strings directly to OpenSSL, which resulted in TLS handshake
failures.

Root cause

The Stream lifecycle was missing initializations that already exist in HTTP:
core.env.init() and apisix_secret.init_worker().

Because of this, environment variables and secrets were not available when
certificates were loaded during the TLS handshake.

Fix

This change aligns Stream initialization with HTTP by initializing the
environment and secret subsystems for Stream.

Notes

This change follows the same initialization flow already used in HTTP mode
and addresses the missing setup in Stream TLS.

Related issue

Fixes #12934

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Jan 23, 2026
@Baoyuantop
Copy link
Contributor

Hi @suryaparua-official, we need add test case for this fix

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jan 23, 2026
@suryaparua-official
Copy link
Author

I’ve added a Stream TLS test covering $ENV:// certificate resolution
in t/stream-node/tls.t. Please let me know if any adjustments are needed.

Comment on lines 202 to 205
END {
delete $ENV{APISIX_STREAM_ENV_CERT};
delete $ENV{APISIX_STREAM_ENV_KEY};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It is recommended to remove the END {} block; manual cleanup of these environment variables is not required.

Comment on lines +28 to +33
BEGIN {
use t::APISIX;

$ENV{APISIX_STREAM_ENV_CERT} = t::APISIX::read_file("t/certs/apisix.crt");
$ENV{APISIX_STREAM_ENV_KEY} = t::APISIX::read_file("t/certs/apisix.key");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

release table plugins
release table api_ctx
=== TEST 6: stream tls supports $ENV certificate reference
Copy link
Contributor

Choose a reason for hiding this comment

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

Test cases for $secret:// should also be added to ensure complete coverage.

@Baoyuantop Baoyuantop added the wait for update wait for the author's response in this issue/PR label Jan 26, 2026
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jan 26, 2026
@suryaparua-official
Copy link
Author

I’ve added test coverage for $secret:// certificate resolution as suggested, followed the pattern from t/node/ssl.t, and removed the END {} block per your recommendation. Please let me know if any further adjustments are needed.

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

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files. user responded wait for update wait for the author's response in this issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: $ENV and $secret SSL cert references not working in Stream TLS mode

2 participants