-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgangway.yaml
312 lines (294 loc) · 10.8 KB
/
gangway.yaml
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
apiVersion: v1
kind: ConfigMap
metadata:
name: custom-template
namespace: auth-system
data:
commandline.tmpl:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Kubeconfig</title>
<base href="{{ .HTTPPath }}/">
<link type="text/css" rel="stylesheet" href="assets/materialize.min.css" media="screen"/>
<link type="text/css" rel="stylesheet" href="assets/prism.css" media="screen"/>
<link type="text/css" rel="stylesheet" href="assets/gangway.css" media="screen"/>
</head>
<body>
<center>
<nav class="light-blue blue">
<div class="nav-wrapper container">
<a href="#" class="brand-logo">K8S</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="/logout">Logout</a></li>
</ul>
</div>
</nav>
<div class="container">
<h4 class="center">Welcome {{ .Username }}.</h4>
<p class="flow-text">In order to get CLI access to the {{ .ClusterName }} Kubernetes cluster, you will need to configure (OIDC) authentication for your client.</p>
<p>
<a href="{{ .HTTPPath }}/kubeconf" class="waves-effect waves-light btn-large blue">Download Kubeconfig</a>
</p>
</div>
<div class="container">
<h5>Config cluster context</h5>
<p>Once kubectl is installed (see below), you may execute the following:</p>
<div class="card">
<div class="card-tabs">
<ul class="tabs">
<li class="tab"><a class="active" href="#config-section-bash">Bash</a></li>
<li class="tab"><a href="#config-section-ps">PowerShell</a></li>
</ul>
</div>
<div class="card-content grey lighten-4">
<div class="right-align">
<a class="waves-effect waves-light btn-small btn-copy blue">Copy to clipboard</a>
</div>
</center>
</body>
<pre id="config-section-bash"><code class="language-bash">echo "{{ .ClusterCA }}" \ > "ca-{{ .ClusterName }}.pem"
kubectl config set-cluster "{{ .ClusterName }}" --server={{ .APIServerURL }} --certificate-authority="ca-{{ .ClusterName }}.pem" --embed-certs
kubectl config set-credentials "{{ .KubeCfgUser }}" \
--auth-provider=oidc \
--auth-provider-arg='idp-issuer-url={{ .IssuerURL }}' \
--auth-provider-arg='client-id={{ .ClientID }}' \
--auth-provider-arg='client-secret={{ .ClientSecret }}' \
--auth-provider-arg='refresh-token={{ .RefreshToken }}' \
--auth-provider-arg='id-token={{ .IDToken }}'
kubectl config set-context "{{ .ClusterName }}" --cluster="{{ .ClusterName }}" --user="{{ .KubeCfgUser }}"
kubectl config use-context "{{ .ClusterName }}"
rm "ca-{{ .ClusterName }}.pem"</code></pre>
<pre id="config-section-ps"><code class="language-powershell">$ClusterCA = "{{ .ClusterCA }}"
Set-Content -Path "ca-{{ .ClusterName }}.pem" -Value $ClusterCA
kubectl config set-cluster "{{ .ClusterName }}" --server={{ .APIServerURL }} --certificate-authority="ca-{{ .ClusterName }}.pem" --embed-certs
kubectl config set-credentials "{{ .KubeCfgUser }}" `
--auth-provider=oidc `
--auth-provider-arg='idp-issuer-url={{ .IssuerURL }}' `
--auth-provider-arg='client-id={{ .ClientID }}' `
--auth-provider-arg='client-secret={{ .ClientSecret }}' `
--auth-provider-arg='refresh-token={{ .RefreshToken }}' `
--auth-provider-arg='id-token={{ .IDToken }}'
kubectl config set-context "{{ .ClusterName }}" --cluster="{{ .ClusterName }}" --user="{{ .KubeCfgUser }}"
kubectl config use-context "{{ .ClusterName }}"
Remove-Item "ca-{{ .ClusterName }}.pem"</code></pre>
</div>
</div>
</div>
<body>
<center>
<div class="container">
<h5>Install kubectl</h5>
<p>The Kubernetes command-line utility, kubectl, may be installed like so:</p>
<div class="card">
<div class="card-tabs">
<ul class="tabs">
<li class="tab"><a class="active" href="#install-section-bash">Bash</a></li>
<li class="tab"><a href="#install-section-ps">PowerShell</a></li>
</ul>
</div>
<div class="card-content grey lighten-4">
<div class="right-align">
<a class="waves-effect waves-light btn-small btn-copy blue">Copy to clipboard</a>
</div>
</center>
</body>
<pre id="install-section-bash"><code class="language-bash">curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/$(uname | awk '{print tolower($0)}')/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl</code></pre>
<pre id="install-section-ps"><code class="language-powershell">Install-Script -Name install-kubectl -Scope CurrentUser -Force
New-Item -Path 'C:\Program Files\Kubectl' -ItemType Directory
install-kubectl.ps1 -DownloadLocation 'C:\Program Files\Kubectl'</code></pre>
</div>
</div>
</div>
<body>
<script type="text/javascript" src="assets/materialize.min.js"></script>
<script type="text/javascript" src="assets/prism.js"></script>
<script type="text/javascript" src="assets/prism-bash.js"></script>
<script type="text/javascript" src="assets/prism-powershell.js"></script>
<script type="text/javascript" src="assets/gangway.js"></script>
</body>
</html>
home.tmpl:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Kubeconfig</title>
<base href="{{ .HTTPPath }}/">
<link type="text/css" rel="stylesheet" href="assets/materialize.min.css" media="screen"/>
<link type="text/css" rel="stylesheet" href="assets/gangway.css" media="screen"/>
</head>
<body>
<center>
<nav class="light-blue blue">
<div class="nav-wrapper container">
<a href="#" class="brand-logo">K8S</a>
</div>
</nav>
<div class="container">
<h1 class="center header">Kubernetes Authentication</h1>
<p class="flow-text center">Kubernetes cluster with OIDC. Sign in to get started.</p>
<p class="center">
<a href="{{ .HTTPPath }}/login" class="waves-effect waves-light btn-large blue">Sign in</a>
</p>
</div>
<script type="text/javascript" src="assets/materialize.min.js"></script>
</center>
</body>
</html>
---
apiVersion: v1
kind: ConfigMap
metadata:
name: gangway
namespace: auth-system
data:
gangway.yaml: |
clusterName: "Kubernetes"
apiServerURL: "https://kubernetes.default"
authorizeURL: "https://auth.apps.k8s.cloudcafe.tech/auth"
tokenURL: "https://auth.apps.k8s.cloudcafe.tech/token"
clientID: "oidc-auth-client"
clientSecret: "secret"
redirectURL: "https://kubectl.apps.k8s.cloudcafe.tech/callback"
scopes: ["openid", "profile", "email", "offline_access"]
usernameClaim: "email"
emailClaim: "email"
# For insecure (selfsign), 509 certificate error
#trustedCAPath: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
trustedCAPath: "/tmp/certs/tls.crt"
---
apiVersion: v1
kind: Secret
metadata:
name: gangway-key
namespace: auth-system
type: Opaque
data:
sesssionkey: VUtvMC9hMk1zaWlkcTU1SmFsNXk3WmJqUExiVFFvalpDZFpYa2wyRHRmZz0=
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: gangway
name: gangway
namespace: auth-system
spec:
replicas: 1
selector:
matchLabels:
app: gangway
template:
metadata:
labels:
app: gangway
spec:
containers:
- command:
- gangway
- -config
- /gangway/gangway.yaml
env:
#- name: GANGWAY_CUSTOM_HTTP_TEMPLATES_DIR
#value: "/tmp/templates"
- name: GANGWAY_SESSION_SECURITY_KEY
valueFrom:
secretKeyRef:
key: sesssionkey
name: gangway-key
#image: gcr.io/heptio-images/gangway:v2.0.0
image: gcr.io/heptio-images/gangway:v3.2.0
imagePullPolicy: Always
name: gangway
ports:
- containerPort: 8080
name: http
protocol: TCP
resources:
limits:
cpu: 100m
memory: 100Mi
requests:
cpu: 100m
memory: 100Mi
volumeMounts:
- mountPath: /etc/ssl/certs
name: certs
- mountPath: /tmp/certs
name: dexcerts
- mountPath: /gangway/
name: gangway
- mountPath: /tmp/templates
name: custom-template
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- configMap:
defaultMode: 420
name: gangway
name: gangway
- configMap:
defaultMode: 420
name: custom-template
name: custom-template
- name: certs
secret:
defaultMode: 420
secretName: gangway
- name: dexcerts
secret:
defaultMode: 420
secretName: dex
---
apiVersion: v1
kind: Service
metadata:
labels:
app: gangway
name: gangway-svc
namespace: auth-system
spec:
type: ClusterIP
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
selector:
app: gangway
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gangway
namespace: auth-system
annotations:
ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
#cert-manager.io/cluster-issuer: "private-ca"
cert-manager.io/cluster-issuer: "selfsigned-issuer"
spec:
ingressClassName: nginx
tls:
- secretName: gangway
hosts:
- kubectl.apps.k8s.cloudcafe.tech
rules:
- host: kubectl.apps.k8s.cloudcafe.tech
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: gangway-svc
port:
number: 80