@@ -43,11 +43,137 @@ type ConsolePluginSpec struct {
4343 Backend ConsolePluginBackend `json:"backend"`
4444 // proxy is a list of proxies that describe various service type
4545 // to which the plugin needs to connect to.
46+ // +listType=atomic
4647 // +optional
4748 Proxy []ConsolePluginProxy `json:"proxy,omitempty"`
4849 // i18n is the configuration of plugin's localization resources.
4950 // +optional
5051 I18n ConsolePluginI18n `json:"i18n"`
52+ // contentSecurityPolicy is a list of Content-Security-Policy (CSP) directives for the plugin.
53+ // Each directive specifies a list of values, appropriate for the given directive type,
54+ // for example a list of remote endpoints for fetch directives such as ScriptSrc.
55+ // Console web application uses CSP to detect and mitigate certain types of attacks,
56+ // such as cross-site scripting (XSS) and data injection attacks.
57+ // Dynamic plugins should specify this field if need to load assets from outside
58+ // the cluster or if violation reports are observed. Dynamic plugins should always prefer
59+ // loading their assets from within the cluster, either by vendoring them, or fetching
60+ // from a cluster service.
61+ // CSP violation reports can be viewed in the browser's console logs during development and
62+ // testing of the plugin in the OpenShift web console.
63+ // Available directive types are DefaultSrc, ScriptSrc, StyleSrc, ImgSrc and FontSrc.
64+ // Each of the available directives may be defined only once in the list.
65+ // The value 'self' is automatically included in all fetch directives by the OpenShift web
66+ // console's backend.
67+ // For more information about the CSP directives, see:
68+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
69+ //
70+ // The OpenShift web console server aggregates the CSP directives and values across
71+ // its own default values and all enabled ConsolePlugin CRs, merging them into a single
72+ // policy string that is sent to the browser via `Content-Security-Policy` HTTP response header.
73+ //
74+ // Example:
75+ // ConsolePlugin A directives:
76+ // script-src: https://script1.com/, https://script2.com/
77+ // font-src: https://font1.com/
78+ //
79+ // ConsolePlugin B directives:
80+ // script-src: https://script2.com/, https://script3.com/
81+ // font-src: https://font2.com/
82+ // img-src: https://img1.com/
83+ //
84+ // Unified set of CSP directives, passed to the OpenShift web console server:
85+ // script-src: https://script1.com/, https://script2.com/, https://script3.com/
86+ // font-src: https://font1.com/, https://font2.com/
87+ // img-src: https://img1.com/
88+ //
89+ // OpenShift web console server CSP response header:
90+ // Content-Security-Policy: default-src 'self'; base-uri 'self'; script-src 'self' https://script1.com/ https://script2.com/ https://script3.com/; font-src 'self' https://font1.com/ https://font2.com/; img-src 'self' https://img1.com/; style-src 'self'; frame-src 'none'; object-src 'none'
91+ //
92+ // +openshift:enable:FeatureGate=ConsolePluginContentSecurityPolicy
93+ // +kubebuilder:validation:MaxItems=5
94+ // +kubebuilder:validation:XValidation:rule="self.map(x, x.values.map(y, y.size()).sum()).sum() < 8192",message="the total combined size of values of all directives must not exceed 8192 (8kb)"
95+ // +listType=map
96+ // +listMapKey=directive
97+ // +optional
98+ ContentSecurityPolicy []ConsolePluginCSP `json:"contentSecurityPolicy"`
99+ }
100+
101+ // DirectiveType is an enumeration of OpenShift web console supported CSP directives.
102+ // LoadType is an enumeration of i18n loading types.
103+ // +kubebuilder:validation:Enum:="DefaultSrc";"ScriptSrc";"StyleSrc";"ImgSrc";"FontSrc"
104+ // +enum
105+ type DirectiveType string
106+
107+ const (
108+ // DefaultSrc directive serves as a fallback for the other CSP fetch directives.
109+ // For more information about the DefaultSrc directive, see:
110+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src
111+ DefaultSrc DirectiveType = "DefaultSrc"
112+ // ScriptSrc directive specifies valid sources for JavaScript.
113+ // For more information about the ScriptSrc directive, see:
114+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
115+ ScriptSrc DirectiveType = "ScriptSrc"
116+ // StyleSrc directive specifies valid sources for stylesheets.
117+ // For more information about the StyleSrc directive, see:
118+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src
119+ StyleSrc DirectiveType = "StyleSrc"
120+ // ImgSrc directive specifies a valid sources of images and favicons.
121+ // For more information about the ImgSrc directive, see:
122+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/img-src
123+ ImgSrc DirectiveType = "ImgSrc"
124+ // FontSrc directive specifies valid sources for fonts loaded using @font-face.
125+ // For more information about the FontSrcdirective, see:
126+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/font-src
127+ FontSrc DirectiveType = "FontSrc"
128+ )
129+
130+ // CSPDirectiveValue is single value for a Content-Security-Policy directive.
131+ // Each directive value must have a maximum length of 1024 characters and must not contain
132+ // whitespace, commas (,), semicolons (;) or single quotes ('). The value '*' is not permitted.
133+ // +kubebuilder:validation:MinLength=1
134+ // +kubebuilder:validation:MaxLength=1024
135+ // +kubebuilder:validation:XValidation:rule="!self.contains(\"'\")",message="CSP directive value cannot contain a quote"
136+ // +kubebuilder:validation:XValidation:rule="!self.matches('\\\\s')",message="CSP directive value cannot contain a whitespace"
137+ // +kubebuilder:validation:XValidation:rule="!self.contains(',')",message="CSP directive value cannot contain a comma"
138+ // +kubebuilder:validation:XValidation:rule="!self.contains(';')",message="CSP directive value cannot contain a semi-colon"
139+ // +kubebuilder:validation:XValidation:rule="self != '*'",message="CSP directive value cannot be a wildcard"
140+ type CSPDirectiveValue string
141+
142+ // ConsolePluginCSP holds configuration for a specific CSP directive
143+ type ConsolePluginCSP struct {
144+ // directive specifies which Content-Security-Policy directive to configure.
145+ // Available directive types are DefaultSrc, ScriptSrc, StyleSrc, ImgSrc and FontSrc.
146+ // DefaultSrc directive serves as a fallback for the other CSP fetch directives.
147+ // For more information about the DefaultSrc directive, see:
148+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src
149+ // ScriptSrc directive specifies valid sources for JavaScript.
150+ // For more information about the ScriptSrc directive, see:
151+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
152+ // StyleSrc directive specifies valid sources for stylesheets.
153+ // For more information about the StyleSrc directive, see:
154+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src
155+ // ImgSrc directive specifies a valid sources of images and favicons.
156+ // For more information about the ImgSrc directive, see:
157+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/img-src
158+ // FontSrc directive specifies valid sources for fonts loaded using @font-face.
159+ // For more information about the FontSrc directive, see:
160+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/font-src
161+ // +kubebuilder:validation:Required
162+ Directive DirectiveType `json:"directive"`
163+ // values defines an array of values to append to the console defaults for this directive.
164+ // Each ConsolePlugin may define their own directives with their values. These will be set
165+ // by the OpenShift web console's backend, as part of its Content-Security-Policy header.
166+ // The array can contain at most 16 values. Each directive value must have a maximum length
167+ // of 1024 characters and must not contain whitespace, commas (,), semicolons (;) or single
168+ // quotes ('). The value '*' is not permitted.
169+ // Each value in the array must be unique.
170+ //
171+ // +kubebuilder:validation:Required
172+ // +kubebuilder:validation:MinItems=1
173+ // +kubebuilder:validation:MaxItems=16
174+ // +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x == y))",message="each CSP directive value must be unique"
175+ // +listType=atomic
176+ Values []CSPDirectiveValue `json:"values"`
51177}
52178
53179// LoadType is an enumeration of i18n loading types
0 commit comments