Skip to content

OCPBUGS-49291: Improving the DevExp for passing the CSP directives to console per flag + Make use of connect-src and object-src directives #14701

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

Merged
merged 2 commits into from
May 8, 2025

Conversation

jhadvig
Copy link
Member

@jhadvig jhadvig commented Jan 27, 2025

Improving the DevExp for passing the CSP directives to console per flag instead of JSON.
New usage will be:

./bin/bridge --content-security-policy ScriptSrc="localhost:1234 localhost:2345" --content-security-policy FontSrc="localhost:3456 localhost:4567"

Also adding connect-src and object-src directives. These will be set to 'none' if no plugin will specify source-expression-list for them. This API was added by https://issues.redhat.com/browse/OCPBUGS-48740

/assign @TheRealJon @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 Jan 27, 2025
@openshift-ci-robot
Copy link
Contributor

@jhadvig: This pull request references Jira Issue OCPBUGS-49291, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.19.0) matches configured target version for branch (4.19.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @yapei

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

Improving the DevExp for passing the CSP directives to console per flag instead of JSON.
New usage will be:

./bin/bridge --content-security-policy ScriptSrc="localhost:1234 localhost:2345" --content-security-policy FontSrc="localhost:3456 localhost:4567"

Also adding connect-src and object-src directives. These will be set to 'none' if no plugin will specify source-expression-list for them. This API was added by https://issues.redhat.com/browse/OCPBUGS-48740

/assign @TheRealJon @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.

@openshift-ci-robot openshift-ci-robot added the jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. label Jan 27, 2025
@openshift-ci openshift-ci bot added component/backend Related to backend approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 27, 2025
Comment on lines 121 to 116
// If the objectSrc directive is not set, add 'none' to it.
if len(objectSrcDirective) == 1 && objectSrcDirective[0] == "object-src" {
objectSrcDirective = append(objectSrcDirective, none)
}

// If the connectSrc directive is not set, add 'none' to it.
if len(connectSrcDirective) == 1 && connectSrcDirective[0] == "connect-src" {
connectSrcDirective = append(connectSrcDirective, none)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think specifying none overrides default-src so things like self would no longer work.

Copy link
Member Author

@jhadvig jhadvig Jan 28, 2025

Choose a reason for hiding this comment

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

ok, I see, in that case we should only set self, for both object-src and connect-src


// If the connectSrc directive is not set, add 'none' to it.
if len(connectSrcDirective) == 1 && connectSrcDirective[0] == "connect-src" {
connectSrcDirective = append(connectSrcDirective, none)
Copy link
Member

Choose a reason for hiding this comment

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

For connect-src, we want self and also a directive for console.redhat.com

fContentSecurityPolicy := fs.String("content-security-policy", "", "Content security policy for the console. (JSON as string)")

consoleCSPFlags := serverconfig.MultiKeyValue{}
fs.Var(&consoleCSPFlags, "content-security-policy", "List of CSP directives that are enabled for the console. Each entry consist of csp-directive-name as a key and csp-directive-value as a value.")
Copy link
Member

Choose a reason for hiding this comment

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

nit: An example here would be nice (like we provide for i18n-namespaces above)

README.md Outdated
Example:

```
./bin/bridge --content-security-policy ScriptSrc="localhost:1234 localhost:2345" --content-security-policy FontSrc="localhost:3456 localhost:4567"
Copy link
Member

Choose a reason for hiding this comment

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

Here I would probably the directive name font-src instead of FontSrc

Suggested change
./bin/bridge --content-security-policy ScriptSrc="localhost:1234 localhost:2345" --content-security-policy FontSrc="localhost:3456 localhost:4567"
./bin/bridge --content-security-policy ScriptSrc="localhost:1234 localhost:2345" --content-security-policy font-src="localhost:3456 localhost:4567"

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 was thinking about it, but then we would need to change the console-config.yaml representation, or accept both formats FontSrc & font-src. Here I would rather go with the first option.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if we need to change console-config.yaml. Can we just translate between the names in config.go instead?

I wouldn't accept both formats. Let's pick one and go with it. If it's difficult, we can stick with PascalCase.

Copy link
Member Author

Choose a reason for hiding this comment

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

We will need the change to the console-config.yaml representation. Currently the in console-config/yaml CSPs are set in FontSrc="localhost:3456 localhost:4567" format. Thats how they are passed to the --content-security-policy flag by bridge. OR we need to update the addContentSecurityPolicy() in pkg/serverconfig/config.go so the cspDirectiveName is transformed into the font-src format.

Copy link
Member

Choose a reason for hiding this comment

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

OR we need to update the addContentSecurityPolicy() in pkg/serverconfig/config.go so the cspDirectiveName is transformed into the font-src format.

This is what I was thinking. We have only a handful of well-defined directives we support, so it doesn't seem too bad?

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 think its reasonable 👍

default:
klog.Warningf("ignored invalid CSP directive: %v", directive)
klog.Infof("ignored invalid CSP directive: %v", directive)
Copy link
Member

Choose a reason for hiding this comment

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

nit: This isn't necessarily an invalid directive since there are many we don't allow to be set

Suggested change
klog.Infof("ignored invalid CSP directive: %v", directive)
klog.Infof("ignored unsupported CSP directive: %v", directive)

@jhadvig
Copy link
Member Author

jhadvig commented Jan 30, 2025

@spadgett I've vendor the object-src removal and updated code and tests accordingly.
PTAL

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.

Thanks @jhadvig 👍

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 6, 2025
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 12, 2025
@jhadvig
Copy link
Member Author

jhadvig commented Feb 12, 2025

@spadgett thanks for review. Addressed your comments. PTAL

@jhadvig
Copy link
Member Author

jhadvig commented Feb 12, 2025

/retest

styleSrcDirective = append(styleSrcDirective, httpLocalHost)
directives := map[string][]string{
baseURI: {self},
defaultSrc: {self, consoleDot},
Copy link
Member

Choose a reason for hiding this comment

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

Can we get away with only adding consoleDot to scriptSrc and connectSrc? It would be better if we can avoid putting it in defaultSrc.

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.

Code looks good. @jhadvig Do you mind cleaning up the git history a little? I don't mind the separate vendor commits, but maybe squash the address comment commits. Thanks!

@spadgett
Copy link
Member

Hmm, looks like there's a build failure anyway

@jhadvig
Copy link
Member Author

jhadvig commented Feb 18, 2025

@spadgett squashed last two commits.
The tests are failing due to the vendored changes which are bumping the openshift/api which now requires go-1.23, thats why I've opened:

@spadgett
Copy link
Member

/retest

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 2025
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 13, 2025
@jhadvig
Copy link
Member Author

jhadvig commented Apr 22, 2025

/retest

@jhadvig
Copy link
Member Author

jhadvig commented Apr 28, 2025

/retest
/cherry-pick release-4.19

@openshift-cherrypick-robot

@jhadvig: once the present PR merges, I will cherry-pick it on top of release-4.19 in a new PR and assign it to you.

In response to this:

/retest
/cherry-pick release-4.19

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.

@jhadvig jhadvig force-pushed the OCPBUGS-49291 branch 2 times, most recently from 81d9465 to ac59501 Compare April 28, 2025 16:33
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.

You have two bump API commits. Not sure if that's intentional.

Thanks @jhadvig

case connectSrc:
connectSrcDirective = append(connectSrcDirective, sources)
default:
klog.Infof("ignored invalid CSP directive: %v", directive)
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 fail here as well

… console per flag + Make use of connect-src directive
@jhadvig
Copy link
Member Author

jhadvig commented Apr 29, 2025

Thank you @spadgett I've addressed your comment and removed unnecessary API bumps. Also added additional commit which is using klog.Fatalf() which is internally calling os.Exit().
PTAL

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.

/lgtm

👍
Thanks @jhadvig

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 5, 2025
Copy link
Contributor

openshift-ci bot commented May 5, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jhadvig, spadgett

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

The pull request process is described 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
Contributor

/retest-required

Remaining retests: 0 against base HEAD cb0532c and 2 for PR HEAD 39d031f in total

6 similar comments
@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD cb0532c and 2 for PR HEAD 39d031f in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD cb0532c and 2 for PR HEAD 39d031f in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD cb0532c and 2 for PR HEAD 39d031f in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD cb0532c and 2 for PR HEAD 39d031f in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD cb0532c and 2 for PR HEAD 39d031f in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD cb0532c and 2 for PR HEAD 39d031f in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD f6d63b5 and 2 for PR HEAD 39d031f in total

3 similar comments
@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD f6d63b5 and 2 for PR HEAD 39d031f in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD f6d63b5 and 2 for PR HEAD 39d031f in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD f6d63b5 and 2 for PR HEAD 39d031f in total

Copy link
Contributor

openshift-ci bot commented May 8, 2025

@jhadvig: The following tests 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/okd-scos-e2e-aws-ovn 39d031f link false /test okd-scos-e2e-aws-ovn
ci/prow/verify-deps 39d031f link true /test verify-deps

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.

@openshift-merge-bot openshift-merge-bot bot merged commit 1fb5c64 into openshift:main May 8, 2025
8 of 9 checks passed
@openshift-ci-robot
Copy link
Contributor

@jhadvig: Jira Issue OCPBUGS-49291: All pull requests linked via external trackers have merged:

Jira Issue OCPBUGS-49291 has been moved to the MODIFIED state.

In response to this:

Improving the DevExp for passing the CSP directives to console per flag instead of JSON.
New usage will be:

./bin/bridge --content-security-policy ScriptSrc="localhost:1234 localhost:2345" --content-security-policy FontSrc="localhost:3456 localhost:4567"

Also adding connect-src and object-src directives. These will be set to 'none' if no plugin will specify source-expression-list for them. This API was added by https://issues.redhat.com/browse/OCPBUGS-48740

/assign @TheRealJon @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.

@openshift-cherrypick-robot

@jhadvig: new pull request created: #15030

In response to this:

/retest
/cherry-pick release-4.19

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/backend Related to backend jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants