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

Clusterwide K8s Cilium Network Policies #9381

Merged
merged 6 commits into from
Nov 11, 2019

Conversation

fristonio
Copy link
Member

@fristonio fristonio commented Oct 9, 2019

Fixes #9200

  • CRD for CiliumClusterwideNetworkPolicy
  • Controller for watching events related to CiliumClusterwideNetworkPolicy
  • RBAC registration for newly created CRD
  • Tests for the new policy CRD.
  • Add documentation for CiliumClusterwideNetworkPolicy resource.

This change is Reviewable

// CiliumGlobalNetworkPolicy is a Kubernetes third-party resource with an extended version
// of CiliumNetworkPolicy which is cluster scoped rather than namespace scoped.
type CiliumGlobalNetworkPolicy struct {
// +k8s:openapi-gen=false
Copy link
Member

Choose a reason for hiding this comment

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

If you do this we get all of the methods already implemented for CNP for free.

type CiliumGlobalNetworkPolicy struct {
    CiliumNetworkPolicy
}

pkg/k8s/apis/cilium.io/v2/types.go Show resolved Hide resolved
pkg/k8s/apis/cilium.io/v2/types.go Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Oct 9, 2019

Coverage Status

Coverage decreased (-0.2%) to 45.418% when pulling 1f7036f on fristonio:pr/fristonio/global-policies into 28002d5 on cilium:master.

@fristonio fristonio force-pushed the pr/fristonio/global-policies branch 2 times, most recently from 8dc8a24 to 800d637 Compare October 9, 2019 17:10
@aanm aanm changed the title Global k8s policies for Cilium Clusterwide K8s Cilium Network Policies Oct 10, 2019
@fristonio fristonio force-pushed the pr/fristonio/global-policies branch 3 times, most recently from 8b979c5 to 79f2142 Compare October 16, 2019 00:56
@fristonio fristonio force-pushed the pr/fristonio/global-policies branch 2 times, most recently from 559fb57 to 2f59927 Compare October 21, 2019 18:38
k8sAPIGroupCRD = "CustomResourceDefinition"
k8sAPIGroupNodeV1Core = "core/v1::Node"
k8sAPIGroupNamespaceV1Core = "core/v1::Namespace"
K8sAPIGroupServiceV1Core = "core/v1::Service"

Choose a reason for hiding this comment

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

exported const K8sAPIGroupServiceV1Core should have comment (or a comment on this block) or be unexported

@nebril nebril marked this pull request as ready for review October 22, 2019 10:13
@nebril nebril requested a review from a team as a code owner October 22, 2019 10:13
@nebril nebril requested a review from a team October 22, 2019 10:13
@nebril
Copy link
Member

nebril commented Oct 22, 2019

Hi @fristonio , sorry for moving the pr from draft, I had to check something in regards to CI failure.

Copy link
Member

@aanm aanm left a comment

Choose a reason for hiding this comment

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

All good so far only small nits. Next step CI! 💯

// rules. This is similar to the parse function used in CiliumNetworkPolicy with
// the only difference that since the CRD is cluster scoped we don't send any namespace
// here.
func (r *CiliumClusterwideNetworkPolicy) Parse() (api.Rules, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Was this removed in follow up commits?

Copy link
Member

Choose a reason for hiding this comment

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

yes

}

// GetControllerName returns the unique name for the controller manager.
func (r *CiliumClusterwideNetworkPolicy) GetControllerName() string {
Copy link
Member

Choose a reason for hiding this comment

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

Was this removed in follow up commits?

Copy link
Member

Choose a reason for hiding this comment

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

yes

}

// GetIdentityLabels returns all rule labels in the CiliumNetworkPolicy.
func (r *CiliumClusterwideNetworkPolicy) GetIdentityLabels() labels.LabelArray {
Copy link
Member

Choose a reason for hiding this comment

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

Was this removed in follow up commits?

Copy link
Member

Choose a reason for hiding this comment

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

tes

@@ -276,58 +276,6 @@ type CiliumClusterwideNetworkPolicy struct {
CiliumNetworkPolicy
}

// Parse parses a CiliumClusterwideNetworkPolicy and returns a list of cilium policy
Copy link
Member

Choose a reason for hiding this comment

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

you can squash this change with the previous commit

pkg/k8s/factory_functions.go Show resolved Hide resolved
@@ -386,24 +387,39 @@ func ConvertToCNPWithStatus(obj interface{}) interface{} {
return &types.SlimCNP{
Copy link
Member

Choose a reason for hiding this comment

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

Please create a new function dedicated for the conversion of CiliumClusterwideNetworkPolicy to types.SlimpCNP

@fristonio fristonio force-pushed the pr/fristonio/global-policies branch 2 times, most recently from 002ddd5 to d39c134 Compare October 22, 2019 18:29
@fristonio fristonio requested a review from a team as a code owner October 26, 2019 20:09
@aanm
Copy link
Member

aanm commented Oct 28, 2019

test-me-please

@fristonio fristonio force-pushed the pr/fristonio/global-policies branch from a0df602 to dd5297d Compare October 29, 2019 02:18
@aanm
Copy link
Member

aanm commented Oct 29, 2019

test-me-please

@fristonio fristonio force-pushed the pr/fristonio/global-policies branch from dd5297d to 1ac45e2 Compare October 29, 2019 13:01
@aanm
Copy link
Member

aanm commented Oct 29, 2019

test-me-please

@fristonio fristonio force-pushed the pr/fristonio/global-policies branch from 1ac45e2 to 9b16060 Compare October 29, 2019 20:25
@fristonio
Copy link
Member Author

test-me-please

1 similar comment
@fristonio
Copy link
Member Author

test-me-please

@fristonio fristonio force-pushed the pr/fristonio/global-policies branch 2 times, most recently from d8082f8 to a96bdf9 Compare October 30, 2019 16:02
@fristonio
Copy link
Member Author

test-me-please

@aanm aanm added the sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers. label Nov 4, 2019
@aanm
Copy link
Member

aanm commented Nov 4, 2019

test-me-please

@aanm aanm removed the sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers. label Nov 4, 2019
@aanm
Copy link
Member

aanm commented Nov 4, 2019

test-upstream-k8s

@aanm
Copy link
Member

aanm commented Nov 4, 2019

test-missed-k8s

previous test https://jenkins.cilium.io/job/Cilium-PR-Ginkgo-Tests-K8s/2603/

@aanm
Copy link
Member

aanm commented Nov 4, 2019

test-missed-k8s

@fristonio
Copy link
Member Author

test-upstream-k8s

@ianvernon
Copy link
Member

Upstream k8s tests got stuck:

23:09:25  Running pods 0
23:09:26  Running pods 0
23:09:27  Running pods 0
23:09:28  Running pods 0
23:09:29  Running pods 0
23:09:30  Sending interrupt signal to process
23:09:31  Running pods 0
23:09:31  Connection to 127.0.0.1 closed by remote host.
23:09:31  script returned exit code 255

I hit this in a recent PR as well; re-running.

@ianvernon
Copy link
Member

test-upstream-k8s

Copy link
Member

@ianvernon ianvernon left a comment

Choose a reason for hiding this comment

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

Overall, looks great! I have a few nits mainly surrounding documentation grammar. Thanks for this contribution!!

@@ -24,6 +24,11 @@ with Kubernetes:
`CustomResourceDefinition` which supports specification of policies
at Layers 3-7 for both ingress and egress.

- The `CiliumClusterwideNetworkPolicy` format which is cluster scoped
Copy link
Member

Choose a reason for hiding this comment

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

a cluster-scoped

@@ -24,6 +24,11 @@ with Kubernetes:
`CustomResourceDefinition` which supports specification of policies
at Layers 3-7 for both ingress and egress.

- The `CiliumClusterwideNetworkPolicy` format which is cluster scoped
`CustomResourceDefinition` for specifying cluster wide policies to be enforced
Copy link
Member

Choose a reason for hiding this comment

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

cluster-wide


`CiliumClusterwideNetworkPolicy` is same as that of `CiliumNetworkPolicy` with the only
difference in the scope of the policy. Policies defined by `CiliumClusterwideNetworkPolicy`
are non namespaced and are cluster scoped. Internally the policy is composed of
Copy link
Member

Choose a reason for hiding this comment

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

non-namespaces and are cluster-scoped.

--------------------

`CiliumNetworkPolicy` only allows to bind a policy restricted to a particular namespace. There can be situations
where one wants to have a cluster scoped effect of the policy, this can be done using cilium's
Copy link
Member

Choose a reason for hiding this comment

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

cluster-scoped

--------------------

`CiliumNetworkPolicy` only allows to bind a policy restricted to a particular namespace. There can be situations
where one wants to have a cluster scoped effect of the policy, this can be done using cilium's
Copy link
Member

Choose a reason for hiding this comment

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

..., which can be done using Cilium's...


`CiliumNetworkPolicy` only allows to bind a policy restricted to a particular namespace. There can be situations
where one wants to have a cluster scoped effect of the policy, this can be done using cilium's
`CiliumClusterwideNetworkPolicy` kubernetes custom resource. The specification of the policy is same as that
Copy link
Member

Choose a reason for hiding this comment

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

kubernetes --> Kubernetes

`CiliumNetworkPolicy` only allows to bind a policy restricted to a particular namespace. There can be situations
where one wants to have a cluster scoped effect of the policy, this can be done using cilium's
`CiliumClusterwideNetworkPolicy` kubernetes custom resource. The specification of the policy is same as that
of `CiliumNetworkPolicy` with the only difference that it is not namespaced.
Copy link
Member

Choose a reason for hiding this comment

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

with the only difference that it is not namespace --> except that it is not namespaced.

CustomResourceDefinitionPluralName = "ciliumclusterwidenetworkpolicies"

// CustomResourceDefinitionShortNames are the abbreviated names to refer to this CRD's instances
CustomResourceDefinitionShortNames = []string{"ccnp", "ciliumcnp"}
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 think ciliumcnp is necessary here - CNP is almost always used to abbeviate CiliumNetworkPolicy, while here it refers to ClusterwideNetworkPolicy. I'd prefer we keep only ccnp.

@fristonio fristonio force-pushed the pr/fristonio/global-policies branch 2 times, most recently from 581835d to 3ac09b4 Compare November 9, 2019 19:14
@fristonio
Copy link
Member Author

test-me-please

1 similar comment
@fristonio
Copy link
Member Author

test-me-please

@fristonio fristonio requested review from ianvernon and tgraf November 10, 2019 16:17
Copy link
Member

@tgraf tgraf left a comment

Choose a reason for hiding this comment

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

Fantastic work. The only change request I have is regarding the name. I think shorter is better but I'm also fine with the current proposal.


// ResourceTypeCiliumClusterwideNetworkPolicy is the resource type used for the
// PolicyLabelDerivedFrom label
ResourceTypeCiliumClusterwideNetworkPolicy = "CiliumClusterwideNetworkPolicy"
Copy link
Member

Choose a reason for hiding this comment

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

I would call this CiliumClusterNetworkPolicy. It's shorter and also clear.

Copy link
Member

@tgraf tgraf Nov 11, 2019

Choose a reason for hiding this comment

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

Discussed offline. The naming was discussed in SIG-policy and the conclusion was CiliumClusterwideNetworkPolicy. I'm OK with this.

@tgraf tgraf added the dont-merge/needs-rebase This PR needs to be rebased because it has merge conflicts. label Nov 11, 2019
* Add CiliumGlobalNetowrkPolicy type to Cilium k8s api client.
* Update k8s utilities to incorporate changes corresponding to cilium
global policies.

Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
* Update k8s_watcher.go to include controller to watch for
CiliumClusterwideNetworkPolicy CRD.
* Update ExtractNamespace function in k8s utils to account for the fact
that any object with empty namespace is a cluster scoped object and we
should not automatically add default namespace to such objects.

Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
* Added k8s manifests for ccnp polices to test common policies
* Updated tests to include ccnp policy test manifests

Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
@fristonio fristonio force-pushed the pr/fristonio/global-policies branch from 3ac09b4 to 1f7036f Compare November 11, 2019 13:15
@aanm
Copy link
Member

aanm commented Nov 11, 2019

test-me-please

@aanm aanm removed the dont-merge/needs-rebase This PR needs to be rebased because it has merge conflicts. label Nov 11, 2019
@aanm aanm merged commit f62e455 into cilium:master Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/major This PR introduces major new functionality to Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support policies across all namespaces
7 participants