Skip to content

fix: allow regular users to push files#4500

Merged
sreya merged 6 commits into
mainfrom
jon/fixfileperms
Oct 13, 2022
Merged

fix: allow regular users to push files#4500
sreya merged 6 commits into
mainfrom
jon/fixfileperms

Conversation

@sreya

@sreya sreya commented Oct 12, 2022

Copy link
Copy Markdown
Collaborator
  • As part of merging support for Template RBAC
    and user groups a permission check on reading files
    was relaxed.

    With the addition of admin roles on individual templates, regular
    users are now able to push template versions if they have
    inherited the 'admin' role for a template. In order to do so
    they need to be able to create and read their own files. Since
    collisions on hash in the past were ignored, this means that a regular user
    who pushes a template version with a file hash that collides with
    an existing hash will not be able to read the file (since it belongs to
    another user).

    This commit fixes the underlying problem which was that
    the files table had a primary key on the 'hash' column.
    This was not a problem at the time because only template
    admins and other users with similar elevated roles were
    able to read all files regardless of ownership. To fix this
    a new column and primary key 'id' has been introduced to the files
    table. The unique constraint has been updated to be hash+created_by.
    Tables (provisioner_jobs) that referenced files.hash have been updated
    to reference files.id. Relevant API endpoints have also been updated.

fixes #4415

sreya added 2 commits October 12, 2022 01:13
- As part of merging support for Template RBAC
  and user groups a permission check on reading files
  was relaxed.

  With the addition of admin roles on individual templates, regular
  users are now able to push template versions if they have
  inherited the 'admin' role for a template. In order to do so
  they need to be able to create and read their own files. Since
  collisions on hash in the past were ignored, this means that a regular user
  who pushes a template version with a file hash that collides with
  an existing hash will not be able to read the file (since it belongs to
  another user).

  This commit fixes the underlying problem which was that
  the files table had a primary key on the 'hash' column.
  This was not a problem at the time because only template
  admins and other users with similar elevated roles were
  able to read all files regardless of ownership. To fix this
  a new column and primary key 'id' has been introduced to the files
  table. The unique constraint has been updated to be hash+created_by.
  Tables (provisioner_jobs) that referenced files.hash have been updated
  to reference files.id. Relevant API endpoints have also been updated.
@sreya sreya requested a review from a team as a code owner October 12, 2022 01:23
@sreya sreya requested review from jsjoeio and removed request for a team October 12, 2022 01:23
@sreya sreya requested review from Emyrk and kylecarbs and removed request for jsjoeio October 12, 2022 01:37

@Emyrk Emyrk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LG. PR comment is great.

Comment thread coderd/coderd.go Outdated
Comment thread coderd/database/migrations/000059_file_id.up.sql
@sreya sreya merged commit 4e57b9f into main Oct 13, 2022
@sreya sreya deleted the jon/fixfileperms branch October 13, 2022 23:02
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 13, 2022
@mafredri

Copy link
Copy Markdown
Member

Should we mark this a breaking change or add backwards compat? It looks like it prevents newer clients from uploading to previous versions of the server (the error is not very user friendly):

> Create and upload "docker-image-builds"? (yes/no) yes
invalid UUID length: 64
Run 'coder templates create --help' for usage.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

template permissions: user with admin access cannot push or pull a template

3 participants