Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] dynamically set iframe domain #127

Open
wants to merge 1 commit into
base: master-3.23.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deploy/crds/operators.ibm.com_commonwebuis_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ spec:
format: int32
type: integer
type: object
iframeDomain:
type: string
license:
description: SwitcherItemSpec defines the desired state of SwitcherItem
properties:
Expand Down
1 change: 1 addition & 0 deletions deploy/crds/operators.ibm.com_v1alpha1_commonwebui_cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spec:
limits:
memory: 256Mi
cpu: 300m
iframeDomain: https://*.multicloud-ibm.com
globalUIConfig:
cloudPakVersion: 3.5.3
defaultAdminUser: admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ metadata:
"osAuth": "",
"sessionPollingInterval": 5000
},
"iframeDomain": "https://*.multicloud-ibm.com",
"operatorVersion": "1.3.3",
"replicas": 1,
"resources": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ spec:
format: int32
type: integer
type: object
iframeDomain:
type: string
license:
description: SwitcherItemSpec defines the desired state of SwitcherItem
properties:
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/operators/v1alpha1/commonwebuiservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type CommonWebUISpec struct {
Replicas int32 `json:"replicas,omitempty"`
Resources Resources `json:"resources,omitempty"`
License License `json:"license,omitempty"`
IframeDomain string `json:"iframeDomain,omitempty"`
}

// CommonWebUIConfig defines the desired state of CommonWebUIConfig
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/operators/v1alpha1/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ func schema_pkg_apis_operators_v1alpha1_CommonWebUISpec(ref common.ReferenceCall
Ref: ref("github.com/ibm/ibm-commonui-operator/pkg/apis/operators/v1alpha1.License"),
},
},
"iframeDomain": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
},
},
},
Expand Down
33 changes: 33 additions & 0 deletions pkg/resources/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package resources

import (
"bytes"
"encoding/json"
"strings"
"text/template"

operatorsv1alpha1 "github.com/ibm/ibm-commonui-operator/pkg/apis/operators/v1alpha1"
certmgr "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
Expand Down Expand Up @@ -127,6 +129,24 @@ var CallbackIngressAnnotations = map[string]string{
"icp.management.ibm.com/secure-backends": "true",
}

//nolint
const templFrame = `
add_header 'X-XSS-Protection' '1' always;
add_header Content-Security-Policy "default-src 'none'; font-src * 'unsafe-inline' 'self' data:; script-src 'unsafe-inline' 'self' blob: cdn.segment.com fast.appcues.com; connect-src 'self' https://api.segment.io wss://api.appcues.net https://notify.bugsnag.com; img-src * data:; frame-src 'self' https://my.appcues.com; style-src 'unsafe-inline' 'self' https://fast.appcues.com; frame-ancestors 'self' {{.Domain}}";`

func BuildAnnotation(data interface{}) string {
reqLogger := log.WithValues("func", "BuildAnnotation", "DomainAnnotation")
t := template.Must(template.New("").Parse(templFrame))
buf := bytes.Buffer{}
err := t.Execute(&buf, data)
if err != nil {
reqLogger.Info("Domain Annotation template build error")
return ""
}
reqLogger.Info("Domain Annotation template build success")
return buf.String()
}

var CommonUIIngressAnnotations = map[string]string{
"kubernetes.io/ingress.class": "ibm-icp-management",
"icp.management.ibm.com/auth-type": "access-token",
Expand Down Expand Up @@ -590,6 +610,19 @@ func NavIngressForCommonWebUI(instance *operatorsv1alpha1.CommonWebUI) *netv1.In
reqLogger.Info("CS??? Entry")
metaLabels := LabelsForMetadata(NavIngress)
Annotations := CommonUIIngressAnnotations
if instance.Spec.IframeDomain != "" {
var domainName = map[string]string{
"Domain": instance.Spec.IframeDomain,
}
Annotations = map[string]string{
"kubernetes.io/ingress.class": "ibm-icp-management",
"icp.management.ibm.com/auth-type": "access-token",
"icp.management.ibm.com/secure-backends": "true",
"icp.management.ibm.com/app-root": "/common-nav?root=true",
//nolint
"icp.management.ibm.com/configuration-snippet": BuildAnnotation(domainName),
}
}
ingress := &netv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: NavIngress,
Expand Down