The Basic Authentication plugin requires at least one Consumer or a principal v3.15+ to work. When you create the Consumer or the principal, you must specify a username and password, for example: Ariel:Password. The credentials must be base64-encoded when it’s used in the Authentication header. For example, Ariel:Password would become QXJpZWw6UGFzc3dvcmQ=.
Then, you can enable the plugin on a Gateway Service, Route, or globally. When either a Consumer or a principal v3.15+ makes a request to the associated Gateway Service or Route, the plugin checks for valid credentials in the Proxy-Authorization and Authorization headers (in that order). In Kong Gateway 3.13 or later, you can protect against brute force attacks by enabling config.brute_force_protection. This will return an 429 Too Many Requests error after the fourth failed login attempt.
The Basic Auth plugin supports two types of authenticating entities: Consumers and principals v3.15+.
The following table will help you decide which to use based on your use case:
|
Use case
|
Choose
|
|
You are running on-prem and need authentication plugins.
|
Consumers
|
|
You have a highly performance-sensitive application that can’t rely on connectivity between your Gateway data planes and Konnect.
|
Consumers
|
|
You are on Konnect and need to share identity across multiple control planes in the same region without manually syncing credentials.
|
Principals
|
|
You have a large population of authenticating entities that would exceed Consumer control plane limits. Konnect loads Consumers into data plane memory, but loads principals on demand and caches them in the data plane.
|
Principals
|
|
You need to attach metadata to an authenticating entity for conditional plugin execution.
|
Principals
|
|
You need a single identity that works across Kong Gateway, Event Gateway, and Dev Portal.
|
Principals
|
You can use the Basic Authentication plugin along with other authentication plugins. This allows clients to use different authentication methods to access a given Gateway Service or Route.
The authentication plugins can be configured to always require authentication or only perform authentication if the Consumer or the principal wasn’t already authenticated. For more information, see Using multiple authentication methods.