Kubernetes
Tinyauth supports Kubernetes based deployments making it easy to add an IdP or an authentication middleware to your Kubernetes cluster.
Requirements
Section titled “Requirements”- A Kubernetes cluster
We will use k3s and Traefik in this tutorial so, ingress instructions may differ for your setup.
Installation
Section titled “Installation”Before installing Tinyauth, we need to give it access to the Kubernetes API in order to be able to discover ACLs from ingresses. To achieve this, we firstly need to create the Tinyauth namespace:
apiVersion: v1kind: Namespacemetadata: name: tinyauth labels: app: tinyauthThen, we need a Cluster Role to give Tinyauth permissions to see the ingresses:
apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: tinyauth-ingressrules: - apiGroups: ["networking.k8s.io"] resources: ["ingresses"] verbs: ["get", "list", "watch"]Finally, we need to create a Cluster Role Binding to give the Tinyauth service account access to the Cluster Role.
apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: tinyauth-ingresssubjects: - kind: ServiceAccount name: tinyauth-sa namespace: tinyauthroleRef: kind: ClusterRole name: tinyauth-ingress apiGroup: rbac.authorization.k8s.ioLet’s also create the Tinyauth service account while we are here:
apiVersion: v1kind: ServiceAccountmetadata: name: tinyauth-sa namespace: tinyauthTo install Tinyauth with helm, firstly add the repository:
helm repo add tinyauth https://helm.tinyauth.apphelm repo updateCreate your values.yaml file, default file with all options can be found
in the repository.
Check the configuration for the required values.
It is recommended (and required for IP address ACLs) that you also set the tinyauth.auth.trustedProxies
environment variable to the IP address of your Traefik instance so Tinyauth can trust the
X-Real-IP and X-Forwarded-Forheaders and get the correct client IP.
Then install the Tinyauth chart:
helm install tinyauth tinyauth/tinyauth -f values.yaml -n tinyauthIf everything goes well, you should see the Tinyauth pod running in the tinyauth namespace.
manual
Section titled “manual”To install Tinyauth manually, we firstly need a secret containing our configuration:
apiVersion: v1kind: Secretmetadata: name: tinyauth-secret namespace: tinyauthtype: OpaquestringData: TINYAUTH_APPURL: http://tinyauth.example.com TINYAUTH_AUTH_USERS: your-username-password-hashIt is recommended (and required for IP address ACLs) that you also set the TINYAUTH_AUTH_TRUSTEDPROXIES
environment variable to the IP address of your Traefik instance so Tinyauth can trust the
X-Real-IP and X-Forwarded-Forheaders and get the correct client IP.
Now, we can safely deploy Tinyauth:
apiVersion: apps/v1kind: Deploymentmetadata: name: tinyauth-dp namespace: tinyauth labels: app: tinyauthspec: replicas: 1 selector: matchLabels: app: tinyauth template: metadata: labels: app: tinyauth spec: serviceAccountName: tinyauth-sa containers: - name: tinyauth image: ghcr.io/tinyauthapp/tinyauth:v5 ports: - containerPort: 3000 name: web envFrom: - secretRef: name: tinyauth-secretThen create a simple Cluster IP to expose Tinyauth:
apiVersion: v1kind: Servicemetadata: name: tinyauth-svc-cip namespace: tinyauthspec: selector: app: tinyauth ports: - name: web protocol: TCP port: 3000 targetPort: web type: ClusterIPAnd finally an ingress exposing Tinyauth:
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: tinyauth-ingress namespace: tinyauthspec: rules: - host: tinyauth.example.com http: paths: - pathType: Prefix path: / backend: service: name: tinyauth-svc-cip port: number: 3000If everything deploys correctly, Tinyauth should start up with no errors and be accessible under
http://tinyauth.example.com.
Using forward-auth
Section titled “Using forward-auth”Tinyauth officially supports only the Traefik proxy for forward-auth. However, it works with other proxies like Istio. Instructions on these proxies can be found in the community guide.
To use Tinyauth as a forward-auth middleware in Traefik, just create a middleware using Traefik’s CRD:
apiVersion: traefik.io/v1alpha1kind: Middlewaremetadata: name: tinyauth namespace: tinyauthspec: forwardAuth: address: http://tinyauth-svc-cip.tinyauth.svc.cluster.local:3000/api/auth/traefik authResponseHeaders: - remote-user - remote-name - remote-email - remote-groups - remote-sub - authorizationNow, in your Ingresses you can just define the Tinyauth middleware and use your ACLs as you would in Docker. For example:
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: annotations: tinyauth.apps.myapp.config.domain: myapp.example.com tinyauth.apps.myapp.path.allow: /foo traefik.ingress.kubernetes.io/router.entrypoints: web traefik.ingress.kubernetes.io/router.middlewares: tinyauth-tinyauth@kubernetescrd name: myapp-ingressspec: rules: - host: myapp.example.com http: paths: - pathType: Prefix path: / backend: service: name: myapp-svc-cip port: number: 80After deploying the ingress and trying to access the app at the configured domain, you should be redirected to Tinyauth for authentication.