Skip to content

tls: SNI-based cert selection during TLS handshake (#22036)#24483

Merged
ggreenway merged 3 commits intoenvoyproxy:mainfrom
LuyaoZhong:sni-based-cert-selection
Dec 14, 2022
Merged

tls: SNI-based cert selection during TLS handshake (#22036)#24483
ggreenway merged 3 commits intoenvoyproxy:mainfrom
LuyaoZhong:sni-based-cert-selection

Conversation

@LuyaoZhong
Copy link
Copy Markdown

@LuyaoZhong LuyaoZhong commented Dec 11, 2022

Envoy supports selecting certs by selecting filter chain based on SNI. But it is possible that we access different services via one filter chain, which requires SNI-based cert selection in one single filter chain during handshake.

This change is merged by #22036 and reverted by #24475.

Signed-off-by: Luyao Zhong luyao.zhong@intel.com

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #24483 was opened by LuyaoZhong.

see: more, trace.

@LuyaoZhong
Copy link
Copy Markdown
Author

resubmit PR due to rollback by #24475, don't merge until https://github.com/envoyproxy/envoy/pull/22036/files#r1044579979 is addressed.

Envoy supports selecting certs by selecting filter chain based on SNI.
But it is possible that we access different services via one filter
chain, which requires SNI-based cert selection in one single filter
chain during handshake.

This change is merged by envoyproxy#22036 and reverted by envoyproxy#24475.

Signed-off-by: Luyao Zhong <luyao.zhong@intel.com>
@LuyaoZhong LuyaoZhong force-pushed the sni-based-cert-selection branch from e185630 to 22228c9 Compare December 11, 2022 13:20
@soulxu
Copy link
Copy Markdown
Member

soulxu commented Dec 11, 2022

/wait

@ggreenway
Copy link
Copy Markdown
Member

@LuyaoZhong can you break this into two commits? One being the revert of the revert, which should be the original change you made, and the 2nd commit for the fix/change that is different from the original PR? You'll have to force-push to the PR branch, but that's fine in this case.

@LuyaoZhong
Copy link
Copy Markdown
Author

LuyaoZhong commented Dec 13, 2022

@LuyaoZhong can you break this into two commits? One being the revert of the revert, which should be the original change you made, and the 2nd commit for the fix/change that is different from the original PR? You'll have to force-push to the PR branch, but that's fine in this case.

Actually I think the root cause of crash is not missing nullptr check, since it gets checked in earlier place. I reply on https://github.com/envoyproxy/envoy/pull/22036/files#r1044579979. And I would like @yanavlasov and @KBaichoo can provide me more context about the crash case.

And I'm OK with adding checking as a second safeguard. Will append a commit for that change.

@LuyaoZhong
Copy link
Copy Markdown
Author

@LuyaoZhong can you break this into two commits? One being the revert of the revert, which should be the original change you made, and the 2nd commit for the fix/change that is different from the original PR? You'll have to force-push to the PR branch, but that's fine in this case.

Actually I think the root cause of crash is not missing nullptr check, since it gets checked in earlier place. I reply on https://github.com/envoyproxy/envoy/pull/22036/files#r1044579979. And I would like @yanavlasov and @KBaichoo can provide me more context about the crash case.

And I'm OK with adding checking as a second safeguard. Will append a commit for that change.

After dig the code, I got that when user has its own handshaker to provide certificates, it might trigger the bug.

@KBaichoo
Copy link
Copy Markdown
Contributor

Thank you @LuyaoZhong! Yes, I think the problem was with using a custom handshaker, this looks good. Can you add a test we could add to capture this?

@LuyaoZhong
Copy link
Copy Markdown
Author

Thank you @LuyaoZhong! Yes, I think the problem was with using a custom handshaker, this looks good. Can you add a test we could add to capture this?

@KBaichoo I think this should be tested in concrete handshaker extension test cases, but there is no any custom handshaker extension in envoy source code. The cert should not be null commonly, this check is just a safeguard to avoid crash.

KBaichoo
KBaichoo previously approved these changes Dec 13, 2022
Copy link
Copy Markdown
Contributor

@KBaichoo KBaichoo left a comment

Choose a reason for hiding this comment

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

That's a fair point, thank you for fixing. It LGTM.

@KBaichoo I think this should be tested in concrete handshaker extension test cases, but there is no any custom handshaker extension in envoy source code

cc @yanavlasov

@ggreenway
Copy link
Copy Markdown
Member

There are at least some tests that involve custom handshakes here. Can this be modified to add a test case for this?

When custom handshaker provides certificates, it's possible
that no certificate is loaded correctly and become a null pointer.
Skip the null cert when populate the map used for SNI-based
certificate selection.

Signed-off-by: Luyao Zhong <luyao.zhong@intel.com>
@LuyaoZhong
Copy link
Copy Markdown
Author

LuyaoZhong commented Dec 14, 2022

There are at least some tests that involve custom handshakes here. Can this be modified to add a test case for this?

Thanks. SslHandshakerImplForTest can not help here, but I found HandshakerFactoryImplForTest can be a test base. I force push the new testcase to second commit, please take a look.

@LuyaoZhong
Copy link
Copy Markdown
Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #24483 (comment) was created by @LuyaoZhong.

see: more, trace.

Copy link
Copy Markdown
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

This looks good; thanks for writing the test. There's a gcc error and a clang-tidy error to fix to make CI pass, but other than that I think this is ready to merge.

/wait

@LuyaoZhong
Copy link
Copy Markdown
Author

/wait confirming the test correctness

Signed-off-by: Luyao Zhong <luyao.zhong@intel.com>
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.

5 participants