What is the API audit log implementation best practice?

0

I want to implement Audit logs for our API, for compliance needs. Every request that a customer performs to the API should be logged. It must be hermetic, we can’t lose any log. The API high level architecture: Cloudfront -> API GW -> LB

I thought about Cloudfront standard logs, but the documentation says that it may not be hermetic, so it’s not relevant for my use case.

API GW access logs seems to be my direction for now, but setting the log template is pretty challenging. I couldn’t get the perfect template with all relevant data:

  • Instead of the request payload, I get “-” (by using $input.body)
  • Useragent is “Amazon CloudFront” instead the actual useragent (makes sense due to the fact that Cloudfront forwards the request)
  • Many more fields are empty

2 comments:

*The log template documentation that I based on - https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference?cmpid=docs_apigateway_console

*I added to the Cloudfront distribution the “AllViewerExceptHostHeader” origin request policy, it didn’t help, looks like API GW still gets the requests with missing metadata from Cloudfront https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html#managed-origin-request-policy-all-viewer-except-host-header

The question is: is this the right direction for implementing API audit log? If not, would you recommend a third party product? I’m trying to avoid developing it in-house.

Thanks, Yedidya

1 Respuesta
0
Respuesta aceptada

Hi,

I think you are on right track. Another option is to provide a Kinesis Data Firehose Delivery stream ARN under the Api Gateway Access Logs Cloudwatch arn.

In this way access logs will be sent to Kinesis Data Firehose, which then could be forwarded, for instance, to s3.

From there you could use lifecycle rules to move data to Glacier/Deep archive for longer retention time.

Hope it helps

profile picture
EXPERTO
respondido hace un año

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas