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

CONSOLE-4327: Add new API field to ConsolePlugin CRD for allowing additional CSP sources #1706

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jhadvig
Copy link
Member

@jhadvig jhadvig commented Oct 24, 2024

Add ConsolePluginCSP Field Documentation to ConsoleDynamicPlugin CRD Enhancement

This pull request updates the enhancement documentation for the ConsoleDynamicPlugin Custom Resource Definition (CRD) by introducing a new section that explains the ConsolePluginCSP field.

Link to the API change: openshift/api#2042

Summary of Changes:

  • New ConsolePluginCSP Field:

    • Adds the capability for dynamic plugins to define their own Content-Security-Policy (CSP) directives.
    • Describes how CSP directives can be used to mitigate security vulnerabilities like cross-site scripting (XSS) and data injection attacks.
  • Supported CSP Directives:

    • Outlines the supported CSP directives: DefaultSrc, ScriptSrc, StyleSrc, ImgSrc, and FontSrc.
    • Describes how the OpenShift web console backend merges these directives with its own default policies into a single CSP header.
  • CSP Directive Validation:

    • Implements validation rules to restrict the number of values for each directive.
    • Enforces value uniqueness.
    • Prohibits certain characters (commas, semicolons, whitespace, wildcard *) and specific formatting (values enclosed in single quotes).
  • Example Usage:

    • Provides an example that demonstrates how different plugins' CSP directives are merged into a unified policy for the OpenShift web console.

Why This Change?

The addition of this field to the ConsoleDynamicPlugin CRD enables plugin developers to configure secure policies for loading external resources while maintaining compliance with OpenShift’s security best practices. This change strengthens the ability to protect against potential vulnerabilities by enforcing clear rules for CSP configuration in dynamic plugins.

/assign @spadgett

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Oct 24, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 24, 2024

@jhadvig: This pull request references CONSOLE-4265 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.18.0" version, but no target version was set.

In response to this:

Add ConsolePluginCSP Field Documentation to ConsoleDynamicPlugin CRD Enhancement

This pull request updates the enhancement documentation for the ConsoleDynamicPlugin Custom Resource Definition (CRD) by introducing a new section that explains the ConsolePluginCSP field.

Link to the API change: openshift/api#2042

Summary of Changes:

  • New ConsolePluginCSP Field:

  • Adds the capability for dynamic plugins to define their own Content-Security-Policy (CSP) directives.

  • Describes how CSP directives can be used to mitigate security vulnerabilities like cross-site scripting (XSS) and data injection attacks.

  • Supported CSP Directives:

  • Outlines the supported CSP directives: DefaultSrc, ScriptSrc, StyleSrc, ImgSrc, and FontSrc.

  • Describes how the OpenShift web console backend merges these directives with its own default policies into a single CSP header.

  • CSP Directive Validation:

  • Implements validation rules to restrict the number of values for each directive.

  • Enforces value uniqueness.

  • Prohibits certain characters (commas, semicolons, whitespace, wildcard *) and specific formatting (values enclosed in single quotes).

  • Example Usage:

  • Provides an example that demonstrates how different plugins' CSP directives are merged into a unified policy for the OpenShift web console.

Why This Change?

The addition of this field to the ConsoleDynamicPlugin CRD enables plugin developers to configure secure policies for loading external resources while maintaining compliance with OpenShift’s security best practices. This change strengthens the ability to protect against potential vulnerabilities by enforcing clear rules for CSP configuration in dynamic plugins.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link
Contributor

openshift-ci bot commented Oct 24, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign adambkaplan for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 24, 2024

@jhadvig: This pull request references CONSOLE-4265 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.18.0" version, but no target version was set.

In response to this:

Add ConsolePluginCSP Field Documentation to ConsoleDynamicPlugin CRD Enhancement

This pull request updates the enhancement documentation for the ConsoleDynamicPlugin Custom Resource Definition (CRD) by introducing a new section that explains the ConsolePluginCSP field.

Link to the API change: openshift/api#2042

Summary of Changes:

  • New ConsolePluginCSP Field:

  • Adds the capability for dynamic plugins to define their own Content-Security-Policy (CSP) directives.

  • Describes how CSP directives can be used to mitigate security vulnerabilities like cross-site scripting (XSS) and data injection attacks.

  • Supported CSP Directives:

  • Outlines the supported CSP directives: DefaultSrc, ScriptSrc, StyleSrc, ImgSrc, and FontSrc.

  • Describes how the OpenShift web console backend merges these directives with its own default policies into a single CSP header.

  • CSP Directive Validation:

  • Implements validation rules to restrict the number of values for each directive.

  • Enforces value uniqueness.

  • Prohibits certain characters (commas, semicolons, whitespace, wildcard *) and specific formatting (values enclosed in single quotes).

  • Example Usage:

  • Provides an example that demonstrates how different plugins' CSP directives are merged into a unified policy for the OpenShift web console.

