GEP-1897: BackendTLSPolicy - Explicit Backend TLS Connection Configuration¶
- Issue: #1897
- Status: Experimental
TLDR¶
This document specifically addresses the topic of conveying HTTPS from the Gateway dataplane to the backend (backend TLS termination), and intends to satisfy the single use case “As a client implementation of Gateway API, I need to know how to connect to a backend pod that has its own certificate”. TLS configuration can be a nebulous topic, so in order to drive resolution this GEP focuses only on this single piece of functionality.
Furthermore, for Gateway API to handle the case where the service or backend owner is doing their own TLS, and the service or backend owner wants to validate the clients connecting to it, two things need to happen:
- The service or backend owner has to provide a method for the Gateway owner to retrieve a certificate.
- Gateway API has to provide a way for the Gateway to configure and apply the validation options.
Immediate Goals¶
- The solution must satisfy the following use case: the backend pod has its own certificate and the gateway implementation client needs to know how to connect to the backend pod. (Use case #4 in Gateway API TLS Use Cases)
- In this GEP, only the application developer persona will have control over TLS settings. This does not preclude adding other personas in future GEPs.
- The solution should consider client TLS settings used in the TLS handshake from Gateway to backend, such as server name indication and trusted CA certificates.
- Both Gateway and Mesh use cases may be supported, depending on the implementation, and will be covered by features in each case.
Longer Term Goals¶
These are worthy goals, but deserve a different GEP for proper attention. This GEP is concerned entirely with the the hop between gateway client and backend.
- TCPRoute and GRPCRoute use cases are not addressed here, because at this point in time these two route types are not graduated to beta.
- Mutual TLS (mTLS) use cases are intentionally out of scope for this GEP for two reasons. First, the design of Gateway API is backend-attached and does not currently support mutual authentication, and also because this GEP does not address the case where connections to TLS are implicitly configured on behalf of the user, which is the norm for mTLS. This GEP is about the case where an application developer needs to explicitly express that they expect TLS when there is no automatic, implicit configuration available.
- Service mesh use cases are not addressed here because this GEP is specifically concerned with the connection between Gateways and Backends, not Service to Service. Service mesh use cases should ignore the design components described in this proposal.
Non-Goals¶
These are worthy goals, but will not be covered by this GEP.
- Changes to the existing mechanisms for edge or passthrough TLS termination
- Providing a mechanism to decorate multiple route instances
- TLSRoute use cases
- UDPRoute use cases
- Controlling TLS versions or cipher suites used in TLS handshakes. (Use case #5 in Gateway API TLS Use Cases)
- Controlling certificates used by more than one workload (#6 in Gateway API TLS Use Cases)
- Client certificate settings used in TLS from external clients to the Listener (#7 in Gateway API TLS Use Cases)
- Service Mesh "mesh transport security".
- Providing a mechanism for the cluster operator to override gateway to backend TLS settings.
It is very common for service mesh implementations to implement some form of transparent transport security, whether that is WireGuard, mTLS, or others. This is completely orthogonal to the use cases being tackled by this GEP. * The "mesh transport security" is something invisible to the user's application, and is simply used to secure communication between components in the mesh. * This proposal, instead, explicitly calls for sending TLS to the user's application. However, this does not mean service meshes are outside of scope for this proposal, merely that only the application-level TLS configuration is in scope.
Already Solved TLS Use Cases¶
These are worthy goals that are already solved and thus will not be modified by the implementation.
- Termination of TLS for HTTP routing (#1 in Gateway API TLS Use Cases)
- HTTPS passthrough use cases (#2 in Gateway API TLS Use Cases)
- Termination of TLS for non-HTTP TCP streams (#3 in Gateway API TLS Use Cases)
Overview - what do we want to do?¶
Given that the current ingress solution specifies edge TLS termination (from the client to the gateway), and how to handle passthrough TLS (from the client to the backend pod), this proposed ingress solution specifies TLS origination to the backend (from the gateway to the backend pod). As mentioned, this solution satisfies the use case in which the backend pod has its own certificate and the gateway client needs to know how to connect to the backend pod.
Gateway API is missing a mechanism for separately providing the details for the backend TLS handshake, including (but not limited to):
- intent to use TLS on the backend hop
- CA certificates to trust
- other properties of the TLS handshake, such as SNI and SAN validation
- client certificate of the gateway (outside of scope for this GEP)
Purpose - why do we want to do this?¶
This proposal is very tightly scoped because we have tried and failed to address this well-known gap in the API specification. The lack of support for this fundamental concept is holding back Gateway API adoption by users that require a solution to the use case. Another reason for the tight scope is that we have been too focused on a generic representation of everything that TLS can do, which covers too much ground to address in a single GEP.
The history of backend TLS¶
Work on this topic has spanned over three years, as documented in our repositories and other references, and summarized below.
In January 2020, in issue TLS Termination Policy #52, this use case was discussed. The discussion ended after being diverted by KEP: Adding AppProtocol to Services and Endpoints #1422, which was implemented and later reverted.
In February 2020, HTTPRoute: Add Reencrypt #81 added the dataplane feature as “reencrypt”, but it went stale and was closed in favor of the work done in the next paragraph, which unfortunately didn’t implement the backend TLS termination feature.
In August 2020, it resurfaced with a comment on this pull request: tls: introduce mode and sni to cert matching behavior. The backend TLS termination feature was deferred at that time. Other TLS discussion was documented in [SIG-NETWORK] TLS config in service-apis , a list of TLS features that had been collected in June 2020, itself based on spreadsheet Service API: TLS related issues.
In December 2021, this was discussed as a beta blocker in issue Docs mentions Reencrypt for HTTPRoute and TLSRoute is available #968.
A March 2022 issue documents another request for it: Provide a way to configure TLS from a Gateway to Backends #1067
A June 2022 issue documents a documentation issue related to it: Unclear how to specify upstream (webserver) HTTP protocol #1244
A July 2022 discussion Specify Re-encrypt TLS Termination (i.e., Upstream TLS) #1285 collected most of the historical context preceding the backend TLS termination feature, with the intention of collecting evidence that this feature is still unresolved. This was followed by GEP: Describe Backend Properties #1282.
In August 2022, Add Provisional GEP-1282 document #1333 was created, and in October 2022, a GEP update with proposed implementation GEP-1282 Backend Properties - Update implementation #1430 was followed by intense discussion and closed in favor of a downsize in scope.
In January 2023 we closed GEP-1282 and began a new discussion on enumerating TLS use cases in Gateway API TLS Use Cases, for the purposes of a clear definition and separation of concerns. This GEP is the outcome of the TLS use case #4 in Gateway API TLS Use Cases as mentioned in the Immediate Goals section above.
API¶
To allow the gateway client to know how to connect to the backend pod, when the backend pod has its own
certificate, we implement a metaresource named BackendTLSPolicy
, that was previously introduced with the name
TLSConnectionPolicy
as a hypothetical Direct Policy Attachment example in
GEP-713: Metaresources and PolicyAttachment.
Because naming is hard, a new name may be
substituted without blocking acceptance of the content of the API change.
The selection of the applicable Gateway API persona is important in the design of BackendTLSPolicy, because it provides a way to explicitly describe the expectations of the connection to the application. In this GEP, BackendTLSPolicy will be configured only by the application developer Gateway API persona to tell gateway clients how to connect to the application, from a TLS perspective. Future iterations may expand this to additionally allow consumer overrides; see Future plans.
During the course of discussion of this proposal, we did consider allowing the cluster operator persona to have some access to Gateway cert validation, but as mentioned, BackendTLSPolicy is used primarily to signal what the application developer expects in the connection. Granting this expectation to any other role would blur the lines between role responsibilities, which compromises the role-oriented design principle of Gateway API. As mentioned in Non-goal #8, providing a mechanism for the cluster operator gateway role to override gateway to backend TLS settings is not covered by this proposal, but should be addressed in a future update. One idea is to use two types: ApplicationBackendTLSPolicy, and GatewayBackendTLSPolicy, where the application developer is responsible for the former, the cluster operator is responsible for the latter, and the cluster operator may configure whether certain settings may be overridden by application developers.
The BackendTLSPolicy must contain these configuration items to allow the Gateway to operate successfully as a TLS Client:
- An explicit signal that TLS should be used by this connection.
- A hostname the Gateway should use to connect to the backend.
- A reference to one or more CA certificates (which could include "system certificates") to validate the server's TLS certificates.
BackendTLSPolicy is defined as a Direct Policy Attachment without defaults or overrides, applied to a Service that accesses the backend in question, where the BackendTLSPolicy resides in the same namespace as the Service it is applied to. For now, the BackendTLSPolicy and the Service must reside in the same namespace in order to prevent the complications involved with sharing trust across namespace boundaries (see Future plans). We chose the Service resource as a target, rather than the Route resource, so that we can reuse the same BackendTLSPolicy for all the different Routes that might point to this Service.
One of the areas of concern for this API is that we need to indicate how and when the API implementations should use the backend destination certificate authority. This solution proposes, as introduced in GEP-713, that the implementation should watch the connections to the specified TargetRefs (Services), and if a Service matches a BackendTLSPolicy, then assume the connection is TLS, and verify that the TargetRef’s certificate can be validated by the client (Gateway) using the provided certificates and hostname before the connection is made. On the question of how to signal that there was a failure in the certificate validation, this is left up to the implementation to return a response error that is appropriate, such as one of the HTTP error codes: 400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), or other signal that makes the failure sufficiently clear to the requester without revealing too much about the transaction, based on established security requirements.
BackendTLSPolicy applies only to TCP traffic. If a policy explicitly attaches to a UDP port of a Service (that is, the targetRef
has a sectionName
specifying a single port or the service has only 1 port), the Accepted: False
Condition with Reason: Invalid
MUST be set. If the policy attaches to a mix of TCP and UDP ports, implementations SHOULD include a warning in the Accepted
condition message (ancestors.conditions
); the policy will only be effective for the TCP ports.
All policy resources must include TargetRefs
with the fields specified
in PolicyTargetReference.
In an upcoming extension to TargetRefs, policy resources
may also choose to include SectionName
and/or Port
in the target reference following the same mechanics as ParentRef
.
BackendTLSPolicySpec contains the TargetRefs
and Validation
fields. The Validation
field is a
BackendTLSPolicyValidation
and contains CACertificateRefs
, WellKnownCACertificates
, and Hostname
.
The names of the fields were chosen to facilitate discussion, but may be substituted without blocking acceptance of the
content of the API change. In fact, the CertRefs
field name was changed to CACertRefs and then to
CACertificateRefs as of April 2024.
The CACertificateRefs
and WellKnownCACertificates
fields are both optional, but one of them must be set for a valid TLS
configuration. CACertificateRefs is an implementation-specific slice of
named object references, each containing a single cert. We originally proposed to follow the convention established by the
CertificateRefs field on Gateway
, but the CertificateRef requires both a tls.key and tls.crt and a certificate reference only requires the tls.crt.
WellKnownCACertificates is an optional enum that allows users to specify whether to use the set of CA certificates trusted by the
Gateway (WellKnownCACertificates specified as "System"), or to use the existing CACertificateRefs (WellKnownCACertificates
specified as ""). The use and definition of system certificates is implementation-dependent, and the intent is that
these certificates are obtained from the underlying operating system. CACertificateRefs contains one or more
references to Kubernetes objects that contain PEM-encoded TLS certificates, which are used to establish a TLS handshake
between the gateway and backend pod. References to a resource in a different namespace are invalid.
If ClientCertificateRefs is unspecified, then WellKnownCACertificates must be set to "System" for a valid configuration.
If WellKnownCACertificates is unspecified, then CACertificateRefs must be specified with at least one entry for a valid configuration.
If WellKnownCACertificates is set to "System" and there are no system trusted certificates or the implementation doesn't define system
trusted certificates, then the associated TLS connection must fail.
The Hostname
field is required and is to be used to configure the SNI the Gateway should use to connect to the backend.
Implementations must validate that at least one name in the certificate served by the backend matches this field.
We originally proposed using a list of allowed Subject Alternative Names, but determined that this was not needed in
the first round,
but may be added in the future.
We originally proposed allowing the configuration of expected TLS versions, but determined that this was not needed in the first round.
Thus, the following additions would be made to the Gateway API:
//TODO: Will update this section once API changes from PR 2955 are approved.
How a client behaves¶
The BackendTLSPolicy
tells a client "Connect to this service using TLS".
This is unconditional to the type of traffic the gateway client is forwarding.
For instance, the following will all have the gateway client add TLS if the backend is targeted by a BackendTLSPolicy:
- A Gateway accepts traffic on an HTTP listener
- A Gateway accepts and terminates TLS on an HTTPS listener
- A Gateway accepts traffic on a TCP listener
There is no need for a Gateway that accepts traffic with Mode: Passthrough
to do anything differently here, but implementations MAY choose to treat TLS passthrough as a special case. Implementations that do this SHOULD clearly document their approach if BackendTLSPolicy is treated differently for TLS passthrough.
Note that there are cases where these patterns may result in multiple layers of TLS on a single connection. There may be even cases where the gateway implementation is unaware of this; for example, processing TCPRoute traffic -- the traffic may or may not be TLS, and the gateway would be unaware. This is intentional to allow full fidelity of the API, as this is commonly desired for tunneling scenarios. When users do not want this, they should ensure that the BackendTLSPolicy is not incorrectly applied to traffic that is already TLS. The Future Plans include more controls over the API to make this easier to manage.
Request Flow¶
Step 6 would be changed in the typical client/gateway API request flow for a gateway implemented using a reverse proxy. This is shown as bolded additions in step 6 below.
- A client makes a request to http://foo.example.com.
- DNS resolves the name to a Gateway address.
- The reverse proxy receives the request on a Listener and uses the Host header to match an HTTPRoute.
- Optionally, the reverse proxy can perform request header and/or path matching based on match rules of the HTTPRoute.
- Optionally, the reverse proxy can modify the request, i.e. add/remove headers, based on filter rules of the HTTPRoute.
- Lastly, the reverse proxy optionally performs a TLS handshake and forwards the request to one or more objects, i.e. Service, in the cluster based on backendRefs rules of the HTTPRoute and the TargetRefs of the BackendTLSPolicy.
Future plans¶
In order to scope this GEP, some some changes are deferred to a near-future GEP. This GEP intends to add the ability for additional control by gateway clients to override TLS settings, following previously established patterns of consumer and producer policies. Additionally, more contextual control over when to apply the policies will be explored, to enable use cases like "apply TLS only from this route" (issue).
While the details of these plans are out of scope for this GEP it is important to be aware of the future plans for the API to ensure the immediate-term plans are future-proofed against the proposed plans.
Implementations should plan for the existence of future fields that may be added that will control where the TLS policy applies. These may include, but are not limited to:
spec.targetRefs.namespace
spec.targetRefs.from
spec.mode
While in some cases adding new fields may be seen as a backwards compatibility risk, due to older implementations not knowing to respect the fields, these fields (or similar, should future GEPs decide on new names) are pre-approved to be added in a future release, should the GEPs to add them are approved in the first place.
Alternatives¶
Most alternatives are enumerated in the section "The history of backend TLS". A couple of additional alternatives are also listed here.
- Expand BackendRef, which is already an expansion point. At first, it seems logical that since listeners are handling the client-gateway certs, BackendRefs could handle the gateway-backend certs. However, when multiple Routes to target the same Service, there would be unnecessary copying of the BackendRef every time the Service was targeted. As well, there could be multiple bBackendRefs with multiple rules on a rRoute, each of which might need the gateway-backend cert configuration, so it is not the appropriate pattern.
- Extend HTTPRoute to indicate TLS backend support. Extending HTTPRoute would interfere with deployed implementations too much to be a practical solution.
- Add a new type of Route for backend TLS. This is impractical because we might want to enable backend TLS on other route types in the future, and because we might want to have both TLS listeners and backend TLS on a single route.
Prior Art¶
TLS from gateway to backend for ingress exists in several implementations, and was developed independently.
Istio Gateway supports this with a DestinationRule:¶
- A secret representing a certificate/key pair, where the certificate is valid for the route host
- Set Gateway spec.servers[].port.protocol: HTTPS, spec.servers[].tls.mode=SIMPLE, spec.servers[].tls.credentialName
- Set DestinationRule spec.trafficPolicy.tls.mode: SIMPLE
Ref: Istio / Understanding TLS Configuration and Istio / Destination Rule
OpenShift Route (comparable to GW API Gateway) supports this with the following route configuration items:¶
- A certificate/key pair, where the certificate is valid for the route host
- A separate destination CA certificate enables the Ingress Controller to trust the destination’s certificate
- An optional, separate CA certificate that completes the certificate chain
Ref: Secured routes - Configuring Routes | Networking | OpenShift Container Platform 4.12
Contour supports this from Envoy to the backend using:¶
- An Envoy client certificate
- A CA certificate and SubjectName which are both used to verify the backend endpoint’s identity
- Kubernetes Service annotation: projectcontour.io/upstream-protocol.tls
Ref: Upstream TLS
GKE supports a way to encrypt traffic to the backend pods using:¶
AppProtocol
on Service set to HTTPS- Load balancer does not verify the certificate used by backend pods
Ref: Secure a Gateway
Emissary supports encrypted traffic to services¶
- In the
Mapping
definition, set https:// in the spec.service field - A spec.tls in the
Mapping
definition, with the name of aTLSContext
- A
TLSContext
to provide a client certificate, set minimum TLS version support, SNI
Ref: TLS Origination
NGINX implementation through CRDs (Comparable to Route or Policy of Gateway API) supports both TLS and mTLS¶
- In the Upstream section of a VirtualServer or VirtualServerRoute (equivalent to HTTPRoute) there is a simple toggle to enable TLS. This does not validate the certificate of the backend and implicitly trusts the backend in order to form the SSL tunnel. This is not about validating the certificate but obfuscating the traffic with TLS/SSL.
- A Policy attachment can be provided when certification validation is required that is called egressMTLS (egress from the proxy to the upstream). This can be tuned to perform various certificate validation tests. It was created as a Policy because it implies some type of AuthN/AuthZ due to the additional checks. This was also compatible with Open Service Mesh and NGINX Service Mesh and removed the need for a sidecar at the ingress controller.
- A corresponding 'IngressMTLS' policy also exists for mTLS verification of client connections to the proxy. The Policy object is used for anything that implies AuthN/AuthZ.
Ref: Upstream.TLS
Ref: EgressMTLS
Ref: IngressMTLS
Answered Questions¶
Q. Bowei recommended that we mention the approach of cross-namespace referencing between Route and Service. Be explicit about using the standard rules with respect to attaching policies to resources.
A. This is mentioned in the API section.
Q. Costin recommended that Gateway SHOULD authenticate with either a JWT with audience or client cert or some other means - so gateway added headers can be trusted, amongst other things.
A. This is out of scope for this proposal, which centers around application developer persona resources such as HTTPRoute and Service.
Q. Costin mentioned we need to answer the question - is configuring the connection to a backend and TLS something the route author decides - or the backend owner?
A. This is decided by the application developer persona, which would more likely, but not exclusively, be the backend owner.
Q.Costin continued, same for SAN (Subject Alternative Name) certificates. The backend owner is the application developer, and the route owner will have to collaborate with the application developer to provide the appropriate configuration for TLS. The implementation would need to take the certificate provided by the application and verify that it satisfies the requirements of the route-as-client, including SAN information. Sometimes the backend owner and route owner are the same entity.
A. This was most recently addressed by adding hostname for SNI and removing allowed SANs.
Graduation Criteria¶
This section is to record issues that were requested for discussion in the API section before this GEP graduates
out of Provisional
status.
- Rob Scott is interested in extending the TargetRef to optionally include port, since we are targeting the entirety of a Service. See the discussion in https://github.com/kubernetes-sigs/gateway-api/pull/2113/files#r1231594914, and follow up issue in https://github.com/kubernetes-sigs/gateway-api/issues/2147
- Michael Pleshakov asked about conflicts that could arise when multiple implementations are running in a cluster. This is a gap in our policy attachment model that needs to be addressed. See the discussion in https://github.com/kubernetes-sigs/gateway-api/pull/2113/files#r1235750540. Graduating this GEP to implementable requires an update to the Policy GEP to define how status can be nested to support multiple implementations. This will likely look very similar to Route status. See comment.
- Rob Scott wanted to note that when this graduates to the standard channel, implementations of HTTPRoute may also be required to watch the BackendTLSPolicy. If one of these policies is attached to a Service targeted by an HTTPRoute, the implementation would be required to fully implement the policy or mark the backend invalid.
References¶
GEP-713: Metaresources and PolicyAttachment