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

How to create secure credentials with custom connection options? #2565

Open
banool opened this issue Sep 1, 2023 · 2 comments
Open

How to create secure credentials with custom connection options? #2565

banool opened this issue Sep 1, 2023 · 2 comments

Comments

@banool
Copy link

banool commented Sep 1, 2023

I have this code at the moment that I use to increase the frame and window sizes:

class CustomChannelCred extends ChannelCredentials {
  constructor(callCredentials?: CallCredentials) {
    super();
  }

  compose(callCredentials: CallCredentials): never {
    throw new Error("Cannot compose insecure credentials");
  }

  _getConnectionOptions(): any {
    return {
      settings: {
        // This will increase the http2 frame size. Default is 16384, which is too small.
        maxFrameSize: 4194304,
        // The initial window size set here is overridden later. We need to patch the grpc-js library to allow this.
        initialWindowSize: 4194304,
        maxHeaderListSize: 8192,
        enablePush: false,
        maxConcurrentStreams: 0,
      },
    };
  }

  _isSecure(): boolean {
    return false;
  }

  _equals(other: ChannelCredentials): boolean {
    return other instanceof CustomChannelCred;
  }
}

Previously I was connecting to an upstream without SSL but that has changed. I can successfully connect to the upstream if I scrap all of that and just use credentials.createSsl(), but then I'm not setting my custom connection options. Making _isSecure return true also doesn't work.

I've tried a variety of ways to create a custom channel credentials class, composing with CallCredentials, etc. but none of that seems to work. I'm reaching for some kind of compose function that works with another instance of ChannelCredentials, but it doesn't exist.

I looked at these docs and they didn't really help either: https://grpc.io/docs/guides/auth/#nodejs.

In short, how can I modify the connection options on an instance of ChannelCredentials?

@banool banool changed the title How to create credentials with custom connection options? How to create secure credentials with custom connection options? Sep 1, 2023
@murgatroid99
Copy link
Member

murgatroid99 commented Sep 1, 2023

Setting custom connection options is not an intended usage of the credentials API. It is just an artifact of how the TLS credentials operate.

We can discuss implementing channel arguments to set those connection options. In particular, regarding the settings you have there:

@banool
Copy link
Author

banool commented Sep 1, 2023

Hahah yeah I could tell from the API that customizing the connection options was not really supported.

Being able to set some of those arguments would be nice indeed, consider this a +1 to the feature request! As it is now, I'm seeing that upgrading from 1.8 to 1.9 actually improves the perf issues we were seeing significantly so this doesn't seem to be a blocker for us anymore.

Thanks a lot for the prompt response!

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

No branches or pull requests

2 participants