Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

website/docs: fix nginx ingress proxy example #8245

Merged
merged 3 commits into from
Jan 22, 2024

Conversation

eliottness
Copy link
Contributor

Details

👋 Hey,

I was trying to add an ingress for my k8s cluster to setup a proxy application and copy-pasting the example clearly did not work. Here is a fix for that.


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)
  • The translation files have been updated (make i18n-extract)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make website)

👋 Hey,

I was trying to add an ingress for my k8s cluster to setup a proxy application and copy-pasting the example clearly did not work. Here is a fix for that

Signed-off-by: Eliott Bouhana <47679741+eliottness@users.noreply.github.com>
@eliottness eliottness requested a review from a team as a code owner January 21, 2024 17:54
Copy link

netlify bot commented Jan 21, 2024

Deploy Preview for authentik-storybook canceled.

Name Link
🔨 Latest commit 58e59d0
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/65ae20ea5c36d90008bf0fbd

Copy link

netlify bot commented Jan 21, 2024

Deploy Preview for authentik ready!

Name Link
🔨 Latest commit 58e59d0
🔍 Latest deploy log https://app.netlify.com/sites/authentik/deploys/65ae20ea54edad0008eceb3e
😎 Deploy Preview https://deploy-preview-8245--authentik.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@rissson rissson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Elliot, fancy seeing you here! Thank you for your contribution!

website/docs/providers/proxy/_nginx_ingress.md Outdated Show resolved Hide resolved
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
@rissson rissson changed the title docs: fix nginx ingress proxy example website/docs: fix nginx ingress proxy example Jan 22, 2024
@rissson rissson enabled auto-merge (squash) January 22, 2024 07:52
Copy link

codecov bot commented Jan 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0467df1) 92.29% compared to head (58e59d0) 92.31%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8245      +/-   ##
==========================================
+ Coverage   92.29%   92.31%   +0.01%     
==========================================
  Files         608      608              
  Lines       30262    30262              
