CR Parser

Airlock Microgateway Engine parses the request body before applying deny rules to a request's content. The parser selection is based on the Content-Type header. The CR Parser can be used to override the built-in default parser selection logic.

  • The built-in parsing logic works well for most cases. Integration with applications may need a custom parser configuration:
  • Built-in parsers can be enabled/disabled individually (e.g. JSON and URL-encoded form parsers).
  • The built-in logic parses requests with Content-Type headers matching .*json.* or .*form-urlencoded.* by default. Custom patterns can be configured to trigger parsing on other content type patterns.
  • For requests without a Content-Type header, an application/x-www-form-urlencoded header is added by the built-in parser logic. However, the default can be customized using the defaultContentType option.

General tips for working with CRs

  • CLI:
  • Use kubectl explain <replace with CRD name> --recursive to list all available options and the YAML structure.
  • Check the CRD description texts with kubectl explain <replace with CRD name and path> of the available options for more details.
  • API Reference documentation:
  • Click on the link to open the CR-related documentation in a new browser tab or window: CRD Reference documentation. See also the API Reference documentation links at the end article.

Example configuration

The example shows the (built-in) default parser logic.

copy
apiVersion: microgateway.airlock.com/v1alpha1 
kind: Parser 
metadata: 
  name: parser-sample 
spec: 
  request: 
    defaultContentType: application/x-www-form-urlencoded 
    parsers: 
      json: 
        enable: true 
        mediaTypePattern: .*json.* 
      form: 
        enable: true 
        mediaTypePattern: .*form-urlencoded.* 
...

Change the settings as required.

See also the API Reference documentation link at the end of this article.

Reference in CR ContentSecurity

The CR Parser needs to be referenced in the CR ContentSecurity.

...
spec: 
   parserRef: 
     name: parser-sample   
...

Replace the name: in our example with the actual name from the metadata section of the respective Parser CR.

See also the API Reference documentation link at the end of this article.