Skip to content

Commit

Permalink
[server]: move the admin telemetry settings out of EE
Browse files Browse the repository at this point in the history
This also moves the `guardAdminAccess` method out of EE. Whilst
this may seem controversial, it is likely that we're going to
be opening up more admin-only dashboard functionality for self-hosted
installation management.
  • Loading branch information
Simon Emms committed Jan 25, 2022
1 parent f11ddae commit fa64af9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
29 changes: 1 addition & 28 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { injectable, inject } from "inversify";
import { GitpodServerImpl, traceAPIParams, traceWI, censor } from "../../../src/workspace/gitpod-server-impl";
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
import { GitpodServer, GitpodClient, AdminGetListRequest, User, AdminGetListResult, Permission, AdminBlockUserRequest, AdminModifyRoleOrPermissionRequest, RoleOrPermission, AdminModifyPermanentWorkspaceFeatureFlagRequest, UserFeatureSettings, AdminGetWorkspacesRequest, WorkspaceAndInstance, GetWorkspaceTimeoutResult, WorkspaceTimeoutDuration, WorkspaceTimeoutValues, SetWorkspaceTimeoutResult, WorkspaceContext, CreateWorkspaceMode, WorkspaceCreationResult, PrebuiltWorkspaceContext, CommitContext, PrebuiltWorkspace, PermissionName, WorkspaceInstance, EduEmailDomain, ProviderRepository, Queue, PrebuildWithStatus, CreateProjectParams, Project, StartPrebuildResult, ClientHeaderFields, Workspace } from "@gitpod/gitpod-protocol";
import { GitpodServer, GitpodClient, AdminGetListRequest, User, AdminGetListResult, Permission, AdminBlockUserRequest, AdminModifyRoleOrPermissionRequest, RoleOrPermission, AdminModifyPermanentWorkspaceFeatureFlagRequest, UserFeatureSettings, AdminGetWorkspacesRequest, WorkspaceAndInstance, GetWorkspaceTimeoutResult, WorkspaceTimeoutDuration, WorkspaceTimeoutValues, SetWorkspaceTimeoutResult, WorkspaceContext, CreateWorkspaceMode, WorkspaceCreationResult, PrebuiltWorkspaceContext, CommitContext, PrebuiltWorkspace, WorkspaceInstance, EduEmailDomain, ProviderRepository, Queue, PrebuildWithStatus, CreateProjectParams, Project, StartPrebuildResult, ClientHeaderFields, Workspace } from "@gitpod/gitpod-protocol";
import { ResponseError } from "vscode-jsonrpc";
import { TakeSnapshotRequest, AdmissionLevel, ControlAdmissionRequest, StopWorkspacePolicy, DescribeWorkspaceRequest, SetTimeoutRequest } from "@gitpod/ws-manager/lib";
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
Expand Down Expand Up @@ -563,24 +563,6 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
return result;
}

async adminSettingsGetTelemetry(ctx: TraceContext): Promise<boolean> {
traceAPIParams(ctx, {});

await this.guardAdminAccess("adminSettingsGetTelemetry", {}, Permission.ADMIN_API);

const settings = await this.installationAdminDb.getTelemetryData();

return settings.settings.sendTelemetry;
}

async adminSettingsSetTelemetry(ctx: TraceContext, send: boolean): Promise<void> {
traceAPIParams(ctx, {});

await this.guardAdminAccess("adminSettingsGetTelemetry", {}, Permission.ADMIN_API);

await this.installationAdminDb.setSendTelemetry(send);
}

async adminForceStopWorkspace(ctx: TraceContext, workspaceId: string): Promise<void> {
traceAPIParams(ctx, { workspaceId });

Expand Down Expand Up @@ -620,15 +602,6 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
});
}

protected async guardAdminAccess(method: string, params: any, requiredPermission: PermissionName) {
const user = this.checkAndBlockUser(method);
if (!this.authorizationService.hasPermission(user, requiredPermission)) {
log.warn({ userId: this.user?.id }, "unauthorised admin access", { authorised: false, method, params });
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
}
log.info({ userId: this.user?.id }, "admin access", { authorised: true, method, params });
}

