syntax = "proto3";

package envoy.extensions.filters.http.basic_auth.v3;

import "envoy/config/core/v3/base.proto";

import "udpa/annotations/sensitive.proto";
import "udpa/annotations/status.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.filters.http.basic_auth.v3";
option java_outer_classname = "BasicAuthProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/basic_auth/v3;basic_authv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Basic Auth]
// Basic Auth :ref:`configuration overview <config_http_filters_basic_auth>`.
// [#extension: envoy.filters.http.basic_auth]

// Basic HTTP authentication.
//
// Example:
//
// .. code-block:: yaml
//
//   users:
//     inline_string: |-
//       user1:{SHA}hashed_user1_password
//       user2:{SHA}hashed_user2_password
//
message BasicAuth {
  // Username-password pairs used to verify user credentials in the "Authorization" header.
  // The value needs to be the htpasswd format.
  // Reference to https://httpd.apache.org/docs/2.4/programs/htpasswd.html
  config.core.v3.DataSource users = 1 [(udpa.annotations.sensitive) = true];

  // This field specifies the header name to forward a successfully authenticated user to
  // the backend. The header will be added to the request with the username as the value.
  //
  // If it is not specified, the username will not be forwarded.
  string forward_username_header = 2
      [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME strict: false}];

  // This field specifies the request header to load the basic credential from.
  //
  // If it is not specified, the filter loads the credential from  the "Authorization" header.
  string authentication_header = 3
      [(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME strict: false}];
}

// Extra settings that may be added to per-route configuration for
// a virtual host or a cluster.
message BasicAuthPerRoute {
  // Username-password pairs for this route.
  config.core.v3.DataSource users = 1
      [(validate.rules).message = {required: true}, (udpa.annotations.sensitive) = true];
}
