Skip to content

[WIP][gp] Support gp env by talking to server directly #3379

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

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 14 additions & 2 deletions components/server/src/auth/resource-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License-AGPL.txt in the project root for license information.
*/

import { Workspace, WorkspaceInstance, User, Snapshot, GitpodToken, Token } from "@gitpod/gitpod-protocol";
import { Workspace, WorkspaceInstance, User, Snapshot, GitpodToken, Token, UserEnvVar } from "@gitpod/gitpod-protocol";

declare var resourceInstance: GuardedResource;
export type GuardedResourceKind = typeof resourceInstance.kind;
Expand All @@ -17,7 +17,8 @@ export type GuardedResource =
GuardedGitpodToken |
GuardedToken |
GuardedUserStorage |
GuardedContentBlob
GuardedContentBlob |
GuardedEnvironmentVariable
;

export interface GuardedWorkspace {
Expand Down Expand Up @@ -66,6 +67,13 @@ export interface GuardedToken {
tokenOwnerID: string;
}

export interface GuardedEnvironmentVariable {
kind: "environmentVariable";
subject: UserEnvVar;
userID: string;
repositoryPattern: string;
}

export type ResourceAccessOp =
"create" |
"update" |
Expand Down Expand Up @@ -110,6 +118,8 @@ export class OwnerResourceGuard implements ResourceAccessGuard {
switch (resource.kind) {
case "contentBlob":
return resource.userID === this.userId;
case "environmentVariable":
return resource.userID === this.userId;
case "gitpodToken":
return resource.subject.user.id === this.userId;
case "snapshot":
Expand Down Expand Up @@ -226,6 +236,8 @@ export namespace ScopedResourceGuard {
switch (resource.kind) {
case "contentBlob":
return `${resource.userID}:${resource.name}`;
case "environmentVariable":
return `${resource.userID}:${resource.repositoryPattern}`;;
case "gitpodToken":
return resource.subject.tokenHash;
case "snapshot":
Expand Down
2 changes: 2 additions & 0 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ export class WorkspaceStarter {
"resource:"+ScopedResourceGuard.marshalResourceScope({kind: "userStorage", subjectID: "*", operations: ["create", "get", "update"]}),
"resource:"+ScopedResourceGuard.marshalResourceScope({kind: "token", subjectID: "*", operations: ["get"]}),
"resource:"+ScopedResourceGuard.marshalResourceScope({kind: "contentBlob", subjectID: "*", operations: ["create", "get"]}),
// TODO: subjectID based on owner/repo from workspace.contextURL?
"resource:"+ScopedResourceGuard.marshalResourceScope({kind: "environmentVariable", subjectID: "*", operations: ["create", "get", "update", "delete"]}),
]
}

Expand Down