From: Ernesto Puerta Date: Fri, 5 Apr 2019 16:22:30 +0000 (+0200) Subject: mgr/dashboard: Add whitelist to guard X-Git-Tag: v14.2.1~42^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0eca5e812052ec749bac9fa91f2e76bb5346fbd5;p=ceph.git 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 (cherry picked from commit c64b815386d9b7b89c69fb7e8387c7b7b7cf408c) Signed-off-by: Ernesto Puerta --- 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 2528826783c25..9912d67bea5e4 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 f37024ea63c34..98c4b490a7039 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) => {