@metaplay/metaplay-auth 1.2.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +0 -42
- package/dist/index.js +395 -48
- package/dist/index.js.map +1 -1
- package/dist/src/auth.js +46 -8
- package/dist/src/auth.js.map +1 -1
- package/dist/src/deployment.js +72 -53
- package/dist/src/deployment.js.map +1 -1
- package/dist/src/stackapi.js +170 -17
- package/dist/src/stackapi.js.map +1 -1
- package/dist/src/utils.js +21 -0
- package/dist/src/utils.js.map +1 -1
- package/index.ts +421 -55
- package/package.json +13 -5
- package/src/auth.ts +50 -8
- package/src/deployment.ts +70 -57
- package/src/stackapi.ts +230 -19
- package/src/utils.ts +37 -0
package/dist/src/stackapi.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { isValidFQDN, getGameserverAdminUrl } from './utils.js';
|
|
2
2
|
import { logger } from './logging.js';
|
|
3
|
+
import { dump } from 'js-yaml';
|
|
4
|
+
import { getUserinfo } from './auth.js';
|
|
3
5
|
export class StackAPI {
|
|
4
6
|
accessToken;
|
|
5
|
-
|
|
6
|
-
constructor(accessToken) {
|
|
7
|
+
_stackApiBaseUrl;
|
|
8
|
+
constructor(accessToken, stackApiBaseUrl) {
|
|
7
9
|
if (accessToken == null) {
|
|
8
10
|
throw new Error('accessToken must be provided');
|
|
9
11
|
}
|
|
10
12
|
this.accessToken = accessToken;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
uri = uri.replace(/\/$/, ''); // Remove trailing slash
|
|
18
|
-
this._stack_api_base_uri = uri;
|
|
13
|
+
if (stackApiBaseUrl) {
|
|
14
|
+
this._stackApiBaseUrl = stackApiBaseUrl.replace(/\/$/, ''); // Remove trailing slash
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this._stackApiBaseUrl = 'https://infra.p1.metaplay.io/stackapi';
|
|
18
|
+
}
|
|
19
19
|
}
|
|
20
20
|
async getAwsCredentials(gs) {
|
|
21
21
|
let url = '';
|
|
@@ -25,11 +25,11 @@ export class StackAPI {
|
|
|
25
25
|
url = `https://${adminUrl}/.infra/credentials/aws`;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
url = `${this.
|
|
28
|
+
url = `${this._stackApiBaseUrl}/v0/credentials/${gs.gameserver}/aws`;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
else if (gs.organization != null && gs.project != null && gs.environment != null) {
|
|
32
|
-
url = `${this.
|
|
32
|
+
url = `${this._stackApiBaseUrl}/v1/servers/${gs.organization}/${gs.project}/${gs.environment}/credentials/aws`;
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
throw new Error('Invalid arguments for getAwsCredentials');
|
|
@@ -55,16 +55,169 @@ export class StackAPI {
|
|
|
55
55
|
url = `https://${adminUrl}/.infra/credentials/k8s`;
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
url = `${this.
|
|
58
|
+
url = `${this._stackApiBaseUrl}/v0/credentials/${gs.gameserver}/k8s`;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
else if (gs.organization != null && gs.project != null && gs.environment != null) {
|
|
62
|
-
url = `${this.
|
|
62
|
+
url = `${this._stackApiBaseUrl}/v1/servers/${gs.organization}/${gs.project}/${gs.environment}/credentials/k8s`;
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
throw new Error('Invalid arguments for getKubeConfig');
|
|
66
66
|
}
|
|
67
67
|
logger.debug(`Getting KubeConfig from ${url}...`);
|
|
68
|
+
let response;
|
|
69
|
+
try {
|
|
70
|
+
response = await fetch(url, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
74
|
+
'Content-Type': 'application/json'
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
logger.error(`Failed to fetch kubeconfig from ${url}`);
|
|
80
|
+
logger.error('Fetch error details:', error);
|
|
81
|
+
if (error.cause?.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
|
|
82
|
+
throw new Error(`Failed to to fetch kubeconfig: SSL certificate validation failed for ${url}. Is someone trying to tamper with your internet connection?`);
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`Failed to fetch kubeconfig from ${url}: ${error}`);
|
|
85
|
+
}
|
|
86
|
+
if (response.status !== 200) {
|
|
87
|
+
throw new Error(`Failed to fetch KubeConfigs: ${response.statusText}`);
|
|
88
|
+
}
|
|
89
|
+
return await response.text();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get a `kubeconfig` payload which invokes `metaplay-auth get-kubernetes-execcredential` to get the actual
|
|
93
|
+
* access credentials each time the kubeconfig is used.
|
|
94
|
+
* @param gs Game server environment to get credentials for.
|
|
95
|
+
* @returns The kubeconfig YAML.
|
|
96
|
+
*/
|
|
97
|
+
async getKubeConfigExecCredential(gs) {
|
|
98
|
+
let url = '';
|
|
99
|
+
let gsSlug = '';
|
|
100
|
+
const execArgs = ['get-kubernetes-execcredential'];
|
|
101
|
+
if (gs.gameserver != null) {
|
|
102
|
+
const adminUrl = getGameserverAdminUrl(gs.gameserver);
|
|
103
|
+
url = `https://${adminUrl}/.infra/credentials/k8s?type=execcredential`;
|
|
104
|
+
gsSlug = gs.gameserver;
|
|
105
|
+
execArgs.push('--gameserver', gs.gameserver);
|
|
106
|
+
}
|
|
107
|
+
else if (gs.organization != null && gs.project != null && gs.environment != null) {
|
|
108
|
+
url = `${this._stackApiBaseUrl}/v1/servers/${gs.organization}/${gs.project}/${gs.environment}/credentials/k8s?type=execcredential`;
|
|
109
|
+
gsSlug = `${gs.organization}.${gs.project}.${gs.environment}`;
|
|
110
|
+
execArgs.push(`${gs.organization}-${gs.project}-${gs.environment}`);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
throw new Error('Invalid arguments for getKubeConfigExecCredential');
|
|
114
|
+
}
|
|
115
|
+
logger.debug(`Getting Kubernetes KubeConfig from ${url}...`);
|
|
116
|
+
let response;
|
|
117
|
+
try {
|
|
118
|
+
response = await fetch(url, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: {
|
|
121
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
122
|
+
'Content-Type': 'application/json'
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
logger.error(`Failed to fetch kubeconfig from ${url}`);
|
|
128
|
+
logger.error('Fetch error details:', error);
|
|
129
|
+
if (error.cause?.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
|
|
130
|
+
throw new Error(`Failed to to fetch kubeconfig: SSL certificate validation failed for ${url}. Is someone trying to tamper with your internet connection?`);
|
|
131
|
+
}
|
|
132
|
+
throw new Error(`Failed to fetch kubeconfig from ${url}: ${error}`);
|
|
133
|
+
}
|
|
134
|
+
if (response.status !== 200) {
|
|
135
|
+
throw new Error(`Failed to fetch Kubernetes KubeConfig: ${response.statusText}`);
|
|
136
|
+
}
|
|
137
|
+
// get the execcredential and morph it into a kubeconfig which calls metaplay-auth for the token
|
|
138
|
+
let kubeExecCredential;
|
|
139
|
+
try {
|
|
140
|
+
kubeExecCredential = await response.json();
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
throw new Error('Failed to fetch Kubernetes KubeConfig: the server response is not JSON');
|
|
144
|
+
}
|
|
145
|
+
if (!kubeExecCredential.spec.cluster) {
|
|
146
|
+
throw new Error('Received kubeExecCredential with missing spec.cluster');
|
|
147
|
+
}
|
|
148
|
+
let namespace = 'default';
|
|
149
|
+
let user = 'user';
|
|
150
|
+
try {
|
|
151
|
+
const environment = await this.getEnvironmentDetails(gs);
|
|
152
|
+
namespace = environment.deployment?.kubernetes_namespace ?? namespace;
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
logger.debug('Failed to get environment details, using defaults', e);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const userinfo = await getUserinfo(this.accessToken);
|
|
159
|
+
user = userinfo.sub ?? user;
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
logger.debug('Failed to get userinfo, using defaults', e);
|
|
163
|
+
}
|
|
164
|
+
const kubeConfig = {
|
|
165
|
+
apiVersion: 'v1',
|
|
166
|
+
kind: 'Config',
|
|
167
|
+
'current-context': gsSlug,
|
|
168
|
+
clusters: [
|
|
169
|
+
{
|
|
170
|
+
cluster: {
|
|
171
|
+
'certificate-authority-data': kubeExecCredential.spec.cluster.certificateAuthorityData,
|
|
172
|
+
server: kubeExecCredential.spec.cluster.server
|
|
173
|
+
},
|
|
174
|
+
name: kubeExecCredential.spec.cluster.server
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
contexts: [
|
|
178
|
+
{
|
|
179
|
+
context: {
|
|
180
|
+
cluster: kubeExecCredential.spec.cluster.server,
|
|
181
|
+
namespace,
|
|
182
|
+
user
|
|
183
|
+
},
|
|
184
|
+
name: gsSlug,
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
users: [
|
|
188
|
+
{
|
|
189
|
+
name: user,
|
|
190
|
+
user: {
|
|
191
|
+
exec: {
|
|
192
|
+
apiVersion: 'client.authentication.k8s.io/v1beta1',
|
|
193
|
+
command: 'metaplay-auth',
|
|
194
|
+
args: execArgs,
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
};
|
|
200
|
+
// return as yaml for easier consumption
|
|
201
|
+
return dump(kubeConfig);
|
|
202
|
+
}
|
|
203
|
+
async getKubeExecCredential(gs) {
|
|
204
|
+
let url = '';
|
|
205
|
+
if (gs.gameserver != null) {
|
|
206
|
+
if (isValidFQDN(gs.gameserver)) {
|
|
207
|
+
const adminUrl = getGameserverAdminUrl(gs.gameserver);
|
|
208
|
+
url = `https://${adminUrl}/.infra/credentials/k8s?type=execcredential`;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
url = `${this._stackApiBaseUrl}/v0/credentials/${gs.gameserver}/k8s?type=execcredential`;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else if (gs.organization != null && gs.project != null && gs.environment != null) {
|
|
215
|
+
url = `${this._stackApiBaseUrl}/v1/servers/${gs.organization}/${gs.project}/${gs.environment}/credentials/k8s?type=execcredential`;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
throw new Error('Invalid arguments for getKubeConfig');
|
|
219
|
+
}
|
|
220
|
+
logger.debug(`Getting Kubernetes ExecCredential from ${url}...`);
|
|
68
221
|
const response = await fetch(url, {
|
|
69
222
|
method: 'POST',
|
|
70
223
|
headers: {
|
|
@@ -73,7 +226,7 @@ export class StackAPI {
|
|
|
73
226
|
}
|
|
74
227
|
});
|
|
75
228
|
if (response.status !== 200) {
|
|
76
|
-
throw new Error(`Failed to fetch
|
|
229
|
+
throw new Error(`Failed to fetch Kubernetes ExecCredential: ${response.statusText}`);
|
|
77
230
|
}
|
|
78
231
|
return await response.text();
|
|
79
232
|
}
|
|
@@ -85,11 +238,11 @@ export class StackAPI {
|
|
|
85
238
|
url = `https://${adminUrl}/.infra/environment`;
|
|
86
239
|
}
|
|
87
240
|
else {
|
|
88
|
-
url = `${this.
|
|
241
|
+
url = `${this._stackApiBaseUrl}/v0/deployments/${gs.gameserver}`;
|
|
89
242
|
}
|
|
90
243
|
}
|
|
91
244
|
else if (gs.organization != null && gs.project != null && gs.environment != null) {
|
|
92
|
-
url = `${this.
|
|
245
|
+
url = `${this._stackApiBaseUrl}/v1/servers/${gs.organization}/${gs.project}/${gs.environment}`;
|
|
93
246
|
}
|
|
94
247
|
else {
|
|
95
248
|
throw new Error('Invalid arguments for environment details');
|
package/dist/src/stackapi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stackapi.js","sourceRoot":"","sources":["../../src/stackapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"stackapi.js","sourceRoot":"","sources":["../../src/stackapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAsEvC,MAAM,OAAO,QAAQ;IACF,WAAW,CAAQ;IAEnB,gBAAgB,CAAQ;IAEzC,YAAa,WAAmB,EAAE,eAAmC;QACnE,IAAI,WAAW,IAAI,IAAI,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;SAChD;QAED,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAE9B,IAAI,eAAe,EAAE;YACnB,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA,CAAC,wBAAwB;SACpF;aAAM;YACL,IAAI,CAAC,gBAAgB,GAAG,uCAAuC,CAAA;SAChE;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAE,EAAgB;QACvC,IAAI,GAAG,GAAG,EAAE,CAAA;QACZ,IAAI,EAAE,CAAC,UAAU,IAAI,IAAI,EAAE;YACzB,IAAI,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE;gBAC9B,MAAM,QAAQ,GAAG,qBAAqB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAA;gBACrD,GAAG,GAAG,WAAW,QAAQ,yBAAyB,CAAA;aACnD;iBAAM;gBACL,GAAG,GAAG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C;iBAAM;gBACL,GAAG,GAAG,GAAG,IAAI,CAAC,gBAAgB,mBAAmB,EAAE,CAAC,UAAU,EAAE,CAAA;aACjE;SACF;aAAM,IAAI,EAAE,CAAC,YAAY,IAAI,IAAI,IAAI,EAAE,CAAC,OAAO,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,IAAI,IAAI,EAAE;YAClF,GAAG,GAAG,GAAG,IAAI,CAAC,gBAAgB,eAAe,EAAE,CAAC,YAAY,IAAI,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;SAC/F;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;SAC7D;QAED,MAAM,CAAC,KAAK,CAAC,oCAAoC,GAAG,KAAK,CAAC,CAAA;QAC1D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;gBAC3C,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAA;QAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,wCAAwC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;SAC/E;QAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC9B,CAAC;CACF"}
|
package/dist/src/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
1
2
|
export function stackApiBaseFromOptions(arg, options) {
|
|
2
3
|
return '';
|
|
3
4
|
}
|
|
@@ -38,4 +39,24 @@ export function getGameserverAdminUrl(uri) {
|
|
|
38
39
|
const domain = uri.substring(hostname.length + 1);
|
|
39
40
|
return `${hostname}-admin.${domain}`;
|
|
40
41
|
}
|
|
42
|
+
export async function executeCommand(command, args) {
|
|
43
|
+
return await new Promise((resolve, reject) => {
|
|
44
|
+
const childProcess = spawn(command, args); //, { stdio: 'inherit' }) -- this pipes stdout & stderr to our output
|
|
45
|
+
let stdout = [];
|
|
46
|
+
let stderr = [];
|
|
47
|
+
childProcess.stdout?.on('data', (data) => {
|
|
48
|
+
stdout += data;
|
|
49
|
+
});
|
|
50
|
+
childProcess.stderr?.on('data', (data) => {
|
|
51
|
+
stderr += data;
|
|
52
|
+
});
|
|
53
|
+
// If program runs to completion, resolve promise with success
|
|
54
|
+
childProcess.on('close', (code) => {
|
|
55
|
+
resolve({ code, stdout, stderr });
|
|
56
|
+
});
|
|
57
|
+
childProcess.on('error', (err) => {
|
|
58
|
+
reject(new Error(`Failed to execute command '${command} ${args.join(' ')}': ${err.message}`));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
41
62
|
//# sourceMappingURL=utils.js.map
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,uBAAuB,CAAE,GAAW,EAAE,OAA4B;IAChF,OAAO,EAAE,CAAA;AACX,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAE,MAAc;IACzC,MAAM,SAAS,GAAG,+EAA+E,CAAA;IAEjG,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAE,SAAiB;IACnD,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;QAE9B,oEAAoE;QACpE,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA,CAAC,2BAA2B;QACpE,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAA;QAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IA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