> ## Documentation Index
> Fetch the complete documentation index at: https://latchkey.getgalaxy.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Latchkey concepts overview

> The model Latchkey evaluates, from kinds and actions to roles and bindings, how a check decides, and a worked example.

Deny is the default. A request is allowed only when a **binding** gives the
caller a **role** that holds the exact **kind** and **action** the request
needs, at a **scope** that covers the resource.

## The model

| Concept | What it is | Example |
| - | - | - |
| Kind | A domain and a resource type, written `domain.type`. A domain is the namespace a product registers, such as `filament`, and each product declares its kinds, the actions each supports, whether it is admin only, and whether it can be bound on one resource. | `filament.pipeline`, `alchemy.function` |
| Action | One fixed vocabulary shared by every product. | `read`, `create`, `update`, `delete`, `invoke`, `use` |
| Scope | Tenant scope covers every resource of a kind in the tenant, for the kinds the role holds. Resource scope covers one resource of one kind, by id. | tenant, `filament.pipeline/abc123` |
| Subject | A user or a service, identified by `(type, id)`. The id is the one the request path carries. In Galaxy Cloud that is the platform user id from `ResolveCaller`, and standalone it is the IdP's immutable id. | `user:00u8f…`, `service:0oa2k…` |
| Group | A flat set of subjects. Manual groups are edited in Latchkey. Directory groups are owned by the IdP, synced in and read only. The built-in Everyone group is computed and holds every active user. | `data-eng` |
| Role | A named set of `(kind, action)` permissions. Built-in Admin, Creator and Viewer, plus custom roles. | Pipeline editor |
| Binding | Gives a role to a subject or group at a scope. It is the only thing that grants access. | `derek` → Pipeline editor → `filament.pipeline/abc123` |

Everyday read comes from a default binding that gives Everyone the Viewer
role. Each tenant starts with it and can remove it.

## Actions and scope

| Action | Meaning | Scope |
| - | - | - |
| `read` | View a resource, its versions, logs and children | Tenant only |
| `create` | Make a new resource of the kind | Tenant only, since the resource does not exist yet |
| `update` | Change a resource or its configuration, including schedules and notifiers | Tenant or resource |
| `delete` | Remove a resource | Tenant or resource |
| `invoke` | Execute a resource, such as running a pipeline, calling a function or signalling a run | Tenant or resource |
| `use` | Act through a resource without changing it, such as browsing a connection's schemas or attaching it to another resource | Tenant or resource |

Child resources, such as a Filament run or an Alchemy invocation, are their
own kinds at tenant scope. Control over one child goes through its parent,
which the product's parent resolver finds. A binding on one resource applies
only the role's permissions for that resource's kind.

## Roles

| Role | Holds | Editable |
| - | - | - |
| Viewer | `read` on every kind that is not admin only | No |
| Creator | Everything Viewer holds, plus every action on every kind that is not admin only | No |
| Admin | Every action on every kind, including Latchkey's own `latchkey.*` kinds | No |

A **custom role** is a name, a description and a list of kind patterns paired
with actions.

* A kind pattern is an exact kind such as `filament.pipeline`, or a domain
  wildcard such as `filament.*`. Wildcards expand when a check runs, so new
  kinds are covered automatically.
* `read` and `create` take effect only through bindings across the tenant. A
  role such as Pipeline operator, with `read` and `invoke` on pipelines, still
  works for a tenant that removed the default Viewer binding.
* Admin-only kinds and `latchkey.*` kinds can never appear in a custom role,
  and patterns never match them, even for a kind that becomes admin only
  later. Admin only always means Admin only.
* The names `admin`, `creator` and `viewer` are reserved, as is the group
  name Everyone.
* An edit takes effect at once on every binding of the role, bumps the access
  revision and is audited.
* A role with bindings cannot be deleted. Remove its bindings first.

## How a check decides

Every decision carries the access revision it was made at.

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
Check(tenant, subject, kind, action, resource_id?, min_revision?, min_instance_revision?, actor?)
  → error  if the tenant has not been provisioned
  → error  if kind is unknown, retired or does not support action
  → error  if resource_id is missing for update/delete/invoke/use (ignored for read/create)
  → wait   until the snapshot reaches min_revision and min_instance_revision (bounded, deny on timeout)
  → treat  an unseen user of this tenant as known and active (saved in the background, no revision bump)
  → deny   if subject is an unknown service or is inactive
  → deny   anything but read when an actor (impersonation) is set
  → load   bindings for the subject and its groups in this tenant
           (user subjects are always in Everyone, service subjects never are)
  → allow  if a tenant-scoped binding's role holds (kind, action)
  → allow  if a resource-scoped binding for (kind, resource_id) holds (kind, action)
  → deny
```

Errors mean a misconfigured product. The interceptor treats them as a deny
but counts them separately, so they show up in metrics rather than as user
reports. Latchkey resolves groups itself and callers never send them. Each
decision returns the binding that allowed it or a deny reason, for the audit
trail and `ExplainAccess`. Products return a plain `PERMISSION_DENIED` to end
users.

## A worked example

One custom role, bound to one resource, lets Derek edit and run pipeline
`abc123` and only read everything else.

* The custom role **Pipeline editor** holds `update` and `invoke` on
  `filament.pipeline`.
* A binding gives `user:derek` the Pipeline editor role on
  `filament.pipeline/abc123`. It is valid because `update` and `invoke` can be
  held on one resource.
* Derek is an active user synced from the directory, so he is in Everyone
  and holds Viewer through the default binding. He has no other bindings and
  no access to the connection `prod-db`.

| Call | Checks | Result | Why |
| - | - | - | - |
| UpdatePipeline abc123 | pipeline update abc123 | Allow | Binding scope and role match |
| RunPipeline abc123 | pipeline invoke abc123 | Allow | Binding scope and role match |
| GetPipeline abc123 | pipeline read | Allow | Everyone → Viewer |
| SignalRun r-9, a run of abc123 | resolver finds abc123, then pipeline invoke abc123 | Allow | Checked on the parent pipeline |
| DeletePipeline abc123 | pipeline delete abc123 | Deny | Delete is not in the role |
| UpdatePipeline def456 | pipeline update def456 | Deny | The binding is on a different pipeline |
| CreatePipelineVersion abc123 with a graph that uses prod-db | pipeline update abc123 and connection use prod-db | Deny | No `use` on prod-db |
| CreatePipelineSchedule on abc123 | pipeline update and invoke abc123 | Allow | The role holds both |
| ListHosts | host read | Deny | Hosts are admin only, which Viewer excludes |
| GetPipeline abc123 as `service:ci-deployer` | pipeline read | Deny | Services are never in Everyone |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.