2024-11-04 06:00:28 +01:00
|
|
|
# Goma Gateway - simple lightweight API Gateway Management.
|
2024-10-27 06:10:27 +01:00
|
|
|
|
|
|
|
|
```
|
|
|
|
|
_____
|
|
|
|
|
/ ____|
|
|
|
|
|
| | __ ___ _ __ ___ __ _
|
|
|
|
|
| | |_ |/ _ \| '_ ` _ \ / _` |
|
|
|
|
|
| |__| | (_) | | | | | | (_| |
|
|
|
|
|
\_____|\___/|_| |_| |_|\__,_|
|
|
|
|
|
|
|
|
|
|
```
|
2024-11-04 06:00:28 +01:00
|
|
|
Goma Gateway is a lightweight API Gateway Management.
|
2024-10-27 06:10:27 +01:00
|
|
|
|
2024-10-27 07:24:50 +01:00
|
|
|
[](https://github.com/jkaninda/goma-gateway/actions/workflows/release.yml)
|
2024-10-29 09:39:31 +01:00
|
|
|
[](https://goreportcard.com/report/github.com/jkaninda/goma-gateway)
|
2024-10-27 06:10:27 +01:00
|
|
|
[](https://pkg.go.dev/github.com/jkaninda/goma-gateway)
|
|
|
|
|

|
|
|
|
|
|
2024-11-02 13:58:01 +01:00
|
|
|
<img src="https://raw.githubusercontent.com/jkaninda/goma-gateway/main/logo.png" width="150" alt="Goma logo">
|
2024-11-02 13:45:17 +01:00
|
|
|
|
2024-11-04 06:00:28 +01:00
|
|
|
----
|
2024-11-02 21:19:35 +01:00
|
|
|
|
|
|
|
|
Architecture:
|
|
|
|
|
|
2024-11-02 21:20:45 +01:00
|
|
|
<img src="https://raw.githubusercontent.com/jkaninda/goma-gateway/main/goma-gateway.png" width="912" alt="Goma archi">
|
2024-11-02 21:19:35 +01:00
|
|
|
|
|
|
|
|
|
2024-10-27 06:10:27 +01:00
|
|
|
## Links:
|
|
|
|
|
|
|
|
|
|
- [Docker Hub](https://hub.docker.com/r/jkaninda/goma-gateway)
|
|
|
|
|
- [Github](https://github.com/jkaninda/goma-gateway)
|
|
|
|
|
|
2024-11-02 12:54:12 +01:00
|
|
|
### Documentation is found at <https://jkaninda.github.io/goma-gateway>
|
|
|
|
|
|
2024-11-02 12:39:31 +01:00
|
|
|
### Features
|
|
|
|
|
|
|
|
|
|
It comes with a lot of integrated features, such as:
|
|
|
|
|
|
|
|
|
|
- RESTFull API Gateway management
|
|
|
|
|
- Domain/host based request routing
|
|
|
|
|
- Multi domain request routing
|
2024-11-04 05:36:52 +01:00
|
|
|
- Reverse Proxy
|
|
|
|
|
- Websocket Proxy
|
2024-11-02 12:39:31 +01:00
|
|
|
- Cross-Origin Resource Sharing (CORS)
|
2024-11-04 05:35:57 +01:00
|
|
|
- Custom Headers
|
|
|
|
|
- Backend Errors interceptor
|
2024-11-02 12:39:31 +01:00
|
|
|
- Authentication middleware
|
|
|
|
|
- JWT `client authorization based on the result of a request`
|
|
|
|
|
- Basic-Auth
|
|
|
|
|
- Rate limiting
|
|
|
|
|
- In-Memory Token Bucket based
|
|
|
|
|
- In-Memory client IP based
|
|
|
|
|
|
|
|
|
|
### Todo:
|
2024-11-03 04:01:18 +01:00
|
|
|
|
|
|
|
|
- [ ] Support TLS
|
2024-11-04 05:35:57 +01:00
|
|
|
- [ ] Blocklist IP address middleware
|
2024-11-03 04:01:18 +01:00
|
|
|
- [ ] OAuth authentication middleware — Optional
|
2024-10-27 06:10:27 +01:00
|
|
|
- [ ] Distributed Rate Limiting for Token based across multiple instances using Redis
|
2024-10-29 09:39:31 +01:00
|
|
|
- [ ] Distributed Rate Limiting for In-Memory client IP based across multiple instances using Redis
|
2024-10-27 06:10:27 +01:00
|
|
|
|
2024-11-04 06:00:28 +01:00
|
|
|
----
|
2024-11-03 04:01:18 +01:00
|
|
|
|
2024-10-27 06:10:27 +01:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
### 1. Initialize configuration
|
|
|
|
|
|
2024-11-04 07:48:03 +01:00
|
|
|
You can generate the configuration file using `config init --output /config/config.yml` command.
|
|
|
|
|
|
|
|
|
|
The default configuration is automatically generated if any configuration file is not provided, and is available at `/config/goma.yml`
|
2024-11-04 07:37:47 +01:00
|
|
|
|
2024-10-27 06:10:27 +01:00
|
|
|
```shell
|
|
|
|
|
docker run --rm --name goma-gateway \
|
|
|
|
|
-v "${PWD}/config:/config" \
|
|
|
|
|
jkaninda/goma-gateway config init --output /config/goma.yml
|
|
|
|
|
```
|
|
|
|
|
### 2. Run server
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
docker run --rm --name goma-gateway \
|
|
|
|
|
-v "${PWD}/config:/config" \
|
|
|
|
|
-p 80:80 \
|
|
|
|
|
jkaninda/goma-gateway server
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3. Start server with a custom config
|
|
|
|
|
```shell
|
|
|
|
|
docker run --rm --name goma-gateway \
|
|
|
|
|
-v "${PWD}/config:/config" \
|
|
|
|
|
-p 80:80 \
|
|
|
|
|
jkaninda/goma-gateway server --config /config/config.yml
|
|
|
|
|
```
|
|
|
|
|
### 4. Healthcheck
|
|
|
|
|
|
2024-10-27 07:24:50 +01:00
|
|
|
- Goma Gateway readiness: `/readyz`
|
|
|
|
|
- Routes health check: `/healthz`
|
|
|
|
|
|
2024-11-04 06:00:28 +01:00
|
|
|
### 5. Simple deployment in docker compose file
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
services:
|
|
|
|
|
goma-gateway:
|
|
|
|
|
image: jkaninda/goma-gateway
|
|
|
|
|
command: server
|
|
|
|
|
healthcheck:
|
|
|
|
|
test: curl -f http://localhost/readyz || exit 1
|
|
|
|
|
interval: 30s
|
|
|
|
|
retries: 5
|
|
|
|
|
start_period: 20s
|
|
|
|
|
timeout: 10s
|
|
|
|
|
ports:
|
|
|
|
|
- "80:80"
|
|
|
|
|
volumes:
|
|
|
|
|
- ./config:/config/
|
|
|
|
|
```
|
|
|
|
|
|
2024-10-27 06:10:27 +01:00
|
|
|
Create a config file in this format
|
|
|
|
|
## Customize configuration file
|
|
|
|
|
|
2024-10-30 04:57:07 +01:00
|
|
|
Example of a configuration file
|
2024-10-27 06:10:27 +01:00
|
|
|
```yaml
|
|
|
|
|
# Goma Gateway configurations
|
|
|
|
|
gateway:
|
|
|
|
|
########## Global settings
|
|
|
|
|
listenAddr: 0.0.0.0:80
|
|
|
|
|
# Proxy write timeout
|
|
|
|
|
writeTimeout: 15
|
|
|
|
|
# Proxy read timeout
|
|
|
|
|
readTimeout: 15
|
|
|
|
|
# Proxy idle timeout
|
|
|
|
|
idleTimeout: 60
|
2024-10-30 04:52:49 +01:00
|
|
|
# Proxy rate limit, it's In-Memory IP based
|
2024-10-27 06:10:27 +01:00
|
|
|
# Distributed Rate Limiting for Token based across multiple instances is not yet integrated
|
|
|
|
|
rateLimiter: 0
|
|
|
|
|
accessLog: "/dev/Stdout"
|
|
|
|
|
errorLog: "/dev/stderr"
|
2024-11-04 14:13:37 +01:00
|
|
|
## Enable, disable routes health check
|
2024-11-04 06:52:41 +01:00
|
|
|
disableHealthCheckStatus: false
|
2024-10-27 06:10:27 +01:00
|
|
|
## Returns backend route healthcheck errors
|
|
|
|
|
disableRouteHealthCheckError: false
|
|
|
|
|
# Disable display routes on start
|
|
|
|
|
disableDisplayRouteOnStart: false
|
2024-10-30 04:57:07 +01:00
|
|
|
# disableKeepAlive allows enabling and disabling KeepALive server
|
2024-10-30 04:52:49 +01:00
|
|
|
disableKeepAlive: false
|
2024-10-29 09:39:31 +01:00
|
|
|
# interceptErrors intercepts backend errors based on defined the status codes
|
|
|
|
|
interceptErrors:
|
2024-10-29 19:38:43 +01:00
|
|
|
- 405
|
|
|
|
|
- 500
|
2024-10-29 09:39:31 +01:00
|
|
|
# - 400
|
2024-10-27 06:10:27 +01:00
|
|
|
# Proxy Global HTTP Cors
|
|
|
|
|
cors:
|
2024-10-28 10:16:44 +01:00
|
|
|
# Global routes cors for all routes
|
2024-10-27 06:10:27 +01:00
|
|
|
origins:
|
2024-10-29 19:38:43 +01:00
|
|
|
- http://localhost:8080
|
2024-10-27 06:10:27 +01:00
|
|
|
- https://example.com
|
2024-10-28 10:16:44 +01:00
|
|
|
# Global routes cors headers for all routes
|
2024-10-27 06:10:27 +01:00
|
|
|
headers:
|
|
|
|
|
Access-Control-Allow-Headers: 'Origin, Authorization, Accept, Content-Type, Access-Control-Allow-Headers, X-Client-Id, X-Session-Id'
|
|
|
|
|
Access-Control-Allow-Credentials: 'true'
|
|
|
|
|
Access-Control-Max-Age: 1728000
|
|
|
|
|
##### Define routes
|
|
|
|
|
routes:
|
|
|
|
|
# Example of a route | 1
|
2024-10-29 19:38:43 +01:00
|
|
|
- name: Public
|
2024-10-28 04:10:24 +01:00
|
|
|
# host Domain/host based request routing
|
2024-10-30 05:02:01 +01:00
|
|
|
host: "" # Host is optional
|
2024-10-29 19:38:43 +01:00
|
|
|
path: /public
|
2024-10-27 06:10:27 +01:00
|
|
|
## Rewrite a request path
|
|
|
|
|
# e.g rewrite: /store to /
|
2024-11-02 12:12:22 +01:00
|
|
|
rewrite: /
|
2024-10-29 19:38:43 +01:00
|
|
|
destination: https://example.com
|
2024-10-27 06:10:27 +01:00
|
|
|
#DisableHeaderXForward Disable X-forwarded header.
|
|
|
|
|
# [X-Forwarded-Host, X-Forwarded-For, Host, Scheme ]
|
|
|
|
|
# It will not match the backend route, by default, it's disabled
|
|
|
|
|
disableHeaderXForward: false
|
|
|
|
|
# Internal health check
|
2024-10-29 19:38:43 +01:00
|
|
|
healthCheck: '' #/internal/health/ready
|
2024-10-28 10:16:44 +01:00
|
|
|
# Route Cors, global cors will be overridden by route
|
2024-10-27 06:10:27 +01:00
|
|
|
cors:
|
2024-11-04 14:13:37 +01:00
|
|
|
# Route Origins Cors, route will override global cors origins
|
2024-10-28 10:16:44 +01:00
|
|
|
origins:
|
|
|
|
|
- https://dev.example.com
|
|
|
|
|
- http://localhost:3000
|
2024-10-29 19:38:43 +01:00
|
|
|
- https://example.com
|
2024-11-04 14:13:37 +01:00
|
|
|
# Route Cors headers, route will override global cors headers
|
2024-10-27 06:10:27 +01:00
|
|
|
headers:
|
|
|
|
|
Access-Control-Allow-Methods: 'GET'
|
|
|
|
|
Access-Control-Allow-Headers: 'Origin, Authorization, Accept, Content-Type, Access-Control-Allow-Headers, X-Client-Id, X-Session-Id'
|
|
|
|
|
Access-Control-Allow-Credentials: 'true'
|
|
|
|
|
Access-Control-Max-Age: 1728000
|
2024-11-04 14:13:37 +01:00
|
|
|
##### Apply middlewares to the route
|
2024-10-27 06:10:27 +01:00
|
|
|
## The name must be unique
|
|
|
|
|
## List of middleware name
|
2024-10-30 18:01:53 +01:00
|
|
|
middlewares:
|
|
|
|
|
- api-forbidden-paths
|
2024-11-04 14:13:37 +01:00
|
|
|
# Example of a route | 2
|
2024-10-29 19:38:43 +01:00
|
|
|
- name: Basic auth
|
|
|
|
|
path: /protected
|
2024-10-27 06:10:27 +01:00
|
|
|
rewrite: /
|
2024-11-02 21:19:35 +01:00
|
|
|
destination: https://example.com
|
2024-10-27 06:10:27 +01:00
|
|
|
healthCheck:
|
|
|
|
|
cors: {}
|
2024-11-02 21:19:35 +01:00
|
|
|
middlewares:
|
|
|
|
|
- api-forbidden-paths
|
|
|
|
|
- basic-auth
|
2024-10-27 06:10:27 +01:00
|
|
|
|
|
|
|
|
#Defines proxy middlewares
|
2024-11-02 11:55:37 +01:00
|
|
|
# middleware name must be unique
|
2024-10-27 06:10:27 +01:00
|
|
|
middlewares:
|
|
|
|
|
# Enable Basic auth authorization based
|
2024-10-30 04:57:07 +01:00
|
|
|
- name: basic-auth
|
2024-10-30 04:52:49 +01:00
|
|
|
# Authentication types | jwt, basic, OAuth
|
2024-10-29 22:55:09 +01:00
|
|
|
type: basic
|
2024-10-30 18:01:53 +01:00
|
|
|
paths:
|
|
|
|
|
- /user
|
|
|
|
|
- /admin
|
|
|
|
|
- /account
|
2024-10-27 06:10:27 +01:00
|
|
|
rule:
|
|
|
|
|
username: admin
|
|
|
|
|
password: admin
|
|
|
|
|
#Enables JWT authorization based on the result of a request and continues the request.
|
2024-10-29 22:55:09 +01:00
|
|
|
- name: google-auth
|
2024-10-30 04:52:49 +01:00
|
|
|
# Authentication types | jwt, basic, OAuth
|
2024-10-29 09:39:31 +01:00
|
|
|
# jwt authorization based on the result of backend's response and continue the request when the client is authorized
|
2024-10-29 22:55:09 +01:00
|
|
|
type: jwt
|
2024-10-30 18:01:53 +01:00
|
|
|
# Paths to protect
|
|
|
|
|
paths:
|
|
|
|
|
- /protected-access
|
|
|
|
|
- /example-of-jwt
|
2024-11-02 11:55:37 +01:00
|
|
|
#- /* or wildcard path
|
2024-10-27 06:10:27 +01:00
|
|
|
rule:
|
2024-10-29 19:38:43 +01:00
|
|
|
# This is an example URL
|
2024-10-27 06:10:27 +01:00
|
|
|
url: https://www.googleapis.com/auth/userinfo.email
|
|
|
|
|
# Required headers, if not present in the request, the proxy will return 403
|
|
|
|
|
requiredHeaders:
|
|
|
|
|
- Authorization
|
2024-11-04 14:13:37 +01:00
|
|
|
# You can also get headers from the authentication request result and inject them into the next request header or params.
|
|
|
|
|
# In case you want to get headers from the authentication service and inject them into the next request headers.
|
|
|
|
|
# Set the request variable to the given value after the authorization request completes.
|
2024-11-02 12:12:22 +01:00
|
|
|
# In case you want to get headers from the authentication service and inject them into the next request headers.
|
2024-11-04 14:13:37 +01:00
|
|
|
# Key is authentication request response header Key. Value is the next Request header Key.
|
2024-10-30 18:01:53 +01:00
|
|
|
headers:
|
2024-11-04 14:13:37 +01:00
|
|
|
userId: Auth-UserId
|
|
|
|
|
userCountryId: Auth-UserCountryId
|
|
|
|
|
# In case you want to get headers from the Authentication service and inject them to the next request params.
|
|
|
|
|
#Key is authentication request response header Key. Value is the next Request parameter Key.
|
2024-10-30 18:01:53 +01:00
|
|
|
params:
|
|
|
|
|
userCountryId: countryId
|
2024-11-02 12:12:22 +01:00
|
|
|
# The server will return 403
|
2024-10-30 18:01:53 +01:00
|
|
|
- name: api-forbidden-paths
|
|
|
|
|
type: access
|
2024-11-02 12:12:22 +01:00
|
|
|
## prevents access paths
|
2024-10-30 18:01:53 +01:00
|
|
|
paths:
|
|
|
|
|
- /swagger-ui/*
|
|
|
|
|
- /v2/swagger-ui/*
|
|
|
|
|
- /api-docs/*
|
|
|
|
|
- /internal/*
|
|
|
|
|
- /actuator/*
|
2024-10-27 06:10:27 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Requirement
|
|
|
|
|
|
|
|
|
|
- Docker
|
2024-11-04 07:37:47 +01:00
|
|
|
|
|
|
|
|
## Contributing
|
|
|
|
|
|
|
|
|
|
The Goma Gateway project welcomes all contributors. We appreciate your help!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Give a Star! ⭐
|
|
|
|
|
|
|
|
|
|
If you like or are using Goma Gateway, please give it a star. Thanks!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
|
|
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Copyright
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2024 Jonas Kaninda
|