Skip to content

Commit 110bcaf

Browse files
authored
Add API changes for HTTP External Auth (#4001)
Updates #1494. Signed-off-by: Nick Young <[email protected]>
1 parent 230b204 commit 110bcaf

15 files changed

+1897
-3
lines changed

apis/v1/httproute_types.go

Lines changed: 225 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ type HTTPRouteMatch struct {
804804
// +kubebuilder:validation:XValidation:message="filter.urlRewrite must be specified for URLRewrite filter.type",rule="!(!has(self.urlRewrite) && self.type == 'URLRewrite')"
805805
// <gateway:experimental:validation:XValidation:message="filter.cors must be nil if the filter.type is not CORS",rule="!(has(self.cors) && self.type != 'CORS')">
806806
// <gateway:experimental:validation:XValidation:message="filter.cors must be specified for CORS filter.type",rule="!(!has(self.cors) && self.type == 'CORS')">
807+
// <gateway:experimental:validation:XValidation:message="filter.externalAuth must be nil if the filter.type is not ExternalAuth",rule="!(has(self.externalAuth) && self.type != 'ExternalAuth')">
808+
// <gateway:experimental:validation:XValidation:message="filter.externalAuth must be specified for ExternalAuth filter.type",rule="!(!has(self.externalAuth) && self.type == 'ExternalAuth')">
807809
// +kubebuilder:validation:XValidation:message="filter.extensionRef must be nil if the filter.type is not ExtensionRef",rule="!(has(self.extensionRef) && self.type != 'ExtensionRef')"
808810
// +kubebuilder:validation:XValidation:message="filter.extensionRef must be specified for ExtensionRef filter.type",rule="!(!has(self.extensionRef) && self.type == 'ExtensionRef')"
809811
type HTTPRouteFilter struct {
@@ -842,7 +844,7 @@ type HTTPRouteFilter struct {
842844
//
843845
// +unionDiscriminator
844846
// +kubebuilder:validation:Enum=RequestHeaderModifier;ResponseHeaderModifier;RequestMirror;RequestRedirect;URLRewrite;ExtensionRef
845-
// <gateway:experimental:validation:Enum=RequestHeaderModifier;ResponseHeaderModifier;RequestMirror;RequestRedirect;URLRewrite;ExtensionRef;CORS>
847+
// <gateway:experimental:validation:Enum=RequestHeaderModifier;ResponseHeaderModifier;RequestMirror;RequestRedirect;URLRewrite;ExtensionRef;CORS;ExternalAuth>
846848
// +required
847849
Type HTTPRouteFilterType `json:"type"`
848850

@@ -901,6 +903,19 @@ type HTTPRouteFilter struct {
901903
// <gateway:experimental>
902904
CORS *HTTPCORSFilter `json:"cors,omitempty"`
903905

906+
// ExternalAuth configures settings related to sending request details
907+
// to an external auth service. The external service MUST authenticate
908+
// the request, and MAY authorize the request as well.
909+
//
910+
// If there is any problem communicating with the external service,
911+
// this filter MUST fail closed.
912+
//
913+
// Support: Extended
914+
//
915+
// +optional
916+
// <gateway:experimental>
917+
ExternalAuth *HTTPExternalAuthFilter `json:"externalAuth,omitempty"`
918+
904919
// ExtensionRef is an optional, implementation-specific extension to the
905920
// "filter" behavior. For example, resource "myroutefilter" in group
906921
// "networking.example.net"). ExtensionRef MUST NOT be used for core and
@@ -972,6 +987,18 @@ const (
972987
// <gateway:experimental>
973988
HTTPRouteFilterCORS HTTPRouteFilterType = "CORS"
974989

990+
// HTTPRouteFilterExternalAuth can be used to configure a Gateway implementation
991+
// to call out to an external Auth server, which MUST perform Authentication
992+
// and MAY perform Authorization on the matched request before the request
993+
// is forwarded to the backend.
994+
//
995+
// Support in HTTPRouteRule: Extended
996+
//
997+
// Feature Name: HTTPRouteExternalAuth
998+
//
999+
// <gateway:experimental>
1000+
HTTPRouteFilterExternalAuth HTTPRouteFilterType = "ExternalAuth"
1001+
9751002
// HTTPRouteFilterExtensionRef should be used for configuring custom
9761003
// HTTP filters.
9771004
//
@@ -1536,6 +1563,203 @@ type HTTPCORSFilter struct {
15361563
MaxAge int32 `json:"maxAge,omitempty"`
15371564
}
15381565

1566+
// HTTPRouteExternalAuthProtcol specifies what protocol should be used
1567+
// for communicating with an external authorization server.
1568+
//
1569+
// Valid values are supplied as constants below.
1570+
type HTTPRouteExternalAuthProtocol string
1571+
1572+
const (
1573+
HTTPRouteExternalAuthGRPCProtocol HTTPRouteExternalAuthProtocol = "GRPC"
1574+
HTTPRouteExternalAuthHTTPProtocol HTTPRouteExternalAuthProtocol = "HTTP"
1575+
)
1576+
1577+
// HTTPExternalAuthFilter defines a filter that modifies requests by sending
1578+
// request details to an external authorization server.
1579+
//
1580+
// Support: Extended
1581+
// Feature Name: HTTPRouteExternalAuth
1582+
// +kubebuilder:validation:XValidation:message="grpc must be specified when protocol is set to 'GRPC'",rule="self.protocol == 'GRPC' ? has(self.grpc) : true"
1583+
// +kubebuilder:validation:XValidation:message="protocol must be 'GRPC' when grpc is set",rule="has(self.grpc) ? self.protocol == 'GRPC' : true"
1584+
// +kubebuilder:validation:XValidation:message="http must be specified when protocol is set to 'HTTP'",rule="self.protocol == 'HTTP' ? has(self.http) : true"
1585+
// +kubebuilder:validation:XValidation:message="protocol must be 'HTTP' when http is set",rule="has(self.http) ? self.protocol == 'HTTP' : true"
1586+
type HTTPExternalAuthFilter struct {
1587+
// ExternalAuthProtocol describes which protocol to use when communicating with an
1588+
// ext_authz authorization server.
1589+
//
1590+
// When this is set to GRPC, each backend must use the Envoy ext_authz protocol
1591+
// on the port specified in `backendRefs`. Requests and responses are defined
1592+
// in the protobufs explained at:
1593+
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/auth/v3/external_auth.proto
1594+
//
1595+
// When this is set to HTTP, each backend must respond with a `200` status
1596+
// code in on a successful authorization. Any other code is considered
1597+
// an authorization failure.
1598+
//
1599+
// Feature Names:
1600+
// GRPC Support - HTTPRouteExternalAuthGRPC
1601+
// HTTP Support - HTTPRouteExternalAuthHTTP
1602+
//
1603+
// +unionDiscriminator
1604+
// +required
1605+
// +kubebuilder:validation:Enum=HTTP;GRPC
1606+
ExternalAuthProtocol HTTPRouteExternalAuthProtocol `json:"protocol,omitempty"`
1607+
1608+
// BackendRef is a reference to a backend to send authorization
1609+
// requests to.
1610+
//
1611+
// The backend must speak the selected protocol (GRPC or HTTP) on the
1612+
// referenced port.
1613+
//
1614+
// If the backend service requires TLS, use BackendTLSPolicy to tell the
1615+
// implementation to supply the TLS details to be used to connect to that
1616+
// backend.
1617+
//
1618+
// +required
1619+
BackendRef BackendObjectReference `json:"backendRef,omitempty"`
1620+
1621+
// GRPCAuthConfig contains configuration for communication with ext_authz
1622+
// protocol-speaking backends.
1623+
//
1624+
// If unset, implementations must assume the default behavior for each
1625+
// included field is intended.
1626+
//
1627+
// +optional
1628+
GRPCAuthConfig *GRPCAuthConfig `json:"grpc,omitempty"`
1629+
1630+
// HTTPAuthConfig contains configuration for communication with HTTP-speaking
1631+
// backends.
1632+
//
1633+
// If unset, implementations must assume the default behavior for each
1634+
// included field is intended.
1635+
//
1636+
// +optional
1637+
HTTPAuthConfig *HTTPAuthConfig `json:"http,omitempty"`
1638+
1639+
// ForwardBody controls if requests to the authorization server should include
1640+
// the body of the client request; and if so, how big that body is allowed
1641+
// to be.
1642+
//
1643+
// It is expected that implementations will buffer the request body up to
1644+
// `forwardBody.maxSize` bytes. Bodies over that size must be rejected with a
1645+
// 4xx series error (413 or 403 are common examples), and fail processing
1646+
// of the filter.
1647+
//
1648+
// If unset, or `forwardBody.maxSize` is set to `0`, then the body will not
1649+
// be forwarded.
1650+
//
1651+
// Feature Name: HTTPRouteExternalAuthForwardBody
1652+
//
1653+
//
1654+
// +optional
1655+
ForwardBody *ForwardBodyConfig `json:"forwardBody,omitempty"`
1656+
}
1657+
1658+
// GRPCAuthConfig contains configuration for communication with Auth server
1659+
// backends that speak Envoy's ext_authz gRPC protocol.
1660+
//
1661+
// Requests and responses are defined in the protobufs explained at:
1662+
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/auth/v3/external_auth.proto
1663+
type GRPCAuthConfig struct {
1664+
// AllowedRequestHeaders specifies what headers from the client request
1665+
// will be sent to the authorization server.
1666+
//
1667+
// If this list is empty, then the following headers must be sent:
1668+
//
1669+
// - `Authorization`
1670+
// - `Location`
1671+
// - `Proxy-Authenticate`
1672+
// - `Set-Cookie`
1673+
// - `WWW-Authenticate`
1674+
//
1675+
// If the list has entries, only those entries must be sent.
1676+
//
1677+
// +optional
1678+
// +listType=set
1679+
// +kubebuilder:validation:MaxLength=64
1680+
AllowedRequestHeaders []string `json:"allowedHeaders,omitempty"`
1681+
}
1682+
1683+
// HTTPAuthConfig contains configuration for communication with HTTP-speaking
1684+
// backends.
1685+
type HTTPAuthConfig struct {
1686+
// Path sets the prefix that paths from the client request will have added
1687+
// when forwarded to the authorization server.
1688+
//
1689+
// When empty or unspecified, no prefix is added.
1690+
//
1691+
// Valid values are the same as the "value" regex for path values in the `match`
1692+
// stanza, and the validation regex will screen out invalid paths in the same way.
1693+
// Even with the validation, implementations MUST sanitize this input before using it
1694+
// directly.
1695+
//
1696+
// +optional
1697+
// +kubebuilder:validation:MaxLength=1024
1698+
// +kubebuilder:validation:Pattern="^(?:[-A-Za-z0-9/._~!$&'()*+,;=:@]|[%][0-9a-fA-F]{2})+$"
1699+
Path string `json:"path,omitempty"`
1700+
1701+
// AllowedRequestHeaders specifies what additional headers from the client request
1702+
// will be sent to the authorization server.
1703+
//
1704+
// The following headers must always be sent to the authorization server,
1705+
// regardless of this setting:
1706+
//
1707+
// * `Host`
1708+
// * `Method`
1709+
// * `Path`
1710+
// * `Content-Length`
1711+
// * `Authorization`
1712+
//
1713+
// If this list is empty, then only those headers must be sent.
1714+
//
1715+
// Note that `Content-Length` has a special behavior, in that the length
1716+
// sent must be correct for the actual request to the external authorization
1717+
// server - that is, it must reflect the actual number of bytes sent in the
1718+
// body of the request to the authorization server.
1719+
//
1720+
// So if the `forwardBody` stanza is unset, or `forwardBody.maxSize` is set
1721+
// to `0`, then `Content-Length` must be `0`. If `forwardBody.maxSize` is set
1722+
// to anything other than `0`, then the `Content-Length` of the authorization
1723+
// request must be set to the actual number of bytes forwarded.
1724+
//
1725+
// +optional
1726+
// +listType=set
1727+
// +kubebuilder:validation:MaxLength=64
1728+
AllowedRequestHeaders []string `json:"allowedHeaders,omitempty"`
1729+
1730+
// AllowedResponseHeaders specifies what headers from the authorization response
1731+
// will be copied into the request to the backend.
1732+
//
1733+
// If this list is empty, then all headers from the authorization server
1734+
// except Authority or Host must be copied.
1735+
//
1736+
// +optional
1737+
// +listType=set
1738+
// +kubebuilder:validation:MaxLength=64
1739+
AllowedResponseHeaders []string `json:"allowedResponseHeaders,omitempty"`
1740+
}
1741+
1742+
// ForwardBody configures if requests to the authorization server should include
1743+
// the body of the client request; and if so, how big that body is allowed
1744+
// to be.
1745+
//
1746+
// If empty or unset, do not forward the body.
1747+
type ForwardBodyConfig struct {
1748+
// MaxSize specifies how large in bytes the largest body that will be buffered
1749+
// and sent to the authorization server. If the body size is larger than
1750+
// `maxSize`, then the body sent to the authorization server must be
1751+
// truncated to `maxSize` bytes.
1752+
//
1753+
// Experimental note: This behavior needs to be checked against
1754+
// various dataplanes; it may need to be changed.
1755+
// See https://github.com/kubernetes-sigs/gateway-api/pull/4001#discussion_r2291405746
1756+
// for more.
1757+
//
1758+
// If 0, the body will not be sent to the authorization server.
1759+
// +optional
1760+
MaxSize uint16 `json:"maxSize,omitempty"`
1761+
}
1762+
15391763
// HTTPBackendRef defines how a HTTPRoute forwards a HTTP request.
15401764
//
15411765
// Note that when a namespace different than the local namespace is specified, a

apis/v1/zz_generated.deepcopy.go

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)