Skip to content

Declare all permission names as constants in pkg/permission #1032

Open

Description

@pbleser-oc

The names of the permissions that reva checks (Drives.List, Drives.ReadWrite, ...) are partly constants and partly string literals. A typo in a literal compiles fine and silently denies the permission at runtime. Declaring every name once as a constant in pkg/permission and using only those would let the compiler catch it, and would let opencloud use the same constants when it defines the permissions.

Current state

  • pkg/permission/permission.go declares constants for some names: ListAllSpaces (Drives.List), CreateSpace (Drives.Create), WritePublicLink, WriteShare, GuestMailWrite, ListFavorites, WriteFavorites, DeleteReadOnlyPassword. The share providers and the OCS sharing handlers use them.
  • pkg/storage/pkg/decomposedfs/permissions/spacepermissions.go checks all space permissions with literals: Drives.Create, Drives.ReadWritePersonalQuota, Drives.ReadWriteProjectQuota, Drives.ReadWrite, Drives.ReadWriteEnabled, Drives.List, Drives.DeleteProject, Drives.DeletePersonal. Two of them (Drives.List, Drives.Create) already have constants that it doesn't use.
  • feat(decomposedfs): personal space permissions #963 adds Drives.ListPersonal and Drives.ReadWritePersonal the same way.

Proposal

  • Add a constant to pkg/permission for every permission name reva checks, with a doc comment saying what it allows.
  • Replace the literals in spacepermissions.go (and anywhere else) with these constants.
  • No behaviour change: the values stay the same.

opencloud defines the permissions in services/settings/pkg/store/defaults/permissions.go with the same names as literals. Once the constants exist here, opencloud can use them from its vendored reva: see opencloud-eu/opencloud#4053.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions