Basic Auth - Add consumer with kubectl (dbless)

Hello,

does somebody know if it is possible to to add a consumer (with username and password) to the kubernetes configuration via kubectl?
My problem is that I have a dbless kong gateway configuration on my kubernetes cluster and I also don’t want to change the declarative configuration file manually. All my deployments are done via helm or kubectl.

I found a way to add a KongConsumer with an Opaque secret but unfortunately this doesn’t work.

Is my approach possible? Hopefully somebody can help me with this :slight_smile:

Thanks!

Yep. Below is an example.

---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: basic-auth-plugin
config: 
  hide_credentials: true
plugin: basic-auth
---
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
  name: basic-auth-user
  annotations:
    kubernetes.io/ingress.class: "kong"
username: basic-auth-username
credentials:
  - basic-auth-secret
---
apiVersion: v1
kind: Secret
metadata:
  name: basic-auth-secret
type: Opaque
stringData:
  kongCredType: basic-auth
  username: testuser
  password: testpass

You saved my day! Thanks!!

I was missing “kongCredType: basic-auth”. I knew I had to put that somewhere but couldn’t find any example.

No worries.

In case you are interested, this github repo has examples for some other plugins like acl, oauth2, key-auth. These plugins also use kongCredType.

1 Like