Skip to content

Commit 129c85e

Browse files
committed
Update RKE2 CIS profile and add backupstore network policy
- Add install_backupstores_networkpolicy function to install backupstore network policy - Apply backupstore network policy in pipeline setup scripts (regression, e2e, helm, rancher, storage_network) - Update RKE2 CIS profile from 'cis-1.23' to 'cis' for latest CIS benchmark support longhorn/longhorn#11672 Signed-off-by: Roger Yao <roger.yao@suse.com>
1 parent a168ec1 commit 129c85e

9 files changed

Lines changed: 75 additions & 2 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: NetworkPolicy
3+
metadata:
4+
# Purpose: Allow ingress traffic to the NFS BackupStore
5+
name: allow-backupstore-nfs-ingress
6+
namespace: default
7+
spec:
8+
# Target: Apply to pods with label app: longhorn-test-nfs
9+
podSelector:
10+
matchLabels:
11+
app: longhorn-test-nfs
12+
policyTypes:
13+
- Ingress
14+
ingress:
15+
# Rule 1: Allow traffic from the longhorn-system namespace (Production Backup Traffic)
16+
- from:
17+
- namespaceSelector:
18+
matchLabels:
19+
kubernetes.io/metadata.name: longhorn-system
20+
# Rule 2: Allow traffic from the Test Client Pod within the SAME namespace (Test Traffic)
21+
# Note: A podSelector without a namespaceSelector implies the current namespace.
22+
- from:
23+
- podSelector:
24+
matchLabels:
25+
longhorn-test: test-job # Matches the specific label of the longhorn-test pod
26+
ports:
27+
- protocol: TCP
28+
port: 2049 # NFS port
29+
- protocol: TCP
30+
port: 111 # RPCBind port
31+
32+
---
33+
apiVersion: networking.k8s.io/v1
34+
kind: NetworkPolicy
35+
metadata:
36+
# Purpose: Allow ingress traffic to the MinIO BackupStore
37+
name: allow-backupstore-minio-ingress
38+
namespace: default
39+
spec:
40+
# Target: Apply to pods with label app: longhorn-test-minio
41+
podSelector:
42+
matchLabels:
43+
app: longhorn-test-minio
44+
policyTypes:
45+
- Ingress
46+
ingress:
47+
# Rule 1: Allow traffic from the longhorn-system namespace (Production Backup Traffic)
48+
- from:
49+
- namespaceSelector:
50+
matchLabels:
51+
kubernetes.io/metadata.name: longhorn-system
52+
# Rule 2: Allow traffic from the Test Client Pod within the SAME namespace (Test Traffic)
53+
- from:
54+
- podSelector:
55+
matchLabels:
56+
longhorn-test: test-job # Matches the specific label of the longhorn-test pod
57+
ports:
58+
- protocol: TCP
59+
port: 9000 # MinIO API port

pipelines/e2e/scripts/longhorn-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ main(){
4444
create_instance_mapping_configmap
4545

4646
install_backupstores
47+
install_backupstores_networkpolicy
4748
setup_azurite_backup_store
4849
install_csi_snapshotter
4950
create_nad_without_storage_network

pipelines/helm/scripts/longhorn-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ main(){
4141

4242
create_longhorn_namespace
4343
install_backupstores
44+
install_backupstores_networkpolicy
4445
setup_azurite_backup_store
4546
install_csi_snapshotter
4647

pipelines/rancher/scripts/longhorn-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ main(){
3535

3636
create_longhorn_namespace
3737
install_backupstores
38+
install_backupstores_networkpolicy
3839
setup_azurite_backup_store
3940
install_csi_snapshotter
4041

pipelines/storage_network/scripts/longhorn-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ main(){
5858

5959
create_longhorn_namespace
6060
install_backupstores
61+
install_backupstores_networkpolicy
6162
setup_azurite_backup_store
6263
install_csi_snapshotter
6364

pipelines/utilities/install_backupstores.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ setup_azurite_backup_store(){
5757
kubectl delete pod az-cli --ignore-not-found
5858
}
5959

60+
install_backupstores_networkpolicy(){
61+
BACKUPSTORE_NETWORK_POLICY_URL="https://raw.githubusercontent.com/longhorn/longhorn-tests/master/manager/integration/deploy/backupstores/backupstore-networkpolicy.yaml"
62+
kubectl create -f ${BACKUPSTORE_NETWORK_POLICY_URL}
63+
}
64+
6065
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
6166
if declare -f "$1" > /dev/null; then
6267
"$@"

test_framework/scripts/longhorn-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ main(){
7676
fi
7777
setup_azurite_backup_store
7878
fi
79+
install_backupstores_networkpolicy
7980
install_csi_snapshotter
8081
if [[ "${TF_VAR_enable_mtls}" == true ]]; then
8182
enable_mtls

test_framework/terraform/aws/sles/user-data-scripts/provision_rke2_agent.sh.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ EOF
8484
systemctl restart systemd-sysctl
8585
useradd -r -c "etcd user" -s /sbin/nologin -M etcd -U
8686
cat << EOF >> /etc/rancher/rke2/config.yaml
87-
profile: "cis-1.23"
87+
profile: "cis"
88+
kube-apiserver-arg:
89+
- 'service-account-extend-token-expiration=false'
8890
EOF
8991
fi
9092

test_framework/terraform/aws/sles/user-data-scripts/provision_rke2_server.sh.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ EOF
6262
systemctl restart systemd-sysctl
6363
useradd -r -c "etcd user" -s /sbin/nologin -M etcd -U
6464
cat << EOF >> /etc/rancher/rke2/config.yaml
65-
profile: "cis-1.23"
65+
profile: "cis"
66+
kube-apiserver-arg:
67+
- 'service-account-extend-token-expiration=false'
6668
EOF
6769
fi
6870

0 commit comments

Comments
 (0)