-
Notifications
You must be signed in to change notification settings - Fork 830
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.luaValidation) || !has(self.lua)",message="only one of luaValidation or lua may be set" | ||
| // +kubebuilder:validation:XValidation:message="mergeGateways and mergeBackends cannot both be enabled",rule="!(has(self.mergeGateways) && self.mergeGateways && has(self.mergeBackends))" | ||
| type EnvoyProxySpec struct { | ||
| // Provider defines the desired resource provider and provider-specific configuration. | ||
|
|
@@ -200,9 +201,19 @@ type EnvoyProxySpec struct { | |
|
|
||
| // LuaValidation determines strictness of the Lua script validation for Lua EnvoyExtensionPolicies | ||
| // Default: Strict | ||
| // | ||
| // Deprecated: Use Lua.ValidationType instead. This field will be removed in a future release. | ||
| // +optional | ||
| LuaValidation *LuaValidation `json:"luaValidation,omitempty"` | ||
|
|
||
| // Lua configures how Lua scripts from EnvoyExtensionPolicy resources are | ||
| // validated in the gateway controller. It selects the validation mode and, for the Strict | ||
| // mode, defines the filesystem paths and environment variables the scripts are permitted to | ||
| // access during validation. | ||
| // | ||
| // +optional | ||
| Lua *LuaValidationConfig `json:"lua,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 | ||
|
|
@@ -269,6 +280,66 @@ const ( | |
| LuaValidationDisabled LuaValidation = "Disabled" | ||
| ) | ||
|
|
||
| // LuaValidationConfig configures how Lua scripts from EnvoyExtensionPolicy resources are validated | ||
| // in the gateway controller. | ||
| // | ||
| // +union | ||
| // +kubebuilder:validation:XValidation:rule="!has(self.strictValidation) || !has(self.validationType) || self.validationType == 'Strict'",message="strictValidation can only be set when validationType is Strict" | ||
| type LuaValidationConfig struct { | ||
| // ValidationType determines the strictness of the Lua script validation. | ||
| // Default: Strict | ||
| // | ||
| // +unionDiscriminator | ||
| // +kubebuilder:default=Strict | ||
| // +optional | ||
| ValidationType *LuaValidation `json:"validationType,omitempty"` | ||
|
|
||
| // StrictValidation configures the security sandbox that the Strict validation mode executes Lua | ||
| // scripts in, defining the filesystem paths and environment variables the scripts are permitted | ||
| // to access during validation. | ||
| // | ||
| // It has no effect for the InsecureSyntax or Disabled modes, which do not execute the security | ||
| // sandbox. | ||
| // | ||
| // +optional | ||
| StrictValidation *StrictValidation `json:"strictValidation,omitempty"` | ||
| } | ||
|
|
||
| // StrictValidation 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 StrictValidation 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. The filesystem root ("/") | ||
| // is likewise rejected, as it would allow access to the entire filesystem and defeat 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" | ||
| // +kubebuilder:validation:XValidation:rule="self.all(p, !p.matches('^/+$'))",message="allowedPaths entries must not be the filesystem root" | ||
| // +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 | ||
|
|
||
|
|
@@ -700,6 +771,8 @@ type EnvoyProxyConditionType string | |
|
|
||
| const ( | ||
| EnvoyProxyConditionAccepted EnvoyProxyConditionType = "Accepted" | ||
|
|
||
| EnvoyProxyConditionWarning EnvoyProxyConditionType = "Warning" | ||
| ) | ||
|
|
||
| type EnvoyProxyConditionReason string | ||
|
|
@@ -708,6 +781,8 @@ const ( | |
| EnvoyProxyReasonAccepted EnvoyProxyConditionReason = "Accepted" | ||
|
|
||
| EnvoyProxyReasonInvalidParameters EnvoyProxyConditionReason = "InvalidParameters" | ||
|
|
||
| EnvoyProxyReasonDeprecatedField EnvoyProxyConditionReason = "DeprecatedField" | ||
| ) | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
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.
FYI: added this new validation as well