-
Notifications
You must be signed in to change notification settings - Fork 881
/
nginx-ing-cntlr-rbac.ts
201 lines (195 loc) · 5.88 KB
/
nginx-ing-cntlr-rbac.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
// Create a ServiceAccount.
interface NginxServiceAccountArgs {
namespace: pulumi.Input<string>;
provider: k8s.Provider;
}
export function makeNginxServiceAccount(
name: string,
args: NginxServiceAccountArgs,
): k8s.core.v1.ServiceAccount {
return new k8s.core.v1.ServiceAccount(
name,
{
metadata: {
namespace: args.namespace,
},
},
{
provider: args.provider,
},
);
}
// Create a ClusterRole.
interface NginxClusterRoleArgs {
provider: k8s.Provider;
}
export function makeNginxClusterRole(
name: string,
args: NginxClusterRoleArgs,
): k8s.rbac.v1.ClusterRole {
return new k8s.rbac.v1.ClusterRole(
name,
{
rules: [
{
apiGroups: [""],
resources: ["configmaps", "endpoints", "nodes", "pods", "secrets"],
verbs: ["list", "watch"],
},
{
apiGroups: [""],
resources: ["nodes"],
verbs: ["get"],
},
{
apiGroups: [""],
resources: ["services"],
verbs: ["get", "list", "watch"],
},
{
// TODO(metral): change to k8s.networking.v1beta.Ingress
// when EKS supports >= 1.14.
apiGroups: ["extensions"],
resources: ["ingresses"],
verbs: ["get", "list", "watch"],
},
{
apiGroups: [""],
resources: ["events"],
verbs: ["create", "patch"],
},
{
// TODO(metral): change to k8s.networking.v1beta.Ingress
// when EKS supports >= 1.14.
apiGroups: ["extensions"],
resources: ["ingresses/status"],
verbs: ["update"],
},
],
},
{
provider: args.provider,
},
);
}
// Create a ClusterRoleBinding of the ServiceAccount -> ClusterRole.
interface NginxClusterRoleBindingArgs {
namespace: pulumi.Input<string>;
serviceAccountName: pulumi.Input<string>;
clusterRoleName: pulumi.Input<string>;
provider: k8s.Provider;
}
export function makeNginxClusterRoleBinding(
name: string,
args: NginxClusterRoleBindingArgs,
): k8s.rbac.v1.ClusterRoleBinding {
return new k8s.rbac.v1.ClusterRoleBinding(
name,
{
subjects: [
{
kind: "ServiceAccount",
name: args.serviceAccountName,
namespace: args.namespace,
},
],
roleRef: {
apiGroup: "rbac.authorization.k8s.io",
kind: "ClusterRole",
name: args.clusterRoleName,
},
},
{
provider: args.provider,
},
);
}
// Create a Role.
interface NginxRoleArgs {
namespace: pulumi.Input<string>;
ingressClass: pulumi.Input<string>;
provider: k8s.Provider;
}
export function makeNginxRole(
name: string,
args: NginxRoleArgs,
): k8s.rbac.v1.Role {
return new k8s.rbac.v1.Role(
name,
{
metadata: {
namespace: args.namespace,
},
rules: [
{
apiGroups: [""],
resources: ["configmaps", "pods", "secrets", "namespaces"],
verbs: ["get"],
},
{
apiGroups: [""],
resources: ["configmaps"],
// Defaults to "<election-id>-<ingress-class>"
// In this setup its specifically: "<ingress-controller-leader>-<my-nginx-class>".
// This has to be adapted if you change either parameter
// (--election-id, and/or --ingress-class) when launching
// the nginx-ing-cntlr. See for more info:
// https://github.com/kubernetes/ingress/tree/master/docs/deploy/rbac.md#namespace-permissions
resourceNames: ["ingress-controller-leader-" + args.ingressClass],
verbs: ["get", "update"],
},
{
apiGroups: [""],
resources: ["configmaps"],
verbs: ["create"],
},
{
apiGroups: [""],
resources: ["endpoints"],
verbs: ["get", "create", "update"],
},
],
},
{
provider: args.provider,
},
);
}
// Create a RoleBinding of the ServiceAccount -> Role.
interface NginxRoleBindingArgs {
namespace: pulumi.Input<string>;
serviceAccountName: pulumi.Input<string>;
roleName: pulumi.Input<string>;
provider: k8s.Provider;
}
export function makeNginxRoleBinding(
name: string,
args: NginxRoleBindingArgs,
): k8s.rbac.v1.RoleBinding {
return new k8s.rbac.v1.RoleBinding(
name,
{
metadata: {
namespace: args.namespace,
},
subjects: [
{
kind: "ServiceAccount",
name: args.serviceAccountName,
namespace: args.namespace,
},
],
roleRef: {
apiGroup: "rbac.authorization.k8s.io",
kind: "Role",
name: args.roleName,
},
},
{
provider: args.provider,
},
);
}