openshift / api

Canonical location of the OpenShift API definition.
http://www.openshift.org
Apache License 2.0
95 stars 510 forks source link

[WIP] CONSOLE-4265: Add new API field to ConsolePlugin CRD for allowing additional CSP sources #2042

Open jhadvig opened 4 days ago

jhadvig commented 4 days ago

When serving Console HTML index page, we generate the policy that includes allowed (trustworthy) sources. It may be necessary for some dynamic plugins to add new sources in order to avoid CSP violations at Console runtime. We need to extend the ConsolePlugin CRD, in order to give the plugin creators a mechanism how to specify these source.

We discussed with @vojtechszocs two possible implementation:

  1. Add a new field to spec for specifying an array of sources which would apply for all the CSP directives - spec.csp.allowedSources. This implementation is pretty straight-forward but automatically applying the same source across different directives could unintentionally block legitimate content or reduce security.

    Example:

    kind: ConsolePlugin
    metadata:
    name: my-console-plugin
    spec:
    displayName: "My Custom Console Plugin"
    backend:
    service:
      name: "plugin-backend-service"
      namespace: "plugin-namespace"
      port: 8080
    csp:
    allowedSources:
      - "self"
      - "https://trusted-images.com"
      - "https://cdn.images.com"
  2. (Proposed solution) Add a new field to spec for specifying an array of sources for each of the directives. Letting users manage different whitelists for different types of content, gives them more flexibility in controlling security settings.

    Example:

    kind: ConsolePlugin
    metadata:
    name: my-console-plugin
    spec:
    displayName: "My Custom Console Plugin"
    backend:
    service:
      name: "plugin-backend-service"
      namespace: "plugin-namespace"
      port: 8080
    csp:
    - directive: script-src
      sources:
        - "self"
        - "https://trusted-scripts.com"
    - directive: img-src
      sources:
        - "self"
        - "https://trusted-images.com"
        - "https://cdn.images.com"
    - directive: style-src
      sources:
        - "self"
        - "https://trusted-styles.com"

Note: The PR is missing some descriptions and validation and unit tests. Will address those once we align on the API structure.

/assign @spadgett @vojtechszocs

Story: https://issues.redhat.com/browse/CONSOLE-4265

openshift-ci-robot commented 4 days ago

@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](https://github.com/openshift/api/pull/2042): >When serving Console HTML index page, we generate the policy that includes allowed (trustworthy) [sources](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources). >It may be necessary for some dynamic plugins to add new sources in order to avoid CSP violations at Console runtime. >We need to extend the ConsolePlugin CRD, in order to give the plugin creators a mechanism how to specify these source. > >We discussed with @vojtechszocs two possible implementation: >1. Add a new field to spec for specifying an array of sources which would apply for all the CSP directives - `spec.csp.allowedSources`. This implementation is pretty straight-forward but automatically applying the same source across different directives could unintentionally block legitimate content or reduce security. > > Example: >```yaml >kind: ConsolePlugin >metadata: > name: my-console-plugin >spec: > displayName: "My Custom Console Plugin" > backend: > service: > name: "plugin-backend-service" > namespace: "plugin-namespace" > port: 8080 > csp: > allowedSources: > - "self" > - "https://trusted-images.com" > - "https://cdn.images.com" >``` > >2. (Proposed solution) Add a new field to spec for specifying an array of sources for each of the directives. Letting users manage different whitelists for different types of content, gives them more flexibility in controlling security settings. > > Example: >```yaml >kind: ConsolePlugin >metadata: > name: my-console-plugin >spec: > displayName: "My Custom Console Plugin" > backend: > service: > name: "plugin-backend-service" > namespace: "plugin-namespace" > port: 8080 > csp: > - directive: script-src > sources: > - "self" > - "https://trusted-scripts.com" > - directive: img-src > sources: > - "self" > - "https://trusted-images.com" > - "https://cdn.images.com" > - directive: style-src > sources: > - "self" > - "https://trusted-styles.com" >``` > >Note: The PR is missing some descriptions and validation and unit tests. Will address those once we align on the API structure. > >/assign @spadgett @vojtechszocs > >Story: https://issues.redhat.com/browse/CONSOLE-4265 > > Instructions for interacting with me using PR comments are available [here](https://prow.ci.openshift.org/command-help?repo=openshift%2Fapi). If you have questions or suggestions related to my behavior, please file an issue against the [openshift-eng/jira-lifecycle-plugin](https://github.com/openshift-eng/jira-lifecycle-plugin/issues/new) repository.
openshift-ci[bot] commented 4 days ago

Hello @jhadvig! Some important instructions when contributing to openshift/api: API design plays an important part in the user experience of OpenShift and as such API PRs are subject to a high level of scrutiny to ensure they follow our best practices. If you haven't already done so, please review the OpenShift API Conventions and ensure that your proposed changes are compliant. Following these conventions will help expedite the api review process for your PR.

openshift-ci[bot] commented 2 days ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jhadvig Once this PR has been reviewed and has the lgtm label, please ask for approval from spadgett. 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: - **[OWNERS](https://github.com/openshift/api/blob/master/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
jhadvig commented 2 days ago

@spadgett thank you for the review. I've address the comments. PTAL

openshift-ci[bot] commented 2 days ago

@jhadvig: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/verify 5521582500c52f49c975a993e38b9482c1d4610f link true /test verify

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).