authentication for APIGateway using CloudFront cookies

0

I am working on a setup where website access to abc.example.com and def.example.com and so on is secured using CloudFront signed cookies set by Lambda@Edge. There also is a central APIGateway-based web API under the domain api.example.com that is being called from all websites.

I am now trying to add authentication to the API so that only users having the cloudfront signed cookies can make a call on behalf of the website where call originates from.

Is there a way to do so?

1개 답변
0
수락된 답변

You could put the traffic to your API gateway via CloudFront, and protect API gateway with API key.

So you would have "api.example.com" -> CloudFront (Where you verify the cookie + add X-API-KEY to request -> API Gateway To add the x-api-key you can specify it in the CloudFront settings without the need to use Lambda@Edge https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/add-origin-custom-headers.html

Here the information on how to set up API Gateway with its own CloudFront distribution

Miki
답변함 2년 전
  • I did check it out but got the impression it is not a fit. the challenge is that I need to use a cookie that belongs to domain abc.example.com to authenticate against api.example.com. But I cannot set that cookie when at abc.example.com as it is another domain. I would have to use a higher domain like example.com. However, then users from abc.example.com could access def.example.com what I don't want them to be able to. I now ended up with a scenario where I have Lambda@Edge create a JWT that has the originating domain, e.g. abc.example.com as payload and I do set that cookie under .example.com so it will be sent along with every api call to api.example.com.

  • still, looks like that approach is the only feasible solution

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인