Skip to content

Commit 94a01ef

Browse files
committed
Refactor gateway (work-in-progress)
1 parent 3aacf0f commit 94a01ef

File tree

18 files changed

+40
-465
lines changed

18 files changed

+40
-465
lines changed

.github/workflows/labs64io-docker-publish.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,7 @@ jobs:
4242
- name: Build and push Docker image
4343
uses: docker/build-push-action@v6
4444
with:
45-
context: ./api-gateway-be
46-
push: true
47-
platforms: linux/amd64,linux/arm64/v8
48-
tags: |
49-
labs64/api-gateway:latest
50-
labs64/api-gateway:${{ steps.get_release_tag.outputs.RELEASE_TAG }}
51-
cache-from: type=gha,scope=${{ github.workflow }}
52-
cache-to: type=gha,mode=max,scope=${{ github.workflow }}
53-
54-
- name: Build and push Traefik AuthProxy Docker image
55-
uses: docker/build-push-action@v6
56-
with:
57-
context: ./traefik-authproxy
45+
context: .
5846
push: true
5947
platforms: linux/amd64,linux/arm64/v8
6048
tags: |
File renamed without changes.

README.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,46 @@
11
<p align="center"><img src="https://raw.githubusercontent.com/Labs64/.github/refs/heads/master/assets/labs64-io-ecosystem.png"></p>
22

3-
# Labs64.IO :: API Gateway
4-
## Unified API Gateway for Labs64.IO Microservices
3+
## Traefik Auth (M2M) Middleware
54

6-
![Docker Image Version](https://img.shields.io/docker/v/labs64/api-gateway?logo=docker&logoColor=%23E14817&color=%23E14817)
5+
This repository contains a custom Traefik ForwardAuth middleware. The middleware is designed to verify M2M (Machine-to-Machine) JWT tokens issued by Keycloak and enforce path-based role-based access control (RBAC) for microservices deployed on Kubernetes.
76

8-
Key responsibilities of the API Gateway:
7+
It receives incoming requests from Traefik, validates the JWT token, extracts user roles, and checks them against a configurable path/role mapping. If the request is authorized, it allows Traefik to forward the request to the backend service. Otherwise, it returns a `401 Unauthorized` or `403 Forbidden` response.
98

10-
- Request Routing: Directs incoming HTTP/S requests to the appropriate backend service or RabbitMQ exchange/queue.
11-
- Protocol Translation: Translates synchronous HTTP/S requests from clients into asynchronous messages for RabbitMQ, and vice-versa for responses.
12-
- Authentication and Authorization: Enforces security policies before requests reach your internal services.
13-
- Rate Limiting and Throttling: Protects your backend from abuse and ensures fair usage.
14-
- Caching: Caches responses for frequently accessed data, reducing load on your backend.
15-
- Request/Response Transformation: Modifies request or response bodies/headers to fit external API contracts.
16-
- Load Balancing: Distributes requests across multiple instances of your services.
17-
- Monitoring and Logging: Provides a central point for tracking API usage and performance.
9+
## Features
1810

19-
## Star History
11+
- JWT Verification: Validates tokens issued by Keycloak using public keys from the `.well-known` endpoint.
12+
- Role-Based Access Control (RBAC): Enforces access based on roles assigned to the user/client.
13+
- Configurable Role Mapping: Allows administrators to define a mapping of URL paths to required roles.
14+
- FastAPI Backend: A lightweight and performant backend for handling authentication logic.
2015

21-
[![Star History Chart](https://api.star-history.com/svg?repos=Labs64/labs64.io-api-gateway&type=Date)](https://www.star-history.com/#Labs64/labs64.io-api-gateway&Date)
16+
## Prerequisites
17+
18+
- A running Kubernetes cluster.
19+
- Traefik installed as an Ingress Controller in your cluster.
20+
- A configured Keycloak instance.
21+
- Docker for building the middleware container image.
22+
23+
## Configuration
24+
25+
The middleware is configured using environment variables.
26+
27+
- `KEYCLOAK_URL`: The base URL of your Keycloak instance (e.g., http://keycloak.default.svc.cluster.local:8080).
28+
- `KEYCLOAK_REALM`: The name of the realm in Keycloak (e.g., labs64io).
29+
- `KEYCLOAK_AUDIENCE`: The audience claim to verify in the JWT (e.g., labs64io_client).
30+
- `KEYCLOAK_DISCOVERY_URL`: The URL to the Keycloak discovery endpoint (e.g., http://keycloak.default.svc.cluster.local:8080/realms/labs64io/.well-known/openid-configuration).
31+
- `ROLE_MAPPING_FILE`: YAML file defining the path-to-role mapping. This can be passed as a ConfigMap in a production environment.
32+
33+
## Usage
34+
35+
- Once deployed, Traefik will intercept any request to *whoami.example.com* and forward it to the auth-middleware for authentication.
36+
- For a request to be successful, it must include a valid JWT in the Authorization header with the format `Bearer <token>`. The roles contained in the JWT must match the required roles for the requested path as defined in your role mapping.
37+
- The role mapping is a key part of the middleware's logic. You would define a dictionary that maps a path prefix to a list of required roles.
38+
39+
### For example:
40+
41+
- A request to `/api/admin` would require the `admin` role.
42+
- A request to `/api/users` would require either the `user` or `admin` role.
43+
44+
## License
45+
46+
This project is licensed under the MIT License.

api-gateway-be/Dockerfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

api-gateway-be/justfile

Lines changed: 0 additions & 22 deletions
This file was deleted.

api-gateway-be/pom.xml

Lines changed: 0 additions & 158 deletions
This file was deleted.

api-gateway-be/src/main/java/io/labs64/apigateway/ApiGatewayApplication.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

api-gateway-be/src/main/java/io/labs64/apigateway/helpers/IpAddressKeyResolver.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

api-gateway-be/src/main/resources/application-local.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)