Skip to content

Commit 04cedce

Browse files
authored
Merge pull request #2 from aws/main
Adding Cluster Network Policy change (#496)
2 parents dbd95be + dec0cf3 commit 04cedce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5639
-707
lines changed

.go-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.24
1+
1.25

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Image URL to use all building/pushing image targets
33
IMAGE ?= amazon/aws-network-policy-agent
44
VERSION ?= $(shell git describe --tags --always --dirty || echo "unknown")
5-
IMAGE_NAME = $(IMAGE)$(IMAGE_ARCH_SUFFIX):$(VERSION)
5+
IMAGE_NAME ?= $(IMAGE)$(IMAGE_ARCH_SUFFIX):$(VERSION)
66
GOLANG_VERSION ?= $(shell cat .go-version)
77
GOLANG_IMAGE ?= public.ecr.aws/eks-distro-build-tooling/golang:$(GOLANG_VERSION)-gcc-al2
88
# TEST_IMAGE is the testing environment container image.
@@ -84,7 +84,7 @@ vet: setup-ebpf-sdk-override # Run go vet against code.
8484

8585
.PHONY: test
8686
test: manifests generate fmt vet envtest ## Run tests.
87-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./cmd/... ./controllers/... ./pkg/... -coverprofile cover.out -v -coverprofile=coverage.txt
87+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./controllers ./pkg/ebpf ./pkg/fwruleprocessor ./pkg/rpc ./pkg/types ./pkg/utils -v -coverprofile=coverage.txt -covermode=atomic
8888

8989
##@ Build
9090

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// Tier defines the tier of the admin policy
24+
// +kubebuilder:validation:Enum={"Admin", "Baseline"}
25+
type Tier string
26+
27+
const (
28+
// AdminTier
29+
AdminTier Tier = "Admin"
30+
// BaselineTier
31+
BaselineTier Tier = "Baseline"
32+
)
33+
34+
// ClusterPolicyAction defines the action to be applied by the admin policy
35+
// +kubebuilder:validation:Enum={"Accept", "Deny", "Pass"}
36+
37+
type ClusterNetworkPolicyRuleAction string
38+
39+
const (
40+
ClusterNetworkPolicyRuleActionAccept ClusterNetworkPolicyRuleAction = "Accept"
41+
ClusterNetworkPolicyRuleActionDeny ClusterNetworkPolicyRuleAction = "Deny"
42+
ClusterNetworkPolicyRuleActionPass ClusterNetworkPolicyRuleAction = "Pass"
43+
)
44+
45+
// ClusterPolicyReference is the reference to the admin network policy resource
46+
type ClusterPolicyReference struct {
47+
// Name is the name of the ClusterNetworkPolicy
48+
Name string `json:"name"`
49+
}
50+
51+
// EndpointInfo defines the network endpoint information for the policy ingress/egress
52+
type ClusterEndpointInfo struct {
53+
54+
// CIDR is the network address(s) of the endpoint
55+
CIDR NetworkAddress `json:"cidr,omitempty"`
56+
57+
// Ports is the list of ports
58+
Ports []Port `json:"ports,omitempty"`
59+
60+
// DomainName is the FQDN for the endpoint (egress-only)
61+
DomainName DomainName `json:"domainName,omitempty"`
62+
63+
// Action from the CNP rule
64+
Action ClusterNetworkPolicyRuleAction `json:"action"`
65+
}
66+
67+
// ClusterPolicyEndpointSpec defines the desired state of ClusterPolicyEndpoint
68+
type ClusterPolicyEndpointSpec struct {
69+
70+
// PolicyRef is a reference to the Kubernetes AdminNetworkPolicy resource.
71+
PolicyRef ClusterPolicyReference `json:"policyRef"`
72+
73+
// Tier defines the type of admin policy
74+
Tier Tier `json:"tier"`
75+
76+
// Priority is the priority of the admin policy endpoint
77+
Priority int32 `json:"priority"`
78+
79+
// PodSelectorEndpoints contains information about the pods
80+
// matching the podSelector
81+
PodSelectorEndpoints []PodEndpoint `json:"podSelectorEndpoints,omitempty"`
82+
83+
// Ingress is the list of ingress rules containing resolved network addresses
84+
Ingress []ClusterEndpointInfo `json:"ingress,omitempty"`
85+
86+
// Egress is the list of egress rules containing resolved network addresses
87+
Egress []ClusterEndpointInfo `json:"egress,omitempty"`
88+
}
89+
90+
// ClusterPolicyEndpointStatus defines the observed state of ClusterPolicyEndpoint
91+
type ClusterPolicyEndpointStatus struct {
92+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
93+
// Important: Run "make" to regenerate code after modifying this file
94+
}
95+
96+
//+kubebuilder:object:root=true
97+
//+kubebuilder:subresource:status
98+
//+kubebuilder:resource:scope=Cluster
99+
100+
// ClusterPolicyEndpoint is the Schema for the ClusterPolicyendpoints API
101+
type ClusterPolicyEndpoint struct {
102+
metav1.TypeMeta `json:",inline"`
103+
metav1.ObjectMeta `json:"metadata,omitempty"`
104+
105+
Spec ClusterPolicyEndpointSpec `json:"spec,omitempty"`
106+
Status ClusterPolicyEndpointStatus `json:"status,omitempty"`
107+
}
108+
109+
//+kubebuilder:object:root=true
110+
111+
// ClusterPolicyEndpointList contains a list of ClusterPolicyEndpoint
112+
type ClusterPolicyEndpointList struct {
113+
metav1.TypeMeta `json:",inline"`
114+
metav1.ListMeta `json:"metadata,omitempty"`
115+
Items []ClusterPolicyEndpoint `json:"items"`
116+
}
117+
118+
func init() {
119+
SchemeBuilder.Register(&ClusterPolicyEndpoint{}, &ClusterPolicyEndpointList{})
120+
}

api/v1alpha1/policyendpoints_types.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ type PolicyReference struct {
3333

3434
type NetworkAddress string
3535

36+
// DomainName describes one or more domain names to be used as a peer.
37+
//
38+
// DomainName can be an exact match, or use the wildcard specifier '*' to match
39+
// one or more labels.
40+
//
41+
// '*', the wildcard specifier, matches one or more entire labels. It does not
42+
// support partial matches. '*' may only be specified as a prefix.
43+
//
44+
// Examples:
45+
// - `kubernetes.io` matches only `kubernetes.io`.
46+
// It does not match "www.kubernetes.io", "blog.kubernetes.io",
47+
// "my-kubernetes.io", or "wikipedia.org".
48+
// - `blog.kubernetes.io` matches only "blog.kubernetes.io".
49+
// It does not match "www.kubernetes.io" or "kubernetes.io".
50+
// - `*.kubernetes.io` matches subdomains of kubernetes.io.
51+
// "www.kubernetes.io", "blog.kubernetes.io", and
52+
// "latest.blog.kubernetes.io" match, however "kubernetes.io", and
53+
// "wikipedia.org" do not.
54+
//
55+
// +kubebuilder:validation:Pattern=`^(\*\.)?([a-zA-z0-9]([-a-zA-Z0-9_]*[a-zA-Z0-9])?\.)+[a-zA-z0-9]([-a-zA-Z0-9_]*[a-zA-Z0-9])?\.?$`
56+
type DomainName string
57+
3658
// Port contains information about the transport port/protocol
3759
type Port struct {
3860
// Protocol specifies the transport protocol, default TCP
@@ -49,7 +71,11 @@ type Port struct {
4971
// EndpointInfo defines the network endpoint information for the policy ingress/egress
5072
type EndpointInfo struct {
5173
// CIDR is the network address(s) of the endpoint
52-
CIDR NetworkAddress `json:"cidr"`
74+
CIDR NetworkAddress `json:"cidr,omitempty"`
75+
76+
// DomainName is the FQDN for the endpoint (mutually exclusive with CIDR, egress-only)
77+
// Note: This field should only be used in egress rules, not ingress
78+
DomainName DomainName `json:"domainName,omitempty"`
5379

5480
// Except is the exceptions to the CIDR ranges mentioned above.
5581
Except []NetworkAddress `json:"except,omitempty"`

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/cli/cli-selector/cli-all.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,22 @@ var mapWalkCmd = &cobra.Command{
6464
Run: func(cmd *cobra.Command, args []string) {
6565
mapID := args[0]
6666
strMapID, _ := strconv.Atoi(mapID)
67-
err := clihelper.MapWalk(strMapID)
67+
err := clihelper.MapWalk(strMapID, "")
68+
if err != nil {
69+
fmt.Println("Failed to execute the cmd - ", err)
70+
}
71+
},
72+
}
73+
74+
var mapWalkCPCmd = &cobra.Command{
75+
Use: "dump-cp-maps",
76+
Aliases: []string{"dcp"},
77+
Short: "Dump all ebpf maps related data",
78+
Args: cobra.ExactArgs(1),
79+
Run: func(cmd *cobra.Command, args []string) {
80+
mapID := args[0]
81+
strMapID, _ := strconv.Atoi(mapID)
82+
err := clihelper.MapWalkCP(strMapID)
6883
if err != nil {
6984
fmt.Println("Failed to execute the cmd - ", err)
7085
}
@@ -77,4 +92,5 @@ func init() {
7792
subCmd.AddCommand(mapCmd)
7893
subCmd.AddCommand(ebpfdataCmd)
7994
subCmd.AddCommand(mapWalkCmd)
95+
subCmd.AddCommand(mapWalkCPCmd)
8096
}

0 commit comments

Comments
 (0)