Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security: OAuth @ Edge, JWT auth in the API #45

Merged
merged 34 commits into from
Mar 24, 2018
Merged

Security: OAuth @ Edge, JWT auth in the API #45

merged 34 commits into from
Mar 24, 2018

Conversation

nzoschke
Copy link
Owner

@nzoschke nzoschke commented Mar 18, 2018

This demonstrates strategies for security.

  • Static content in S3 is only accessible through CloudFront
  • Requests through CloudFront do Google OAuth exchange w/ Lambda @ Edge JavaScript func
  • Successful OAuth exchange sets access_token cookie with JWT
  • API allows CORS from static site
  • API helper to verify JWT or return 401

This also introduces a work API (which fixes #6) that uses JWT auth.

The OAuth stuff requires creating a Google OAuth 2.0 web application client and enabling the Google Plus API.

Todo:

  • Config - Grant web auth func access to less parameters?
  • Docs - Security with CloudFront, Lambda @ Edge, JWT and Google OAuth
  • Docs - Parameter store
  • Docs - Update static sites with improved S3 origin strategy

@nzoschke nzoschke changed the title WIP: Authentication OAuth @ Edge, JWT auth in the API Mar 18, 2018
@nzoschke
Copy link
Owner Author

nzoschke commented Mar 18, 2018

# s3 bucket is not accessable
$ curl http://private.gofaas.net.s3-website-us-east-1.amazonaws.com/
<head><title>403 Forbidden</title></head>...

# distribution redirects to OAuth
$ curl -i https://private.gofaas.net/
HTTP/2 302
location: https://accounts.google.com/o/oauth2/v2/auth?response_type=code...

# valid access_token cookie returns content
$ curl --cookie "access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Im5vYWhAZ29mYWFzLm5ldCJ9.x8w23sGhkTX97BZe3jsXnj0VL9ZrM_cbtoIHyqSVK8Q" https://private.gofaas.net/
<title>My first gofaas/Vue app</title>...
# gateway enforces CORS
$ curl -i -X OPTIONS https://api.gofaas.net/
HTTP/2 200
content-type: application/json
content-length: 3
date: Sun, 18 Mar 2018 21:50:42 GMT
x-amzn-requestid: 676936da-2af6-11e8-83ab-1138cf2b9b7d
access-control-allow-origin: https://private.gofaas.net
access-control-allow-headers: Accept, Authorization, Content-Type
access-control-allow-methods: GET,OPTIONS
# API validates token
$ curl -X POST https://api.gofaas.net/work
HTTP/2 401
{"error": "token contains an invalid number of segments"}

$ curl -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Im5vYWhAZ29mYWFzLm5ldCJ9.x8w23sGhkTX97BZe3jsXnj0VL9ZrM_cbtoIHyqSVK8Q" -X POST https://api.gofaas.net/work
HTTP/2 200
{"ExecutedVersion":null,"FunctionError":null,"LogResult":null,"Payload":"","StatusCode":202}

@nzoschke nzoschke changed the title OAuth @ Edge, JWT auth in the API Security: OAuth @ Edge, JWT auth in the API Mar 18, 2018
@nzoschke
Copy link
Owner Author

nzoschke commented Mar 18, 2018

We might want to add a bit more CF conditional logic, not configuring the Lambda @ Edge func unless OAuth client parameters are specified.

Edit: done in 24aa04c

@nzoschke nzoschke merged commit 243157a into master Mar 24, 2018
This was referenced Mar 24, 2018
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API endpoint to invoke worker
1 participant