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

[fga] added create_snapshot permission #18559

Merged
merged 1 commit into from
Aug 23, 2023
Merged

[fga] added create_snapshot permission #18559

merged 1 commit into from
Aug 23, 2023

Conversation

svenefftinge
Copy link
Member

@svenefftinge svenefftinge commented Aug 21, 2023

Description

This pull request adds a new feature to enable users to create snapshots of workspaces in an organization. It defines new relations and permissions in the definitions.ts and schema.yaml files, and implements the authorization logic in the authorizer.ts and gitpod-server-impl.ts files.

Related Issue(s)

Fixes EXP-348

How to test

  • Verify you can create a snapshot of a workspace using the preview env.
  • Verify you can create a workspace from a snapshot. click me

Documentation

Preview status

Gitpod was successfully deployed to your preview environment.

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

@@ -45,6 +45,9 @@ schema: |-
relation member: user
// Some users in an organization may additionally have the `owner` role
relation owner: user
// users who can snapshot workspaces
relation snapshoter: user | organization#member
Copy link
Member

@geropl geropl Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the intend behind this relation, especially how it is intended to be expanded upon in the future.

The permission create_snapshot itself is clear: Owners can take snapshots, if the org allows them to.
The I would expect the relation to either look like:

  • for making it an explicit role on the org which has to be added : relation snapshoter: organization#member
    • this would need to be added to every member, though ah, TIL that this can reference the membership of another group 💡 Then this is probably what we want. 🙃
  • for making it a toggle: relation snapshoter: user:*
    • in this case only the owner & ensure's that only the owner can do it. I'd rename it to sth like enable_snapshotting

Copy link
Member Author

@svenefftinge svenefftinge Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to enable/disable snapshotting on org level, by setting the organization#membership relation every member can snapshot their workspaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep the user there, then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not used indeed but since we allow assigning roles to users everywhere I thought I'd do it here as well for consistency reasons. I can remove it if you like that better also because YAGNI

Copy link
Member

@geropl geropl Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove it if you like that better also because YAGNI

👍

if (!workspace || workspace.ownerId !== user.id) {
// we use the workspacService which checks if the requesting user has access to the workspace. If that is the case they have access to snapshots as well.
// below is the old permission check which would also check if the user has access to the snapshot itself. This is not the case anymore.
const workspace = await this.workspaceService.getWorkspace(user.id, workspaceId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be awesome to have a test for this 🧡

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I test here exactly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a workspace from a snapshot context, to validate the fact that all users (incl member + strangers) can create workspace from a Snapshot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you know how painful it would be to write a test against gitpod-server-iml. Do you suggest to extract this logic into a service and write a test?

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested and works ✔️

a nit on clarity: https://github.com/gitpod-io/gitpod/pull/18559/files#r1302563299

@svenefftinge
Copy link
Member Author

/unhold

@roboquat roboquat merged commit 7e484dc into main Aug 23, 2023
12 of 13 checks passed
@roboquat roboquat deleted the se/create-snapshot branch August 23, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants