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

Add ACNP copy span for multi-cluster #3363

Merged
merged 7 commits into from
Mar 22, 2022
Merged

Conversation

Dyanngg
Copy link
Contributor

@Dyanngg Dyanngg commented Feb 25, 2022

With this change, Antrea Multi-cluster admins can specify certain ClusterNetworkPolicies to be replicated
across the entire ClusterSet. This is especially useful for ClusterSet admins who want all clusters in the
ClusterSet to be applied with a consistent security posture (for example, all namespaces in all clusters can
only communicate with Pods in their own namespaces).

To achieve such ACNP copy-span, admins can, in the acting leader cluster of a Multi-cluster deployment,
create a ResourceExport of kind AntreaClusterNetworkPolicy which contains the ClusterNetworkPolicy spec
they wish to be replicated. The ResourceExport should be created in the Namespace which implements the
Common Area of the ClusterSet. In future releases, some additional tooling may become available to
automate the creation of such ResourceExport and make ACNP replication across clusters easier.

apiVersion: multicluster.crd.antrea.io/v1alpha1
kind: ResourceExport
metadata:
  name: strict-namespace-isolation-for-test-clusterset
  namespace: antrea-mcs-ns          # Namespace that implements Common Area of test-clusterset
spec:
  kind: AntreaClusterNetworkPolicy  
  name: strict-namespace-isolation  # In each importing cluster, an ACNP of name antrea-mc-strict-namespace-isolation will be created with the spec below
  clusternetworkpolicy:
    priority: 1
    tier: securityops
    appliedTo:
      - namespaceSelector: {}       # Selects all Namespaces in the member cluster
    ingress:
      - action: Pass
        from:
        - namespaces:
            match: Self            # Skip drop rule for traffic from Pods in the same Namespace
        - podSelector:
            matchLabels:
              k8s-app: kube-dns    # Skip drop rule for traffic from the core-dns components
      - action: Drop
        from:
        - namespaceSelector: {}    # Drop from Pods from all other Namespaces

The above sample spec will create an ACNP in each member cluster which implements strict namespace
isolation for that cluster.

@codecov-commenter
Copy link

codecov-commenter commented Feb 26, 2022

Codecov Report

Merging #3363 (2982920) into main (f7e980e) will decrease coverage by 10.57%.
The diff coverage is 64.24%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #3363       +/-   ##
===========================================
- Coverage   65.56%   54.99%   -10.58%     
===========================================
  Files         268      375      +107     
  Lines       26909    51719    +24810     
===========================================
+ Hits        17643    28443    +10800     
- Misses       7354    20793    +13439     
- Partials     1912     2483      +571     
Flag Coverage Δ
e2e-tests 53.48% <ø> (?)
integration-tests 35.83% <ø> (?)
kind-e2e-tests 55.55% <ø> (-0.22%) ⬇️
unit-tests 42.84% <64.24%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ticluster/commonarea/remote_common_area_manager.go 56.16% <ø> (ø)
...trollers/multicluster/resourceexport_controller.go 69.39% <61.36%> (-0.53%) ⬇️
...uster/controllers/multicluster/stale_controller.go 51.69% <62.06%> (+2.21%) ⬆️
...uster/commonarea/acnp_resourceimport_controller.go 65.26% <65.26%> (ø)
...lticluster/commonarea/resourceimport_controller.go 70.24% <66.66%> (+1.76%) ⬆️
...icluster/cmd/multicluster-controller/controller.go 6.15% <100.00%> (+1.46%) ⬆️
multicluster/controllers/multicluster/test_data.go 100.00% <100.00%> (ø)
pkg/agent/cniserver/pod_configuration_linux.go 26.31% <0.00%> (-40.36%) ⬇️
pkg/controller/ipam/antrea_ipam_controller.go 48.71% <0.00%> (-31.57%) ⬇️
pkg/controller/networkpolicy/endpoint_querier.go 61.46% <0.00%> (-29.97%) ⬇️
... and 344 more

@luolanzone
Copy link
Contributor

@Dyanngg the unit test and DCO check are failed, you may take a look at them first.

@luolanzone luolanzone added the area/multi-cluster Issues or PRs related to multi cluster. label Feb 28, 2022
@Dyanngg Dyanngg force-pushed the mcs-copy-span-policy branch from 7d637a9 to c132869 Compare February 28, 2022 07:00
@Dyanngg
Copy link
Contributor Author

Dyanngg commented Feb 28, 2022

@Dyanngg the unit test and DCO check are failed, you may take a look at them first.

Fixed

@Dyanngg Dyanngg force-pushed the mcs-copy-span-policy branch from c132869 to 3bbd2f5 Compare February 28, 2022 07:04
@Dyanngg Dyanngg force-pushed the mcs-copy-span-policy branch 2 times, most recently from 2c34d57 to 43fcb0c Compare February 28, 2022 22:23
@luolanzone
Copy link
Contributor

/test-multicluster-e2e

@luolanzone
Copy link
Contributor

@Dyanngg you probably need to rebase the codes,there is a github build error from build-ubi, I noticed there was a change revert for ubi related change.

@Dyanngg Dyanngg force-pushed the mcs-copy-span-policy branch 2 times, most recently from 1229564 to b7f8cb9 Compare March 8, 2022 05:28
@Dyanngg Dyanngg requested review from luolanzone and jianjuns March 8, 2022 05:31
@Dyanngg Dyanngg force-pushed the mcs-copy-span-policy branch from b7f8cb9 to 405369e Compare March 8, 2022 05:33
@Dyanngg Dyanngg requested a review from tnqn March 8, 2022 05:34
@Dyanngg Dyanngg force-pushed the mcs-copy-span-policy branch 2 times, most recently from fbc8122 to a3bf01a Compare March 8, 2022 06:03
@luolanzone
Copy link
Contributor

/test-multicluster-e2e

@Dyanngg Dyanngg force-pushed the mcs-copy-span-policy branch 2 times, most recently from 7c97846 to bc9b6c1 Compare March 9, 2022 00:01
@Dyanngg Dyanngg requested a review from luolanzone March 9, 2022 01:03
Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

LGTM overall, two minor comments.

multicluster/Makefile Outdated Show resolved Hide resolved
Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

LGTM

@Dyanngg
Copy link
Contributor Author

Dyanngg commented Mar 11, 2022

/test-all E2E test for this feature is passing according to #3435

@Dyanngg Dyanngg requested a review from luolanzone March 11, 2022 18:57
luolanzone
luolanzone previously approved these changes Mar 15, 2022
Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

LGTM overall, one nit

Comment on lines 181 to 193
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
// #nosec G404: random number generator not used for security purposes
randIdx := rand.Intn(len(lettersAndDigits))
b[i] = lettersAndDigits[randIdx]
}
return string(b)
}

func randName(prefix string) string {
return prefix + randSeq(nameSuffixLength)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed there are a few duplicate code in test framework, can we share them somewhere? maybe address it in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

@luolanzone
Copy link
Contributor

@jianjuns do you have any new comment? @tnqn Could you help to take a look at this PR? it's a core feature from MC in v1.6.0. a few other e2e PRs are based on this, thanks!

@jianjuns
Copy link
Contributor

No further comment from me.

docs/multicluster/getting-started.md Outdated Show resolved Hide resolved
@@ -63,6 +64,8 @@ type ResourceExportSpec struct {
Endpoints *EndpointsExport `json:"endpoints,omitempty"`
// If exported resource is ExternalEntity.
ExternalEntity *ExternalEntityExport `json:"externalentity,omitempty"`
// If exported resource is AntreaClusterNetworkPolicy.
ClusterNetworkPolicy *v1alpha1.ClusterNetworkPolicySpec `json:"clusternetworkpolicy,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Not starting from this PR, the json field name is not following the convention, which should be "clusterNetworkPolicy".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's address json field names in a separate PR then.

FirstTimestamp: metav1.Now(),
LastTimestamp: metav1.Now(),
ReportingController: acnpEventReportingController,
ReportingInstance: acnpEventReportingInstance,
Copy link
Member

Choose a reason for hiding this comment

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

this could be the podName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, see my TODO on L41

- list
- patch
- update
- watch
Copy link
Member

Choose a reason for hiding this comment

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

does leader need any cnp permission?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it does not. However this rbac manifest is generated and the only place I've added cnp permissions is in resourceimport_controller.go:
//+kubebuilder:rbac:groups=crd.antrea.io,resources=clusternetworkpolicies,verbs=get;list;watch;create;update;patch;delete
Not sure how to strip this permission from leader cluster specifically. @luolanzone any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

When we split them into member and leader manifests, we didn't separate these accesses setting in fine-grained way, I think we may need a follow up PR to fix these access right. I will create an issue for this first.
@tnqn do you think it's OK to fix this kind of issue in a new PR?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but please address it in release 1.6. We had such issues before and should ensure all components only get permissions they require.

Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

- list
- patch
- update
- watch
Copy link
Member

Choose a reason for hiding this comment

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

Yes, but please address it in release 1.6. We had such issues before and should ensure all components only get permissions they require.

@luolanzone
Copy link
Contributor

sure, @tnqn I have made the PR #3491, I think we need to merge this first, then I will rebase my PR and update the role added by ACNP copy-span. thanks.

@tnqn
Copy link
Member

tnqn commented Mar 22, 2022

/test-all
/test-multicluster-e2e

@tnqn
Copy link
Member

tnqn commented Mar 22, 2022

/skip-conformance

3 similar comments
@tnqn
Copy link
Member

tnqn commented Mar 22, 2022

/skip-conformance

@tnqn
Copy link
Member

tnqn commented Mar 22, 2022

/skip-conformance

@tnqn
Copy link
Member

tnqn commented Mar 22, 2022

/skip-conformance

@tnqn
Copy link
Member

tnqn commented Mar 22, 2022

/test-conformance

@tnqn
Copy link
Member

tnqn commented Mar 22, 2022

Conformance succeeded but failed on cleanup

@tnqn tnqn merged commit 37291dd into antrea-io:main Mar 22, 2022
@tnqn tnqn added the action/release-note Indicates a PR that should be included in release notes. label Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes. area/multi-cluster Issues or PRs related to multi cluster.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants