Skip to content

Commit baf54a7

Browse files
authored
Merge from release-v1.1.0 to main (#203)
<!-- Thanks for sending a pull request! Here are some tips for you: 1. Ensure you have added the unit tests for your changes. 2. Ensure you have included output of manual testing done in the Testing section. 3. Ensure number of lines of code for new or existing methods are within the reasonable limit. 4. Ensure your change works on existing clusters after upgrade. --> **What type of PR is this?** <!-- Add one of the following: bug cleanup documentation feature --> **Which issue does this PR fix**: **What does this PR do / Why do we need it**: **If an issue # is not available please add steps to reproduce and the controller logs**: **Testing done on this change**: <!-- output of manual testing/integration tests results and also attach logs showing the fix being resolved --> **Automation added to e2e**: <!-- List the e2e tests you added as part of this PR. If no, create an issue with enhancement/testing label --> **Will this PR introduce any new dependencies?**: <!-- e.g. new K8s API --> **Will this break upgrades or downgrades. Has updating a running cluster been tested?**: **Does this PR introduce any user-facing change?**: <!-- If yes, a release note update is required: Enter your extended release note in the block below. If the PR requires additional actions from users switching to the new release, include the string "action required". --> ```release-note ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
2 parents cc47bc8 + 92660bd commit baf54a7

File tree

71 files changed

+14380
-212
lines changed

Some content is hidden

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

71 files changed

+14380
-212
lines changed

.github/workflows/pr-tests.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
go install golang.org/x/tools/cmd/goimports@latest
3232
- name: Run code checks
3333
run: |
34+
make prepare-embed
3435
make check-format
3536
make vet
3637
- name: Build
@@ -42,9 +43,17 @@ jobs:
4243
docker-build:
4344
name: Build Docker images
4445
runs-on: ubuntu-latest
46+
env:
47+
GOTOOLCHAIN: auto
4548
steps:
4649
- name: Checkout latest commit in the PR
4750
uses: actions/checkout@v3
51+
- name: Set up Go
52+
uses: actions/setup-go@v4
53+
with:
54+
go-version-file: go.mod
55+
check-latest: true
56+
cache-dependency-path: "**/go.sum"
4857
- name: Set up QEMU
4958
uses: docker/setup-qemu-action@v2
5059
- name: Set up Docker Buildx

.go-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.23
1+
1.25.5

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ COPY internal/ internal/
2424

2525

2626
# Copy CRD file for embedding
27-
COPY charts/amazon-network-policy-controller-k8s/crds/crds.yaml pkg/crd/crds.yaml
27+
COPY pkg/crd/crds.yaml pkg/crd/crds.yaml
2828
# Short-term workaround for controller-gen version mismatch, should remove once the CRD removed from vpc-cni addon
2929
RUN sed -i 's/controller-gen.kubebuilder.io\/version: v[0-9]\+\.[0-9]\+\.[0-9]\+/controller-gen.kubebuilder.io\/version: v0.11.3/' pkg/crd/crds.yaml
3030

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ vet: ## Run go vet against code.
7676
go vet ./...
7777

7878
.PHONY: test
79-
test: manifests generate fmt vet envtest ## Run tests.
79+
test: manifests generate fmt vet envtest prepare-embed ## Run tests.
8080
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
8181

8282
##@ Build
8383
.PHONY: prepare-embed
8484
prepare-embed: ## Prepare files for go:embed.
85-
cp charts/amazon-network-policy-controller-k8s/crds/crds.yaml pkg/crd/crds.yaml
86-
sed -i 's/controller-gen.kubebuilder.io\/version: v[0-9]\+\.[0-9]\+\.[0-9]\+/controller-gen.kubebuilder.io\/version: v0.11.3/' pkg/crd/crds.yaml
85+
cat config/crd/bases/*.yaml > pkg/crd/crds.yaml
86+
sed -i '1834s/v0\.17\.0/v0.11.3/' pkg/crd/crds.yaml
8787

8888

8989
.PHONY: build
@@ -144,7 +144,7 @@ MOCKGEN ?= $(LOCALBIN)/mockgen
144144

145145
## Tool Versions
146146
KUSTOMIZE_VERSION ?= v5.4.3
147-
CONTROLLER_TOOLS_VERSION ?= v0.16.3
147+
CONTROLLER_TOOLS_VERSION ?= v0.17.0
148148

149149
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
150150
.PHONY: kustomize

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,47 @@ The controller does not require any IAM policies. It does not make AWS API calls
1717
- Kubernetes Version - 1.25+
1818
- Amazon VPC CNI version - 1.14.0+
1919

20+
## Deploy Controller on Dataplane for Development Testing
21+
22+
To deploy the network policy controller on dataplane nodes for development and testing:
23+
24+
1. **Deploy the controller:**
25+
This will deploy the image specified in helm chart
26+
```bash
27+
make deploy-controller-on-dataplane
28+
```
29+
If want to deploy a custom image, you can use the cmd
30+
```bash
31+
make deploy-controller-on-dataplane NP_CONTROLLER_IMAGE=<your-image-repository> NP_CONTROLLER_TAG=<your-image-tag>
32+
```
33+
Verify the image deployed
34+
```bash
35+
kubectl get deployment amazon-network-policy-controller-k8s -n kube-system | grep -i image
36+
```
37+
38+
**Optional steps (only needed if using custom images with additional CRDs/permissions):**
39+
40+
2. **Apply updated RBAC permissions:**
41+
```bash
42+
kubectl apply -f config/rbac/role.yaml
43+
```
44+
45+
3. **Apply latest CRDs:**
46+
```bash
47+
kubectl apply -f config/crd/bases/
48+
```
49+
50+
4. **Restart controller to pick up new permissions:**
51+
```bash
52+
kubectl rollout restart deployment/amazon-network-policy-controller-k8s -n kube-system
53+
```
54+
55+
**Verify deployment:**
56+
```bash
57+
kubectl get deployment amazon-network-policy-controller-k8s -n kube-system
58+
kubectl logs deployment/amazon-network-policy-controller-k8s -n kube-system
59+
```
60+
2061
## Security Disclosures
2162

2263
If you think you’ve found a potential security issue, please do not post it in the Issues. Instead, please follow the
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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+
networking "k8s.io/api/networking/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// ApplicationNetworkPolicySpec defines the desired state of ApplicationNetworkPolicy
25+
type ApplicationNetworkPolicySpec struct {
26+
// PodSelector selects the pods to which this ApplicationNetworkPolicy object applies.
27+
PodSelector metav1.LabelSelector `json:"podSelector"`
28+
29+
// PolicyTypes is a list of rule types that the ApplicationNetworkPolicy relates to.
30+
// Valid options are ["Ingress"], ["Egress"], or ["Ingress", "Egress"].
31+
// If this field is not specified, it will default based on the existence of ingress or egress rules.
32+
// +optional
33+
PolicyTypes []networking.PolicyType `json:"policyTypes,omitempty"`
34+
35+
// Ingress is a list of ingress rules to be applied to the selected pods.
36+
// Traffic is allowed to a pod if there are no ApplicationNetworkPolicies selecting the pod
37+
// (and cluster policy otherwise allows the traffic), OR if the traffic source is
38+
// the pod's local node, OR if the traffic matches at least one ingress rule
39+
// across all of the ApplicationNetworkPolicy objects whose podSelector matches the pod.
40+
// +optional
41+
Ingress []networking.NetworkPolicyIngressRule `json:"ingress,omitempty"`
42+
43+
// Egress is a list of egress rules to be applied to the selected pods. Outgoing traffic
44+
// is allowed if there are no ApplicationNetworkPolicies selecting the pod (and cluster policy
45+
// otherwise allows the traffic), OR if the traffic matches at least one egress rule
46+
// across all of the ApplicationNetworkPolicy objects whose podSelector matches the pod.
47+
// +optional
48+
Egress []ApplicationNetworkPolicyEgressRule `json:"egress,omitempty"`
49+
}
50+
51+
// DomainName describes one or more domain names to be used as a peer.
52+
//
53+
// DomainName can be an exact match, or use the wildcard specifier '*' to match
54+
// one or more labels.
55+
//
56+
// '*', the wildcard specifier, matches one or more entire labels. It does not
57+
// support partial matches. '*' may only be specified as a prefix.
58+
//
59+
// Examples:
60+
// - `kubernetes.io` matches only `kubernetes.io`.
61+
// It does not match "www.kubernetes.io", "blog.kubernetes.io",
62+
// "my-kubernetes.io", or "wikipedia.org".
63+
// - `blog.kubernetes.io` matches only "blog.kubernetes.io".
64+
// It does not match "www.kubernetes.io" or "kubernetes.io".
65+
// - `*.kubernetes.io` matches subdomains of kubernetes.io.
66+
// "www.kubernetes.io", "blog.kubernetes.io", and
67+
// "latest.blog.kubernetes.io" match, however "kubernetes.io", and
68+
// "wikipedia.org" do not.
69+
//
70+
// +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])?\.?$`
71+
type DomainName string
72+
73+
// ApplicationNetworkPolicyPeer describes a peer to allow traffic to/from.
74+
// Only certain combinations of fields are allowed
75+
// +kubebuilder:validation:XValidation:rule="!(has(self.ipBlock) && has(self.domainNames))",message="ipBlock and domainNames are mutually exclusive"
76+
// +kubebuilder:validation:XValidation:rule="!(has(self.podSelector) && has(self.domainNames))",message="podSelector and domainNames are mutually exclusive"
77+
// +kubebuilder:validation:XValidation:rule="!(has(self.namespaceSelector) && has(self.domainNames))",message="namespaceSelector and domainNames are mutually exclusive"
78+
type ApplicationNetworkPolicyPeer struct {
79+
// PodSelector is a label selector which selects pods. This field follows standard label
80+
// selector semantics; if present but empty, it selects all pods.
81+
//
82+
// If namespaceSelector is also set, then the NetworkPolicyPeer as a whole selects
83+
// the pods matching podSelector in the Namespaces selected by NamespaceSelector.
84+
// Otherwise it selects the pods matching podSelector in the policy's own namespace.
85+
// +optional
86+
PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"`
87+
88+
// NamespaceSelector selects namespaces using cluster-scoped labels. This field follows
89+
// standard label selector semantics; if present but empty, it selects all namespaces.
90+
//
91+
// If podSelector is also set, then the NetworkPolicyPeer as a whole selects
92+
// the pods matching podSelector in the namespaces selected by namespaceSelector.
93+
// Otherwise it selects all pods in the namespaces selected by namespaceSelector.
94+
// +optional
95+
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
96+
97+
// IPBlock defines policy on a particular IPBlock. If this field is set then
98+
// neither of the other fields can be.
99+
// +optional
100+
IPBlock *networking.IPBlock `json:"ipBlock,omitempty"`
101+
102+
// DomainNames provides a way to specify domain names as peers.
103+
//
104+
// DomainNames is only supported for Allow rules. In order to control
105+
// access, DomainNames Allow rules should be used with a lower priority
106+
// egress deny -- this allows the admin to maintain an explicit "allowlist"
107+
// of reachable domains.
108+
//
109+
// This field is mutually exclusive with PodSelector, NamespaceSelector, and IPBlock.
110+
// FQDN rules are ALLOW-only and do not support DENY semantics.
111+
//
112+
// +optional
113+
// +listType=set
114+
// +kubebuilder:validation:MinItems=1
115+
DomainNames []DomainName `json:"domainNames,omitempty"`
116+
}
117+
118+
// ApplicationNetworkPolicyEgressRule describes a particular set of traffic that is allowed out of pods
119+
// matched by an ApplicationNetworkPolicySpec's podSelector. The traffic must match both ports and to.
120+
type ApplicationNetworkPolicyEgressRule struct {
121+
// Ports is a list of destination ports for outgoing traffic.
122+
// Each item in this list is combined using a logical OR. If this field is
123+
// empty or missing, this rule matches all ports (traffic not restricted by port).
124+
// If this field is present and contains at least one item, then this rule allows
125+
// traffic only if the traffic matches at least one port in the list.
126+
// +optional
127+
Ports []networking.NetworkPolicyPort `json:"ports,omitempty"`
128+
129+
// To is a list of destinations for outgoing traffic of pods selected for this rule.
130+
// Items in this list are combined using a logical OR operation. If this field is
131+
// empty or missing, this rule matches all destinations (traffic not restricted by
132+
// destination). If this field is present and contains at least one item, this rule
133+
// allows traffic only if the traffic matches at least one item in the to list.
134+
// +optional
135+
To []ApplicationNetworkPolicyPeer `json:"to,omitempty"`
136+
}
137+
138+
// ApplicationNetworkPolicyStatus defines the observed state of ApplicationNetworkPolicy
139+
type ApplicationNetworkPolicyStatus struct {
140+
// Conditions represent the latest available observations of the ApplicationNetworkPolicy's current state.
141+
// +optional
142+
Conditions []metav1.Condition `json:"conditions,omitempty"`
143+
}
144+
145+
//+kubebuilder:object:root=true
146+
//+kubebuilder:subresource:status
147+
//+kubebuilder:resource:shortName=anp
148+
149+
// ApplicationNetworkPolicy is the Schema for the applicationnetworkpolicies API
150+
type ApplicationNetworkPolicy struct {
151+
metav1.TypeMeta `json:",inline"`
152+
metav1.ObjectMeta `json:"metadata,omitempty"`
153+
154+
Spec ApplicationNetworkPolicySpec `json:"spec,omitempty"`
155+
Status ApplicationNetworkPolicyStatus `json:"status,omitempty"`
156+
}
157+
158+
//+kubebuilder:object:root=true
159+
160+
// ApplicationNetworkPolicyList contains a list of ApplicationNetworkPolicy
161+
type ApplicationNetworkPolicyList struct {
162+
metav1.TypeMeta `json:",inline"`
163+
metav1.ListMeta `json:"metadata,omitempty"`
164+
Items []ApplicationNetworkPolicy `json:"items"`
165+
}
166+
167+
func init() {
168+
SchemeBuilder.Register(&ApplicationNetworkPolicy{}, &ApplicationNetworkPolicyList{})
169+
}

0 commit comments

Comments
 (0)