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

[Flow Exporter] Fix deny connections tracking for ANP baseline tier #2542

Merged
merged 1 commit into from
Aug 27, 2021

Conversation

zyiou
Copy link
Contributor

@zyiou zyiou commented Aug 5, 2021

If we apply a baseline ANP, in deny connections tracking of Flow
Exporter, it will be filled as K8s NetworkPolicy instead of ANP
since we are ignoring ANP associate tables IngressDefaultTable
and EgressDefaultTable for these connections.
This PR fixes it by changing the logic for assigning policy type.

Signed-off-by: zyiou zyiou@vmware.com

@zyiou zyiou force-pushed the zyiou/fix_deny_connections branch from 4e3808f to 3ab3c06 Compare August 5, 2021 17:42
@codecov-commenter
Copy link

codecov-commenter commented Aug 5, 2021

Codecov Report

Merging #2542 (2d50641) into main (9ea4e86) will decrease coverage by 5.59%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2542      +/-   ##
==========================================
- Coverage   58.82%   53.23%   -5.60%     
==========================================
  Files         281      281              
  Lines       22271    22268       -3     
==========================================
- Hits        13101    11854    -1247     
- Misses       7796     9132    +1336     
+ Partials     1374     1282      -92     
Flag Coverage Δ
kind-e2e-tests 35.13% <0.00%> (-10.17%) ⬇️
unit-tests 42.23% <0.00%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
pkg/agent/controller/networkpolicy/packetin.go 4.43% <0.00%> (-68.39%) ⬇️
pkg/apis/controlplane/v1beta2/helper.go 25.00% <0.00%> (-75.00%) ⬇️
...formers/externalversions/security/v1alpha1/tier.go 0.00% <0.00%> (-64.29%) ⬇️
...ers/externalversions/core/v1alpha2/clustergroup.go 0.00% <0.00%> (-64.29%) ⬇️
...s/externalversions/core/v1alpha2/externalentity.go 0.00% <0.00%> (-64.29%) ⬇️
...xternalversions/security/v1alpha1/networkpolicy.go 0.00% <0.00%> (-64.29%) ⬇️
...versions/security/v1alpha1/clusternetworkpolicy.go 0.00% <0.00%> (-64.29%) ⬇️
pkg/controller/networkpolicy/mutate.go 0.00% <0.00%> (-62.07%) ⬇️
.../agent/apiserver/handlers/networkpolicy/handler.go 0.00% <0.00%> (-58.34%) ⬇️
... and 74 more

@zyiou zyiou force-pushed the zyiou/fix_deny_connections branch 3 times, most recently from dfa16d4 to 499d9c0 Compare August 5, 2021 20:24
@zyiou zyiou marked this pull request as ready for review August 10, 2021 23:22
pkg/agent/controller/networkpolicy/packetin.go Outdated Show resolved Hide resolved
denyConn.EgressNetworkPolicyRuleAction = flowexporter.RuleActionToUint8(disposition)
}
} else { // Get name and namespace for Antrea Network Policy or Antrea Cluster Network Policy
if tableID == openflow.AntreaPolicyIngressRuleTable {
Copy link
Contributor

@Dyanngg Dyanngg Aug 11, 2021

Choose a reason for hiding this comment

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

Why are cases 1,3 / 2,4 not grouped? i.e.
if tableID == openflow.AntreaPolicyIngressRuleTable || tableID == tableID == openflow.IngressDefaultTable
unless I'm missing something obvious....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, these can be combined. Thanks!

denyConn.EgressNetworkPolicyType = flowexporter.PolicyTypeToUint8(policy.Type)
denyConn.EgressNetworkPolicyRuleName = rule.Name
denyConn.EgressNetworkPolicyRuleAction = flowexporter.RuleActionToUint8(disposition)
} else if tableID == openflow.IngressDefaultTable {
Copy link
Contributor

@Dyanngg Dyanngg Aug 11, 2021

Choose a reason for hiding this comment

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

Also if we don't want to refer to ad-hoc table names here, there are actually exported functions GetAntreaPolicyEgressTables() and GetAntreaPolicyIngressTables() in pipeline.go that gives the list of tables ACNP/ANP uses for ingress/egress. Although in this particular case it seems an overkill, since we would need to check tableID for list membership to determine the direction of conn. However, it is more future-proof, in the sense that in case ACNP/ANP uses additional tables in the future, this approach saves additional changes in this file and potential bugs.

} else if tableID == openflow.EgressDefaultTable {
denyConn.EgressNetworkPolicyType = registry.PolicyTypeK8sNetworkPolicy
denyConn.EgressNetworkPolicyRuleAction = flowexporter.RuleActionToUint8(disposition)
} else { // Get name and namespace for Antrea Network Policy or Antrea Cluster Network Policy
Copy link
Member

Choose a reason for hiding this comment

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

Bug seems to be we are ignoring the ANP associated tables.

If so, please revise this description. Connection is not inside the specified table, but they are just associated with those tables.

it will be filled as K8s NetworkPolicy instead of ANP
since the connection will be in IngressDefaultTable/EgressDefaultTable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thanks!

@zyiou zyiou self-assigned this Aug 11, 2021
@zyiou zyiou added area/flow-visibility Issues or PRs related to flow visibility support in Antrea area/flow-visibility/exporter Issues or PRs related to the Flow Exporter functions in the Agent labels Aug 11, 2021
@zyiou zyiou force-pushed the zyiou/fix_deny_connections branch 2 times, most recently from daf7ecf to f349100 Compare August 12, 2021 00:26
antoninbas
antoninbas previously approved these changes Aug 12, 2021
Comment on lines 400 to 410
for _, table := range openflow.GetAntreaPolicyIngressTables() {
if table == tableID {
denyConn.IngressNetworkPolicyName = policy.Name
denyConn.IngressNetworkPolicyNamespace = policy.Namespace
denyConn.IngressNetworkPolicyType = flowexporter.PolicyTypeToUint8(policy.Type)
denyConn.IngressNetworkPolicyRuleName = rule.Name
denyConn.IngressNetworkPolicyRuleAction = flowexporter.RuleActionToUint8(disposition)
} else if tableID == openflow.AntreaPolicyEgressRuleTable {
}
}
for _, table := range openflow.GetAntreaPolicyEgressTables() {
if table == tableID {
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 it would be nice to define some local helper closure functions isAntreaPolicyIngressTables and isAntreaPolicyEgressTables

srikartati
srikartati previously approved these changes Aug 12, 2021
Copy link
Member

@srikartati srikartati left a comment

Choose a reason for hiding this comment

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

LGTM

@srikartati
Copy link
Member

/test-all

@zyiou zyiou force-pushed the zyiou/fix_deny_connections branch 2 times, most recently from fae2d14 to 2c64a21 Compare August 18, 2021 05:17
@zyiou
Copy link
Contributor Author

zyiou commented Aug 18, 2021

/test-all

dreamtalen
dreamtalen previously approved these changes Aug 18, 2021
Copy link
Contributor

@dreamtalen dreamtalen left a comment

Choose a reason for hiding this comment

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

LGTM

@zyiou
Copy link
Contributor Author

zyiou commented Aug 19, 2021

/test-e2e

@zyiou
Copy link
Contributor Author

zyiou commented Aug 25, 2021

/test-e2e
/test-ipv6-e2e
/test-ipv6-only-e2e

srikartati
srikartati previously approved these changes Aug 26, 2021
Copy link
Member

@srikartati srikartati left a comment

Choose a reason for hiding this comment

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

LGTM

@srikartati srikartati added this to the Antrea v1.3 release milestone Aug 26, 2021
@srikartati
Copy link
Member

/test-ipv6-e2e /test-ipv6-only-e2e

antoninbas
antoninbas previously approved these changes Aug 26, 2021
Comment on lines 354 to 355
}
if isAntreaPolicyEgressTable(tableID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: else if to avoid the duplicate check for ingress policy tables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks!

If we apply a baseline ANP, in deny connections tracking of Flow
Exporter, it will be filled as K8s NetworkPolicy instead of ANP
since we are ignoring ANP associate tables IngressDefaultTable
and EgressDefaultTable for these connections.
This PR fixes it by changing the logic for assigning policy type.

Signed-off-by: zyiou <zyiou@vmware.com>
@zyiou zyiou dismissed stale reviews from antoninbas, srikartati, and dreamtalen via cdc4a3d August 26, 2021 20:42
@zyiou zyiou force-pushed the zyiou/fix_deny_connections branch from 2c64a21 to cdc4a3d Compare August 26, 2021 20:42
@zyiou
Copy link
Contributor Author

zyiou commented Aug 26, 2021

/test-all
/test-ipv6-e2e
/test-ipv6-only-e2e

@antoninbas antoninbas merged commit 55ec2ad into antrea-io:main Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flow-visibility/exporter Issues or PRs related to the Flow Exporter functions in the Agent area/flow-visibility Issues or PRs related to flow visibility support in Antrea
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants