Skip to content

Build failure in grpc-js-xds: TS2345 type mismatch on PeerCertificate.subject.CN in rbac.ts #3041

@ganesh-tn

Description

@ganesh-tn

Problem description

Problem descriptionWhen compiling the @grpc/grpc-js-xds package with strict TypeScript checks, the build fails with a TS2345 error due to a type mismatch on PeerCertificate.subject.CN. The Node.js TLS definitions correctly type this as string | string[] | undefined, but the codebase passes it directly to nameMatcher.apply(), which strictly expects a string. This results in an exit code 1 and aborts automated Docker builds.

Reproduction steps

  1. Pull the Docker base image docker.io/library/node:18-bookworm.
  2. Clone the grpc/grpc-node repository and checkout commit 61208ea8557bdfa2d9ff5ce64e15943ae493c3e7.
  3. Navigate to the packages/grpc-js-xds directory.
  4. Run the build command: npm run generate-types && npm run generate-interop-types && npm run generate-test-types && npm run compile.
  5. Observe the TypeScript compiler fail on src/rbac.ts at line 228.

Environment

  • OS name, version and architecture: Host is Ubuntu 20.04.6 LTS x86_64; Container is Debian Bookworm (node:18-bookworm Docker image).
  • Node version: 18.x (via node:18-bookworm).
  • Node installation method: Docker Image.
  • If applicable, compiler version: tsc (TypeScript version bundled with @grpc/grpc-js-xds@1.13.0 dev dependencies).
  • Package name and version: @grpc/grpc-js-xds@1.13.0.

Additional context

This failure was observed during the automated Kokoro CI build for grpc_e2e_performance_gke. The specific compiler error output is:

src/rbac.ts:228:35 - error TS2345: Argument of type 'string | string[] | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.

228     return this.nameMatcher.apply(info.peerCertificate.subject.CN);
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in src/rbac.ts:228
npm error code 1
npm error path /pre/packages/grpc-js-xds

The issue stems from the assumption that the certificate's Common Name (CN) is always a strictly defined string, which conflicts with modern @types/node definitions reflecting that a CN can be an array or undefined. Adding a type guard or fallback string before nameMatcher.apply() should resolve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions