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

NETOBSERV-4 Create NetworkPolicy dialog #8655

Merged
merged 2 commits into from Jul 12, 2021

Conversation

jotak
Copy link
Contributor

@jotak jotak commented Apr 14, 2021

New form to create network policies as an alternative to yaml
cf https://issues.redhat.com/browse/NETOBSERV-4

Checklist:

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 14, 2021
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jotak
To complete the pull request process, please assign rawagner after the PR has been reviewed.
You can assign the PR to them by writing /assign @rawagner in a comment when ready.

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 openshift-ci-robot added the component/core Related to console core functionality label Apr 14, 2021
@openshift-ci-robot openshift-ci-robot added the kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated label Apr 14, 2021
@openshift-ci-robot
Copy link
Contributor

Hi @jotak. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 14, 2021
@jotak
Copy link
Contributor Author

jotak commented May 6, 2021

Hey @andrew-ronaldson , @astoycos
Concerning the 3 different options provided when a peer is added, what do you think about renaming them:

  • Allow namespace-wide inbound traffic (or outbound)
  • Allow cluster-wide inbound traffic (or outbound)
  • Allow inbound traffic per IP block

Currently it's:
Capture d’écran de 2021-05-06 18-58-14

I'm suggesting this because, especially the second option "Allow traffic from another namespace in the cluster" doesn't sound good to me, first because it can be from more than just one namespace, and secondly because it's not necessarily other namespaces, it could very well include the present namespace. What do you think?

Also, something else: since network policies with openshift-sdn work sometimes differently, what do you think about having a warning when a field might not be supported by some network types? E.g. the whole egress section could have such a warning note: "Egress network policies aren't supported with OpenShiftSDN network type." in the explanation text.

Ideally I'd like to detect automatically which network type is in use, but afaik this is a cluster configuration that requires admin role, hence normal users wouldn't have access to it (unless you see another way to get that than fetching the cluster Network config?)

@astoycos
Copy link

astoycos commented May 6, 2021

Hey Joel!

For starters I think we should change "Add from source'" to "Add NetworkPolicyPeer"

Apart from that I agree the way the things are worded now is a bit confusing. Lets take a step back, The options we must be able to express when defining a single network policy peer are

A Peer defined with....

  1. A Pod Selector
  2. A Namespace Selector
  3. A Namespace Selector && Pod Selector
  4. An IpBlock

based on the design When we add a New "From Source" we just need to narrow down to

  • Same Namespace (i.e 1.)
  • Different Namespace (i.e 2 OR (1&&2))
  • IPBlock (i.e 4)

So Regarding

Allow namespace-wide inbound traffic (or outbound)

"namespace-wide" is a bit confusing to me here

Allow cluster-wide inbound traffic (or outbound)
Allow inbound traffic per IP block

I think its mostly there but i'd rather see

-- Allow traffic from/to same namespace
-- Allow traffic from/to different namespace
-- Allow traffic from/to IpBlock

Also, something else: since network policies with openshift-sdn work sometimes differently, what do you think about having a warning when a field might not be supported by some network types? E.g. the whole egress section could have such a warning note: "Egress network policies aren't supported with OpenShiftSDN network type." in the explanation text.

This is a REALLY good point and I definitely think if we don't have a dynamic warning we need to have at least a static warning somewhere on the form.

Ideally I'd like to detect automatically which network type is in use, but afaik this is a cluster configuration that requires admin role, hence normal users wouldn't have access to it (unless you see another way to get that than fetching the cluster Network config?)

So its a cluster configuration yes, but it can't be RE-configured after cluster installation, so I don't really see any point in hiding it from Developers... but yeah I'm not sure what the default is there

Regardless if we can't fetch the config from the CC, you can always just look to see what namespace is there.... In OCP-SDN's case I think it's just openshift-sdn and in OVN-K's case its openshift-ovn-kubernetes, if you want to be more through you can also see what pods are deployed there as well. This is a bit hacky but would work.

@jotak
Copy link
Contributor Author

jotak commented May 7, 2021

For starters I think we should change "Add from source'" to "Add NetworkPolicyPeer"

I'm fine with renaming this as well (tbh i was thinking about something like "Add allowed source" to make it more visible that it's about allowing, not restricting - although it's also mentioned elsewhere). Anyway we can discuss about all these points in the next meeting.

I think its mostly there but i'd rather see

-- Allow traffic from/to same namespace
-- Allow traffic from/to different namespace
-- Allow traffic from/to IpBlock

Well, it doesn't really address my point, because the second option may still include the policy's namespace, so it's not 'different' namespace. I don't think I'm nitpicking, take the example of an application than spans over several namespaces, and you want to restrict the traffic to pods belonging to that application. If I read the options that you're suggesting, my first guess would be that I have to create 2 network policies, one for the same namespace, and another for the other namespaces. But in reality I could perfectly just have 1 network policy, which IMO is more obvious to understand with a wording like "cluster-wide traffic".

Said differently, I'm trying to make apparent the different scopes that are proposed, given those scopes are not exclusive, but inclusive. Unless I'm wrong, it looks like that:


 ┌───────────────────────────────────────┐
 │Scope: all (ipblock)                   │
 │                                       │
 │  ┌───────────────────────────────┐    │
 │  │Scope: cluster (pod+ns selec)  │    │
 │  │                               │    │
 │  │  ┌───────────────────────┐    │    │
 │  │  │Scope: namespace       │    │    │
 │  │  │                       │    │    │
 │  │  │  (pod selec)          │    │    │
 │  │  │                       │    │    │
 │  │  └───────────────────────┘    │    │
 │  │                               │    │
 │  └───────────────────────────────┘    │
 │                                       │
 └───────────────────────────────────────┘

What about something like:

  • Allow peers from the same namespace
  • Allow peers from the cluster
  • Allow peers by IP block

Regardless if we can't fetch the config from the CC, you can always just look to see what namespace is there.... In OCP-SDN's case I think it's just openshift-sdn and in OVN-K's case its openshift-ovn-kubernetes, if you want to be more through you can also see what pods are deployed there as well. This is a bit hacky but would work.

That's a good trick, thanks! (I just need also to check if the console can get these names despite logged in user not seeing them)

@andrew-ronaldson
Copy link

Sorry if I'm not understanding this Joel but if you want to use the Policy namespace would you just add source "Allow traffic from same namespace" then the dropdown option "All pods in the namespace"? That's how I see it but maybe that's just me.

I like "Add allowed source" instead of from sources. In the description area below the ingress rule heading we could explain the Peers so it is clearer. I agree the wording needs work and I will work with writers on the team.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 9, 2021
@jotak
Copy link
Contributor Author

jotak commented May 10, 2021

Sorry if I'm not understanding this Joel but if you want to use the Policy namespace would you just add source "Allow traffic from same namespace" then the dropdown option "All pods in the namespace"? That's how I see it but maybe that's just me.

We can discuss this in our meeting if needed. My point is if you want to create a rule that is both for the same namespace and other namespaces (since a rule can target multiple namespaces at once)

@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 10, 2021
@astoycos
Copy link

Hey Joel, thanks for the descriptive feedback! And no worries it's good to nitpick here since it's pretty confusing, I see what you mean...

Said differently, I'm trying to make apparent the different scopes that are proposed, given those scopes are not exclusive, but inclusive. Unless I'm wrong, it looks like that:

 ┌───────────────────────────────────────┐
 │Scope: all (ipblock)                   │
 │                                       │
 │  ┌───────────────────────────────┐    │
 │  │Scope: cluster (pod+ns selec)  │    │
 │  │                               │    │
 │  │  ┌───────────────────────┐    │    │
 │  │  │Scope: namespace       │    │    │
 │  │  │                       │    │    │
 │  │  │  (pod selec)          │    │    │
 │  │  │                       │    │    │
 │  │  └───────────────────────┘    │    │
 │  │                               │    │
 │  └───────────────────────────────┘    │
 │                                       │
 └───────────────────────────────────────┘

This scope diagram is definitely correct, and well done btw! It's counter intuitive but you're 100% right you could allow/deny traffic from pods in the SAME namespace and DIFFERENT namespaces with a single rule. I like this suggestion

What about something like:

Allow peers from the same namespace
Allow peers from the cluster
Allow peers by IP block

