1

I have written an API in Go for Authentication.

  • You can POST /register which will create a new user and save it in the Postgres DB Let's say I have an Ingress setup somewhat like this.
  • Afterward you can POST /login with your credentials. This will create a session token and attach it to the cookie and creates an entry for the session in a Redis
  • You can also GET /logout which will revoke your token by deleting it from Redis and expiring your cookie

The API itself is also running in the kubernetes cluster in its own deployment with its own service and is also exposed via its own ingress.

Now I have a different Ingress for another service setup somewhat like this.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo
spec:
  tls:
    - hosts:
      - foo.domain.com
  rules:
  - host: foo.domain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: foo
            port:
              number: 5050

I want to setup Ingress with something similar to a Middleware in a way so every time someone wants to access the address foo.domain.com it directs the request to the Go API to check if the cookie is valid and then either allow or deny the access.

Is this possible or do I have to do it completely differently? I quite new to kubernetes so I need some help.

Thanks in advance :)

I have found this post where the answer was this:

annotations:
  nginx.ingress.kubernetes.io/auth-url: "https://$host/oauth2/auth"
  nginx.ingress.kubernetes.io/auth-signin: "https://$host/oauth2/start?rd=$escaped_request_uri"

But I have only found this in relation to an OAuth2 setup which I don't have.

gkit5
  • 63
  • 4
  • how do you test it locally with nginx same config you can use with ingress, so if you could share your nginx snippet or config then could get more idea. Never tried same similar mostly used oath only. Just looking forward to check cookie ? if ($http_cookie !~ 'Cookie' return the 401 ? – Harsh Manvar Dec 01 '22 at 14:48
  • @HarshManvar i don't know what an nginx snippet is it's the first time i have ever worked with kubernetes, ingress, etc. on this scale. In general i want to check the cookie, extract the attached session_token and validate that token. – gkit5 Dec 02 '22 at 09:25

0 Answers0