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

Enhance L7 NetworkPolicy to support TLS protocol #4932

Merged
merged 2 commits into from
Jul 21, 2023

Conversation

hongliangl
Copy link
Contributor

No description provided.

@hongliangl hongliangl requested review from tnqn and qiyueyao May 4, 2023 13:09
@hongliangl hongliangl force-pushed the 20230312-l7-tls branch 2 times, most recently from fab937c to ac943e8 Compare May 5, 2023 00:38
@hongliangl hongliangl added the action/release-note Indicates a PR that should be included in release notes. label May 5, 2023
@hongliangl hongliangl added this to the Antrea v1.13 release milestone May 5, 2023
@hongliangl hongliangl force-pushed the 20230312-l7-tls branch 2 times, most recently from 50ba5ea to 4366978 Compare May 6, 2023 02:37
@luolanzone
Copy link
Contributor

@hongliangl I didn't see any doc update in this PR, do you plan to create a separate PR to update L7 NP doc for tls protocol?

@hongliangl
Copy link
Contributor Author

@hongliangl I didn't see any doc update in this PR, do you plan to create a separate PR to update L7 NP doc for tls protocol?

Will add a doc later. I'm not sure if this PR could be merge in v1.12. If we plan to merge this PR, I can add a doc quickly.

@luolanzone luolanzone modified the milestone: Antrea v1.13 release Jul 6, 2023
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.

Please resolve conflicts and update docs for L7 TLS support.

if tls.SNI != "" {
keywords = append(keywords, fmt.Sprintf(`tls.sni; content:"%s"; nocase; pcre:"/%s$/;"`, tls.SNI, tls.SNI))
}
return strings.Join(keywords, " ")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need a slice keywords here? seems there will be only one string.

Copy link
Contributor Author

@hongliangl hongliangl Jul 19, 2023

Choose a reason for hiding this comment

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

We could add more key words in the future.

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 overall, can we have an e2e test to cover it? And please update antrea-l7-network-policy.md.

pkg/agent/controller/networkpolicy/l7engine/reconciler.go Outdated Show resolved Hide resolved
pkg/apis/crd/v1alpha1/types.go Outdated Show resolved Hide resolved
@hongliangl
Copy link
Contributor Author

LGTM overall, can we have an e2e test to cover it? And please update antrea-l7-network-policy.md.

Thanks for reviewing this PR, will address the comments and update antrea-l7-network-policy.md later

@@ -320,6 +321,14 @@ type HTTPProtocol struct {
Path string `json:"path,omitempty" protobuf:"bytes,3,opt,name=path"`
}

// TLSProtocol matches TLS requests with specific SNI. If the field is not provided, this
Copy link
Contributor

Choose a reason for hiding this comment

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

What does "TLS requests" refer to?

Copy link
Contributor

Choose a reason for hiding this comment

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

the specific SNI

Copy link
Contributor Author

@hongliangl hongliangl Jul 19, 2023

Choose a reason for hiding this comment

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

I follow the style of HTTP like the following in existing code:

// HTTPProtocol matches HTTP requests with specific host, method, and path. All
// fields could be used alone or together. If all fields are not provided, this
// matches all HTTP requests.
type HTTPProtocol struct {
	// Host represents the hostname present in the URI or the HTTP Host header to match.
	// It does not contain the port associated with the host.
	Host string
	// Method represents the HTTP method to match.
	// It could be GET, POST, PUT, HEAD, DELETE, TRACE, OPTIONS, CONNECT and PATCH.
	Method string
	// Path represents the URI path to match (Ex. "/index.html", "/admin").
	Path string
}

Is the comment "TLS requests" confused in some degree? If so, could you give some suggestions? Thanks a lot @jianjuns

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps say TLS handshake?

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 think TLS handshake is okay for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it "TLS handshake requests"?

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 searched for the words TLS handshake requests but found no usage of TLS handshake and requests together. How about just TLS handshake?

Copy link
Contributor

Choose a reason for hiding this comment

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

Then let us use "handshake packets". "handshake" is a process that includes rounds of message exchanges.

