From c64b815386d9b7b89c69fb7e8387c7b7b7cf408c Mon Sep 17 00:00:00 2001 From: Ernesto Puerta Date: Fri, 5 Apr 2019 18:22:30 +0200 Subject: [PATCH] mgr/dashboard: Add whitelist to guard After PR https://github.com/ceph/ceph/pull/26572, when RGW is not configured, accessing /rgw drop-down (daemons, users or buckets) results in nothing apparently happening (not even an error). Under the curtains, what is happening is that the ModuleStatusGuard has redirected the route to the rgw/501, but as this route is now under parent rgw route handler, which sets CanActivateChild guards, this results in a new ModuleStatusGuard invokation, a subsequent failure and a new redirection to rgw/501. Several approaches could be taken here: - Remove error pages from lazy-loaded modules. Probably it does not make sense to have a 501 page per component. - Add some whitelist to avoid this kind of loop (e.g.: 501, or any error page). - Set a max number of redirections (cautionary measure). Fixes: https://tracker.ceph.com/issues/39125 Signed-off-by: Ernesto Puerta --- .../app/shared/services/module-status-guard.service.spec.ts | 1 + .../src/app/shared/services/module-status-guard.service.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts index 2528826783c..9912d67bea5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.spec.ts @@ -53,6 +53,7 @@ describe('ModuleStatusGuardService', () => { httpClient = TestBed.get(HttpClient); router = TestBed.get(Router); route = new ActivatedRouteSnapshot(); + route.url = []; route.data = { moduleStatusGuardConfig: { apiPath: 'bar', diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.ts index f37024ea63c..98c4b490a70 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/module-status-guard.service.ts @@ -36,6 +36,9 @@ import { ServicesModule } from './services.module'; providedIn: ServicesModule }) export class ModuleStatusGuardService implements CanActivate, CanActivateChild { + // TODO: Hotfix - remove WHITELIST'ing when a generic ErrorComponent is implemented + static readonly WHITELIST: string[] = ['501']; + constructor(private http: HttpClient, private router: Router) {} canActivate(route: ActivatedRouteSnapshot) { @@ -47,6 +50,9 @@ export class ModuleStatusGuardService implements CanActivate, CanActivateChild { } private doCheck(route: ActivatedRouteSnapshot) { + if (route.url.length > 0 && ModuleStatusGuardService.WHITELIST.includes(route.url[0].path)) { + return observableOf(true); + } const config = route.data['moduleStatusGuardConfig']; return this.http.get(`/api/${config.apiPath}/status`).pipe( map((resp: any) => { -- 2.39.5