Skip to content

Commit

Permalink
Merge pull request #35 from carverauto/updates/use_gofr_oauth
Browse files Browse the repository at this point in the history
Updates/use gofr oauth
  • Loading branch information
mfreeman451 authored Oct 26, 2024
2 parents a7cb621 + ef677fd commit 8b621ae
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 230 deletions.
4 changes: 2 additions & 2 deletions cmd/jwks-server/Makefile → cmd/auth-server/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Define variables
KO_DOCKER_REPO := ghcr.io/carverauto/jwks-server
KO_DOCKER_REPO := ghcr.io/carverauto/auth-server
VERSION := v0.0.01

# Default target
all: build

# Build the binary locally
build:
go build -o jwks-server .
go build -o auth-server .

# Build and push the container image using ko
ko-build:
Expand Down
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions cmd/auth-server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"encoding/json"
"os"

"gofr.dev/pkg/gofr"
"gofr.dev/pkg/gofr/http/response"
)

const (
rulesPath = "/app/config/rules.json"
)

func main() {
app := gofr.New()

app.GET("/rules.json", RulesHandler)

app.Run()
}

func RulesHandler(c *gofr.Context) (interface{}, error) {
data, err := os.ReadFile(rulesPath)
if err != nil {
return nil, err
}

var jsonObj interface{}
if err := json.Unmarshal(data, &jsonObj); err != nil {
return nil, err
}

return response.Raw{Data: jsonObj}, nil
}
46 changes: 0 additions & 46 deletions cmd/jwks-server/main.go

This file was deleted.

105 changes: 105 additions & 0 deletions k8s/auth-server/base/auth-server-configmaps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: oathkeeper-rules-data
namespace: eventrunner
data:
rules.json: |
[
{
"id": "api-health-check",
"upstream": {
"preserve_host": true,
"url": "http://eventrunner-api.eventrunner.svc.cluster.local:8200"
},
"match": {
"url": "/api/v1/health",
"methods": ["GET"]
},
"authenticators": [
{
"handler": "anonymous",
"config": {
"subject": "guest"
}
}
],
"authorizer": {
"handler": "allow"
},
"mutators": [
{
"handler": "noop"
}
]
},
{
"id": "auth-check",
"upstream": {
"preserve_host": true,
"url": "http://eventrunner-api.eventrunner.svc.cluster.local:8200"
},
"match": {
"url": "/judge",
"methods": ["GET"]
},
"authenticators": [
{
"handler": "anonymous",
"config": {
"subject": "anonymous"
}
}
],
"authorizer": {
"handler": "allow"
},
"mutators": [
{
"handler": "header",
"config": {
"headers": {
"X-User": "anonymous",
"X-Tenant-ID": "default",
"X-Request-Id": "{{ print .RequestID }}"
}
}
}
]
},
{
"id": "protected-endpoints",
"upstream": {
"preserve_host": true,
"url": "http://eventrunner-api.eventrunner.svc.cluster.local:8200"
},
"match": {
"url": "/api/v1/<.*>",
"methods": ["GET", "POST", "PUT", "DELETE", "PATCH"]
},
"authenticators": [
{
"handler": "jwt",
"config": {
"jwks_urls": ["https://affectionate-brattain-fl0yahcycw.projects.oryapis.com/.well-known/jwks.json"],
"trusted_issuers": ["https://affectionate-brattain-fl0yahcycw.projects.oryapis.com"]
}
}
],
"authorizer": {
"handler": "allow"
},
"mutators": [
{
"handler": "header",
"config": {
"headers": {
"X-User": "{{ print .Subject }}",
"X-Tenant-ID": "{{ print .Extra.tenant_id }}",
"X-Request-Id": "{{ print .RequestID }}"
}
}
}
]
}
]
34 changes: 34 additions & 0 deletions k8s/auth-server/base/auth-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-server
namespace: eventrunner
spec:
replicas: 1
selector:
matchLabels:
app: auth-server
template:
metadata:
labels:
app: auth-server
spec:
containers:
- name: auth-server
image: ghcr.io/carverauto/auth-server:v0.0.06
imagePullPolicy: Always
ports:
- containerPort: 8000
volumeMounts:
- name: rules-volume
mountPath: /app/config/rules.json
subPath: rules.json
volumes:
- name: rules-volume
configMap:
name: oathkeeper-rules-data
items:
- key: rules.json
path: rules.json
imagePullSecrets:
- name: ghcr-io-cred
4 changes: 4 additions & 0 deletions k8s/auth-server/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
- auth-server-configmaps.yaml
- auth-server.yaml
- service.yaml
13 changes: 13 additions & 0 deletions k8s/auth-server/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: auth-server
namespace: eventrunner
spec:
selector:
app: auth-server
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: ClusterIP
8 changes: 0 additions & 8 deletions k8s/er-api/base/db_secret.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions k8s/er/base/kustomization.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data:
DB_NAME=eventrunner
DB_PORT=2001
DB_DIALECT=mongo
DB_URL=mongodb://mongodb.svc.cluster.local:27017
DB_URL=mongodb://er-mongodb.svc.cluster.local:27017
.staging.env: |
LOG_LEVEL=DEBUG
APP_NAME=eventrunner
Expand All @@ -27,4 +27,4 @@ data:
DB_NAME=eventrunner
DB_PORT=2001
DB_DIALECT=mongo
DB_URL=mongodb://mongodb.svc.cluster.local:27017
DB_URL=mongodb://er-mongodb.svc.cluster.local:27017
File renamed without changes.
29 changes: 29 additions & 0 deletions k8s/eventrunner-api/base/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: eventrunner-api
namespace: eventrunner
annotations:
cert-manager.io/cluster-issuer: threadr-issuer
nginx.ingress.kubernetes.io/auth-url: "http://oathkeeper-proxy.default.svc.cluster.local:4455/judge"
nginx.ingress.kubernetes.io/auth-response-headers: "X-User,X-Tenant-ID,X-Request-Id"
nginx.ingress.kubernetes.io/auth-preserve-uri: "true"
nginx.ingress.kubernetes.io/auth-always-set-cookie: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- api.tunnel.threadr.ai
secretName: eventrunner-api-tls
rules:
- host: api.tunnel.threadr.ai
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: eventrunner-api
port:
number: 8200
7 changes: 7 additions & 0 deletions k8s/eventrunner-api/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
namespace: eventrunner
resources:
- eventrunner.yaml
- configmap.yaml
- service.yaml
- ingress.yaml
13 changes: 13 additions & 0 deletions k8s/eventrunner-api/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: eventrunner-api
namespace: eventrunner
spec:
selector:
app: eventrunner-api
ports:
- protocol: TCP
port: 8200
targetPort: 8200
type: ClusterIP
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 0 additions & 35 deletions k8s/jwks-server/base/jwks-server.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions k8s/jwks-server/base/kustomization.yaml

This file was deleted.

Loading

0 comments on commit 8b621ae

Please sign in to comment.