Skip to content

Commit bc955d3

Browse files
Serverless initial implementation [MAJOR] (#250)
* serverless initial commit * feat: Initial changes to module, docs, and apply process for serverless * move sam policy out into user_access files * small syntax fixes * add security group and VPC connection for lambda * create user-db from lambda instead of k8s * support database list and mysql * App secret name from /kubernetes to /application * fix wrong env-var and unnecessary escape * split route53 and loggroup IAM permissions * Move k8s auth out of infra terraform (#246) * refactor: move k8s auth out of infra terraform and into kubernetes * fix: removed a couple leftover reference to k8s in infrastructure tf * fix: fix name of var and tf typo * fix: made variable name more clear * fix: remove unnecessary merge * fix: misc fixes, plus added some deps to avoid race conditions * fix: bump eks and user_access module versions * fix: Add missing vars in prod/main.tf * add some documentation around setting up auth0 * work in progress diagrams for serverless * template out auth0 due to provider constrains * more documentation around serverless * better naming and adding comments * fix syntax error in user_access.tf * fix some prod deployment problems * fixes secret prefix and assumable roles * fixes around roles and permissions * update diagrams * makefile and typo fixes * bump user_auth for secret creation conflict Co-authored-by: Bill Monkman <[email protected]>
1 parent 28d1574 commit bc955d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1737
-287
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SHELL := /bin/bash
55
run: make-apply
66

77
make-apply:
8-
cd $(PROJECT_DIR) && AUTO_APPROVE="-auto-approve" make
8+
@export AUTO_APPROVE="-auto-approve" && cd $(PROJECT_DIR) && (if [[ "${backendApplicationHosting}" =~ "kubernetes" ]]; then make apply; else make apply-without-eks; fi)
99

1010
summary:
1111
@echo "zero-aws-eks-stack:"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ The root folder is used for declaring parameters required by the templates, and
2828
```
2929

3030
## AWS EKS Stack
31-
The Zero-awk-eks stack is designed with scalability and maintainability in mind, this repo is a series of templates indented to be filled in with modules parameters, and executed by zero
31+
The Zero-aws-eks stack is designed with scalability and maintainability in mind, this repo is a series of templates indented to be filled in with modules parameters, and executed by zero
3232
This is a [Zero][zero] module which sets up a
3333
hosting environment on AWS running Kubernetes. It will generate terraform output
34-
which describes the environment mapped in this [architecture diagram][arch-diagram].
34+
which describes the environment mapped in this [architecture diagram][arch-diagram].
3535

3636
**Resource List**: [Link][resource-list]
3737

doc-site/docs/components/kubernetes/external-secrets.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ You can see the `external-secrets` configuration in [kubernetes/overlays/staging
2020

2121
To work with the secret in AWS you can use the web interface or the cli tool:
2222
```
23-
aws secretsmanager get-secret-value --secret=<project-name>/kubernetes/stage/<project-name>
23+
aws secretsmanager get-secret-value --secret=<project-name>/application/stage/<project-name>
2424
```
2525

26-
The intent is that the last part of the secret name is the component of your application this secret is for. For example: if you were adding a new billing service, the secret might be called `<project-name>/kubernetes/stage/billing`
26+
The intent is that the last part of the secret name is the component of your application this secret is for. For example: if you were adding a new billing service, the secret might be called `<project-name>/application/stage/billing`
2727

2828
## Documentation
2929
Checkout [External secrets's documentation][docs] for more information.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Authentication
3+
sidebar_label: Authentication
4+
sidebar_position: 3
5+
---
6+
7+
Authentication is invoked through the API gateway, this allows the decoupling of Authentication from the business logic, and also allows reusing this authentication logic for other endpoints.
8+
9+
Our implementation uses the [Lambda-authorizer flow][lambda-authorizer-flow] documented in AWS, this gives more flexibility of the behavior than the JWT authorizer flow which perform similar functionality. Such as implementing login/logout/callback endpoints, configuring HTTPs cookie and etc.
10+
11+
## OIDC Authorizer
12+
Supports OpenID Connect compliant solutions with Oauth2 based authentication flow
13+
14+
| Environment Variables | Description | Defaults |
15+
|------------------------|-------------|----------|
16+
| NODE_ENV | When set as `development` the authenticator listens on a PORT instead of exporting as lambda function | - |
17+
| ISSUER_BASE_URL | Issuer with OpenID Connect configured, should have a `.well-known/openid-configuration` setup | - |
18+
| CLIENT_ID | Client ID for issuer to exchange for tokens | - |
19+
| CLIENT_SECRET | Client Secret for issuer to exchange for tokens | - |
20+
| COOKIE_DOMAIN | Scoping Cookies to be only readable in configured domains | - |
21+
| COOKIE_SIGNING_SECRET | Secret used to encrypt the cookie secret | - |
22+
| AUTH_ENDPOINT | Authentication service callbacks to exchange and set token | - |
23+
| FRONTEND_URL | Frontend for CORS and redirection to web application | - |
24+
| AUTH_SCOPE | scope of authentication | `openid profile email` |
25+
| ALLOW_INSECURE_COOKIES | Allow insecure cookie to be set on client, this should only be allowed in testing environments | `false` |
26+
| JWT_COOKIE_KEY | By default authenticator will sign a JWE, specify this key to set a JWT in the cookie | - |
27+
28+
## Auth Middleware
29+
Authenticator is invoked by API Gateway and the context is passed down via `requestContext.authorizer.lambda`, all the JWT claims will also be available in this context, to change or modify the context you can update the authorizer lambda function.
30+
31+
## Application
32+
By default all endpoints except for `GET /status*` will go through authentication, this is configured in `template.yaml` in the backend application.
33+
34+
[lambda-authorizer-flow]: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html#api-gateway-lambda-authorizer-flow
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Concepts and building blocks
3+
sidebar_label: Concepts
4+
sidebar_position: 1
5+
---
6+
7+
## CI/CD Pipeline
8+
We use Github actions to invoke the Cloudformation pipeline, it consists of 2 steps:
9+
- `aws sam build`
10+
- `aws sam deploy`
11+
The `build` step compiles the container images, and the `deploy` step uses Cloudformation to get the resources to the desired state.
12+
13+
## Environment Configuration
14+
Managed by `config.toml` in the backend repository.
15+
This is the deploy step's configuration, determines where the artifacts are saved and allows configuration of parameters of each environment, such as image repositories and S3 to store build configurations.
16+
17+
## CloudFormation template
18+
Managed by `template.yaml` in the backend repository.
19+
This is the configuration of your infrastructure and application setup, this configures how the Gateway, authenticator, application, logging and routes are setup.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Routing
3+
sidebar_label: Routing
4+
sidebar_position: 2
5+
---
6+
7+
8+
## Routes
9+
All the routes are configured in AWS API Gateway in backend's [`template.yaml`][template-yaml]
10+
11+
## Domain
12+
The domain is expected to pointed to an AWS hosted-zone same as our EKS setup, in terraform we provision a TLS certificate and store the ARN in SSM for reference in the `template.yaml`. With the Certificate setup AWS SAM will help you modify the Route53 entry to point to API Gateway.
13+
14+
### Authenticator
15+
Endpoints setup for authenticator, these are used to facilitate the login and token exchange flow, and allow web applications to get the authentication status of a client.
16+
- `GET /login`
17+
- `GET /logout`
18+
- `GET /callback`
19+
- `GET /whoami`
20+
21+
22+
23+
### Application
24+
#### Requires Authentication
25+
- `GET /{proxy+}`
26+
- `POST /{proxy+}`
27+
- `PUT /{proxy+}`
28+
- `PATCH /{proxy+}`
29+
- `DELETE /{proxy+}`
30+
31+
:::note
32+
Wildcard HTTP Method is not used because if `OPTIONS` are routed to the application it will need to specifically handle this case
33+
:::
34+
#### No Authentication
35+
- `GET /status`
36+
37+
38+
39+
[template-yaml]: https://github.com/commitdev/zero-backend-node/blob/577af42c78f936b9e6d8cd09eac0f57a610b5cd2/templates/template.yaml
88.6 KB
Loading
66.6 KB
Loading
53.1 KB
Loading
131 KB
Loading

0 commit comments

Comments
 (0)