// Copyright 2025 Envoy Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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];
}
