Skip to content

Commit b8ca958

Browse files
authored
feat: introduce validation levels for lua (#6355)
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
1 parent c05d438 commit b8ca958

File tree

14 files changed

+74
-35
lines changed

14 files changed

+74
-35
lines changed

api/v1alpha1/envoyproxy_types.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,27 @@ type EnvoyProxySpec struct {
158158
// +optional
159159
PreserveRouteOrder *bool `json:"preserveRouteOrder,omitempty"`
160160

161-
// DisableLuaValidation disables the Lua script validation for Lua EnvoyExtensionPolicies
162-
// +kubebuilder:default=false
161+
// LuaValidation determines strictness of the Lua script validation for Lua EnvoyExtensionPolicies
162+
// Default: Strict
163163
// +optional
164-
DisableLuaValidation *bool `json:"disableLuaValidation,omitempty"`
164+
LuaValidation *LuaValidation `json:"luaValidation,omitempty"`
165165
}
166166

167+
// +kubebuilder:validation:Enum=Strict;Disabled
168+
type LuaValidation string
169+
170+
const (
171+
// LuaValidationStrict is the default level and checks for issues during script execution.
172+
// Recommended if your scripts only use the standard Envoy Lua stream handle API.
173+
// For supported APIs, see: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#stream-handle-api
174+
LuaValidationStrict LuaValidation = "Strict"
175+
176+
// LuaValidationDisabled disables all validation of Lua scripts.
177+
// Scripts will be accepted and executed without any validation checks.
178+
// This is not recommended unless your scripts import libraries that are not supported by Lua runtime validation.
179+
LuaValidationDisabled LuaValidation = "Disabled"
180+
)
181+
167182
// RoutingType defines the type of routing of this Envoy proxy.
168183
type RoutingType string
169184

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyproxies.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,6 @@ spec:
270270
the number of cpuset threads on the platform.
271271
format: int32
272272
type: integer
273-
disableLuaValidation:
274-
default: false
275-
description: DisableLuaValidation disables the Lua script validation
276-
for Lua EnvoyExtensionPolicies
277-
type: boolean
278273
extraArgs:
279274
description: |-
280275
ExtraArgs defines additional command line options that are provided to Envoy.
@@ -442,6 +437,14 @@ spec:
442437
and the log level is the value. If unspecified, defaults to "default: warn".
443438
type: object
444439
type: object
440+
luaValidation:
441+
description: |-
442+
LuaValidation determines strictness of the Lua script validation for Lua EnvoyExtensionPolicies
443+
Default: Strict
444+
enum:
445+
- Strict
446+
- Disabled
447+
type: string
445448
mergeGateways:
446449
description: |-
447450
MergeGateways defines if Gateway resources should be merged onto the same Envoy Proxy Infrastructure.

charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,6 @@ spec:
269269
the number of cpuset threads on the platform.
270270
format: int32
271271
type: integer
272-
disableLuaValidation:
273-
default: false
274-
description: DisableLuaValidation disables the Lua script validation
275-
for Lua EnvoyExtensionPolicies
276-
type: boolean
277272
extraArgs:
278273
description: |-
279274
ExtraArgs defines additional command line options that are provided to Envoy.
@@ -441,6 +436,14 @@ spec:
441436
and the log level is the value. If unspecified, defaults to "default: warn".
442437
type: object
443438
type: object
439+
luaValidation:
440+
description: |-
441+
LuaValidation determines strictness of the Lua script validation for Lua EnvoyExtensionPolicies
442+
Default: Strict
443+
enum:
444+
- Strict
445+
- Disabled
446+
type: string
444447
mergeGateways:
445448
description: |-
446449
MergeGateways defines if Gateway resources should be merged onto the same Envoy Proxy Infrastructure.

internal/cmd/egctl/testdata/translate/out/invalid-envoyproxy.all.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ envoyProxyForGatewayClass:
1919
socket_address:
2020
address: 127.0.0.1
2121
port_value: 19000
22-
disableLuaValidation: false
2322
logging:
2423
level:
2524
default: warn

internal/cmd/egctl/testdata/translate/out/valid-envoyproxy.all.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ envoyProxyForGatewayClass:
66
name: example
77
namespace: default
88
spec:
9-
disableLuaValidation: false
109
logging:
1110
level:
1211
default: warn

internal/gatewayapi/envoyextensionpolicy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ func (t *Translator) buildLua(
452452
if err != nil {
453453
return nil, err
454454
}
455-
if envoyProxy != nil && envoyProxy.Spec.DisableLuaValidation != nil && *envoyProxy.Spec.DisableLuaValidation {
455+
if envoyProxy != nil && envoyProxy.Spec.LuaValidation != nil &&
456+
*envoyProxy.Spec.LuaValidation == egv1a1.LuaValidationDisabled {
456457
return &ir.Lua{
457458
Name: name,
458459
Code: luaCode,

internal/gatewayapi/resource/testdata/all-resources.out.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ envoyProxyForGatewayClass:
169169
name: example
170170
namespace: default
171171
spec:
172-
disableLuaValidation: false
173172
logging:
174173
level:
175174
default: warn

internal/gatewayapi/testdata/envoyextensionpolicy-with-invalid-lua-validation-disabled.in.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ envoyProxyForGatewayClass:
55
namespace: envoy-gateway-system
66
name: test
77
spec:
8-
disableLuaValidation: true
8+
luaValidation: Disabled
99
gateways:
1010
- apiVersion: gateway.networking.k8s.io/v1
1111
kind: Gateway

internal/gatewayapi/testdata/envoyextensionpolicy-with-invalid-lua-validation-disabled.out.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ infraIR:
120120
name: test
121121
namespace: envoy-gateway-system
122122
spec:
123-
disableLuaValidation: true
124123
logging: {}
124+
luaValidation: Disabled
125125
status: {}
126126
listeners:
127127
- address: null

0 commit comments

Comments
 (0)