2 KongConsumer for apikey authentication for 1 service with different path

Hi,
I am a new beginner of kong for kubernetes and for my case that i need to create 2 consumers and use these 2 consumers with 1 service but with different kong url, like one with /a and one with /b. so how can i use these 2 Kongconsumer for the apikey authentication?

For example, i deploy a simple service echo. And then create an ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo
annotations:
kubernetes.io/ingress.class: kong
spec:
rules:

  • http:
    paths:
    • path: /foo
      backend:
      serviceName: echo
      servicePort: 80
    • path: /hoo
      backend:
      serviceName: echo
      servicePort: 80

for example the key and consumer setup.
apiVersion: v1
kind: Secret
metadata:
name: ’ my-secret’
stringData:
kongCredType: ‘key-auth’
key: mytestkey

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: echo-auth
plugin: key-auth

apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: ‘my-consumer’
annotations:
kubernetes.io/ingress.class: kong
username: ‘my-user’
credentials:

  • my-secret

apiVersion: v1
kind: Secret
metadata:
name: ’ my-secret1’
stringData:
kongCredType: ‘key-auth’
key: mytestkey1

apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: ‘my-consumer1’
annotations:
kubernetes.io/ingress.class: kong
username: ‘my-user1’
credentials:

  • my-secret1

So i can access it by both /foo and /hoo, then i want to use the KongConsumer to do the auth apikey check for /foo and use kongconsumer1 to do the auth apikey check for /hoo, then what should I do?
Thanks.

From what you described so far, it seems you want to allow consumer1 to access /foo and consumer2 to access /hoo only, is that right?

If that’s true, you need to add ACL plugin.

1 Like

Thank you for the info. If possible can you guide me how to set it with acl? Can you please create an example for it? Thanks.

I believe the best learning method is by exploring docs and do the tests yourself.

Please have a look at the official doc first. If you can’t get it to work, please share what you’ve tried and people can help you.

Thank you. It works now. :slight_smile: