-
Notifications
You must be signed in to change notification settings - Fork 392
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
feat: implement Lua EnvoyExtensionPolicy #5171
Open
rudrakhp
wants to merge
1
commit into
envoyproxy:main
Choose a base branch
from
rudrakhp:feat_lua_extension
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,105
−14
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package luavalidator | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"strings" | ||
|
||
lua "github.com/yuin/gopher-lua" | ||
) | ||
|
||
// mockData contains mocks of Envoy supported APIs for Lua filters. | ||
// Refer: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#stream-handle-api | ||
// | ||
//go:embed mocks.lua | ||
var mockData []byte | ||
|
||
// LuaValidator validates user provided Lua for compatibility with Envoy supported Lua HTTP filter | ||
type LuaValidator struct { | ||
body string | ||
} | ||
|
||
// NewLuaValidator returns a LuaValidator for user provided Lua body | ||
func NewLuaValidator(body string) *LuaValidator { | ||
return &LuaValidator{ | ||
body: body, | ||
} | ||
} | ||
|
||
// Validate runs all validations for the LuaValidator | ||
func (l *LuaValidator) Validate() error { | ||
if !strings.Contains(l.body, "envoy_on_request") && !strings.Contains(l.body, "envoy_on_response") { | ||
return fmt.Errorf("expected one of envoy_on_request() or envoy_on_response() to be defined") | ||
} | ||
if strings.Contains(l.body, "envoy_on_request") { | ||
if err := l.runLua(string(mockData) + "\n" + l.body + "\nenvoy_on_request(StreamHandle)"); err != nil { | ||
return fmt.Errorf("failed to mock run envoy_on_request: %w", err) | ||
} | ||
} | ||
if strings.Contains(l.body, "envoy_on_response") { | ||
if err := l.runLua(string(mockData) + "\n" + l.body + "\nenvoy_on_response(StreamHandle)"); err != nil { | ||
return fmt.Errorf("failed to mock run envoy_on_response: %w", err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// runLua interprets and runs the provided Lua body in runtime | ||
func (l *LuaValidator) runLua(body string) error { | ||
L := lua.NewState() | ||
defer L.Close() | ||
if err := L.DoString(body); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add CEL validations to ensure that
inline
must be configured forinline
type andvalueRef
must be configured forvalueRef
type?Similar to:
gateway/api/v1alpha1/shared_types.go
Lines 730 to 731 in c492089