Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displays the current authentication mechanism in the admin panel #981

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions app/client/ui/AdminPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ export class AdminPanel extends Disposable {
value: this._buildSandboxingDisplay(owner),
expandedContent: this._buildSandboxingNotice(),
}),
dom.create(AdminSectionItem, {
id: 'authentication',
name: t('Authentication'),
description: t('Current authentication method'),
value: this._buildAuthenticationDisplay(owner),
expandedContent: this._buildAuthenticationNotice(owner),
})
]),

dom.create(AdminSection, t('Version'), [
Expand Down Expand Up @@ -156,6 +163,37 @@ isolated from other documents and isolated from the network.'),
];
}

private _buildAuthenticationDisplay(owner: IDisposableOwner) {
return dom.domComputed(
use => {
const req = this._checks.requestCheckById(use, 'authentication');
const result = req ? use(req.result) : undefined;
if (!result) {
return cssValueLabel(cssErrorText('unavailable'));
}

const { success, details } = result;
const loginSystemId = details?.loginSystemId;

if (!success || !loginSystemId) {
return cssValueLabel(cssErrorText('auth error'));
}

if (loginSystemId === 'no-logins') {
return cssValueLabel(cssDangerText('no authentication'));
}

return cssValueLabel(cssHappyText(loginSystemId));
}
);
}

private _buildAuthenticationNotice(owner: IDisposableOwner) {
return t('Grist allows different types of authentication to be configured, including SAML and OIDC. \
We recommend enabling one of these if Grist is accessible over the network or being made available \
to multiple people.');
}

private _buildUpdates(owner: MultiHolder) {
// We can be in those states:
enum State {
Expand Down Expand Up @@ -446,6 +484,10 @@ const cssErrorText = styled('span', `
color: ${theme.errorText};
`);

export const cssDangerText = styled('div', `
color: ${theme.dangerText};
`);

const cssHappyText = styled('span', `
color: ${theme.controlFg};
`);
1 change: 1 addition & 0 deletions app/client/ui/AdminPanelCss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const cssItemName = styled('div', `
font-weight: bold;
display: flex;
align-items: center;
margin-right: 14px;
font-size: ${vars.largeFontSize};
padding-left: 24px;
&-prefixed {
Expand Down
3 changes: 2 additions & 1 deletion app/common/BootProbe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export type BootProbeIds =
'reachable' |
'host-header' |
'sandboxing' |
'system-user'
'system-user' |
'authentication'
;

export interface BootProbeResult {
Expand Down
15 changes: 15 additions & 0 deletions app/server/lib/BootProbes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class BootProbes {
this._probes.push(_bootProbe);
this._probes.push(_hostHeaderProbe);
this._probes.push(_sandboxingProbe);
this._probes.push(_authenticationProbe);
this._probeById = new Map(this._probes.map(p => [p.id, p]));
}
}
Expand Down Expand Up @@ -202,3 +203,17 @@ const _sandboxingProbe: Probe = {
};
},
};

const _authenticationProbe: Probe = {
id: 'authentication',
name: 'Authentication system',
apply: async(server, req) => {
const loginSystemId = server.getInfo('loginMiddlewareComment');
return {
success: loginSystemId != undefined,
details: {
loginSystemId,
}
};
},
};
5 changes: 5 additions & 0 deletions app/server/lib/FlexServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,11 @@ export class FlexServer implements GristServer {
return this._sandboxInfo;
}

public getInfo(key: string): any {
const infoPair = this.info.find(([keyToCheck]) => key === keyToCheck);
return infoPair?.[1];
}

public disableExternalStorage() {
if (this.deps.has('doc')) {
throw new Error('disableExternalStorage called too late');
Expand Down
2 changes: 2 additions & 0 deletions app/server/lib/GristServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface GristServer {
getBundledWidgets(): ICustomWidget[];
hasBoot(): boolean;
getSandboxInfo(): SandboxInfo|undefined;
getInfo(key: string): any;
}

export interface GristLoginSystem {
Expand Down Expand Up @@ -157,6 +158,7 @@ export function createDummyGristServer(): GristServer {
getBundledWidgets() { return []; },
hasBoot() { return false; },
getSandboxInfo() { return undefined; },
getInfo(key: string) { return undefined; }
};
}

Expand Down
Loading