-
Notifications
You must be signed in to change notification settings - Fork 820
feat: whitelist for allowed env and paths for lua #9220
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ type EnvoyProxy struct { | |
| } | ||
|
|
||
| // EnvoyProxySpec defines the desired state of EnvoyProxy. | ||
| // +kubebuilder:validation:XValidation:rule="!has(self.luaStrictValidation) || !has(self.luaValidation) || self.luaValidation == 'Strict'",message="luaStrictValidation can only be set when luaValidation is Strict" | ||
| type EnvoyProxySpec struct { | ||
| // Provider defines the desired resource provider and provider-specific configuration. | ||
| // If unspecified, the "Kubernetes" resource provider is used with default configuration | ||
|
|
@@ -189,6 +190,20 @@ type EnvoyProxySpec struct { | |
| // +optional | ||
| LuaValidation *LuaValidation `json:"luaValidation,omitempty"` | ||
|
|
||
| // LuaStrictValidation defines the filesystem paths and environment variables that Lua | ||
| // scripts from EnvoyExtensionPolicy resources are permitted to access during Strict | ||
| // validation in the gateway controller. | ||
| // | ||
| // The allowlist is fail-closed: when unset or empty, Lua scripts are denied access to ALL | ||
| // filesystem paths and environment variables during validation. Only entries that match the | ||
| // allowlist are permitted. | ||
| // | ||
| // This field only takes effect when LuaValidation is Strict (the default). It has no effect | ||
| // for the InsecureSyntax or Disabled validation modes, which do not execute the security sandbox. | ||
| // | ||
| // +optional | ||
| LuaStrictValidation *LuaStrictValidation `json:"luaStrictValidation,omitempty"` | ||
|
|
||
| // DynamicModules defines the set of dynamic modules that are allowed to be | ||
| // used by EnvoyExtensionPolicy resources and dynamic module load balancer | ||
| // policies. Each entry registers a module by a logical name and specifies | ||
|
|
@@ -250,6 +265,39 @@ const ( | |
| LuaValidationDisabled LuaValidation = "Disabled" | ||
| ) | ||
|
|
||
| // LuaStrictValidation defines the configuration that Strict Lua validation runs with. | ||
| // | ||
| // This configuration only applies to the Strict validation mode; it has no effect on the | ||
| // InsecureSyntax and Disabled modes. | ||
| type LuaStrictValidation struct { | ||
| // AllowedPaths is the list of filesystem path prefixes that Lua scripts are permitted to | ||
| // access during validation (via io.open, io.input, io.output, io.lines, os.remove, os.rename). | ||
| // A path is allowed when it equals an entry or is contained within an entry's subtree | ||
| // (e.g. "/tmp" allows "/tmp/file.txt"). Paths are normalized (separators collapsed, made | ||
| // absolute) before matching, and any "." or ".." traversal segment is always rejected. | ||
| // When empty, all filesystem access is denied. Blank or whitespace-only entries are rejected, | ||
| // as they would otherwise match every path and disable the sandbox. | ||
| // | ||
| // +kubebuilder:validation:MaxItems=64 | ||
| // +kubebuilder:validation:items:MinLength=1 | ||
| // +kubebuilder:validation:items:MaxLength=4096 | ||
| // +kubebuilder:validation:XValidation:rule="self.all(p, p.trim() != '')",message="allowedPaths entries must not be blank or whitespace-only" | ||
| // +optional | ||
| AllowedPaths []string `json:"allowedPaths,omitempty"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the configuration looks a little redundant. luaValidationAllowlist:
allowedPaths:what about using following? luaValidation:
allowedPaths:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem is there is an existing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm mostly concerts with the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it how about:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me. |
||
|
|
||
| // AllowedEnvVars is the list of environment variable names that Lua scripts are permitted to | ||
| // access during validation (via os.getenv, os.setenv). Matching is exact and case-sensitive. | ||
| // When empty, access to all environment variables is denied. Blank or whitespace-only entries | ||
| // are rejected. | ||
| // | ||
| // +kubebuilder:validation:MaxItems=64 | ||
| // +kubebuilder:validation:items:MinLength=1 | ||
| // +kubebuilder:validation:items:MaxLength=256 | ||
| // +kubebuilder:validation:XValidation:rule="self.all(e, e.trim() != '')",message="allowedEnvVars entries must not be blank or whitespace-only" | ||
| // +optional | ||
| AllowedEnvVars []string `json:"allowedEnvVars,omitempty"` | ||
| } | ||
|
|
||
| // RoutingType defines the type of routing of this Envoy proxy. | ||
| type RoutingType string | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
naive question: does this only worked when LuaValidation=Strict?
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.
Yes, because we don't do any security validation in non-strict modes.
Uh oh!
There was an error while loading. Please reload this page.
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.
Actually let me add a CEL validation for this
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.
if so, I'm wandering should we make a breaking change to luaValidation like following:
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.
Yes I was trying to avoid a breaking change. Since we don't do any kind of validation that requires settings in other modes, having a separate one for strict only can be ok ig?
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.
@envoyproxy/gateway-maintainers any opinions?
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.
Suggest deprecating
luaValidationand adding a union.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.
Works, with minor renames if that feels more intuitive:
LuaScriptValidation->LuaValidationConfigLuaStrictValidation->StrictValidation(since it is already underLuaValidationConfigWDYT @zhaohuabing ?
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.
+1 to a new top level lua field