Skip to content

Commit bc9f435

Browse files
committed
inital commit
1 parent eb7978b commit bc9f435

31 files changed

+1416
-0
lines changed

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/target/
2+
/config/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
.sts4-cache
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
20+
### NetBeans ###
21+
/nbproject/private/
22+
/build/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM anapsix/alpine-java:8
2+
3+
ADD /target/forwardauth.jar forwardauth.jar
4+
5+
EXPOSE 8080
6+
CMD ["java", "-jar", "forwardauth.jar"]

Jenkinsfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env groovy
2+
def dockerCredentials = "docker-hub-credentials"
3+
def dockerImage = "dniel/forwardauth"
4+
def appVersion
5+
6+
pipeline {
7+
agent any
8+
9+
stages {
10+
stage('Prepare') {
11+
steps {
12+
slackSend "Started ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
13+
14+
deleteDir()
15+
checkout scm
16+
17+
script {
18+
def gitShortCommit = sh([
19+
returnStdout: true,
20+
script : 'git rev-parse --short HEAD'
21+
]).trim()
22+
23+
def gitCommitTime = sh([
24+
returnStdout: true,
25+
script : 'git log -1 --pretty=format:%ct|date +"%m%d%Y-%H%M"'
26+
]).trim()
27+
28+
appVersion = "${gitCommitTime}-${gitShortCommit}"
29+
}
30+
}
31+
}
32+
33+
stage('Build') {
34+
steps {
35+
container('maven') {
36+
sh "mvn clean deploy -Dsha1=${appVersion} -Dchangelist=${env.BRANCH_NAME}"
37+
}
38+
}
39+
}
40+
41+
stage('Docker') {
42+
steps {
43+
container('docker') {
44+
withCredentials([usernamePassword(credentialsId: dockerCredentials, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
45+
sh "docker login -u ${USERNAME} -p ${PASSWORD}"
46+
sh "docker build -t ${dockerImage} ."
47+
sh "docker tag ${dockerImage} ${dockerImage}:${appVersion}"
48+
sh "docker push ${dockerImage}"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
post {
55+
success {
56+
slackSend(color: 'GREEN',
57+
message: "${env.JOB_NAME} ${env.BUILD_NUMBER} completed successfully :) (<${env.BUILD_URL}|Open>)")
58+
}
59+
failure {
60+
slackSend(color: 'RED',
61+
message: "${env.JOB_NAME} ${env.BUILD_NUMBER} completed failed :( (<${env.BUILD_URL}|Open>)")
62+
}
63+
}
64+
}

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Traefik Forward Auth0
2+
3+
# Development
4+
5+
## Compile
6+
`mvn clean install`
7+
8+
## Run
9+
`mvn spring-boot:run` or start the main class `AuthApplication` from IDE
10+
11+
## Configuration
12+
Put the application config somewhere where SpringBoot can find it.
13+
For example in a /config application directory.
14+
15+
### Example config
16+
```yaml
17+
domain: https://xxxxx.xx.auth0.com/
18+
token-endpoint: https://xxx.xx.auth0.com/oauth/token
19+
redirect-uri: http://www.example.test/oauth2/signin
20+
authorize-url: https://xxxx.xx.auth0.com/authorize
21+
22+
default:
23+
name: www.example.test
24+
client-id: <from auth0 application config>
25+
client-secret: <from auth0 application config>
26+
audience: <from auth0 api config> or blank
27+
scope: "profile openid email"
28+
redirect-uri: http://www.example.test/oauth2/signin
29+
token-cookie-domain: example.test
30+
31+
apps:
32+
- name: www.example.test
33+
client-id: <from auth0 application config>
34+
client-secret: <from auth0 application config>
35+
audience: <from auth0 api config> or blank
36+
scope: "profile openid email"
37+
redirect-uri: http://www.example.test/oauth2/signin
38+
token-cookie-domain: example.test
39+
40+
- name: traefik.example.test
41+
client-id: <from auth0 application config>
42+
client-secret: <from auth0 application config>
43+
audience: <from auth0 api config> or blank
44+
scope: "profile openid email"
45+
redirect-uri: http://traefik.example.test/oauth2/signin
46+
token-cookie-domain: traefik.example.test
47+
```
48+
49+
# Publishing
50+
I am publishing my Docker images to https://hub.docker.com/r/dniel/forwardauth
51+
If you want to build your own images, use the docker CLI to build and publish images to your own repo instead.
52+
53+
## Deployment to Kubernetes
54+
Check out the helm chart directory `helm` for template for the Helm chart to create Kubernetes deployment configuration.
55+
56+
# Tech
57+
- Java8
58+
- Tomcat
59+
- Kotlin
60+
- JAX-RS
61+
- Kubernetes
62+
- Helm
63+
- Docker
64+
65+
# TODO
66+
- create unit tests
67+
- create integration tests
68+
- signout endpoint
69+
- user profile endpoint
70+
- error handling, the current code is not handling much of Auth0 errormessages and does not format errors to the users.

helm/.helmignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
config/
23+
target/
24+
.mvn
25+
src/

helm/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
appVersion: "1.0"
3+
description: A Helm chart for Kubernetes to install Auth0 Authorization application for Traefik forward authentication.
4+
name: forwardauth
5+
version: 0.1.0

helm/templates/NOTES.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range .Values.ingress.hosts }}
4+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
5+
{{- end }}
6+
{{- else if contains "NodePort" .Values.service.type }}
7+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "helm.fullname" . }})
8+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
9+
echo http://$NODE_IP:$NODE_PORT
10+
{{- else if contains "LoadBalancer" .Values.service.type }}
11+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
12+
You can watch the status of by running 'kubectl get svc -w {{ template "helm.fullname" . }}'
13+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "helm.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
14+
echo http://$SERVICE_IP:{{ .Values.service.port }}
15+
{{- else if contains "ClusterIP" .Values.service.type }}
16+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "helm.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
17+
echo "Visit http://127.0.0.1:8080 to use your application"
18+
kubectl port-forward $POD_NAME 8080:80
19+
{{- end }}

helm/templates/_helpers.tpl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "helm.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "helm.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "helm.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}

helm/templates/configmap.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ template "helm.fullname" . }}-config
5+
labels:
6+
app: {{ template "helm.name" . }}
7+
chart: {{ template "helm.chart" . }}
8+
release: {{ .Release.Name }}
9+
heritage: {{ .Release.Service }}
10+
data:
11+
application.yaml: TODO: add config here for spring boot app.

helm/templates/deployment.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ template "helm.fullname" . }}
5+
labels:
6+
app: {{ template "helm.name" . }}
7+
chart: {{ template "helm.chart" . }}
8+
release: {{ .Release.Name }}
9+
heritage: {{ .Release.Service }}
10+
spec:
11+
replicas: {{ .Values.replicaCount }}
12+
selector:
13+
matchLabels:
14+
app: {{ template "helm.name" . }}
15+
release: {{ .Release.Name }}
16+
template:
17+
metadata:
18+
labels:
19+
app: {{ template "helm.name" . }}
20+
release: {{ .Release.Name }}
21+
spec:
22+
containers:
23+
- name: {{ .Chart.Name }}
24+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
25+
imagePullPolicy: {{ .Values.image.pullPolicy }}
26+
ports:
27+
- name: http
28+
containerPort: 8080
29+
protocol: TCP
30+
volumeMounts:
31+
- name: config-volume
32+
mountPath: /config
33+
34+
# TODO: Fix probes
35+
# livenessProbe:
36+
# httpGet:
37+
# path: /
38+
# port: 8080
39+
# readinessProbe:
40+
# httpGet:
41+
# path: /actuator/health
42+
# port: 8080
43+
resources:
44+
{{ toYaml .Values.resources | indent 12 }}
45+
46+
volumes:
47+
- name: config-volume
48+
configMap:
49+
name: {{ template "helm.fullname" . }}-config
50+
51+
{{- with .Values.nodeSelector }}
52+
nodeSelector:
53+
{{ toYaml . | indent 8 }}
54+
{{- end }}
55+
{{- with .Values.affinity }}
56+
affinity:
57+
{{ toYaml . | indent 8 }}
58+
{{- end }}
59+
{{- with .Values.tolerations }}
60+
tolerations:
61+
{{ toYaml . | indent 8 }}
62+
{{- end }}

helm/templates/ingress.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{- if .Values.ingress.enabled -}}
2+
{{- $fullName := include "helm.fullname" . -}}
3+
{{- $servicePort := .Values.service.port -}}
4+
{{- $ingressPath := .Values.ingress.path -}}
5+
apiVersion: extensions/v1beta1
6+
kind: Ingress
7+
metadata:
8+
name: {{ $fullName }}
9+
labels:
10+
app: {{ template "helm.name" . }}
11+
chart: {{ template "helm.chart" . }}
12+
release: {{ .Release.Name }}
13+
heritage: {{ .Release.Service }}
14+
{{- with .Values.ingress.annotations }}
15+
annotations:
16+
{{ toYaml . | indent 4 }}
17+
{{- end }}
18+
spec:
19+
{{- if .Values.ingress.tls }}
20+
tls:
21+
{{- range .Values.ingress.tls }}
22+
- hosts:
23+
{{- range .hosts }}
24+
- {{ . }}
25+
{{- end }}
26+
secretName: {{ .secretName }}
27+
{{- end }}
28+
{{- end }}
29+
rules:
30+
{{- range .Values.ingress.hosts }}
31+
- host: {{ . }}
32+
http:
33+
paths:
34+
- path: {{ $ingressPath }}
35+
backend:
36+
serviceName: {{ $fullName }}
37+
servicePort: http
38+
{{- end }}
39+
{{- end }}

helm/templates/service.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ template "helm.fullname" . }}
5+
labels:
6+
app: {{ template "helm.name" . }}
7+
chart: {{ template "helm.chart" . }}
8+
release: {{ .Release.Name }}
9+
heritage: {{ .Release.Service }}
10+
spec:
11+
type: {{ .Values.service.type }}
12+
ports:
13+
- port: {{ .Values.service.port }}
14+
targetPort: 8080
15+
protocol: TCP
16+
name: http
17+
selector:
18+
app: {{ template "helm.name" . }}
19+
release: {{ .Release.Name }}

0 commit comments

Comments
 (0)