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

Enable test mode on API gateway #389

Merged
merged 12 commits into from
Sep 11, 2023
Merged

Enable test mode on API gateway #389

merged 12 commits into from
Sep 11, 2023

Conversation

nicoloboschi
Copy link
Member

@nicoloboschi nicoloboschi commented Sep 8, 2023

Changes:

  • Added boolean field allow-test-mode to the authentication gateway field. By default is true.
- id: consume-output-auth-github
      type: consume
      topic: output-topic
      authentication:
        provider: github
        configuration:
          clientId: "{{ secrets.github.client-id }}"
        allow-test-mode: true
  • In the api gateway it's possible to configure the test gateway authentication provider
  • The principal values are computed based on the input credentials. The computation is sha256+base64. Better to not "store" test credentials in plain text, but the computed value must be the same for the same token/credential.

There are two new auth implementations:

  • http that performs a GET to a fixed url passing the header and check the status
  • jwt that performs JWT validation

They can be used also by the gateway for production authentications.

  • The client needs to pass a test-credentials param instead of credentials to enter the test mode.

Client connect string example with token:

ws://localhost:8091/v1/consume/tenant1/application1/consume?test-credentials=TOKEN
  • In the api gateway, you have to configure the test auth provider

HTTP

application.gateways.auth.test.type=http
application.gateways.auth.test.configuration.base-url=http://xxxx
application.gateways.auth.test.configuration.path-template=/token/{tenant}
application.gateways.auth.test.configuration.headers.myheader=myvalue
application.gateways.auth.test.configuration.accepted-statuses=200,201	

JWT

application.gateways.auth.test.type=jwt
application.gateways.auth.test.configuration.secretKey=xxx
application.gateways.auth.test.configuration.authClaim=sub
application.gateways.auth.test.configuration.adminRoles=adminuser

@nicoloboschi nicoloboschi marked this pull request as draft September 8, 2023 15:54
@@ -21,20 +21,20 @@ gateways:
topic: input-topic
parameters:
- sessionId
produceOptions:
produce-options:
Copy link
Member

Choose a reason for hiding this comment

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

this reads like a breaking change and we have stuff in production, please don't do it

Copy link
Member Author

Choose a reason for hiding this comment

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

no it's not, it's an alias and they both work

Copy link
Member

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Nice work but:

  • I don't think we need a separate class hierarchy, we can make jwt and http regular authentication providers
  • I don't think we need the ability to override the values (if we need it then we have to configure it statically somewhere, not let the client override security related pieces of information)
  • I don't think we need to have a different admin-credentials parameter, it is enough to have "credentials"

My idea is that if you enable the system authentication then you gateway accepts also the credentials for the system provider and run the authentication flow.

The question maybe is "how do the gateway know that the client is authenticating with one provider, like Google, or another provider, like the System provider ?"

if that's the problem maybe it is good to have "admin-credentials", but I won't create different class hierarchies for the "System Gateway Authentication" and the regular Gateway Authentication

import java.util.Map;
import lombok.SneakyThrows;

public class JwtAdminAuthenticationProvider implements GatewayAdminAuthenticationProvider {
Copy link
Member

Choose a reason for hiding this comment

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

why only "admin", we can make it a regular implementation

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HttpAdminAuthenticationProvider implements GatewayAdminAuthenticationProvider {
Copy link
Member

Choose a reason for hiding this comment

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

why only "admin", we can make it a regular implementation

@@ -30,5 +30,7 @@
<modules>
<module>langstream-google-api-gateway-auth</module>
<module>langstream-github-api-gateway-auth</module>
<module>langstream-jwt-gateway-admin-auth</module>
Copy link
Member

Choose a reason for hiding this comment

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

I would drop "admin" from everywhere

}

final GatewayAdminAuthenticationProvider gatewayAdminAuthenticationProvider =
adminAuthProviders.get(provider);
Copy link
Member

Choose a reason for hiding this comment

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

I think that we shouldn't let the client decide which provider,
there will be only one configured, there is no need to have more

Map<String, String> pathVars,
Map<String, String> queryString,
Map<String, String> httpHeaders) {
Map<String, String> options = new HashMap<>();
Map<String, String> userParameters = new HashMap<>();

final String credentials = queryString.remove("credentials");
final String adminCredentials = queryString.remove("admin-credentials");
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there is need to have a different parameter


for (Map.Entry<String, String> entry : queryString.entrySet()) {
if (entry.getKey().startsWith("admin-credentials-input-")) {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure we need this thing, it seems like a security hole, what's the use case ?

@@ -42,4 +42,26 @@ public static GatewayAuthenticationProvider loadProvider(
store.initialize(configuration);
return store;
}

public static GatewayAdminAuthenticationProvider loadAdminProvider(
Copy link
Member

Choose a reason for hiding this comment

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

no need to have a different mechanism

@@ -67,6 +67,21 @@ public class ChatGatewayCmd extends BaseGatewayCmd {
description = "Connect timeout for WebSocket connections in seconds.")
private long connectTimeoutSeconds = 0;

@CommandLine.Option(
Copy link
Member

Choose a reason for hiding this comment

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

no need

@nicoloboschi nicoloboschi changed the title Enable admin authentication on API gateway Enable test mode on API gateway Sep 11, 2023
@nicoloboschi nicoloboschi marked this pull request as ready for review September 11, 2023 12:58
Copy link
Member

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

@nicoloboschi nicoloboschi merged commit 0b72100 into main Sep 11, 2023
8 checks passed
@nicoloboschi nicoloboschi deleted the jwt-on-gw branch September 11, 2023 13:24
benfrank241 pushed a commit to vectorize-io/langstream that referenced this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants