Skip to content

Make role names an enum in the DB #8554

@david-crespo

Description

@david-crespo

Followup to #7477, especially #7477 (comment).

Role names are currently represented as free-form strings, but as far as I know the only actual values are admin, collaborator, viewer, or external-authenticator. This was originally expected to be a more flexible system, but we've managed to get a lot out of this basic set of roles. After the cleanup in #7477 made clear we are not using a dynamic list of roles, we have an opportunity to simplify things even further by locking down the set of roles to a Rust enum backed by a Rust enum.

omicron/schema/crdb/dbinit.sql

Lines 2919 to 2922 in 2561a7a

CREATE TABLE IF NOT EXISTS omicron.public.role_assignment (
/* Composite foreign key into "role_builtin" table */
resource_type STRING(63) NOT NULL,
role_name STRING(63) NOT NULL,

/// Describes an assignment of a built-in role for a user
#[derive(Clone, Queryable, Insertable, Debug, Selectable)]
#[diesel(table_name = role_assignment)]
pub struct RoleAssignment {
pub identity_type: IdentityType,
pub identity_id: Uuid,
pub resource_type: String,
pub resource_id: Uuid,
pub role_name: String,
}

External API structs

Missing external-authenticator because it is never exposed externally.

pub enum FleetRole {
Admin,
Collaborator,
Viewer,
// There are other Fleet roles, but they are not externally-visible and so
// they do not show up in this enum.
}

pub enum SiloRole {
Admin,
Collaborator,
Viewer,
}

pub enum ProjectRole {
Admin,
Collaborator,
Viewer,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions