Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Add Azure-npm to provide native k8s network policy support #3205

Merged
merged 18 commits into from
Jun 28, 2018

Conversation

saiyan86
Copy link
Contributor

@saiyan86 saiyan86 commented Jun 6, 2018

What this PR does / why we need it:

This PR provides native k8s policy support.
Azure-npm is a Microsoft Azure's fault-tolerant and scalable implementation of Kubernetes Network Policy plugin.
Azure-npm supports all network policies specified by current version of Kubernetes, and will continue to support future versions.

Azure-npm only supports Kubernetes v1.8 or later, as it requires NetworkPolicy API v1beta1.

@acs-bot acs-bot added the size/L label Jun 6, 2018
@saiyan86
Copy link
Contributor Author

saiyan86 commented Jun 8, 2018

/assign @jackfrancis

@@ -50,6 +50,8 @@ const (
NetworkPolicyCalico = "calico"
// NetworkPolicyCilium is the string expression for cilium network policy config option
NetworkPolicyCilium = "cilium"
// NetworkPolicyAzure is the string expression for cilium network policy config option
Copy link
Contributor

Choose a reason for hiding this comment

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

copy paste typo in the comment, should say Azure CNI, not cilium

@@ -50,6 +50,8 @@ const (
NetworkPolicyCalico = "calico"
// NetworkPolicyCilium is the string expression for cilium network policy config option
NetworkPolicyCilium = "cilium"
// NetworkPolicyAzure is the string expression for cilium network policy config option
NetworkPolicyAzure = "azure"
// NetworkPluginAzure is the string expression for Azure CNI network policy
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be network plugin instead of network policy since you are adding one for network policy. Or maybe we could reuse the same constant for both? Your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jackfrancis separated NetworkPolicy & NetworkPlugin. So basically NetworkPlugin means CNI and NetworkPolicy means network policy plugin. These are two different things.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I meant the comment should reflect that, right it's // NetworkPluginAzure is the string expression for Azure CNI network policy which is confusing

@@ -384,7 +384,7 @@ func setOrchestratorDefaults(cs *api.ContainerService) {
switch o.KubernetesConfig.NetworkPolicy {
case NetworkPluginAzure:
o.KubernetesConfig.NetworkPlugin = NetworkPluginAzure
o.KubernetesConfig.NetworkPolicy = DefaultNetworkPolicy
o.KubernetesConfig.NetworkPolicy = NetworkPolicyAzure
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for changing the default here? This might break backwards compatibility so we'll have to do some extensive testing if this is something we want. cc: @jackfrancis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously we don't have network policy support in Azure CNI, now we just released it. Therefore we want to set default NetworkPolicy to azure.

api.KubernetesConfig.NetworkPlugin = vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy
api.KubernetesConfig.NetworkPolicy = "" // no-op but included for emphasis
} else if vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy == NetworkPolicyNone {
if vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy == NetworkPolicyNone {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For setting default NetworkPolicy to azure

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand how this is setting the default NetworkPolicy to azure? What I'm reading is "if NetworkPolicy is none. set NetworkPolicy to "" and NetworkPlugin to kubenet". What am I missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously it overwrites NetworkPolicy to "" if NetworkPolicy == NetworkPolicyAzure. It's not needed anymore.

Copy link
Member

Choose a reason for hiding this comment

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

These changes need to be removed from this PR. The entire reason for this code (as described in the comments) is to maintain backwards-compatibility with prior usage patterns. This code is not meant to accommodate ongoing usage pattern changes/additions.

@@ -430,10 +430,6 @@ func TestNetworkPolicyDefaults(t *testing.T) {
t.Fatalf("NetworkPlugin did not have the expected value, got %s, expected %s",
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin, "azure")
}
if properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy != "" {

This comment was marked as resolved.

@CecileRobertMichon
Copy link
Contributor

Azure-npm only supports Kubernetes v1.8 or later, as it requires NetworkPolicy API v1beta1. does this mean we should add some validation on the k8s version? Right now it looks like it is being enabled by default, even if I specify k8s 1.7.x

@saiyan86
Copy link
Contributor Author

@CecileRobertMichon You're right. We could overwrite the NetworkPolicy to DefaultNetworkPolicy for k8s < 1.8.

@saiyan86 saiyan86 force-pushed the networkPolicyManager branch from fd63aa4 to 60ebf34 Compare June 12, 2018 21:15
api.KubernetesConfig.NetworkPlugin = NetworkPluginKubenet
api.KubernetesConfig.NetworkPolicy = "" // no-op but included for emphasis
} else if vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy == NetworkPolicyAzure {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should happen in defaults.go since it is modifying the default behavior

@codecov
Copy link

codecov bot commented Jun 12, 2018

Codecov Report

Merging #3205 into master will increase coverage by 0.04%.
The diff coverage is 84%.

@@            Coverage Diff             @@
##           master    #3205      +/-   ##
==========================================
+ Coverage   54.55%   54.59%   +0.04%     
==========================================
  Files         104      104              
  Lines       15739    15759      +20     
==========================================
+ Hits         8586     8604      +18     
- Misses       6404     6405       +1     
- Partials      749      750       +1

@CecileRobertMichon
Copy link
Contributor

How does this PR relate to #3198 ?

@saiyan86
Copy link
Contributor Author

@CecileRobertMichon PR #3198 is Azure Container Network Monitering Service, which is used for container networking telemetry purposes. This PR adds native k8s network policy support.

@saiyan86 saiyan86 changed the title Add Azure-npm to provide k8s network policy support Add Azure-npm to provide native k8s network policy support Jun 12, 2018
@@ -394,6 +394,12 @@ func setOrchestratorDefaults(cs *api.ContainerService) {
o.KubernetesConfig.NetworkPlugin = NetworkPolicyCilium
}

if o.KubernetesConfig.NetworkPolicy == NetworkPolicyAzure {
if !common.IsKubernetesVersionGe(k8sVersion, "1.8.0") {
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this < 1.8.0 logic up into the above switch/case statement, as it is executing against an identical condition (NetworkPolicy == "azure")

@CecileRobertMichon
Copy link
Contributor

CecileRobertMichon commented Jun 25, 2018

What is the expected default behavior for network policy after this PR if a user does not pass in any netork plugin/policy value? ie. with the default kubernetes example apimodel

We need to update the relevant docs (especially since the default behavior isn't straightforward by looking at the code because of all the back compat cruft), specifically https://github.com/Azure/acs-engine/blob/master/examples/networkpolicy/README.md and clusterdefinition.md

@jackfrancis
Copy link
Member

This change should have no impact on the current expected default configuration outcome. From a high level, this PR:

  • introduces a new allowd networkPlugin/networkPolicy combination of "azure"/"azure"
  • The above, new, configuration installs the Azure NetworkPolicy daemonset via the addons vector onto their cluster

That should be it. I believe our unit tests should ensure no regressions in our default configuration cases.

Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

/lgtm

@jackfrancis jackfrancis force-pushed the networkPolicyManager branch from 8ed0bcc to 959b5ba Compare June 25, 2018 22:36
@acs-bot acs-bot removed the lgtm label Jun 25, 2018
@jackfrancis
Copy link
Member

/lgtm

@acs-bot acs-bot added the lgtm label Jun 28, 2018
@acs-bot
Copy link

acs-bot commented Jun 28, 2018

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CecileRobertMichon, jackfrancis, saiyan86

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:
  • OWNERS [CecileRobertMichon,jackfrancis]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jackfrancis jackfrancis merged commit 8f401a1 into Azure:master Jun 28, 2018
@ghost ghost removed the awaiting review label Jun 28, 2018
@marrobi
Copy link
Contributor

marrobi commented Jul 4, 2018

@saiyan86 Great to see this progressing. Where do we report issues with azure-npm? Is there a repo available? Certain policies do not seem to function correctly, for example try https://github.com/ahmetb/kubernetes-network-policy-recipes/blob/master/04-deny-traffic-from-other-namespaces.md . This does not seem to work with azure-npm, but does with kube-router. Policies using pod selectors do seem to work.

@jackfrancis @CecileRobertMichon are you aware of a project that tests various network policies?

Thanks.

@sharmasushant
Copy link
Contributor

@marrobi Thank you for trying it out. Please file the issue @ https://github.com/Azure/azure-container-networking/issues

@marrobi
Copy link
Contributor

marrobi commented Jul 5, 2018

@jackfrancis
Copy link
Member

@marrobi I'm not! We have a very basic NetworkPolicy validation in our E2E tests, would love to introduce something more thorough if you discover a comprehensive lib/project.

@saiyan86
Copy link
Contributor Author

saiyan86 commented Jul 5, 2018

@jackfrancis I will add some tests soon that should work for both Calico and us.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants