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

chore: add proxy support #67

Merged
merged 2 commits into from
Nov 18, 2022
Merged

chore: add proxy support #67

merged 2 commits into from
Nov 18, 2022

Conversation

pgautier404
Copy link
Collaborator

@pgautier404 pgautier404 commented Nov 16, 2022

This contains initial R&D on adding proxy support in SimpleCacheClient. It adds a proxy-aware credential provider to route gRPC calls through a proxy (currently haproxy on layer 4) to the appropriate Momento endpoints. The proxy endpoints are passed in the constructor to the credential provider and the Momento endpoints are parsed out of the JWT token as before.

An haproxy instance configured to send requests on to the Momento backend is required to successfully run the proxy-example.php example. You can add the below configuration to your haproxy.cfg (after replacing the placeholders with the actual hostnames from your JWT in the server directives) to work with the configuration expected by that script.

frontend control-plane-fe
  bind momento-control:4443
  option tcplog
  mode tcp
  default_backend control-plane-be

backend control-plane-be
  mode tcp
  server server1 [control-plane-hostname-from-JWT]:443

frontend data-plane-fe
  bind momento-cache:4444
  option tcplog
  mode tcp
  default_backend data-plane-fe

backend data-plane-fe
  mode tcp
  server server1 [data-plane-hostname-from-JWT]:443

Copy link
Contributor

@cprice404 cprice404 left a comment

Choose a reason for hiding this comment

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

this is looking great, the way you got it working seems totally reasonable to me. Just need to finalize our API design.

As an artifact of this ticket I'd appreciate it if you could file a PR against standards and practices repo that includes the haproxy config that you included in your commit message, and a few (language-agnostic) words about how we support reverse proxying and when it might be useful. Then we can add a bit more detail to the README in this repo and include a link to the s&p doc

"MOMENTO_AUTH_TOKEN",
"momento-control:4443",
"momento-cache:4444"
);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is so much other code in this example that this bit gets lost in the noise. tbh I think if we want to have a proxy example it should probably just have the auth provider instantiation, with more comments about what it's doing and why, and then like one call to "listCaches" or something. and we should remove the rest of the stuff that's duplicated from the other examples so that their attention is drawn to the important thing.

public function getCacheProxyEndpoint(): string|null
{
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Left you some input in slack about some other ideas for this interface.

@pgautier404 pgautier404 force-pushed the proxy-support branch 3 times, most recently from 24101cf to bccc429 Compare November 18, 2022 20:16
@pgautier404 pgautier404 marked this pull request as ready for review November 18, 2022 20:19
Copy link
Contributor

@cprice404 cprice404 left a comment

Choose a reason for hiding this comment

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

nits, could be handled in separate pr

mode tcp
default_backend cache-plane-fe

backend cache-plane-fe
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be -be

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thanks.

```php
$authProvider = new EnvMomentoTokenProvider(
// name of the environment variable that contains our auth token
"MOMENTO_AUTH_TOKEN",
Copy link
Contributor

Choose a reason for hiding this comment

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

does php support named args?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does, I'll add them in, thanks.

if (!$this->allAreDefined($endpointArgs)) {
throw new InvalidArgumentError(
"If any of controlEndpoint, cacheEndpoint, trustedCacheEndpointCertificateName, or " .
"trustedControlEndpointCertificateName are provided, they must all be.");
Copy link
Contributor

Choose a reason for hiding this comment

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

you can address this in a follow-up pr but why would we disallow the first two being passed by themselves?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point.

@pgautier404
Copy link
Collaborator Author

I'll address all feedback in a followup PR coming up in just a minute.

@pgautier404 pgautier404 merged commit 3693980 into main Nov 18, 2022
@malandis malandis deleted the proxy-support branch November 1, 2024 21:19
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.

2 participants