protected async findPrebuiltWorkspace(parentCtx: TraceContext, user: User, context: WorkspaceContext, mode: CreateWorkspaceMode): Promise<WorkspaceCreationResult | PrebuiltWorkspaceContext | undefined> {
const ctx = TraceContext.childContext("findPrebuiltWorkspace", parentCtx);

Expand Down
26 changes: 22 additions & 4 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { DownloadUrlRequest, DownloadUrlResponse, UploadUrlRequest, UploadUrlResponse } from '@gitpod/content-service/lib/blobs_pb';
import { AppInstallationDB, UserDB, UserMessageViewsDB, WorkspaceDB, DBWithTracing, TracedWorkspaceDB, DBGitpodToken, DBUser, UserStorageResourcesDB, TeamDB, InstallationAdminDB } from '@gitpod/gitpod-db/lib';
import { AuthProviderEntry, AuthProviderInfo, CommitContext, Configuration, CreateWorkspaceMode, DisposableCollection, GetWorkspaceTimeoutResult, GitpodClient as GitpodApiClient, GitpodServer, GitpodToken, GitpodTokenType, InstallPluginsParams, PermissionName, PortVisibility, PrebuiltWorkspace, PrebuiltWorkspaceContext, PreparePluginUploadParams, ResolvedPlugins, ResolvePluginsParams, SetWorkspaceTimeoutResult, StartPrebuildContext, StartWorkspaceResult, Terms, Token, UninstallPluginParams, User, UserEnvVar, UserEnvVarValue, UserInfo, WhitelistedRepository, Workspace, WorkspaceContext, WorkspaceCreationResult, WorkspaceImageBuild, WorkspaceInfo, WorkspaceInstance, WorkspaceInstancePort, WorkspaceInstanceUser, WorkspaceTimeoutDuration, GuessGitTokenScopesParams, GuessedGitTokenScopes, Team, TeamMemberInfo, TeamMembershipInvite, CreateProjectParams, Project, ProviderRepository, TeamMemberRole, WithDefaultConfig, FindPrebuildsParams, PrebuildWithStatus, StartPrebuildResult, ClientHeaderFields } from '@gitpod/gitpod-protocol';
import { AuthProviderEntry, AuthProviderInfo, CommitContext, Configuration, CreateWorkspaceMode, DisposableCollection, GetWorkspaceTimeoutResult, GitpodClient as GitpodApiClient, GitpodServer, GitpodToken, GitpodTokenType, InstallPluginsParams, PermissionName, PortVisibility, PrebuiltWorkspace, PrebuiltWorkspaceContext, PreparePluginUploadParams, ResolvedPlugins, ResolvePluginsParams, SetWorkspaceTimeoutResult, StartPrebuildContext, StartWorkspaceResult, Terms, Token, UninstallPluginParams, User, UserEnvVar, UserEnvVarValue, UserInfo, WhitelistedRepository, Workspace, WorkspaceContext, WorkspaceCreationResult, WorkspaceImageBuild, WorkspaceInfo, WorkspaceInstance, WorkspaceInstancePort, WorkspaceInstanceUser, WorkspaceTimeoutDuration, GuessGitTokenScopesParams, GuessedGitTokenScopes, Team, TeamMemberInfo, TeamMembershipInvite, CreateProjectParams, Project, ProviderRepository, TeamMemberRole, WithDefaultConfig, FindPrebuildsParams, PrebuildWithStatus, StartPrebuildResult, ClientHeaderFields, Permission } from '@gitpod/gitpod-protocol';
import { AccountStatement } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
import { AdminBlockUserRequest, AdminGetListRequest, AdminGetListResult, AdminGetWorkspacesRequest, AdminModifyPermanentWorkspaceFeatureFlagRequest, AdminModifyRoleOrPermissionRequest, WorkspaceAndInstance } from '@gitpod/gitpod-protocol/lib/admin-protocol';
import { GetLicenseInfoResult, LicenseFeature, LicenseValidationResult } from '@gitpod/gitpod-protocol/lib/license-protocol';
Expand Down Expand Up @@ -565,6 +565,15 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
await this.internalStopWorkspaceInstance(ctx, instance.id, instance.region, policy);
}

protected async guardAdminAccess(method: string, params: any, requiredPermission: PermissionName) {
const user = this.checkAndBlockUser(method);
if (!this.authorizationService.hasPermission(user, requiredPermission)) {
log.warn({ userId: this.user?.id }, "unauthorised admin access", { authorised: false, method, params });
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
}
log.info({ userId: this.user?.id }, "admin access", { authorised: true, method, params });
}

protected async internalStopWorkspaceInstance(ctx: TraceContext, instanceId: string, instanceRegion: string, policy?: StopWorkspacePolicy): Promise<void> {
const req = new StopWorkspaceRequest();
req.setId(instanceId);
Expand Down Expand Up @@ -2008,12 +2017,21 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
}

async adminSettingsGetTelemetry(ctx: TraceContext): Promise<boolean> {
console.log(2222)
return false;
traceAPIParams(ctx, {});

await this.guardAdminAccess("adminSettingsGetTelemetry", {}, Permission.ADMIN_API);

const settings = await this.installationAdminDb.getTelemetryData();

return settings.settings.sendTelemetry;
}

async adminSettingsSetTelemetry(ctx: TraceContext, send: boolean): Promise<void> {
console.log(3333);
traceAPIParams(ctx, {});

await this.guardAdminAccess("adminSettingsGetTelemetry", {}, Permission.ADMIN_API);

await this.installationAdminDb.setSendTelemetry(send);
}

async getLicenseInfo(): Promise<GetLicenseInfoResult> {
Expand Down

0 comments on commit fa64af9

Please sign in to comment.