Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

credentials: Reject server connections with ALPN disabled #7184

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

arjan-bal
Copy link
Collaborator

@arjan-bal arjan-bal commented May 3, 2024

Fixes #434

Since HTTP/2 mandates the use of ALPN during the TLS handshake to establish connections, gRPC clients will reject connections to servers that don't have ALPN enabled. gRPC servers will also reject TLS connections from clients with ALPN disabled.
As this change can break existing clients, this behaviour is guarded by an environment variable flag. The error message returned is similar to the message returned by the C++ implementation.

RELEASE NOTES:

  • Clients will reject connections to servers that don't support ALPN when environment variable "GRPC_ENFORCE_ALPN_ENABLED" is set to "true" (case insensitive).
  • Server will reject connections from clients that don't support ALPN when environment variable "GRPC_ENFORCE_ALPN_ENABLED" is set to "true" (case insensitive).

@arjan-bal arjan-bal self-assigned this May 3, 2024
@arjan-bal arjan-bal changed the title Unconditionally reject server connections with ALPN disabled when using TLS Reject server connections with ALPN disabled when using TLS May 3, 2024
@arjan-bal arjan-bal removed their assignment May 3, 2024
@arjan-bal arjan-bal marked this pull request as ready for review May 3, 2024 09:47
@arjan-bal arjan-bal requested a review from easwars May 3, 2024 09:53
@easwars easwars self-assigned this May 6, 2024
Copy link
Collaborator

@purnesh42H purnesh42H left a comment

Choose a reason for hiding this comment

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

LGTM overall! Thanks for picking this up


matchPat, err := regexp.Compile(tc.wantErrMatchPattern)
if err != nil {
t.Fatalf("Error message match pattern %q is invalid due to error: %v", tc.wantErrMatchPattern, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

it should be changed to got before want? Similar for line 328

https://google.github.io/styleguide/go/decisions#got-before-want

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The regex pattern is expected to always be valid, the want is implicitly nil. There is not want in this message. If this line executes, it means that the test case is invalid.

@arjan-bal arjan-bal added the Type: Behavior Change Behavior changes not categorized as bugs label May 7, 2024
credentials/tls.go Outdated Show resolved Hide resolved
credentials/tls.go Outdated Show resolved Hide resolved
credentials/tls.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
@easwars easwars assigned arjan-bal and unassigned easwars May 8, 2024
@arjan-bal arjan-bal marked this pull request as ready for review May 13, 2024 21:11
@arjan-bal arjan-bal requested a review from easwars May 13, 2024 21:11
@arjan-bal arjan-bal assigned easwars and dfawley and unassigned arjan-bal May 13, 2024
@arjan-bal
Copy link
Collaborator Author

@dfawley @easwars added the checks for ALPN in the ServerHandshake method to ensure clients also have ALPN enabled. Added unit tests for the same. Please have another look.

credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
credentials/tls_ext_test.go Outdated Show resolved Hide resolved
@easwars easwars assigned arjan-bal and unassigned easwars May 15, 2024
@arjan-bal arjan-bal requested a review from easwars May 15, 2024 20:25
@arjan-bal arjan-bal assigned easwars and unassigned arjan-bal May 15, 2024
t.Fatalf("Error starting server: %v", err)
}

errCh := make(chan error)
Copy link
Contributor

Choose a reason for hiding this comment

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

This one needs a buffer of size 1 too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed.

credentials/tls_ext_test.go Outdated Show resolved Hide resolved
@easwars easwars assigned arjan-bal and unassigned easwars May 15, 2024
@arjan-bal arjan-bal assigned easwars and unassigned arjan-bal May 15, 2024
@arjan-bal arjan-bal requested a review from easwars May 15, 2024 21:23
@easwars easwars removed their assignment May 15, 2024
@easwars
Copy link
Contributor

easwars commented May 15, 2024

@dfawley : For second set of eyes.

@arjan-bal arjan-bal changed the title Reject server connections with ALPN disabled when using TLS credentials: Reject server connections with ALPN disabled when using TLS May 16, 2024
@arjan-bal arjan-bal changed the title credentials: Reject server connections with ALPN disabled when using TLS credentials: Reject server connections with ALPN disabled May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Behavior Change Behavior changes not categorized as bugs Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TLS does not enforce ALPN protocol
5 participants