Malachi.Auth.ConsoleRole (malachi v0.22.7)

View Source

The three console roles, the one place they are listed. A console role says what an operator may do through the dashboard and the console, and nothing about the wire protocol: the wire permissions (:admin, :produce, :consume) stay what they are, and holding one grants no console role except :admin, the superuser (Malachi.Auth.Authorization.superuser?/1).

The roles are strictly nested, as in the reference product the specification studied (section 6.10.1 of docs/design/operator-interfaces.md): :viewer reads, :editor adds the mutations that are not security, and :admin adds users, ACLs and diagnostics. They are cluster wide and stored in the replicated user registry (Malachi.Auth.UserRegistry). What each role may reach is decided by Malachi.Console.Access.

Summary

Functions

Every role, from the least to the most privileged.

Whether role includes everything required grants. No role includes nothing.

The more privileged of two roles, either of which may be nil.

Parses a role string into its atom, or :error. "none" and nil mean no role. Mapping explicitly (rather than String.to_atom/1) keeps an untrusted client from exhausting the atom table.

Whether value is a role, or nil (no role).

Types

t()

@type t() :: :viewer | :editor | :admin

Functions

all()

@spec all() :: [t()]

Every role, from the least to the most privileged.

includes?(role, required)

@spec includes?(t() | nil, t()) :: boolean()

Whether role includes everything required grants. No role includes nothing.

Examples

iex> Malachi.Auth.ConsoleRole.includes?(:editor, :viewer)
true

iex> Malachi.Auth.ConsoleRole.includes?(:viewer, :editor)
false

iex> Malachi.Auth.ConsoleRole.includes?(nil, :viewer)
false

max(role, role)

@spec max(t() | nil, t() | nil) :: t() | nil

The more privileged of two roles, either of which may be nil.

Examples

iex> Malachi.Auth.ConsoleRole.max(:viewer, :admin)
:admin

iex> Malachi.Auth.ConsoleRole.max(nil, :viewer)
:viewer

parse(arg1)

@spec parse(String.t() | nil) :: {:ok, t() | nil} | :error

Parses a role string into its atom, or :error. "none" and nil mean no role. Mapping explicitly (rather than String.to_atom/1) keeps an untrusted client from exhausting the atom table.

Examples

iex> Malachi.Auth.ConsoleRole.parse("editor")
{:ok, :editor}

iex> Malachi.Auth.ConsoleRole.parse("none")
{:ok, nil}

iex> Malachi.Auth.ConsoleRole.parse("root")
:error

valid?(value)

@spec valid?(term()) :: boolean()

Whether value is a role, or nil (no role).