Why This Change?

The addition of this field to the ConsoleDynamicPlugin CRD enables plugin developers to configure secure policies for loading external resources while maintaining compliance with OpenShift’s security best practices. This change strengthens the ability to protect against potential vulnerabilities by enforcing clear rules for CSP configuration in dynamic plugins.

/assign @spadgett

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

#### Validation Rules
- Each directive can have up to 16 unique values.
- The total size of all values across directives must not exceed 8192 bytes (8KB).
- Each value must be unique, and there are additional validation rules to ensure no quotes, spaces, commas, or wildcard symbols are used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the controller will deduplicate if multiple ConsolePlugins do end up duplicating values, since we don't validate for duplications across multiple resources

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this will be responsibility of the console-operator's controller 👍

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. @JoelSpeed let us know what you think.

@opayne1 We'll want to cover this in the console plugin docs and release notes.

`ConsolePlugin` introduces the ability for dynamic plugins to specify their own Content Security Policy (CSP) directives in the OpenShift web console, using the `ConsolePluginCSP` field in the `ConsolePluginSpec`. This field is crucial for mitigating potential security risks, such as cross-site scripting (XSS) and data injection attacks, by controlling which external resources the browser can load.

#### Content Security Policy (CSP) Overview
CSP is a security feature that helps detect and mitigate attacks by specifying which sources are allowed for fetching content like scripts, styles, images, and fonts. For dynamic plugins that require loading resources from external sources, defining custom CSP rules ensures secure integration into the OpenShift console.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd link out to the MDN documentation for Content Security Policy either here or above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added below

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are good, but, we don't have a plan for moving from TechPreview to GA. What requirements would you expect of this new feature/what testing would you want to see, before you're ready to ship, can that be added to the graduation criteria section?

(This is something we are trying to promote engineers to think more about at the moment, in an effort to deliver complete and quality features first time)

@jhadvig
Copy link
Member Author

jhadvig commented Oct 25, 2024

@JoelSpeed @spadgett I've added additional commit with the Graduation Criteria as suggested.
PTAL

Comment on lines 621 to 649
Note: Currently Console uses `Content-Security-Policy-Report-Only` instead of
`Content-Security-Policy` header. Due to that the browser will only warn about
Console CSP violations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we discuss when we decide to turn on enforcement? It's an important date for plugins because they'll need to adopt these changes before it's enforced.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk about this @jhadvig and come up with a plan.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spadgett so when discussed with @vojtechszocs there should be at least 2-3 releases before we flip the switch.
First we need to:

Probably there will be more steps that we need to meet, this is just how I see right now.

* Update the OpenShift official documentation to include detailed guidelines
on configuring `ConsolePluginCSP` in the `ConsoleDynamicPlugin` CRD, along with
recommendations.
* Add CSP feature to release notes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document clearly when this will be enforced in the release notes.

on configuring `ConsolePluginCSP` in the `ConsoleDynamicPlugin` CRD, along with
recommendations.
* Add CSP feature to release notes.
* Extend e2e test suit for console-operator repository:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there interactions with other components at all? Do you think adding something to the origin test suite that runs across all PRs in openshift, to prevent other components causing regressions in this feature?

Copy link
Member

@spadgett spadgett Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @JoelSpeed. The two out-of-the-box console plugins enabled by default are the monitoring plugin and networking plugin. I think we should work with those teams to add Cypress tests for CSP violations in their plugins.

I'm hesitant to add it to the origin suite because we'd be exposing everyone to UI flakes when only a handful of components impact us, and it would mean introducing an entirely new library for UI testing (Cypress). In the past, we've targeted adding UI tests to specific repos we know can break console like the authentication and OLM.

cc @jgbernalp @tnisan

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @spadgett 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, please clarify that within the doc and when it comes to feature promotion, I'd expect to see links to tests that cover this outside of origin, and their results being green over a couple of weeks ideally

@jhadvig jhadvig changed the title CONSOLE-4265: Add new API field to ConsolePlugin CRD for allowing additional CSP sources CONSOLE-4327: Add new API field to ConsolePlugin CRD for allowing additional CSP sources Oct 29, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 29, 2024

@jhadvig: This pull request references CONSOLE-4327 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.18.0" version, but no target version was set.

In response to this:

Add ConsolePluginCSP Field Documentation to ConsoleDynamicPlugin CRD Enhancement