@hongliangl hongliangl force-pushed the 20230312-l7-tls branch 4 times, most recently from fc32b93 to 1fd3087 Compare July 19, 2023 08:49
@@ -7,7 +7,9 @@
- [Prerequisites](#prerequisites)
- [Usage](#usage)
- [HTTP](#http)
- [More examples](#more-examples)
- [More examples - HTTP](#more-examples-http)
Copy link
Member

Choose a reason for hiding this comment

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

This is inconsistent with the actual section name. TOC check should be failing.
And I feel redundant to append HTTP when its parent section is already HTTP. If you are trying to avoid section name conflict, the second anchor of the second section will have "-1", and toc generator tool will do it automatically.

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 didn't know that we could generate TOC by calling make toc. I have updated and checked.

docs/antrea-l7-network-policy.md Outdated Show resolved Hide resolved
apiVersion: crd.antrea.io/v1alpha1
kind: NetworkPolicy
metadata:
name: ingress-allow-tls-request-to-api-v2
Copy link
Member

Choose a reason for hiding this comment

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

The name doesn't reflect what the policy really does

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 to ingress-allow-tls-hanshake

docs/antrea-l7-network-policy.md Outdated Show resolved Hide resolved
docs/antrea-l7-network-policy.md Outdated Show resolved Hide resolved
apiVersion: crd.antrea.io/v1alpha1
kind: NetworkPolicy
metadata:
name: allow-http-only
Copy link
Member

Choose a reason for hiding this comment

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

wrong name

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 to allow-tls-only

apiVersion: crd.antrea.io/v1alpha1
kind: ClusterNetworkPolicy
metadata:
name: allow-web-tls-access-to-internal-domain
Copy link
Member

Choose a reason for hiding this comment

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

web should not be part of it. this rule doesn't indicate web at all.

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 to allow-tls-handshake-to-internal

@@ -356,7 +356,7 @@ spec:
template:
metadata:
annotations:
checksum/config: 7eb0f1e65f7eb3e35b0739d6064b92b7621af0f4e41813c35bfdee71ceaefbe2
checksum/config:
Copy link
Member

Choose a reason for hiding this comment

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

Is it correct to use empty?

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. I found that in MACOS, sha256sum used in multicluster/hack/update-checksum.sh is not available. I have regenerated the manifest files with alternative shasum -a 256.

Comment on lines 337 to 338
// SNI indicates the domain name in the TLS hello message, allowing the server to match it with the correct digital
// certificate for that domain.
Copy link
Member

Choose a reason for hiding this comment

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

"allowing the server to match it with the correct digital certificate for that domain."
I don't think we have this functionality? We just check if the actual SNI matches the one set in the policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed allowing the server to match it with the correct digital certificate for that domain.

Comment on lines +337 to +328
time.Sleep(networkPolicyDelay)

Copy link
Member

Choose a reason for hiding this comment

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

Check www.google.com is not reachable now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to apis.google.com.

@hongliangl hongliangl force-pushed the 20230312-l7-tls branch 6 times, most recently from 403767b to ace16ad Compare July 19, 2023 13:46
@@ -201,6 +203,92 @@ spec:
- http: {} # automatically dropped, and subsequent rules will not be considered.
```

### TLS

A typical layer 7 NetworkPolicy for TLS protocol is as below:
Copy link
Contributor

Choose a reason for hiding this comment

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

A typical -> An example

Copy link
Contributor

Choose a reason for hiding this comment

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

as -> like

Copy link
Contributor

Choose a reason for hiding this comment

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

the TLS protocol

matchLabels:
app: web
ingress:
- name: allow-tls # Allow inbound TLS/SSL handshakes to server name "foo.bar.com" from Pods with app=client label.
Copy link
Contributor

Choose a reason for hiding this comment

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

"handshake requests" or "handshake packets"

Copy link
Contributor

Choose a reason for hiding this comment

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

with label "app=client"

action: Drop
```

**sni**: The `sni` field matches the TLS/SSL Server Name Indication (SNI) field included in the TLS/SSL handshake process.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove "included"?

port: 53
- name: allow-tls-only # Allow outbound SSL/TLS handshakes towards "*.bar.com".
action: Allow # As the rule's "to" and "ports" are empty, which means it selects traffic to any network
l7Protocols: # peer's any port using any transport protocol, all outbound SSL/TLS handshakes towards other
Copy link
Contributor

Choose a reason for hiding this comment

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

using -> of

sni: "*.bar.com" # will not be considered.
```

The following NetworkPolicy blocks network traffic using an unauthorized application protocol regardless of port used.
Copy link
Contributor

Choose a reason for hiding this comment

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

port -> the port

matchLabels:
app: web
ingress:
- name: tls-only # Allow inbound SSL/TLS requests only.
Copy link
Contributor

Choose a reason for hiding this comment

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

handshake requests

@@ -330,6 +331,13 @@ type HTTPProtocol struct {
Path string
}

// TLSProtocol matches TLS handshakes with specific SNI. If the field is not provided, this
Copy link
Contributor

Choose a reason for hiding this comment

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

handshake requests or packets

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
@hongliangl hongliangl force-pushed the 20230312-l7-tls branch 2 times, most recently from 0f2aa1d to 1b4d153 Compare July 20, 2023 06:50
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, but defer to @jianjuns for final approval

jianjuns
jianjuns previously approved these changes Jul 20, 2023
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.

A nit.

@@ -75,7 +77,7 @@ welcome feature requests for protocols that you are interested in.

### HTTP

A typical layer 7 NetworkPolicy for HTTP protocol is as below:
An example of layer 7 NetworkPolicy for the HTTP protocol is like below:
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove "of"

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 for reviewing this PRs.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
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

@tnqn
Copy link
Member

tnqn commented Jul 21, 2023

/test-all

@tnqn tnqn merged commit 9c09f7c into antrea-io:main Jul 21, 2023
41 of 43 checks passed
@hongliangl hongliangl deleted the 20230312-l7-tls branch July 21, 2023 08:46
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants