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

feat: add ingress network policy with generic sandbox label #1086

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions deploy/nstemplatetiers/appstudio-env/ns_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ objects:
podSelector: {}
policyTypes:
- Ingress
- apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-dev-sandbox-managed-ns
namespace: ${SPACE_NAME}-env
spec:
ingress:
- from:
- namespaceSelector:
matchLabels:
dev-sandbox/policy-group: ingress
policyTypes:
- Ingress
parameters:
- name: SPACE_NAME
required: true
Expand Down
13 changes: 13 additions & 0 deletions deploy/nstemplatetiers/appstudio/ns_tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ objects:
podSelector: {}
policyTypes:
- Ingress
- apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-dev-sandbox-managed-ns
namespace: ${SPACE_NAME}-tenant
spec:
ingress:
- from:
- namespaceSelector:
matchLabels:
dev-sandbox/policy-group: ingress
policyTypes:
- Ingress
# ServiceAccount and RoleBindings for running Pipelines.
# appstudio-pipelines-runner-clusterrole is deployed by the pipeline-service component.
- apiVersion: v1
Expand Down
19 changes: 12 additions & 7 deletions testsupport/tiers/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (a *baseTierChecks) GetNamespaceObjectChecks(nsType string) []namespaceObje
case "stage":
otherNamespaceKind = "dev"
}
checks = append(checks, networkPolicyAllowFromCRW(), networkPolicyAllowFromVirtualizationNamespaces(), networkPolicyAllowFromRedHatODSNamespaceToModelMesh(), networkPolicyAllowFromRedHatODSNamespaceToMariaDB(), networkPolicyAllowFromOtherNamespace(otherNamespaceKind), numberOfNetworkPolicies(10))
checks = append(checks, networkPolicyAllowFromCRW(), networkPolicyAllowFromVirtualizationNamespaces(), networkPolicyAllowFromRedHatODSNamespaceToModelMesh(), networkPolicyAllowFromRedHatODSNamespaceToMariaDB(), networkPolicyAllowFromOtherNamespace(otherNamespaceKind), numberOfNetworkPolicies(11))

return checks
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func (a *base1nsTierChecks) GetNamespaceObjectChecks(_ string) []namespaceObject
crtadminViewRoleBinding(),
}
checks = append(checks, commonNetworkPolicyChecks()...)
checks = append(checks, networkPolicyAllowFromCRW(), networkPolicyAllowFromVirtualizationNamespaces(), networkPolicyAllowFromRedHatODSNamespaceToMariaDB(), networkPolicyAllowFromRedHatODSNamespaceToModelMesh(), numberOfNetworkPolicies(9))
checks = append(checks, networkPolicyAllowFromCRW(), networkPolicyAllowFromVirtualizationNamespaces(), networkPolicyAllowFromRedHatODSNamespaceToMariaDB(), networkPolicyAllowFromRedHatODSNamespaceToModelMesh(), numberOfNetworkPolicies(10))
return checks
}

Expand Down Expand Up @@ -381,6 +381,7 @@ func commonNetworkPolicyChecks() []namespaceObjectsCheck {
networkPolicyAllowFromIngress(),
networkPolicyAllowFromOlmNamespaces(),
networkPolicyAllowFromConsoleNamespaces(),
networkPolicyIngressAllowFromDevSandboxPolicyGroup(),
}
}

Expand Down Expand Up @@ -465,7 +466,7 @@ func (a *appstudioTierChecks) GetNamespaceObjectChecks(_ string) []namespaceObje
resourceQuotaComputeBuild("120", "128Gi", "60", "64Gi"),
}
checks = append(checks, commonAppstudioTierChecks()...)
checks = append(checks, append(commonNetworkPolicyChecks(), networkPolicyAllowFromCRW(), numberOfNetworkPolicies(6))...)
checks = append(checks, append(commonNetworkPolicyChecks(), networkPolicyAllowFromCRW(), numberOfNetworkPolicies(7))...)
return checks
}

Expand Down Expand Up @@ -558,7 +559,7 @@ func (a *appstudiolargeTierChecks) GetNamespaceObjectChecks(_ string) []namespac
resourceQuotaStorage("50Gi", "400Gi", "50Gi", "180"),
}
checks = append(checks, commonAppstudioTierChecks()...)
checks = append(checks, append(commonNetworkPolicyChecks(), networkPolicyAllowFromCRW(), numberOfNetworkPolicies(6))...)
checks = append(checks, append(commonNetworkPolicyChecks(), networkPolicyAllowFromCRW(), numberOfNetworkPolicies(7))...)
return checks
}

Expand Down Expand Up @@ -596,7 +597,7 @@ func (a *appstudioEnvTierChecks) GetNamespaceObjectChecks(_ string) []namespaceO
appstudioWorkSpaceNameLabel(),
}

checks = append(checks, append(commonNetworkPolicyChecks(), networkPolicyAllowFromCRW(), numberOfNetworkPolicies(6))...)
checks = append(checks, append(commonNetworkPolicyChecks(), networkPolicyAllowFromCRW(), numberOfNetworkPolicies(7))...)
return checks
}

Expand Down Expand Up @@ -656,7 +657,7 @@ func (a *intelMediumTierChecks) GetNamespaceObjectChecks(_ string) []namespaceOb
crtadminViewRoleBinding(),
}
checks = append(checks, commonNetworkPolicyChecks()...)
checks = append(checks, networkPolicyAllowFromCRW(), networkPolicyAllowFromVirtualizationNamespaces(), networkPolicyAllowFromRedHatODSNamespaceToMariaDB(), networkPolicyAllowFromRedHatODSNamespaceToModelMesh(), numberOfNetworkPolicies(9))
checks = append(checks, networkPolicyAllowFromCRW(), networkPolicyAllowFromVirtualizationNamespaces(), networkPolicyAllowFromRedHatODSNamespaceToMariaDB(), networkPolicyAllowFromRedHatODSNamespaceToModelMesh(), numberOfNetworkPolicies(10))
return checks
}

Expand Down Expand Up @@ -736,7 +737,7 @@ func getNamespaceObjectChecksForIntelLarge(memoryLimit string) []namespaceObject
crtadminViewRoleBinding(),
}
checks = append(checks, commonNetworkPolicyChecks()...)
checks = append(checks, networkPolicyAllowFromCRW(), networkPolicyAllowFromVirtualizationNamespaces(), networkPolicyAllowFromRedHatODSNamespaceToMariaDB(), networkPolicyAllowFromRedHatODSNamespaceToModelMesh(), numberOfNetworkPolicies(9))
checks = append(checks, networkPolicyAllowFromCRW(), networkPolicyAllowFromVirtualizationNamespaces(), networkPolicyAllowFromRedHatODSNamespaceToMariaDB(), networkPolicyAllowFromRedHatODSNamespaceToModelMesh(), numberOfNetworkPolicies(10))
return checks
}

Expand Down Expand Up @@ -1242,6 +1243,10 @@ func networkPolicyIngressFromPolicyGroup(name, group string) namespaceObjectsChe
return assertNetworkPolicyIngressForNamespaces(name, metav1.LabelSelector{}, "network.openshift.io/policy-group", group)
}

func networkPolicyIngressAllowFromDevSandboxPolicyGroup() namespaceObjectsCheck {
return assertNetworkPolicyIngressForNamespaces("allow-from-dev-sandbox-managed-ns", metav1.LabelSelector{}, "dev-sandbox/policy-group", "ingress")
}

func assertNetworkPolicyIngressForNamespaces(name string, podSelector metav1.LabelSelector, labelNameValuePairs ...string) namespaceObjectsCheck {
return func(t *testing.T, ns *corev1.Namespace, memberAwait *wait.MemberAwaitility, userName string) {
require.Equal(t, 0, len(labelNameValuePairs)%2, "labelNameValuePairs must be a list of key-value pairs")
Expand Down
Loading