The only thing I would advocate against is using the word cluster simply because I would't want any user getting Network Policy (Which is ultimately namespaced scoped) with Cluster Network Policy (which will be cluster scoped) I would just follow what they do in the K8's docs and say like

Allow peers from (Specified, Selected, particular, etc) namespaces

Whatever word there would work ^

@jotak jotak force-pushed the netpolicy-form branch 2 times, most recently from 284ea65 to b1dcc4b Compare May 12, 2021 15:32
@jotak jotak marked this pull request as ready for review May 12, 2021 15:34
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 12, 2021
@jotak jotak changed the title NETOBSERV-1 Create NetworkPolicy dialog (WIP) NETOBSERV-1 Create NetworkPolicy dialog May 12, 2021
@jotak
Copy link
Contributor Author

jotak commented May 12, 2021

It's ready for review.

(Side note: I also did some tries to have multiple views (form / yaml / split) as discussed with @andrew-ronaldson , enabling to switch between views without loosing context, this is pretty promising IMO, but leaving it aside for the moment so that it can be discussed in a more global context)

see preview branch: https://github.com/jotak/console/tree/netpolicy-form-edit

@jotak
Copy link
Contributor Author

jotak commented May 17, 2021

/retest

@openshift-ci openshift-ci bot added the kind/cypress Related to Cypress e2e integration testing label May 17, 2021
@jotak jotak force-pushed the netpolicy-form branch 2 times, most recently from f2935b6 to 8ac8f28 Compare May 19, 2021 08:07
@jotak jotak force-pushed the netpolicy-form branch 3 times, most recently from aa7dfe1 to 4563c2e Compare June 8, 2021 08:57
@yapei
Copy link
Contributor

yapei commented Jun 8, 2021

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Jun 8, 2021
@jotak
Copy link
Contributor Author

jotak commented Jun 16, 2021

@kyoto @spadgett this is waiting for approval

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 @jotak. Great work on this overall.

}
}

