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

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

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

回答問題指南