-
Notifications
You must be signed in to change notification settings - Fork 361
/
ext-auth-http-service.yaml
91 lines (87 loc) · 2.25 KB
/
ext-auth-http-service.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
---
apiVersion: v1
kind: ConfigMap
metadata:
name: http-ext-auth
namespace: gateway-conformance-infra
data:
http-ext-auth.js: |
const Http = require("http");
const path = require("path");
const tokens = {
"token1": "user1",
"token2": "user2",
"token3": "user3"
};
const server = new Http.Server((req, res) => {
const authorization = req.headers["authorization"] || "";
const extracted = authorization.split(" ");
if (extracted.length === 2 && extracted[0] === "Bearer") {
const user = checkToken(extracted[1]);
console.log(`token: "${extracted[1]}" user: "${user}`);
if (user !== undefined) {
// The authorization server returns a response with "x-current-user" header for a successful
// request.
res.writeHead(200, { "x-current-user": user });
return res.end();
}
}
res.writeHead(403);
res.end();
});
const port = process.env.PORT || 9002;
server.listen(port);
console.log(`starting HTTP server on: ${port}`);
function checkToken(token) {
return tokens[token];
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: http-ext-auth
namespace: gateway-conformance-infra
spec:
replicas: 1
selector:
matchLabels:
app: http-ext-auth
template:
metadata:
labels:
app: http-ext-auth
spec:
containers:
- name: http-ext-auth
command:
- node
- /usr/src/app/http-ext-auth.js
image: node:19-bullseye
ports:
- containerPort: 9002
volumeMounts:
- name: http-ext-auth
mountPath: /usr/src/app
readinessProbe:
httpGet:
httpHeaders:
- name: authorization
value: "Bearer token1"
port: 9002
volumes:
- name: http-ext-auth
configMap:
name: http-ext-auth
---
apiVersion: v1
kind: Service
metadata:
name: http-ext-auth
namespace: gateway-conformance-infra
spec:
selector:
app: http-ext-auth
ports:
- protocol: TCP
port: 9002
targetPort: 9002