Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/ws-proxy/rolebinding.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 wsproxy
6
7
import (
8
"fmt"
9
10
"github.com/gitpod-io/gitpod/installer/pkg/common"
11
12
rbacv1 "k8s.io/api/rbac/v1"
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
"k8s.io/apimachinery/pkg/runtime"
15
)
16
17
func rolebinding(ctx *common.RenderContext) ([]runtime.Object, error) {
18
return []runtime.Object{
19
&rbacv1.ClusterRoleBinding{
20
TypeMeta: common.TypeMetaClusterRoleBinding,
21
ObjectMeta: metav1.ObjectMeta{
22
Name: fmt.Sprintf("%s-%s-kube-rbac-proxy", ctx.Namespace, Component),
23
Labels: common.DefaultLabels(Component),
24
},
25
RoleRef: rbacv1.RoleRef{
26
Kind: "ClusterRole",
27
Name: fmt.Sprintf("%s-kube-rbac-proxy", ctx.Namespace),
28
APIGroup: "rbac.authorization.k8s.io",
29
},
30
Subjects: []rbacv1.Subject{
31
{
32
Kind: "ServiceAccount",
33
Name: Component,
34
Namespace: ctx.Namespace,
35
},
36
},
37
},
38
&rbacv1.RoleBinding{
39
TypeMeta: common.TypeMetaRoleBinding,
40
ObjectMeta: metav1.ObjectMeta{
41
Name: Component,
42
Namespace: ctx.Namespace,
43
Labels: common.DefaultLabels(Component),
44
},
45
RoleRef: rbacv1.RoleRef{
46
Kind: "ClusterRole",
47
Name: fmt.Sprintf("%s-ns-psp:unprivileged", ctx.Namespace),
48
APIGroup: "rbac.authorization.k8s.io",
49
},
50
Subjects: []rbacv1.Subject{{
51
Kind: "ServiceAccount",
52
Name: Component,
53
}},
54
},
55
&rbacv1.RoleBinding{
56
TypeMeta: common.TypeMetaRoleBinding,
57
ObjectMeta: metav1.ObjectMeta{
58
Name: Component + "-api",
59
Namespace: ctx.Namespace,
60
Labels: common.DefaultLabels(Component),
61
},
62
RoleRef: rbacv1.RoleRef{
63
Kind: "Role",
64
Name: Component,
65
APIGroup: "rbac.authorization.k8s.io",
66
},
67
Subjects: []rbacv1.Subject{{
68
Kind: "ServiceAccount",
69
Name: Component,
70
}},
71
},
72
}, nil
73
}
74
75