-
Notifications
You must be signed in to change notification settings - Fork 370
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
Conversation
fab937c
to
ac943e8
Compare
50ba5ea
to
4366978
Compare
@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. |
There was a problem hiding this 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, " ") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the specific SNI
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps say TLS handshake?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
fc32b93
to
1fd3087
Compare
docs/antrea-l7-network-policy.md
Outdated
@@ -7,7 +7,9 @@ | |||
- [Prerequisites](#prerequisites) | |||
- [Usage](#usage) | |||
- [HTTP](#http) | |||
- [More examples](#more-examples) | |||
- [More examples - HTTP](#more-examples-http) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
apiVersion: crd.antrea.io/v1alpha1 | ||
kind: NetworkPolicy | ||
metadata: | ||
name: ingress-allow-tls-request-to-api-v2 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
apiVersion: crd.antrea.io/v1alpha1 | ||
kind: NetworkPolicy | ||
metadata: | ||
name: allow-http-only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong name
There was a problem hiding this comment.
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
docs/antrea-l7-network-policy.md
Outdated
apiVersion: crd.antrea.io/v1alpha1 | ||
kind: ClusterNetworkPolicy | ||
metadata: | ||
name: allow-web-tls-access-to-internal-domain |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
pkg/apis/controlplane/types.go
Outdated
// SNI indicates the domain name in the TLS hello message, allowing the server to match it with the correct digital | ||
// certificate for that domain. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
time.Sleep(networkPolicyDelay) | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
403767b
to
ace16ad
Compare
docs/antrea-l7-network-policy.md
Outdated
@@ -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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A typical -> An example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as -> like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the TLS protocol
docs/antrea-l7-network-policy.md
Outdated
matchLabels: | ||
app: web | ||
ingress: | ||
- name: allow-tls # Allow inbound TLS/SSL handshakes to server name "foo.bar.com" from Pods with app=client label. |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with label "app=client"
docs/antrea-l7-network-policy.md
Outdated
action: Drop | ||
``` | ||
|
||
**sni**: The `sni` field matches the TLS/SSL Server Name Indication (SNI) field included in the TLS/SSL handshake process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "included"?
docs/antrea-l7-network-policy.md
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using -> of
docs/antrea-l7-network-policy.md
Outdated
sni: "*.bar.com" # will not be considered. | ||
``` | ||
|
||
The following NetworkPolicy blocks network traffic using an unauthorized application protocol regardless of port used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
port -> the port
docs/antrea-l7-network-policy.md
Outdated
matchLabels: | ||
app: web | ||
ingress: | ||
- name: tls-only # Allow inbound SSL/TLS requests only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handshake requests
pkg/apis/controlplane/types.go
Outdated
@@ -330,6 +331,13 @@ type HTTPProtocol struct { | |||
Path string | |||
} | |||
|
|||
// TLSProtocol matches TLS handshakes with specific SNI. If the field is not provided, this |
There was a problem hiding this comment.
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 <[email protected]>
0f2aa1d
to
1b4d153
Compare
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nit.
docs/antrea-l7-network-policy.md
Outdated
@@ -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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "of"
There was a problem hiding this comment.
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 <[email protected]>
1b4d153
to
2063059
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/test-all |
No description provided.