Skip to content

Commit

Permalink
Add helm charts for 'dex' and 'dex-k8s-authenticator', add README, ge…
Browse files Browse the repository at this point in the history
…t Docker to ignore the charts folder
  • Loading branch information
whereisaaron committed Feb 16, 2018
1 parent 92d2b0d commit 5d647f4
Show file tree
Hide file tree
Showing 26 changed files with 1,164 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*~
charts
examples
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*~
bin
vendor
32 changes: 32 additions & 0 deletions charts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Helm charts for installing `dex` with `dex-k8s-authenticator`

The charts in this folder install [`dex`](https://github.com/coreos/dex)
with [`dex-k8s-authenticator`](https://github.com/mintel/dex-k8s-authenticator)

`dex-k8s-authenticator` is a helper application for `dex`. `dex` lets you use external
Identify Providers (like Google, Microsoft, GitHUb, LDAP) to authenticate access to Kubernetes cluster
(e.g. for `kubectl`). This helper makes it easy to provide a web UI for one or more clusters.
It give uses the information and commands to configure `kubectl` to work with the credentials `dex` provides.

Each install of `dex` and/or `dex-k8s-authenticator` can support multiple Kubernetes clusters.
So you can install one of each for all your clusters, one in each cluster, or any combination.

```
git clone [email protected]:mintel/dex-k8s-authenticator.git
helm inspect values charts/dex > dex.yaml
helm inspect values charts/dex-k8s-authenticator > dex-k8s-authenticator.yaml
```
Edit the values files for your environment and requirements (`dex.yaml` and `dex-k8s-authenticator.yaml`).

Create the DNS names for your `dex` (e.g. 'dex.example.com') and `dex-k8s-authenticator` (e.g. 'login.example.com')
pointed at the ingress controller you are using. Be sure to enable HTTPS. You can install
[`cert-manager`](https://github.com/jetstack/cert-manager) to automatically issue Lets Encrypt certificates.

You also need to configure each Kubernetes cluster to use `dex` at e.g. 'dex.example.com' by [setting the OIDC parameters
for the Kubernetes API server](https://kubernetes.io/docs/admin/authentication/#openid-connect-tokens).
This is easy using [`kube-aws` installer](https://github.com/kubernetes-incubator/kube-aws/tree/master/contrib/dex).

```
helm install --namespace dex --values dex.yaml charts/dex
helm install --namespace dex --values dex-k8s-authenticator charts/dex-k8s-authenticator
```
21 changes: 21 additions & 0 deletions charts/dex-k8s-authenticator/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
5 changes: 5 additions & 0 deletions charts/dex-k8s-authenticator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "0.1"
description: "Authenticator for using Dex with Kubernetes"
name: dex-k8s-authenticator
version: 0.1.0
76 changes: 76 additions & 0 deletions charts/dex-k8s-authenticator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Helm chart for dex-k8s-authenticator

This chart installs [`dex-k8s-authenticator`](https://github.com/mintel/dex-k8s-authenticator) in a Kubernetes cluster.
`dex-k8s-authenticator` is a helper application for [`dex`](https://github.com/coreos/dex). `dex` lets you use external
Identify Providers (like Google, Microsoft, GitHUb, LDAP) to authenticate access to Kubernetes cluster
(e.g. for `kubectl`). This helper makes it easy to provide a web UI for one or more clusters.
It give uses the information and commands to configure `kubectl` to work with the credentials `dex` provides.

You can configure one or more clusters in this chart configuration, for the one or more `dex` installs you may have.

```
# Default values for dex-k8s-authenticator.
# Deploy environment label, e.g. dev, test, prod
global:
deployEnv: dev
replicaCount: 1
image:
repository: 212381861325.dkr.ecr.ap-southeast-2.amazonaws.com/kube/dex-k8s-authenticator
tag: latest
pullPolicy: Always
dexK8sAuthenticator:
port: 5555
debug: false
#logoUrl: http://<path-to-your-logo.png>
#tlsCert: /path/to/dex-client.crt
#tlsKey: /path/to/dex-client.key
clusters:
- name: my-cluster
short_description: "My Cluster"
description: "Example Cluster Long Description..."
client_secret: ZXhhbXBsZS1hcHAtc2VjcmV0
issuer: https://dex.example.com
k8s_master_uri: https://my-cluster.example.com
client_id: my-cluster
redirect_uri: https://login.example.com/callback/my-cluster
k8s_ca_uri: https://url-to-your-ca.crt
service:
type: ClusterIP
port: 5555
ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- chart-example.local
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}
```
19 changes: 19 additions & 0 deletions charts/dex-k8s-authenticator/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "dex-k8s-authenticator.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "dex-k8s-authenticator.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "dex-k8s-authenticator.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "dex-k8s-authenticator.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
32 changes: 32 additions & 0 deletions charts/dex-k8s-authenticator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "dex-k8s-authenticator.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "dex-k8s-authenticator.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "dex-k8s-authenticator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
26 changes: 26 additions & 0 deletions charts/dex-k8s-authenticator/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "dex-k8s-authenticator.fullname" . }}
labels:
app: {{ template "dex-k8s-authenticator.fullname" . }}
env: {{ default "dev" .Values.global.deployEnv }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
config.yaml: |-
{{- with .Values.dexK8sAuthenticator }}
listen: http://0.0.0.0:{{ default "5555" .port }}
debug: {{ default "false" .debug }}
{{- if .logoUrl }}
logo_uri: {{ .logoUrl }}
{{- end }}
{{- if and .tlsCert .tlsKey }}
tls_cert: "{{ .tlsCert }}"
tls_key: "{{ .tlsKey }}"
{{- end }}
clusters:
{{ toYaml .clusters | indent 4 }}
{{- end }}

63 changes: 63 additions & 0 deletions charts/dex-k8s-authenticator/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ template "dex-k8s-authenticator.fullname" . }}
labels:
app: {{ template "dex-k8s-authenticator.name" . }}
env: {{ default "dev" .Values.global.deployEnv }}
chart: {{ template "dex-k8s-authenticator.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "dex-k8s-authenticator.name" . }}
env: {{ default "dev" .Values.global.deployEnv }}
release: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ template "dex-k8s-authenticator.name" . }}
env: {{ default "dev" .Values.global.deployEnv }}
release: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: [ "--config", "config.yaml" ]
ports:
- name: http
containerPort: {{ default "5555" .Values.dexK8sAuthenticator.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
volumeMounts:
- name: config
subPath: config.yaml
mountPath: /app/config.yaml
resources:
{{ toYaml .Values.resources | indent 10 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 6 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 6 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 6 }}
{{- end }}
volumes:
- name: config
configMap:
name: {{ template "dex-k8s-authenticator.name" . }}
40 changes: 40 additions & 0 deletions charts/dex-k8s-authenticator/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "dex-k8s-authenticator.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app: {{ template "dex-k8s-authenticator.name" . }}
env: {{ default "dev" .Values.global.deployEnv }}
chart: {{ template "dex-k8s-authenticator.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . }}
http:
paths:
- path: {{ $ingressPath }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}
20 changes: 20 additions & 0 deletions charts/dex-k8s-authenticator/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "dex-k8s-authenticator.fullname" . }}
labels:
app: {{ template "dex-k8s-authenticator.name" . }}
env: {{ default "dev" .Values.global.deployEnv }}
chart: {{ template "dex-k8s-authenticator.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app: {{ template "dex-k8s-authenticator.name" . }}
release: {{ .Release.Name }}
Loading

0 comments on commit 5d647f4

Please sign in to comment.