How to use basic-auth in kong.yaml?

I’m new to Kong and I have a question about configuring the basic-auth plugin using deck.
I’m trying to define everything in my kong.yaml file, but I’m not sure where to put the consumers and where to define their basic-auth credentials inside the file.

Here is an example of what I currently have:

services:
  - name: monitoring
    host: 10.66.66.16
    port: 3000

routes:
  - name: monitoring
    service:
      name: monitoring
    tags:
      - "monitoring"
    hosts:
      - host.name

plugins:
  - name: basic-auth
    service: "monitoring"
    config:
      hide_credentials: false

My doubts:

  • Where in kong.yaml should I define consumers?

  • How do I add basic-auth credentials (username/password) for these consumers?

  • Should the credentials be in a separate section, or nested under consumers?

@LuizOt I ran your question through our AI Assistant on developer.konghq.com and here is the response:


You define Consumers and their basic-auth credentials as top-level entities in the same kong.yaml, alongside services, routes, and plugins.

1. Where to define Consumers

Add a consumers: section at the top level of your file. For example, from the basic-auth how-to: [Create Consumer]

_format_version: "3.0"

services:
  - name: monitoring
    host: 10.66.66.16
    port: 3000

routes:
  - name: monitoring
    service:
      name: monitoring
    tags:
      - "monitoring"
    hosts:
      - host.name

plugins:
  - name: basic-auth
    service: monitoring
    config:
      hide_credentials: false

consumers:
  - username: jsmith
    basicauth_credentials:
      - username: jsmith
        password: my-password

2. How to add basic-auth credentials

Credentials are nested under each Consumer using the basicauth_credentials array. Each entry contains the username and password. This pattern is shown in multiple docs: [Create Consumer; Multiple auth]

consumers:
  - username: jsmith
    basicauth_credentials:
      - username: jsmith
        password: my-password
  - username: Dana
    basicauth_credentials:
      - username: Dana
        password: dana

So:

  • Consumers go in a top-level consumers: block in kong.yaml.

  • Basic-auth credentials are nested under each consumer in basicauth_credentials, not in a separate top-level section.

Please check out the AI Assistant on the docs site for other questions, I hope that helps

Hi, Rick! Thanks for the response, I did not know about the AI agent on the site. I will use more times from now on!

1 Like