.co-create-networkpolicy__deny .checkbox {
Copy link
Member

Choose a reason for hiding this comment

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

When possible, give the checkbox element itself a classname rather than nesting selectors. We've found this to be more maintainable and in the spirit of BEM. (Here and below.)

Copy link
Contributor Author

@jotak jotak Jul 1, 2021

Choose a reason for hiding this comment

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

Ok, I'm adding a surrounding div with className


/* Style override for FormFieldGroupExpandable: bigger font (~h2), move toggle icon a little bit lower */
.co-create-networkpolicy__expandable-xl > .pf-c-form__field-group-header .pf-c-form__field-group-header-title-text {
font-size: var(--pf-global--FontSize--xl);
Copy link
Member

Choose a reason for hiding this comment

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

nit: we try to alphabetize rules. (We have a backlog story to enforce this with a linter.)

@@ -0,0 +1,56 @@
.co-create-networkpolicy {
Copy link
Member

Choose a reason for hiding this comment

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

New code generally should go under the console-app package. We will eventually move everything out of public into packages

}

.co-create-networkpolicy__expandable-xl > .pf-c-form__field-group-toggle {
margin-top: 0.3rem;
Copy link
Member

Choose a reason for hiding this comment

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

It seems odd to mix rem and px styles (although I don't know if there is a best practice here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moving all to rem

Copy link
Member

Choose a reason for hiding this comment

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

We've used px in most contexts in console. @rhamilto @sg00dwin any opinion on this?


.co-create-networkpolicy__rule-header .pf-m-secondary {
margin: 8px;
top: -8px;
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why these overrides are needed? We try to use the PF components without overrides as much as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't remember, and it doesn't seem necessary anymore, I'm removing it.

id={`exception-${idx}`}
value={exc}
/>
<Button
Copy link
Member

Choose a reason for hiding this comment

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

This button needs an aria-label for screen readers.

const helpTextPodSelector =
direction === 'ingress'
? namespaceSelector
? t(
Copy link
Member

Choose a reason for hiding this comment

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

Avoid nested ternaries, they're hard to follow.

id={`${key}-port`}
value={port.port}
/>
<Button
Copy link
Member

Choose a reason for hiding this comment

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

Missing aria-label

};

return (
<Card style={{ marginBottom: 15 }}>
Copy link
Member

Choose a reason for hiding this comment

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

Avoid inline styles

id: `peer-header-${idx}`,
}}
actions={
<Button
Copy link
Member

Choose a reason for hiding this comment

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

Missing aria-label

Comment on lines 222 to 228
<Alert
variant="info"
title={t(
'public~When using the OpenShift SDN cluster network provider, egress network policy is not supported.',
)}
actionClose={<AlertActionCloseButton onClose={() => setShowSDNAlert(false)} />}
/>
Copy link
Member

Choose a reason for hiding this comment

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

Screen Shot 2021-06-30 at 12 44 10 PM

Seems this should be a warning alert?
In other forms we display <Alert> inline so they aren't floating.

Suggested change
<Alert
variant="info"
title={t(
'public~When using the OpenShift SDN cluster network provider, egress network policy is not supported.',
)}
actionClose={<AlertActionCloseButton onClose={() => setShowSDNAlert(false)} />}
/>
<Alert
variant="warning"
isInline
className="co-alert"
title={t(
'public~When using the OpenShift SDN cluster network provider, egress network policy is not supported.',
)}
actionClose={<AlertActionCloseButton onClose={() => setShowSDNAlert(false)} />}
/>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was using a warning at first but changed to info. The reason is that this banner is always displayed, even when there's no problem because the user uses ovn-k cni, and we don't want to sound too aggressive or worrying while there are chances that there's no issue at all. Also, having it as a floating box allows the user to dismiss it if desired (if it's perceived as annoying).

This situation isn't perfect for sure, but it's temporary, there's a task with the SDN team to expose information about the CNI plugin in use; when it's done, we will be able to remove this message and adapt the display to whatever is relevant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW I could add something to the message like "If your network provider is OVN-Kubernetes, please ignore this message"

Copy link
Member

Choose a reason for hiding this comment

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

I agree it should be an info message for the reasons you state.

We could try to get the configuration for users who have authority, but if the SDN team is working to expose it to normal users, I'm fine leaving it as-is.

@jotak
Copy link
Contributor Author

jotak commented Jul 1, 2021

@spadgett @sg00dwin thanks for reviewing. If I didn't forget anything, all comments should have been addressed or answered.

@dtaylor113
Copy link
Contributor

/retest

@spadgett
Copy link
Member

spadgett commented Jul 9, 2021

/ok-to-test

@openshift-ci openshift-ci bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 9, 2021
New form to create network policies as an alternative to yaml
cf https://issues.redhat.com/browse/NETOBSERV-1

UX feedbacks

- Restore h2 style for ingress/egress section titles
- Full-width dropdowns
- Replace openshiftSDN related warnings with pf Alerts (info)
- Hide pods selector unless explicitly wanted
- Adding items to list puts them in first position
- Remove rules numbering
- Show description text along with pod selector (hence remove the
  tooltip)
- Show description text along with peers in rules

Hide/show selectors mechanism

... allowing to get rid of some intermediate options (subtype dropdown)

New component NetworkPolicyConditionalSelector

IPBlock: hide exceptions until one is added

Also use NetworkPolicyKind in network-policy-model.ts, and have more
strict typing

Fix code review comments

- Move files from public to packages/console-app
- Move networkPolicy state to inner level
- Remove form pre-validation (validation entirely performed from backend)
- Couple of CSS fix (remove unneeded, avoid inline styles...), prefer
  rem to px
- Add keys to model (cf rule react/no-array-index-key)
- Add several aria-labels
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2021
@jotak
Copy link
Contributor Author

jotak commented Jul 12, 2021

PR rebased, @spadgett @andrew-ronaldson I removed the namespace field

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

];
return (
<div className="form-group co-create-networkpolicy__add-peer">
<Dropdown
Copy link
Member

Choose a reason for hiding this comment

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

Note: For new dropdowns, you should prefer the PatternFly dropdown. We're trying to move away from the internal one.

OK to leave as-is for this PR, though.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 12, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 12, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jotak, 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 openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 12, 2021
@openshift-merge-robot openshift-merge-robot merged commit fad7259 into openshift:master Jul 12, 2021
@spadgett spadgett added this to the v4.9 milestone Jul 14, 2021
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/core Related to console core functionality component/shared Related to console-shared kind/cypress Related to Cypress e2e integration testing kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. qe-approved Signifies that QE has signed off on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants