# How to use basic-auth in kong.yaml?

**URL:** <https://discuss.konghq.com/t/how-to-use-basic-auth-in-kong-yaml/13830>\
**Category:** Questions\
**Tags:** plugins\
**Created:** [November 28, 2025, 5:32pm UTC](https://discuss.konghq.com/t/how-to-use-basic-auth-in-kong-yaml/13830 "2025-11-28T17:32:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuizOt](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@LuizOt](https://discuss.konghq.com/u/LuizOt)\
**Post date:** [November 28, 2025, 5:32pm UTC](https://discuss.konghq.com/t/how-to-use-basic-auth-in-kong-yaml/13830/1 "2025-11-28T17:32:19Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![rick](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/rick/32/4446_2.png) [@rick](https://discuss.konghq.com/u/rick)\
**Post date:** [November 28, 2025, 6:51pm UTC](https://discuss.konghq.com/t/how-to-use-basic-auth-in-kong-yaml/13830/2 "2025-11-28T18:51:56Z")

</div>

@LuizOt I ran your question through our AI Assistant on [developer.konghq.com](http://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](https://developer.konghq.com/how-to/authenticate-consumers-with-basic-authentication/#create-a-consumer)]

```auto
_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](https://developer.konghq.com/how-to/authenticate-consumers-with-basic-authentication/#create-a-consumer); [Multiple auth](https://developer.konghq.com/how-to/allow-multiple-authentication/#configure-credentials)]

```auto
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.

> **[How to: Allow clients to choose their authentication methods and prevent...](https://developer.konghq.com/how-to/allow-multiple-authentication/#configure-credentials)**
>
> Learn how to allow different clients to access an upstream service with different authentication types, and forbid access to any unauthenticated clients.

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

> **[Kong Docs](https://developer.konghq.com/)**
>
> Documentation for Kong, the Cloud Connectivity Company for APIs and Microservices.

---

<div class="post-metadata">

**Author:** ![LuizOt](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@LuizOt](https://discuss.konghq.com/u/LuizOt)\
**Post date:** [December 1, 2025, 4:35pm UTC](https://discuss.konghq.com/t/how-to-use-basic-auth-in-kong-yaml/13830/3 "2025-12-01T16:35:43Z")

</div>

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!
