Skip to content

[WIP] fix(auth): set default max_metadata_size to 32KB in gRPC channels#17661

Draft
ohmayr wants to merge 1 commit into
mainfrom
pqc-google-auth-grpc-metadata
Draft

[WIP] fix(auth): set default max_metadata_size to 32KB in gRPC channels#17661
ohmayr wants to merge 1 commit into
mainfrom
pqc-google-auth-grpc-metadata

Conversation

@ohmayr

@ohmayr ohmayr commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@ohmayr ohmayr self-assigned this Jul 8, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request configures a default grpc.max_metadata_size of 32 KB (32768 bytes) in secure_authorized_channel to prevent metadata limit rejections when using Post-Quantum Cryptography (PQC) bearer tokens or large trace headers. It also adds a unit test to verify this behavior when no options are explicitly provided. The reviewer recommended expanding the unit tests to cover scenarios where options are explicitly passed, both with and without grpc.max_metadata_size already specified, to ensure complete test coverage of the new logic.

Comment on lines +278 to +298
def test_secure_authorized_channel_pqc_max_metadata_size(
self,
secure_channel,
ssl_channel_credentials,
metadata_call_credentials,
composite_channel_credentials,
get_client_ssl_credentials,
):
credentials = mock.Mock()
request = mock.Mock()
target = "example.com:80"
ssl_credentials = mock.Mock()

# Call without explicit options; should automatically add grpc.max_metadata_size=32768
google.auth.transport.grpc.secure_authorized_channel(
credentials, request, target, ssl_credentials=ssl_credentials
)

_, kwargs = secure_channel.call_args
assert "options" in kwargs
assert ("grpc.max_metadata_size", 32768) in kwargs["options"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current test only verifies the case where options is not provided. To ensure full coverage and robust behavior, we should also test when options is explicitly passed (both with and without grpc.max_metadata_size already set).

    def test_secure_authorized_channel_pqc_max_metadata_size(
        self,
        secure_channel,
        ssl_channel_credentials,
        metadata_call_credentials,
        composite_channel_credentials,
        get_client_ssl_credentials,
    ):
        credentials = mock.Mock()
        request = mock.Mock()
        target = "example.com:80"
        ssl_credentials = mock.Mock()

        # Call without explicit options; should automatically add grpc.max_metadata_size=32768
        google.auth.transport.grpc.secure_authorized_channel(
            credentials, request, target, ssl_credentials=ssl_credentials
        )

        _, kwargs = secure_channel.call_args
        assert "options" in kwargs
        assert ("grpc.max_metadata_size", 32768) in kwargs["options"]

        # Call with explicit options not containing grpc.max_metadata_size
        google.auth.transport.grpc.secure_authorized_channel(
            credentials,
            request,
            target,
            ssl_credentials=ssl_credentials,
            options=[("some_option", 1)],
        )
        _, kwargs = secure_channel.call_args
        assert ("some_option", 1) in kwargs["options"]
        assert ("grpc.max_metadata_size", 32768) in kwargs["options"]

        # Call with explicit options already containing grpc.max_metadata_size
        google.auth.transport.grpc.secure_authorized_channel(
            credentials,
            request,
            target,
            ssl_credentials=ssl_credentials,
            options=[("grpc.max_metadata_size", 1024)],
        )
        _, kwargs = secure_channel.call_args
        assert ("grpc.max_metadata_size", 1024) in kwargs["options"]
        assert ("grpc.max_metadata_size", 32768) not in kwargs["options"]

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant