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

Auth: Allow admins to manually change external user's role if oauth_skip_org_role_update_sync or saml skip_org_role_sync is enabled #55182

Merged
merged 5 commits into from Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .betterer.results
Expand Up @@ -1028,7 +1028,7 @@ exports[`better eslint`] = {
],
"packages/grafana-runtime/src/config.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Do not use any type assertions.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
],
Expand Down
5 changes: 5 additions & 0 deletions packages/grafana-data/src/types/config.ts
Expand Up @@ -153,6 +153,7 @@ export interface GrafanaConfig {
isPublicDashboardView: boolean;
datasources: { [str: string]: DataSourceInstanceSettings };
panels: { [key: string]: PanelPluginMeta };
auth: AuthSettings;
minRefreshInterval: string;
appSubUrl: string;
windowTitlePrefix: string;
Expand Down Expand Up @@ -214,3 +215,7 @@ export interface GrafanaConfig {
rudderstackSdkUrl: string | undefined;
rudderstackConfigUrl: string | undefined;
}

export interface AuthSettings {
OAuthSkipOrgRoleUpdateSync?: boolean;
}
4 changes: 3 additions & 1 deletion packages/grafana-runtime/src/config.ts
@@ -1,6 +1,7 @@
import { merge } from 'lodash';

import {
AuthSettings,
BootData,
BuildInfo,
createTheme,
Expand All @@ -27,6 +28,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
isPublicDashboardView: boolean;
datasources: { [str: string]: DataSourceInstanceSettings } = {};
panels: { [key: string]: PanelPluginMeta } = {};
auth: AuthSettings = {} as AuthSettings;
gamab marked this conversation as resolved.
Show resolved Hide resolved
minRefreshInterval = '';
appUrl = '';
appSubUrl = '';
Expand Down Expand Up @@ -107,7 +109,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
pluginAdminExternalManageEnabled = false;
pluginCatalogHiddenPlugins: string[] = [];
expressionsEnabled = false;
customTheme?: any;
customTheme?: undefined;
Jguer marked this conversation as resolved.
Show resolved Hide resolved
awsAllowedAuthProviders: string[] = [];
awsAssumeRoleEnabled = false;
azure: AzureSettings = {
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/frontendsettings.go
Expand Up @@ -136,6 +136,8 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i
"editorsCanAdmin": hs.Cfg.EditorsCanAdmin,
"disableSanitizeHtml": hs.Cfg.DisableSanitizeHtml,
"pluginsToPreload": pluginsToPreload,
"auth": map[string]interface{}{
"OAuthSkipOrgRoleUpdateSync": hs.Cfg.OAuthSkipOrgRoleUpdateSync},
"buildInfo": map[string]interface{}{
"hideVersion": hideVersion,
"version": version,
Expand Down
10 changes: 9 additions & 1 deletion public/app/features/admin/UserAdminPage.tsx
Expand Up @@ -4,6 +4,7 @@ import { connect, ConnectedProps } from 'react-redux';
import { NavModelItem } from '@grafana/data';
import { featureEnabled } from '@grafana/runtime';
import { Page } from 'app/core/components/Page/Page';
import config from 'app/core/config';
import { contextSrv } from 'app/core/core';
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
import { StoreState, UserDTO, UserOrg, UserSession, SyncInfo, UserAdminError, AccessControlAction } from 'app/types';
Expand Down Expand Up @@ -38,6 +39,8 @@ interface OwnProps extends GrafanaRouteComponentProps<{ id: string }> {
error?: UserAdminError;
}

const SyncedOAuthLabels: string[] = ['GitHub', 'GitLab', 'AzureAD', 'OAuth'];

export class UserAdminPage extends PureComponent<Props> {
async componentDidMount() {
const { match, loadAdminUserPage } = this.props;
Expand Down Expand Up @@ -105,6 +108,11 @@ export class UserAdminPage extends PureComponent<Props> {
const isLDAPUser = user && user.isExternal && user.authLabels && user.authLabels.includes('LDAP');
const canReadSessions = contextSrv.hasPermission(AccessControlAction.UsersAuthTokenList);
const canReadLDAPStatus = contextSrv.hasPermission(AccessControlAction.LDAPStatusRead);
const isOAuthUserWithSkippableSync =
user && user.isExternal && user.authLabels && user.authLabels.some((r) => SyncedOAuthLabels.includes(r));
gamab marked this conversation as resolved.
Show resolved Hide resolved
const isUserSynced =
(user?.isExternal && !isOAuthUserWithSkippableSync) ||
(!config.auth.OAuthSkipOrgRoleUpdateSync && isOAuthUserWithSkippableSync);

const pageNav: NavModelItem = {
text: user?.login ?? '',
Expand Down Expand Up @@ -137,7 +145,7 @@ export class UserAdminPage extends PureComponent<Props> {
<UserOrgs
user={user}
orgs={orgs}
isExternalUser={user?.isExternal}
isExternalUser={isUserSynced}
onOrgRemove={this.onOrgRemove}
onOrgRoleChange={this.onOrgRoleChange}
onOrgAdd={this.onOrgAdd}
Expand Down