This pull request updates the enhancement documentation for the ConsoleDynamicPlugin Custom Resource Definition (CRD) by introducing a new section that explains the ConsolePluginCSP field.

Link to the API change: openshift/api#2042

Summary of Changes:

  • New ConsolePluginCSP Field:

  • Adds the capability for dynamic plugins to define their own Content-Security-Policy (CSP) directives.

  • Describes how CSP directives can be used to mitigate security vulnerabilities like cross-site scripting (XSS) and data injection attacks.

  • Supported CSP Directives:

  • Outlines the supported CSP directives: DefaultSrc, ScriptSrc, StyleSrc, ImgSrc, and FontSrc.

  • Describes how the OpenShift web console backend merges these directives with its own default policies into a single CSP header.

  • CSP Directive Validation:

  • Implements validation rules to restrict the number of values for each directive.

  • Enforces value uniqueness.

  • Prohibits certain characters (commas, semicolons, whitespace, wildcard *) and specific formatting (values enclosed in single quotes).

  • Example Usage:

  • Provides an example that demonstrates how different plugins' CSP directives are merged into a unified policy for the OpenShift web console.

Why This Change?

The addition of this field to the ConsoleDynamicPlugin CRD enables plugin developers to configure secure policies for loading external resources while maintaining compliance with OpenShift’s security best practices. This change strengthens the ability to protect against potential vulnerabilities by enforcing clear rules for CSP configuration in dynamic plugins.

/assign @spadgett

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me. Let's get buy in from the plugin teams that need to update their CI.

Comment on lines +643 to +644
* All the dynamic plugins which are enabled on the cluster by default will
update their CI to check for CSP violations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgbernalp @tnisan Any concerns about adding this into CI for the monitoring and networking plugins?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no concerns from my side.

Comment on lines 651 to 652
Once all the above listed requests are met, Console will switch will be switched
to use `Content-Security-Policy` header and start enforcing the policies.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to give teams outside of Red Hat authoring plugins a chance to update their plugins before we begin enforcing, so minimally that at least one release where we report only. I think it would be better to have a 2-3 release grace period, though.

(But of course we need the API available before then so plugins can adopt it and test.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spadgett definitely it will need to be at least 2-3 releases. I've rather avoid mentioning that in the doc, since its a bit unclear, instead I've only listed necessary tasks which need to be done before we actually start think about flipping the switch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we say we will stay in report-only mode for at least one release (which doesn't stop us from waiting longer).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add 👍

name: cron-tab
spec:
displayName: 'Cron Tab'
contentSecurityPolicy:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this new field be required? I'd assume is optional with default directives that come from the console.

There might be other directives that we need to consider like web workers, fonts, media source and images loaded using base64 data, for example:

base-uri 'self'; object-src 'self'; style-src 'self' 'unsafe-inline'; worker-src 'self'; font-src 'self' blob:; img-src 'self' data: blob:; media-src 'self'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgbernalp yes this will be an optional field. Defaults indeed come from console server.

There might be other directives that we need to consider like web workers, fonts, media source and images loaded using base64 data

Does the monitoring plugin use those ATM?
We wanted to start by exposing a minimal set of directives and making the API easy to extend.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgbernalp We set default-src: 'self' in console, so 'self' should be supported for all of the fetch directives. Here is what we set:

https://github.com/openshift/console/blob/eb90edbc440cec97c2bab04ee4e791bc51fba45a/pkg/server/server.go#L678-L697

We also have 'unsafe-inline' for stylesheets.

You could add other fetch directives we don't expose by setting DefaultSrc if needed. Maybe we should expose all the fetch directives as config options, though. That lets plugins do the right thing and only set the specific directives they need instead of the default fallback.

It looks like the only things you would need on top of console defaults are font-src blob:; img-src: blob:.

cc @vojtechszocs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhadvig the plugin does not use these rules ATM, I wanted to provide an example. But as @spadgett shared, it seems we already have the defaults.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should expose all the fetch directives as config options, though.

@spadgett you mean as we discussed per CM which will operator use to assemble the CSP for the frontend ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhadvig I'm a little unclear on the question. I only mean we should consider whether to add all fetch directives (like WorkerSrc and ObjectSrc) to the config, even if console doesn't have defaults for these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spadgett I think that its not necessary for the initial implementation. If there will a need for them we can add them down the road, but until then plugins will be able to use the DefaultSrc for these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the CSP spec, I see a lot of fetch directives. I'm OK with what we have to start.

@jhadvig
Copy link
Member Author

jhadvig commented Nov 5, 2024

@spadgett I've addressed the last pending comment and squashed the commits.
PTAL :)

Copy link
Contributor

openshift-ci bot commented Nov 5, 2024

@jhadvig: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants