Skip to content

Commit

Permalink
Implementing and Documenting GEP 746 (TLS Updates)
Browse files Browse the repository at this point in the history
  • Loading branch information
robscott committed Aug 12, 2021
1 parent a209add commit cf0a14d
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 259 deletions.
54 changes: 9 additions & 45 deletions apis/v1alpha2/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,35 +267,6 @@ const (
UDPProtocolType ProtocolType = "UDP"
)

// TLSRouteOverrideType type defines the level of allowance for Routes
// to override a specific TLS setting.
// +kubebuilder:validation:Enum=Allow;Deny
// +kubebuilder:default=Deny
type TLSRouteOverrideType string

const (
// Allows the parameter to be configured from all routes.
TLSROuteOVerrideAllow TLSRouteOverrideType = "Allow"

// Prohibits the parameter from being configured from any route.
TLSRouteOverrideDeny TLSRouteOverrideType = "Deny"
)

// TLSOverridePolicy defines a schema for overriding TLS settings at the Route
// level.
type TLSOverridePolicy struct {
// Certificate dictates if TLS certificates can be configured
// via Routes. If set to 'Allow', a TLS certificate for a hostname
// defined in a Route takes precedence over the certificate defined in
// Gateway.
//
// Support: Core
//
// +optional
// +kubebuilder:default=Deny
Certificate *TLSRouteOverrideType `json:"certificate,omitempty"`
}

// GatewayTLSConfig describes a TLS configuration.
type GatewayTLSConfig struct {
// Mode defines the TLS behavior for the TLS session initiated by the client.
Expand All @@ -316,8 +287,14 @@ type GatewayTLSConfig struct {

// CertificateRef is a reference to a Kubernetes object that contains a TLS
// certificate and private key. This certificate is used to establish a TLS
// handshake for requests that match the hostname of the associated listener.
// The referenced object MUST reside in the same namespace as Gateway.
// handshake for requests that match the hostname of the associated
// listener.
//
// When this references a resource in a different namespace than the
// Gateway, a ReferencePolicy in the target namespace MUST allow this
// reference for the certificate to be attached. If a ReferencePolicy does
// not allow this reference, the "ResolvedRefs" condition MUST be set to
// false for this listener with the "InvalidCertificateRef" reason.
//
// This field is required when mode is set to "Terminate" (default) and
// optional otherwise.
Expand All @@ -330,20 +307,7 @@ type GatewayTLSConfig struct {
// Support: Implementation-specific (Other resource types)
//
// +optional
CertificateRef *LocalObjectReference `json:"certificateRef,omitempty"`

// RouteOverride dictates if TLS settings can be configured
// via Routes or not.
//
// CertificateRef must be defined even if `routeOverride.certificate` is
// set to 'Allow' as it will be used as the default certificate for the
// listener.
//
// Support: Core
//
// +optional
// +kubebuilder:default={certificate:Deny}
RouteOverride *TLSOverridePolicy `json:"routeOverride,omitempty"`
CertificateRef *ObjectReference `json:"certificateRef,omitempty"`

// Options are a list of key/value pairs to give extended options
// to the provider.
Expand Down
38 changes: 0 additions & 38 deletions apis/v1alpha2/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,6 @@ type HTTPRouteSpec struct {
// +kubebuilder:validation:MaxItems=16
Hostnames []Hostname `json:"hostnames,omitempty"`

// TLS defines the TLS certificate to use for Hostnames defined in this
// Route. This configuration only takes effect if the AllowRouteOverride
// field is set to true in the associated Gateway resource.
//
// Collisions can happen if multiple HTTPRoutes define a TLS certificate
// for the same hostname. In such a case, conflict resolution guiding
// principles apply, specifically, if hostnames are same and two different
// certificates are specified then the certificate in the
// oldest resource wins.
//
// Please note that HTTP Route-selection takes place after the
// TLS Handshake (ClientHello). Due to this, TLS certificate defined
// here will take precedence even if the request has the potential to
// match multiple routes (in case multiple HTTPRoutes share the same
// hostname).
//
// Support: Core
//
// +optional
TLS *RouteTLSConfig `json:"tls,omitempty"`

// Rules are a list of HTTP matchers, filters and actions.
//
// +optional
Expand All @@ -140,23 +119,6 @@ type HTTPRouteSpec struct {
Rules []HTTPRouteRule `json:"rules,omitempty"`
}

// RouteTLSConfig describes a TLS configuration defined at the Route level.
type RouteTLSConfig struct {
// CertificateRef is a reference to a Kubernetes object that contains a TLS
// certificate and private key. This certificate is used to establish a TLS
// handshake for requests that match the hostname of the associated HTTPRoute.
// The referenced object MUST reside in the same namespace as HTTPRoute.
//
// CertificateRef can reference a standard Kubernetes resource, i.e. Secret,
// or an implementation-specific custom resource.
//
// Support: Core (Kubernetes Secrets)
//
// Support: Implementation-specific (Other resource types)
//
CertificateRef LocalObjectReference `json:"certificateRef"`
}

// HTTPRouteRule defines semantics for matching an HTTP request based on
// conditions, optionally executing additional processing steps, and forwarding
// the request to an API object.
Expand Down
48 changes: 1 addition & 47 deletions apis/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 27 additions & 31 deletions config/crd/bases/gateway.networking.k8s.io_gateways.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 0 additions & 47 deletions config/crd/bases/gateway.networking.k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/v1alpha2/0-namespaces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# These namespaces can be used for examples without recreating them each time.
---
kind: Namespace
apiVersion: v1
metadata:
name: gateway-api-example-ns1
---
kind: Namespace
apiVersion: v1
metadata:
name: gateway-api-example-ns2
23 changes: 23 additions & 0 deletions examples/v1alpha2/tls-basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1alpha2
metadata:
name: tls-basic
spec:
gatewayClassName: acme-lb
listeners:
- protocol: HTTPS
port: 443
hostname: foo.example.com
tls:
certificateRef:
kind: Secret
group: ""
name: foo-example-com-cert
- protocol: HTTPS
port: 443
hostname: bar.example.com
tls:
certificateRef:
kind: Secret
group: ""
name: bar-example-com-cert
Loading

0 comments on commit cf0a14d

Please sign in to comment.