==========================================
+ Hits        27929    27935       +6     
+ Misses       2333     2327       -6     
Flag Coverage Δ
e2e 50.59% <ø> (+0.01%) ⬆️
integration 26.39% <ø> (ø)
unit 89.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
@rissson rissson merged commit 2bc865b into goauthentik:main Jan 22, 2024
67 checks passed
@eliottness eliottness deleted the patch-1 branch January 22, 2024 14:19
kensternberg-authentik added a commit that referenced this pull request Jan 22, 2024
* main: (21 commits)
  stages/authenticator_validate: use friendly_name for stage selector when enrolling (#8255)
  web: bump vite from 5.0.10 to 5.0.12 in /web (#8241)
  web: bump the wdio group in /tests/wdio with 4 updates (#8253)
  web: bump rollup from 4.9.5 to 4.9.6 in /web (#8251)
  web: bump core-js from 3.35.0 to 3.35.1 in /web (#8250)
  web: bump the sentry group in /web with 1 update (#8249)
  core: bump ruff from 0.1.13 to 0.1.14 (#8247)
  website: bump react-tooltip from 5.25.2 to 5.26.0 in /website (#8248)
  Update applications.md
  website/docs: fix nginx ingress proxy example (#8245)
  website/blog: add Rebecca's byline, add links for Reddit screenshots (#8238)
  website/blog: Security hygiene Blog (#8225)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh_CN (#8235)
  translate: Updates for file web/xliff/en.xlf in zh-Hans (#8232)
  web: bump the storybook group in /web with 7 updates (#8231)
  core: bump drf-spectacular from 0.27.0 to 0.27.1 (#8230)
  translate: Updates for file web/xliff/en.xlf in zh_CN (#8233)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh-Hans (#8234)
  web/components: improve error handling in ak-search-select (#8228)
  rbac: fix invitations listing with restricted permissions (#8227)
  ...
@drg-tanasescu
Copy link

@eliottness Do you have any working example of a nginx ingress with authentik on it ? (Authentik deployed with helm on a different cluster, external Outpost)

@eliottness
Copy link
Contributor Author

eliottness commented Jun 4, 2024

I don't have an external outpost but I have this if it can help:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app
  namespace: app
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
    nginx.ingress.kubernetes.io/auth-url: http://ak-outpost-authentik-embedded-outpost.authentik.svc.cluster.local:9000/outpost.goauthentik.io/auth/nginx
    nginx.ingress.kubernetes.io/auth-signin: https://app.domain.com/outpost.goauthentik.io/start?rd=$escaped_request_uri
    nginx.ingress.kubernetes.io/auth-response-headers: Set-Cookie,X-authentik-username,X-authentik-groups,X-authentik-email,X-authentik-name,X-authentik-uid
    nginx.ingress.kubernetes.io/auth-snippet: |
      proxy_set_header X-Forwarded-Host $http_host;
  labels:
    name: app
spec:
  rules:
  - host: app.domain.com
    http:
      paths:
      - pathType: Prefix
        path: "/outpost.goauthentik.io"
        backend:
          service:
            name: authentik
            port: 
              number: 9000
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: app
            port: 
              number: 80
  tls:
    - hosts:
      - app.domain.com
      secretName: letsencrypt

I had to add controller.allowSnippetAnnotations=true to the nginx ingress helm chart deployment to register the auth-snippet annotation

@eliottness
Copy link
Contributor Author

@drg-tanasescu ☝️

@drg-tanasescu
Copy link

drg-tanasescu commented Jun 4, 2024

Thank you, but for this to work you need to have the app and the authentik in same namespace or am i wrong ?

    http:
      paths:
      - pathType: Prefix
        path: "/outpost.goauthentik.io"
        backend:
          service:
            name: authentik
            port: 
              number: 9000

@eliottness
Copy link
Contributor Author

eliottness commented Jun 4, 2024

Thank you, but for this to work you need to have the app and the authentik in same namespace or am i wrong ?

@drg-tanasescu Ah yes, you made me remember that there is a little trickery: an ExternalName service.

apiVersion: v1
kind: Service
metadata:
  name: authentik
  namespace: app
spec:
  externalName: ak-outpost-authentik-embedded-outpost.authentik.svc.cluster.local
  type: ExternalName

@drg-tanasescu
Copy link

I tried with a service like this and didn't work.

apiVersion: v1
kind: Service
metadata:
  name: authentik-external-service
spec:
  type: ExternalName
  externalName: auth.dev.example.com

This svc is not created automatically: ak-outpost-authentik-embedded-outpost

$ ktools get svc
authentik-postgresql        ClusterIP 
authentik-postgresql-hl    ClusterIP   
authentik-redis-headless  ClusterIP  
authentik-redis-master     ClusterIP  
authentik-server                ClusterIP  

And this worked (with traefik ingress)

---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: whoamiv1
  labels:
    name: whoamiv1
spec:
  replicas: 1
  selector:
    matchLabels:
      task: whoamiv1
  template:
    metadata:
      labels:
        task: whoamiv1
    spec:
      containers:
        - name: whoamiv1
          image: traefik/traefikee-webapp-demo:v2
          args:
            - -ascii
            - -name=whoami-traefik
          ports:
            - containerPort: 80
          readinessProbe:
            httpGet:
              path: /ping
              port: 80
            failureThreshold: 1
            initialDelaySeconds: 2
            periodSeconds: 3
            successThreshold: 1
            timeoutSeconds: 2
---
apiVersion: v1
kind: Service
metadata:
  name: whoamiv1
spec:
  ports:
    - name: http
      port: 80
  selector:
    task: whoamiv1

---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: middlewares-authentik
  namespace: internal-tools
spec:
  forwardAuth:
    address: https://auth.dev.example.com/outpost.goauthentik.io/auth/traefik
    trustForwardHeader: true
    authResponseHeaders:
      - X-authentik-username
      - X-authentik-groups
      - X-authentik-email
      - X-authentik-name
      - X-authentik-uid
      - X-authentik-jwt
      - X-authentik-meta-jwks
      - X-authentik-meta-outpost
      - X-authentik-meta-provider
      - X-authentik-meta-app
      - X-authentik-meta-version
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami-http-ing
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: web
    kubernetes.io/ingress.class: traefik-internal
    traefik.ingress.kubernetes.io/router.middlewares: internal-tools-middlewares-authentik@kubernetescrd
spec:
  rules:
    - host: whoami-internal.dev.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: whoamiv1
                port:
                  number: 80

I will create tomorrow an issue if i get no answers on the Discord channel and ping you there, hope we can create a working example like this one with traefik.

@eliottness
Copy link
Contributor Author

@drg-tanasescu All the mentions to ak-outpost-authentik-embedded-outpost.authentik.svc.cluster.local in my code are referring to the embedded outpost (e.g. authentik itself). It should be changed to the url of your outpost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants