Skip to content

Commit 1ded290

Browse files
author
Brendan Shephard
committed
Enable HSTS on OCP route
This change adds the required annotation to the OCP route to enable HSTS headers as per: https://access.redhat.com/documentation/en-us/openshift_container_platform/4.7/html/networking/configuring-routes\#nw-enabling-hsts_route-configuration Signed-off-by: Brendan Shephard <bshephar@redhat.com>
1 parent 63e2b64 commit 1ded290

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎pkg/openstack/horizon.go‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import (
2222

2323
// ReconcileHorizon -
2424
func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *helper.Helper) (ctrl.Result, error) {
25+
const (
26+
HorizonHSTSHeaderAnnotation string = "haproxy.router.openshift.io/hsts_header"
27+
HorizonHSTSHeaderAnnotationValue string = "max-age=31536000;includeSubDomains;preload"
28+
)
29+
2530
horizon := &horizonv1.Horizon{
2631
ObjectMeta: metav1.ObjectMeta{
2732
Name: "horizon",
@@ -73,6 +78,14 @@ func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackContro
7378
return ctrl.Result{}, err
7479
}
7580

81+
// Set HSTS Headers for Horizon Route
82+
//
83+
apiOverrides := instance.Spec.Horizon.APIOverride
84+
85+
if _, ok := apiOverrides.Route.Annotations[HorizonHSTSHeaderAnnotation]; !ok {
86+
apiOverrides.Route.Annotations[HorizonHSTSHeaderAnnotation] = HorizonHSTSHeaderAnnotationValue
87+
}
88+
7689
// make sure to get to EndpointConfig when all service got created
7790
if len(svcs.Items) == 1 {
7891
endpointDetails, ctrlResult, err := EnsureEndpointConfig(
@@ -82,7 +95,7 @@ func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackContro
8295
horizon,
8396
svcs,
8497
serviceOverrides,
85-
instance.Spec.Horizon.APIOverride,
98+
apiOverrides,
8699
corev1beta1.OpenStackControlPlaneExposeHorizonReadyCondition,
87100
false, // TODO (mschuppert) could be removed when all integrated service support TLS
88101
tls.API{
@@ -117,7 +130,6 @@ func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackContro
117130
}
118131
return nil
119132
})
120-
121133
if err != nil {
122134
instance.Status.Conditions.Set(condition.FalseCondition(
123135
corev1beta1.OpenStackControlPlaneHorizonReadyCondition,

0 commit comments

Comments
 (0)