Skip to content

Commit

Permalink
Add grpc waf vs test
Browse files Browse the repository at this point in the history
  • Loading branch information
ciarams87 committed Dec 1, 2021
1 parent d334ef9 commit fbc43df
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 3 deletions.
32 changes: 32 additions & 0 deletions tests/data/ap-waf-grpc/grpc-block-saygoodbye.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: appprotect.f5.com/v1beta1
kind: APPolicy
metadata:
name: grpc-block-saygoodbye
spec:
policy:
blocking-settings:
violations:
- name: VIOL_GRPC_METHOD
block: true
alarm: true
applicationLanguage: utf-8
bot-defense:
settings:
isEnabled: false
grpc-profiles:
- associateUrls: true
defenseAttributes:
allowUnknownFields: false
maximumDataLength: "10000"
description: My first profile
idlFiles:
- idlFile:
fileName: autheid.proto
name: gProf1
idl-files:
- isBase64: true
fileName: autheid.proto
contents: Ly8gVGhlIGdyZWV0aW5nIHNlcnZpY2UgZGVmaW5pdGlvbi4KCnN5bnRheCA9ICJwcm90bzMiOwoKcGFja2FnZSBoZWxsb3dvcmxkOwoKc2VydmljZSBHcmVldGVyIHsKICAvLyBTZW5kcyBhIGdyZWV0aW5nCiAgcnBjIFNheUhlbGxvIChIZWxsb1JlcXVlc3QpIHJldHVybnMgKEhlbGxvUmVwbHkpIHt9Cn0KCi8vIFRoZSByZXF1ZXN0IG1lc3NhZ2UgY29udGFpbmluZyB0aGUgdXNlcidzIG5hbWUuCm1lc3NhZ2UgSGVsbG9SZXF1ZXN0IHsKICBzdHJpbmcgbmFtZSA9IDE7Cn0KCi8vIFRoZSByZXNwb25zZSBtZXNzYWdlIGNvbnRhaW5pbmcgdGhlIGdyZWV0aW5ncwptZXNzYWdlIEhlbGxvUmVwbHkgewogIHN0cmluZyBtZXNzYWdlID0gMTsKfQo=
name: valid_string_encoding_policy
template:
name: POLICY_TEMPLATE_NGINX_BASE
32 changes: 32 additions & 0 deletions tests/data/ap-waf-grpc/grpc-block-sayhello.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: appprotect.f5.com/v1beta1
kind: APPolicy
metadata:
name: grpc-block-sayhello
spec:
policy:
blocking-settings:
violations:
- name: VIOL_GRPC_METHOD
block: true
alarm: true
applicationLanguage: utf-8
bot-defense:
settings:
isEnabled: false
grpc-profiles:
- associateUrls: true
defenseAttributes:
allowUnknownFields: false
maximumDataLength: "10000"
description: My first profile
idlFiles:
- idlFile:
fileName: autheid.proto
name: gProf1
idl-files:
- isBase64: true
fileName: autheid.proto
contents: Ly8gVGhlIGdyZWV0aW5nIHNlcnZpY2UgZGVmaW5pdGlvbi4KCnN5bnRheCA9ICJwcm90bzMiOwoKcGFja2FnZSBoZWxsb3dvcmxkOwoKc2VydmljZSBHcmVldGVyIHsKICAvLyBTZW5kcyBhIGdyZWV0aW5nCiAgcnBjIFNheUdvb2RieWUgKEhlbGxvUmVxdWVzdCkgcmV0dXJucyAoSGVsbG9SZXBseSkge30KfQoKLy8gVGhlIHJlcXVlc3QgbWVzc2FnZSBjb250YWluaW5nIHRoZSB1c2VyJ3MgbmFtZS4KbWVzc2FnZSBIZWxsb1JlcXVlc3QgewogIHN0cmluZyBuYW1lID0gMTsKfQoKLy8gVGhlIHJlc3BvbnNlIG1lc3NhZ2UgY29udGFpbmluZyB0aGUgZ3JlZXRpbmdzCm1lc3NhZ2UgSGVsbG9SZXBseSB7CiAgc3RyaW5nIG1lc3NhZ2UgPSAxOwp9Cg==
name: valid_string_encoding_policy
template:
name: POLICY_TEMPLATE_NGINX_BASE
11 changes: 11 additions & 0 deletions tests/data/ap-waf-grpc/logconf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: appprotect.f5.com/v1beta1
kind: APLogConf
metadata:
name: logconf
spec:
content:
format: default
max_message_size: 64k
max_request_size: any
filter:
request_type: all
7 changes: 7 additions & 0 deletions tests/data/ap-waf-grpc/nginx-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: nginx-config
namespace: nginx-ingress
data:
http2: "true"
13 changes: 13 additions & 0 deletions tests/data/ap-waf-grpc/policies/waf-block-saygoodbye.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: k8s.nginx.org/v1
kind: Policy
metadata:
name: waf-policy
spec:
ingressClassName: nginx
waf:
enable: true
apPolicy: "default/grpc-block-saygoodbye"
securityLog:
enable: true
apLogConf: "default/logconf"
logDest: "syslog:server=127.0.0.1:514"
12 changes: 12 additions & 0 deletions tests/data/ap-waf-grpc/policies/waf-block-sayhello.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: k8s.nginx.org/v1
kind: Policy
metadata:
name: waf-policy
spec:
waf:
enable: true
apPolicy: "default/grpc-block-sayhello"
securityLog:
enable: true
apLogConf: "default/logconf"
logDest: "syslog:server=127.0.0.1:514"
70 changes: 70 additions & 0 deletions tests/data/ap-waf-grpc/syslog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: syslog
spec:
replicas: 1
selector:
matchLabels:
app: syslog
template:
metadata:
labels:
app: syslog
spec:
containers:
- name: syslog
image: balabit/syslog-ng:3.31.2-buster
ports:
- containerPort: 514
- containerPort: 601
volumeMounts:
- name: config-volume
mountPath: /etc/syslog-ng/syslog-ng.conf
subPath: syslog-ng.conf
volumes:
- name: config-volume
configMap:
name: syslog-config
---
apiVersion: v1
kind: Service
metadata:
name: syslog-svc
spec:
ports:
- port: 514
targetPort: 514
protocol: TCP
selector:
app: syslog
---
apiVersion: v1
kind: ConfigMap
metadata:
name: syslog-config
data:
syslog-ng.conf: |-
@version: 3.29
@include "scl.conf"
source s_local {
internal();
};
source s_network {
default-network-drivers(
max_connections(300)
);
};
destination d_local {
file("/var/log/messages");
file("/var/log/messages-kv.log" template("$ISODATE $HOST $(format-welf --scope all-nv-pairs)\n") frac-digits(3));
};
log {
source(s_local);
source(s_network);
destination(d_local);
};
8 changes: 8 additions & 0 deletions tests/data/ap-waf-grpc/tls-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: virtual-server-tls-grpc-secret
type: kubernetes.io/tls
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURzakNDQXBvQ0NRREdqUVE5L3hnejZqQU5CZ2txaGtpRzl3MEJBUXNGQURDQm1qRUxNQWtHQTFVRUJoTUMKU1VVeERUQUxCZ05WQkFnTUJFTnZjbXN4RFRBTEJnTlZCQWNNQkVOdmNtc3hFekFSQmdOVkJBb01DazVIU1U1WQpMQ0JKYm1NeERqQU1CZ05WQkFzTUJVNUhTVTVZTVNNd0lRWURWUVFEREJwMmFYSjBkV0ZzTFhObGNuWmxjaTVsCmVHRnRjR3hsTG1OdmJURWpNQ0VHQ1NxR1NJYjNEUUVKQVJZVWEzVmlaWEp1WlhSbGMwQnVaMmx1ZUM1amIyMHcKSGhjTk1qRXhNVEkxTVRrek5qUXdXaGNOTWpNeE1ESTJNVGt6TmpRd1dqQ0JtakVMTUFrR0ExVUVCaE1DU1VVeApEVEFMQmdOVkJBZ01CRU52Y21zeERUQUxCZ05WQkFjTUJFTnZjbXN4RXpBUkJnTlZCQW9NQ2s1SFNVNVlMQ0JKCmJtTXhEakFNQmdOVkJBc01CVTVIU1U1WU1TTXdJUVlEVlFRRERCcDJhWEowZFdGc0xYTmxjblpsY2k1bGVHRnQKY0d4bExtTnZiVEVqTUNFR0NTcUdTSWIzRFFFSkFSWVVhM1ZpWlhKdVpYUmxjMEJ1WjJsdWVDNWpiMjB3Z2dFaQpNQTBHQ1NxR1NJYjNEUUVCQVFVQUE0SUJEd0F3Z2dFS0FvSUJBUUNoYnlha0tlbzZzR2Q0eFBva3dQaHpjMGcvCnNiNXZpZnNnbHJvc2IyUjhjaGJtQlJRV1lGZlNzbldidWtkejB2RFVaWHhlY1hOZUdKVFc0WWdOOUZUS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FBSSVZBVEUgS0VZLS0tLS0K
26 changes: 26 additions & 0 deletions tests/data/ap-waf-grpc/virtual-server-waf-spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: virtual-server
spec:
host: virtual-server.example.com
policies:
- name: waf-policy
tls:
secret: virtual-server-tls-grpc-secret
upstreams:
- name: grpc1
service: grpc1-svc
port: 50051
type: grpc
- name: grpc2
service: grpc2-svc
port: 50051
type: grpc
routes:
- path: "/helloworld.Greeter"
action:
pass: grpc1
- path: "/notimplemented"
action:
pass: grpc2
5 changes: 3 additions & 2 deletions tests/suite/ap_resources_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_ap_waf_policy_from_yaml(
appolicy,
aplogconf,
logdest,
) -> None:
) -> str:
"""
Create a Policy based on yaml file.
Expand All @@ -55,7 +55,7 @@ def create_ap_waf_policy_from_yaml(
:param appolicy: AppProtect policy name
:param aplogconf: Logconf name
:param logdest: AP log destination (syslog)
:return: None
:return: str
"""
with open(yaml_manifest) as f:
dep = yaml.safe_load(f)
Expand All @@ -70,6 +70,7 @@ def create_ap_waf_policy_from_yaml(
"k8s.nginx.org", "v1", namespace, "policies", dep
)
print(f"Policy created: {dep}")
return dep["metadata"]["name"]
except ApiException:
logging.exception(f"Exception occurred while creating Policy: {dep['metadata']['name']}")
raise
Expand Down
Loading

0 comments on commit fbc43df

Please sign in to comment.