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

add BackendSecurityPolicy for traffic (authN/authZ) from gateway to provider #43

Open
wants to merge 45 commits into
base: main
Choose a base branch
from

Conversation

aabchoo
Copy link

@aabchoo aabchoo commented Dec 12, 2024

  • add backend security policy for traffic from gateway to backend provider
  • introduces api key, oidc, and static key auth
  • add reference to backendSecurityPolicy on llmbackend
  • add provider type on llmbackend

api/v1alpha1/api.go Outdated Show resolved Hide resolved
@aabchoo aabchoo force-pushed the aaron/authorization-api branch 2 times, most recently from 52e389b to 89ee946 Compare December 12, 2024 19:35
aabchoo and others added 7 commits December 12, 2024 14:50
Signed-off-by: Aaron Choo <[email protected]>

Signed-off-by: Aaron Choo <[email protected]>
This commit is a follow up on #20. Basically, this makes LLMRoute
a pure "addition" to the existing standardized HTTPRoute.
This makes it possible to configure something like
```
kind: LLMRoute
metadata:
  name: llm-route
spec:
  inputSchema: OpenAI
  httpRouteRef:
    name: my-llm-route
---
kind: HTTPRoute
metadata:
  name: my-llm-route
spec:
  matches:
     - headers:
         key: x-envoy-ai-gateway-llm-model
         value: llama3-70b
       backendRefs:
       - kserve:
         weight: 20
       - aws-bedrock:
         weight: 80
```

where LLMRoute is purely referencing HTTPRoute and
users can configure whatever routing condition in a standardized way
via HTTPRoute while leveraging the LLM specific information, in this
case
x-envoy-ai-gateway-llm-model header.

In the implementation, though it's not merged yet, we have to do the
routing calculation in the extproc by actually analyzing the referenced
HTTPRoute, and emulate the behavior in order to do the transformation.
The reason is that the routing decision is made at the very end of
filter chain
in general, and by the time we invoke extproc, we don't have that info.
Furthermore, `x-envoy-ai-gateway-llm-model` is not available before
extproc.

As a bonus of this, we no longer need TargetRef at LLMRoute level since
that's within
the HTTPRoute resources. This will really simplify the PoC
implementation.

---------

Signed-off-by: Takeshi Yoneda <[email protected]>
This adds `backendRef` to LLMBackendSpec which specifies
the "backend" either Service or Backend resource of Envoy Gateway.

The choice of not embedding is intentional - A backend can be a target
of routing in HTTPRoute and can be either of these two types. Hence
this is not suitable for embedding. In addition, in the implementation, 
we won't directly use or reference them, but just simply attach the 
necessary logic by the names, so basically no benefit by doing so.

---------

Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
@aabchoo aabchoo force-pushed the aaron/authorization-api branch from 9fb8a19 to ea69193 Compare December 12, 2024 19:54
Signed-off-by: Aaron Choo <[email protected]>
api/v1alpha1/api.go Outdated Show resolved Hide resolved
api/v1alpha1/api.go Outdated Show resolved Hide resolved
@aabchoo aabchoo force-pushed the aaron/authorization-api branch from a829fe8 to 57e0fa1 Compare December 13, 2024 15:38
api/v1alpha1/api.go Outdated Show resolved Hide resolved
api/v1alpha1/api.go Outdated Show resolved Hide resolved
api/v1alpha1/api.go Outdated Show resolved Hide resolved
Signed-off-by: Aaron Choo <[email protected]>
@aabchoo aabchoo force-pushed the aaron/authorization-api branch from 19c1337 to d2f72ed Compare December 16, 2024 15:56
api/v1alpha1/api.go Outdated Show resolved Hide resolved
api/v1alpha1/api.go Outdated Show resolved Hide resolved
aabchoo and others added 5 commits January 3, 2025 09:24
Co-authored-by: Dan Sun <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
@aabchoo aabchoo requested review from arkodg and removed request for zhaohuabing January 3, 2025 20:37
api/v1alpha1/api.go Outdated Show resolved Hide resolved
@yuzisun
Copy link
Contributor

yuzisun commented Jan 4, 2025

@mathetake @arkodg @zhaohuabing can you take another look?

api/v1alpha1/api.go Outdated Show resolved Hide resolved
api/v1alpha1/api.go Outdated Show resolved Hide resolved
api/v1alpha1/api.go Outdated Show resolved Hide resolved
Copy link
Member

@mathetake mathetake left a comment

Choose a reason for hiding this comment

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

LGTM per nits above!

Comment on lines +113 to +114
// +optional
BackendSecurityPolicyRef *gwapiv1.LocalObjectReference `json:"backendSecurityPolicyRef,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

can you add a CEL validation to ensure that both apiKey and cloudProviderCredentials won't be defined at the same time

Copy link
Author

Choose a reason for hiding this comment

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

I've set a MaxProperties validation to 2

This will allow for the combos:
(BackendSecurityPolicyType AND (BackendSecurityPolicyAPIKey OR BackendSecurityPolicyCloudProviderCredentials))

// CloudProviderCredentials is a mechanism to access a backend(s). Cloud provider specific logic will be applied.
//
// +optional
CloudProviderCredentials *AuthenticationCloudProviderCredentials `json:"cloudProviderCredentials,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

so i wonder what kind of logic will make cloud providers special compared to others (currently only apiKey though). how do you envision this additional indirect layer will be used? in other words, what kind of logic will be shared among cloud providers

Copy link
Contributor

@yuzisun yuzisun Jan 4, 2025

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

yeah i get that it's complex, but my question is why this another layer is needed and what kind of logic will be shared among cloud providers? what becomes difficult to achieve when you have *AWSCredentials directly here without another layer of AuthenticationCloudProviderCredentials. How does having AuthenticationCloudProviderCredentials helps implement various cloud providers vs having them in here

Copy link
Contributor

Choose a reason for hiding this comment

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

This is mainly a yaml UX, the additional layer for grouping is there for readability, if we list the individual types then it is not intuitive for user to see the classification. The cloud provider security implementations are different but they share the same high level concepts.

api/v1alpha1/api.go Outdated Show resolved Hide resolved
aabchoo and others added 9 commits January 6, 2025 14:54
Co-authored-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
Co-authored-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
Co-authored-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
Co-authored-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Aaron Choo <[email protected]>
api/v1alpha1/api.go Show resolved Hide resolved
// Only one type of BackendSecurityPolicy can be defined.
// +kubebuilder:validation:MaxProperties=2
type BackendSecurityPolicySpec struct {
// Type specifies the auth mechanism used to access the provider. Currently, only "APIKey", AND "AWS_IAM" are supported.
Copy link
Member

Choose a reason for hiding this comment

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

well, shouldn't the type be "CloudProviders" instead of AWS_IAM? The "type" field is for union type assertion and this feels a weird because AWS_IAM is not for the union type assertion but for the higher layer. @yuzisun @arkodg

Copy link
Member

Choose a reason for hiding this comment

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

This is relevant to the thread to #43 (comment) I am still not convinced by the "Yaml UX" stuff there. I am fine with that but at least to be consistent could you make this CloudProviders and have a type inside it for a specific cloud provider? (which i think is a worse UX vs the flat one)

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.

6 participants