feat: add gRPC mutual TLS support for the OAP channel - #146
Merged
Merged
Conversation
Upgrade gRPC credentials from createInsecure() to createSsl() with
mutual authentication options. New environment variables:
SW_AGENT_SECURE enable TLS (fail-closed; must be set
explicitly)
SW_AGENT_SSL_TRUSTED_CA_PATH trusted CA cert for OAP server verification
SW_AGENT_SSL_KEY_PATH client private key for mTLS
SW_AGENT_SSL_CERT_CHAIN_PATH client certificate chain for mTLS
SW_AGENT_SSL_TARGET_NAME_OVERRIDE
override SNI / authority when OAP cert
hostname does not match the network address
The implementation:
- Fails closed (throws) on incomplete or contradictory TLS config.
- Supports one-way TLS (system CA), custom CA, and mTLS (CA + key + cert).
- Accepts PKCS#1 and PKCS#8 private keys via Node crypto.
- Exposes grpc.ssl_target_name_override + grpc.default_authority
for hostname mismatch scenarios.
Tests:
- 11 unit tests covering all credential branches and error paths.
- 2 E2E tests against a real OAP + BanyanDB container:
(1) OAP rejects TLS without a client certificate — only explicit
certificate-required alerts/codes pass; a bare post-handshake
close is treated as failure, not success.
(2) Agent reports traces through mTLS. listServices proves
Management gRPC; queryTraces (v2) proves TraceSegment
client-streaming persisted segments (flush HTTP 200 alone is
insufficient because flush swallows report failures).
- Local/CI share tests/remote-e2e/mtls/generate-certs.sh so private
keys are never committed and the suite can be run outside Actions.
CI generates fresh test certificates each run so no private keys are
committed to the repository.
wu-sheng
reviewed
Sep 16, 2026
Comment on lines
+72
to
+77
| logger.debug( | ||
| 'gRPC TLS credentials built: ca=%s key=%s cert=%s', | ||
| trustedCaPath ?? '(system)', | ||
| keyPath ?? '(none)', | ||
| certChainPath ?? '(none)', | ||
| ); |
Member
There was a problem hiding this comment.
Minor logging issue (P3): these new calls use printf-style %s placeholders, but createLogger() intentionally omits winston.format.splat(), so the certificate paths and hostname override are not included in the messages.
For example, with SW_AGENT_LOGGING_LEVEL=debug and sslTargetNameOverride: 'example.test', I reproduced:
gRPC TLS credentials built: ca=%s key=%s cert=%s
gRPC TLS hostname override set to [%s]
The second message should say:
gRPC TLS hostname override set to [example.test]
Could these calls use template strings or structured metadata? For example, the hostname message can be:
logger.debug(`gRPC TLS hostname override set to [${sslTargetNameOverride}]`);The credential-path message needs the same adjustment. This only affects troubleshooting output; TLS/mTLS behavior is unaffected.
createLogger intentionally omits winston.format.splat(), so printf-style %s placeholders were logged literally. Use template strings so ca/key/cert paths and hostname override appear in debug output.
wu-sheng
approved these changes
Sep 16, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add gRPC mutual TLS (mTLS) support for the Node.js agent → OAP channel.
createInsecure()tocreateSsl()when TLS is enabled.ssl_target_name_override/default_authorityfor hostname / SAN mismatch cases.New configuration
agent.start()optionSW_AGENT_SECUREsecureSW_AGENT_SSL_TRUSTED_CA_PATHsslTrustedCaPathSW_AGENT_SSL_KEY_PATHsslKeyPathSW_AGENT_SSL_CERT_CHAIN_PATHsslCertChainPathSW_AGENT_SSL_TARGET_NAME_OVERRIDEsslTargetNameOverrideMotivation
Align the Node.js agent with Java/Python collector TLS/mTLS capabilities so Agent → OAP traffic can use mutual authentication against OAP
receiver-sharing-server.Implementation notes
grpc.credentials.createSsl(...)at channel build time.secure=falsealso throw.queryTraces(Trace Query V2) against BanyanDB-backed OAP; flush HTTP 200 alone is not treated as proof because flush is best-effort.Test plan
tests/remote/TLSChannelBuilder.test.ts(credential branches and error paths)generate-certs.sh+npm run test tests/remote-e2e/mtls/)TestRemoteE2EMTLSon Node 20 / 22 / 24docs/en/setup/configuration.md,docs/en/advanced/troubleshooting.md,tests/remote-e2e/mtls/README.mdRelated
test/e2e-v2/cases/simple/mtls/in apache/skywalking