You can create your own policies and apply them for either all or specific ingress rules, set exceptions and other advanced options using K8S native declarative configuration.
Using open-appsec K8S Custom Resources
open-appsec configuration is done using Kubernetes Custom Resource Definition (CRD). Custom Resources are extensions of the Kubernetes API that allow powerful yet standard way of managing policies in a declarative way as well as using infrastructure-as-code paradigm. This support is an important goal of managing changes as part of your CI/CD processes.
open-appsec provides seven CRDs. The main one is policy - which defines default behaviors that will apply to all Ingress rules and also behaviours that you wish to apply just to specific rules. The policy resource refers to all other CRDs.
The Kubernetes API serves and handles the storage of custom resources. They can be accessed and managed using standard tools: kubectl, a REST client that you write, Go and Python client libraries and more.
In case you want to edit one of your own policies, e.g. your own default-policy you can do this with the following command (see further below for an example to create your own custom policy resource):
modestring enum - security engines operation mode. Blocking will only happen in prevent-learn mode
prevent-learn / detect-learn / prevent / detect / inactive
(note that prevent and detect are just aliases for prevent-learn and detect-learn)
practicesarray of strings - defines which security engines to activate and their specific settings (Note there cannot be multiple practices of the same kind specified here!)
reference to Practice resource(s)
triggersarray of strings - defines logging verbosity and destination (stdout, syslog, cloud, etc) (Note for now only a single trigger is supported!)
reference to LogTrigger resource(s)
custom-responsestring - defines prevent mode behaviors upon decision to block: HTTP response code, block page, http redirect
reference to CustomResponse resource
source-identifiersstring - defines how ML engine will distinguish between sources based on IP address, X-Foward-For, Key in Header/Cookie/JWT
reference to SourcesIdentifier resource
trusted-sourcesstring - defines which traffic sources are very unlikely to be malicious. Used for Machine Learning engine.
exceptionsarrays of strings - defines exceptions to be applied based on e.g. countryCode, countryName, sourceIP, URL, hostName, sourceIdentifier
reference to Exception resource(s)
specific-rules list
list of one or more per-host (ingress rule) policies that will override the defaults above
hoststring - policy will apply to this host
network path (exactly as appear in ingress rules)
All other keys can be used same as decribed above for default.
Practice
Practice resources define which security engine will be active and their settings.
configmaparray of strings - specify configmap(s) containing snort signatures
Custom Response
Practice resources define which security engine will be active and their settings.
Examples
apiVersion:openappsec.io/v1beta1kind:CustomResponsemetadata:name:appsec-web-user-response-examplespec:mode:block-pagehttp-response-code:403message-title:Block page titlemessage-body:"<h1>Access blocked by open-appsec.</h1><p>Your access will be logged.</p>"apiVersion:openappsec.io/v1beta1kind:CustomResponsemetadata:name:appsec-default-web-user-responsespec:mode:response-code-onlyhttp-response-code:403
Specification
mode enum - engine will take one of these actions upon decision to block request
block-page - send HTML with text to client + HTTP response code
response-code-only - send only response code
message-title string - title of block page that will be displayed only in case mode is block page and engine decided to block
message-body string - content of block page that will be displayed only in case mode is block page and engine decided to block
http-response-code integer between 100-599 - http code that will be returned to client upon engine decision to block; default is 403 - HTTP Forbidden
request-body boolean, default: false - log the request body (has performance impact)
true / false
log-destination
cloud boolean, default: false - enable or disable logging to the appsec-open Cloud Service (relevant when being connected to SaaS Mgmt WebUI)
true / false
file string - define file path to save logs to (local path from root directory of the open-appsec container, could also refer to a mountPath for a mounted Persistent Volume in the container)
stdout - configure logging to standard-out
format string enum - define the desired log format
json / json-formatted - select between formatted or standard json
syslog-service objects array - define one or more syslog servers and corresponding ports to send logs to
address string - Syslog server IP address
port integer - Syslog server port
cef-service - allows sending files to a log destination in CEF format
address string - CEF server IP address
port integer - CEFserver port
proto string enum Select the correct protocol
tcp / udp - Chose TCP or UDP protocol
Exceptions
Example
apiVersion:openappsec.io/v1beta1kind:Exceptionmetadata:name:appsec-exception-examplespec:- action:skipcomment:This is an example exception commentcountryCode: - CA - ILcountryName: - Israel - CanadahostName: - fffparamName: - keyparamValue: - rrrprotectionName: - cveeesourceIdentifier: - davidsourceIp: - 1.2.3.4 - '3.3.3.3'url: - "/rrr"- action:accepthostName: - fffurl: - "/rrr"- action:dropcomment:This is an example exception commentcountryName: - Israel - CanadaprotectionName: - cveeesourceIdentifier: - davidsourceIp: - 1.2.3.4 - 2.3.4.5url: - "/rrr"- action:suppressLogcomment:This is an example exception commentcountryCode: - CA - ILcountryName: - Israel - CanadahostName: - fffurl: - "/rrr"
Specification
Define a list of actions-objects with the corresponding parameters to match to configure flexible custom exceptions/rules, each having the following configurable keys:
action string enum - Action to be performed when exception matches
Define trusted sources by referencing the source identifiers custom resources as well as setting the minimum amount of sources that need to be observed by the behavioural ML engine sending certain identical traffic patterns in order to learn this behaviour as being benign.
minNumOfSources integer - Minimum amount of sources having to be observed sending same traffic patterns to learn behaviour as benign.
sourcesIdentifiers string array - Specify one or more source identifiers