Skip to content

Commit 1e23cab

Browse files
Merge pull request #819 from bshephar/horizon-hsts-headers
Enable HSTS on OCP route
2 parents aa91068 + 1ded290 commit 1e23cab

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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)