Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/dashboard/networkpolicy.go
2501 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package dashboard
6
7
import (
8
"fmt"
9
10
"github.com/gitpod-io/gitpod/installer/pkg/common"
11
"github.com/gitpod-io/gitpod/installer/pkg/components/proxy"
12
13
networkingv1 "k8s.io/api/networking/v1"
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
"k8s.io/apimachinery/pkg/runtime"
16
"k8s.io/apimachinery/pkg/util/intstr"
17
)
18
19
func networkpolicy(ctx *common.RenderContext) ([]runtime.Object, error) {
20
labels := common.DefaultLabels(Component)
21
22
return []runtime.Object{&networkingv1.NetworkPolicy{
23
TypeMeta: common.TypeMetaNetworkPolicy,
24
ObjectMeta: metav1.ObjectMeta{
25
Name: fmt.Sprintf("%s-deny-all-allow-explicit", Component),
26
Namespace: ctx.Namespace,
27
Labels: labels,
28
},
29
Spec: networkingv1.NetworkPolicySpec{
30
PodSelector: metav1.LabelSelector{MatchLabels: labels},
31
PolicyTypes: []networkingv1.PolicyType{"Ingress"},
32
Ingress: []networkingv1.NetworkPolicyIngressRule{{
33
Ports: []networkingv1.NetworkPolicyPort{
34
{
35
Protocol: common.TCPProtocol,
36
Port: &intstr.IntOrString{IntVal: ContainerPort},
37
},
38
},
39
From: []networkingv1.NetworkPolicyPeer{{
40
PodSelector: &metav1.LabelSelector{MatchLabels: map[string]string{
41
"component": proxy.Component,
42
}},
43
}},
44
}},
45
},
46
}}, nil
47
}
48
49