How to redact headers from WAF logging using Java CDK v2?

0

How do you exclude header fields from logging using the Java v2 CDK patch 2.85? This does not work:

var header = CfnLoggingConfiguration.SingleHeaderProperty .builder() .name("header") .build();

var headerMatcher = CfnLoggingConfiguration.FieldToMatchProperty.builder() .singleHeader(header) .build();

CfnLoggingConfiguration loggingConfig = CfnLoggingConfiguration.Builder ... .redactedFields(List.of(headerMatcher)) ...

because this runs into this error message on a cdk deployment:

#/RedactedFields/0/SingleHeader: required key [Name] not found #/RedactedFields/0/SingleHeader: extraneous key [name] is not permitted

It would seem that the class SingleHeaderProperty has the property "name", but the JSON serialization is supposed to use upper case "Name", which is also used in the JavaDoc.

1 Risposta
0

Hi, Cloudformation doc says that header name is not case-sensitive

See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-wafv2-loggingconfiguration-fieldtomatch.html

SingleHeader
Redact a single header. Provide the name of the header to inspect, for example, User-Agent 
or Referer. 
This setting isn't case sensitive.

Example JSON: "SingleHeader": { "Name": "haystack" }

Required: No

Type: SingleHeader

Update requires: No interruption

So, can you try with "name" and see if it works?

profile pictureAWS
ESPERTO
con risposta un anno fa
  • Thanks for the answer: The header is not case sensitive, but the problem seems to be the JSON key "Name", not the name of the header, which, as you quote from the docs, should be upper case, but is generated as lower case "name" by the CDK classes. The key "name" is hard coded in the implementation class of the CfnLoggingConfiguration.SingleHeaderProperty interface and cannot be set by the caller.

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande