From a8e3d616ff173ae3efa9b1a63433cd60746667f0 Mon Sep 17 00:00:00 2001 From: Shu Muto Date: Thu, 20 Feb 2020 22:07:03 +0900 Subject: [PATCH] Set default login mode to first authentication-mode option (#4921) * Set default login mode to first authentication-mode option authentication-mode options specified in backend, i.e. `token` (default), `basic` or both, are retrieved from frontend, and login mode selections are set in order of the options specified. But `Kubeconfig` is set as default in frontend for now. This commit enables to set default selection by operator's specification of authentication-mode. * Simplify logic * Fix test Co-authored-by: Sebastian Florek --- docs/common/dashboard-arguments.md | 2 +- src/app/frontend/login/component.spec.ts | 2 +- src/app/frontend/login/component.ts | 10 ++-------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/common/dashboard-arguments.md b/docs/common/dashboard-arguments.md index ccc8c6c53..cc56a0fb5 100644 --- a/docs/common/dashboard-arguments.md +++ b/docs/common/dashboard-arguments.md @@ -23,7 +23,7 @@ Dashboard container accepts multiple arguments that can be used to customize it | kubeconfig | - | Path to kubeconfig file with authorization and master location information. | | namespace | kube-system | When non-default namespace is used, create encryption key in the specified namespace. | | token-ttl | 900 | Expiration time (in seconds) of JWE tokens generated by dashboard. '0' never expires. -| authentication-mode | token | Enables authentication options that will be reflected on login screen. Supported values: token, basic. Note that basic option should only be used if apiserver has '--authorization-mode=ABAC' and '--basic-auth-file' flags set. | +| authentication-mode | token | Enables authentication options that will be reflected on the login screen in the same order as provided. Multiple options can be used at once. Supported values: token, basic. Note that basic option should only be used if apiserver has '--authorization-mode=ABAC' and '--basic-auth-file' flags set. | | enable-insecure-login | false | When enabled, Dashboard login view will also be shown when Dashboard is not served over HTTPS. | | enable-skip-login | false | When enabled, the skip button on the login page will be shown. | | disable-settings-authorizer | false | When enabled, Dashboard settings page will not require user to be logged in and authorized to access settings page. | diff --git a/src/app/frontend/login/component.spec.ts b/src/app/frontend/login/component.spec.ts index 0e9f90626..0d913d44c 100644 --- a/src/app/frontend/login/component.spec.ts +++ b/src/app/frontend/login/component.spec.ts @@ -138,7 +138,7 @@ describe('LoginComponent', () => { const req = httpTestingController.expectOne('api/v1/login/modes'); req.flush(mockEnabledAuthenticationModes); fixture.detectChanges(); - expect(fixture.debugElement.queryAll(By.css('mat-radio-button')).length).toEqual(5); + expect(fixture.debugElement.queryAll(By.css('mat-radio-button')).length).toEqual(6); }); it('renders skip button if login is skippable', () => { diff --git a/src/app/frontend/login/component.ts b/src/app/frontend/login/component.ts index 27db06dda..5ce2cf6e0 100644 --- a/src/app/frontend/login/component.ts +++ b/src/app/frontend/login/component.ts @@ -65,6 +65,8 @@ export class LoginComponent implements OnInit { .get('api/v1/login/modes') .subscribe((enabledModes: EnabledAuthenticationModes) => { this.enabledAuthenticationModes_ = enabledModes.modes; + this.enabledAuthenticationModes_.push(LoginModes.Kubeconfig); + this.selectedAuthenticationMode = this.enabledAuthenticationModes_[0] as LoginModes; }); this.http_ @@ -81,14 +83,6 @@ export class LoginComponent implements OnInit { } getEnabledAuthenticationModes(): AuthenticationMode[] { - if ( - this.enabledAuthenticationModes_.length > 0 && - this.enabledAuthenticationModes_.indexOf(LoginModes.Kubeconfig) < 0 - ) { - // Push this option to the beginning of the list - this.enabledAuthenticationModes_.splice(0, 0, LoginModes.Kubeconfig); - } - return this.enabledAuthenticationModes_; } -- GitLab