Skip to content

Commit

Permalink
add istio policies
Browse files Browse the repository at this point in the history
  • Loading branch information
anusha94 committed Feb 26, 2025
1 parent 6e5b71e commit 6641881
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 38 deletions.
38 changes: 0 additions & 38 deletions tetrate/tis0102/restrict-invalid-http-method.yaml

This file was deleted.

48 changes: 48 additions & 0 deletions tetrate/tis0102/restrict-invalid-method-authorization-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
annotations:
policies.kyverno.io/category: Security
policies.kyverno.io/description: |
This policy ensures that in AuthorizationPolicy resources, the spec.rules[].to[].operation.method[] field contains only valid HTTP methods or properly formatted gRPC method names in the form /package.service/method.
policies.kyverno.io/severity: medium
policies.kyverno.io/title: Validate Authorization Policy Methods
name: validate-authorization-policy-methods
spec:
background: true
rules:
- match:
any:
- resources:
kinds:
- AuthorizationPolicy
name: validate-methods
validate:
foreach:
- elementScope: rules
foreach:
- elementScope: to
foreach:
- deny:
conditions:
all:
- key: '{{ element }}'
operator: AnyNotIn
value:
- GET
- POST
- PUT
- DELETE
- PATCH
- HEAD
- OPTIONS
- CONNECT
- TRACE
- key: '{{ regex_match(''^/[a-zA-Z0-9.]+/[a-zA-Z0-9]+$'', element) }}'
operator: Equals
value: false
list: to.operation.methods || []
list: rules.to
list: request.object.spec.rules
message: Methods must be either valid HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT, TRACE) or valid gRPC methods in the form /package.service/method
validationFailureAction: Enforce
38 changes: 38 additions & 0 deletions tetrate/tis0102/restrict-invalid-method-virtualservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
annotations:
policies.kyverno.io/category: Security
policies.kyverno.io/description: Ensures that HTTP methods specified in VirtualService resources are from an allowed set
policies.kyverno.io/severity: medium
policies.kyverno.io/title: Validate VirtualService HTTP Methods
name: validate-vs-http-methods
spec:
background: true
rules:
- match:
any:
- resources:
kinds:
- VirtualService
name: validate-http-methods
validate:
foreach:
- deny:
conditions:
all:
- key: '{{ element }}'
operator: NotIn
value:
- GET
- HEAD
- POST
- PUT
- DELETE
- CONNECT
- OPTIONS
- TRACE
- PATCH
list: request.object.spec.http[*].match[*].method.type
message: 'The HTTP method must be one of: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH'
validationFailureAction: Enforce

0 comments on commit 6641881

Please sign in to comment.