Skip to content

Commit 4109208

Browse files
authored
Return Generated Console Credentials (#217)
Whe Console is configured, we auto generate credentials for Console and store them in a secret but we need to return them to the user so he knows what credentials he/she can use to log in to console.
1 parent 3ffaece commit 4109208

File tree

4 files changed

+136
-20
lines changed

4 files changed

+136
-20
lines changed

models/create_tenant_response.go

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

restapi/admin_tenants.go

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ func listTenants(ctx context.Context, operatorClient OperatorClient, namespace s
254254
}
255255

256256
var tenants []*models.TenantList
257-
var totalSize int64
258257

259-
for _, minInst := range minTenants.Items {
258+
for _, tenant := range minTenants.Items {
259+
var totalSize int64
260260
var instanceCount int64
261261
var volumeCount int64
262-
for _, zone := range minInst.Spec.Zones {
262+
for _, zone := range tenant.Spec.Zones {
263263
instanceCount = instanceCount + int64(zone.Servers)
264264
volumeCount = volumeCount + int64(zone.Servers*zone.VolumesPerServer)
265265
if zone.VolumeClaimTemplate != nil {
@@ -269,20 +269,20 @@ func listTenants(ctx context.Context, operatorClient OperatorClient, namespace s
269269
}
270270

271271
tenants = append(tenants, &models.TenantList{
272-
CreationDate: minInst.ObjectMeta.CreationTimestamp.String(),
273-
Name: minInst.ObjectMeta.Name,
274-
ZoneCount: int64(len(minInst.Spec.Zones)),
272+
CreationDate: tenant.ObjectMeta.CreationTimestamp.String(),
273+
Name: tenant.ObjectMeta.Name,
274+
ZoneCount: int64(len(tenant.Spec.Zones)),
275275
InstanceCount: instanceCount,
276276
VolumeCount: volumeCount,
277-
CurrentState: minInst.Status.CurrentState,
278-
Namespace: minInst.ObjectMeta.Namespace,
277+
CurrentState: tenant.Status.CurrentState,
278+
Namespace: tenant.ObjectMeta.Namespace,
279279
TotalSize: totalSize,
280280
})
281281
}
282282

283283
return &models.ListTenantsResponse{
284284
Tenants: tenants,
285-
Total: 0,
285+
Total: int64(len(tenants)),
286286
}, nil
287287
}
288288

@@ -332,6 +332,13 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
332332
}
333333
minioImage = *minImg
334334
}
335+
// get Kubernetes Client
336+
clientset, err := cluster.K8sClient(session.SessionToken)
337+
if err != nil {
338+
return nil, err
339+
}
340+
341+
ns := *params.Body.Namespace
335342

336343
// if access/secret are provided, use them, else create a random pair
337344
accessKey := RandomCharString(16)
@@ -355,11 +362,6 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
355362
},
356363
}
357364

358-
clientset, err := cluster.K8sClient(session.SessionToken)
359-
if err != nil {
360-
return nil, err
361-
}
362-
ns := *params.Body.Namespace
363365
_, err = clientset.CoreV1().Secrets(ns).Create(context.Background(), &instanceSecret, metav1.CreateOptions{})
364366
if err != nil {
365367
return nil, err
@@ -389,10 +391,13 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
389391
},
390392
}
391393
// optionals are set below
392-
394+
var consoleAccess string
395+
var consoleSecret string
393396
if enableConsole {
394397
consoleSelector := fmt.Sprintf("%s-console", *params.Body.Name)
395398
consoleSecretName := fmt.Sprintf("%s-secret", consoleSelector)
399+
consoleAccess = RandomCharString(16)
400+
consoleSecret = RandomCharString(32)
396401
imm := true
397402
instanceSecret := corev1.Secret{
398403
ObjectMeta: metav1.ObjectMeta{
@@ -403,8 +408,8 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
403408
"CONSOLE_HMAC_JWT_SECRET": []byte(RandomCharString(16)),
404409
"CONSOLE_PBKDF_PASSPHRASE": []byte(RandomCharString(16)),
405410
"CONSOLE_PBKDF_SALT": []byte(RandomCharString(8)),
406-
"CONSOLE_ACCESS_KEY": []byte(RandomCharString(16)),
407-
"CONSOLE_SECRET_KEY": []byte(RandomCharString(32)),
411+
"CONSOLE_ACCESS_KEY": []byte(consoleAccess),
412+
"CONSOLE_SECRET_KEY": []byte(consoleSecret),
408413
},
409414
}
410415
_, err = clientset.CoreV1().Secrets(ns).Create(context.Background(), &instanceSecret, metav1.CreateOptions{})
@@ -462,11 +467,16 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
462467
return nil, err
463468
}
464469
}
465-
466-
return &models.CreateTenantResponse{
470+
response := &models.CreateTenantResponse{
467471
AccessKey: accessKey,
468472
SecretKey: secretKey,
469-
}, nil
473+
}
474+
// Attach Console Credentials
475+
if enableConsole {
476+
response.Console.AccessKey = consoleAccess
477+
response.Console.SecretKey = consoleSecret
478+
}
479+
return response, nil
470480
}
471481

472482
// updateTenantAction does an update on the minioTenant by patching the desired changes

restapi/embedded_spec.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,13 @@ definitions:
18171817
type: string
18181818
secret_key:
18191819
type: string
1820+
console:
1821+
type: object
1822+
properties:
1823+
access_key:
1824+
type: string
1825+
secret_key:
1826+
type: string
18201827
zone:
18211828
type: object
18221829
required:

0 commit comments

Comments
 (0)