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 個回答
0
已接受的答案

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
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南