Skip to content

Commit

Permalink
Fix login pop up when requesting bootstrap.js (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyan-amazon authored Oct 7, 2020
1 parent 652746e commit 29596f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 11 additions & 5 deletions server/auth/types/authentication_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ export abstract class AuthenticationType implements IAuthenticationType {
}

public authHandler: AuthenticationHandler = async (request, response, toolkit) => {
// allow access to assets
if (request.url.pathname && request.url.pathname.startsWith('/bundles/')) {
return toolkit.authenticated();
}

// skip auth for APIs that do not require auth
if (this.authNotRequired(request)) {
return toolkit.authenticated();
Expand Down Expand Up @@ -119,6 +114,14 @@ export abstract class AuthenticationType implements IAuthenticationType {
if (!cookie || !(await this.isValidCookie(cookie))) {
// clear cookie
this.sessionStorageFactory.asScoped(request).clear();

// for assets, we can still pass it to resource handler as notHandled.
// marking it as authenticated may result in login pop up when auth challenge
// is enabled.
if (request.url.pathname && request.url.pathname.startsWith('/bundles/')) {
return toolkit.notHandled();
}

// send to auth workflow
return this.handleUnauthedRequest(request, response, toolkit);
}
Expand Down Expand Up @@ -157,6 +160,9 @@ export abstract class AuthenticationType implements IAuthenticationType {
} catch (error) {
this.logger.error(`Failed to resolve user tenant: ${error}`);
if (error instanceof UnauthenticatedError) {
if (request.url.pathname && request.url.pathname.startsWith('/bundles/')) {
return toolkit.notHandled();
}
return this.handleUnauthedRequest(request, response, toolkit);
}
throw error;
Expand Down
2 changes: 2 additions & 0 deletions server/multitenancy/tenant_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export function isMultitenantPath(request: KibanaRequest): boolean {
request.url.pathname?.startsWith('/elasticsearch') ||
request.url.pathname?.startsWith('/api') ||
request.url.pathname?.startsWith('/app') ||
// bootstrap.js depends on tenant info to fetch kibana configs in tenant index
(request.url.pathname?.indexOf('bootstrap.js') || -1) > -1 ||
request.url.pathname === '/'
);
}
Expand Down

0 comments on commit 29596f0

Please sign in to comment.