# Identity, Role, RolesAssignment and Policy spec

URL: /docs/develop/security-and-networking/security/spec

Every field of Identity, Role, RolesAssignment and Policy: its type, its limits and its description.

This page lists the spec and status fields of Identity, Role, RolesAssignment and Policy, each with its type, its limits and its description. The [Platform page](/docs/platform/security-and-networking/security.md) explains the concept, and the `metadata` of every kind is [the same](/docs/develop/common-definitions.md#objectmeta).

## Identity [#identity]

```yaml
apiVersion: funcd.io/v1alpha1
kind: Identity
metadata:
  name: analyst
  namespace: default
  resourceGroup: rg1
spec:
  type: external
```

| apiVersion | kind |
| --- | --- |
| `funcd.io/v1alpha1` | `Identity` |

### `Identity.spec` [#identityspec]

| Field | Type and limits | Description |
| --- | --- | --- |
| `credentialSecretName` | string, a DNS-1123 label | The Secret, in the Identity's namespace, that funcd writes the credential to and deletes with the Identity: the S3 key pair as accessKeyId and secretAccessKey, and the Lake token as lakeToken. Empty means the Identity's name. funcd leaves alone a Secret of that name that no Identity of this name controls, and the Identity then stays Pending with reason SecretNotOwned; a Secret left by a deleted Identity of the same name is issued again. |
| `rotate` | integer | Raise it above status.observedRotate to rotate the credential: funcd writes a new secretAccessKey and lakeToken under the same access key id, and the old ones stop authenticating, with no overlap. |
| `type` | string, required, one of `external` | What the Identity stands for: external, a caller outside funcd that authenticates with the credential funcd issues. The credential grants nothing: a RolesAssignment or a Policy grants the Identity its access. |

### `Identity.status` [#identitystatus]

| Field | Type and limits | Description |
| --- | --- | --- |
| `accessKeyId` | string | The access key id of the issued key pair, also in the Secret. funcd derives it from the Identity's namespace and name, so it stays the same when the credential rotates. |
| `conditions` | array of [Condition](/docs/develop/common-definitions.md#condition) | The conditions that explain the phase. |
| `observedGeneration` | integer | The generation of the spec that funcd last acted on. |
| `observedRotate` | integer | The spec.rotate value that funcd last acted on: a rotation is done once it equals spec.rotate. |
| `phase` | string, one of `Pending`, `Deploying`, `Ready`, `Idle`, `Degraded`, `Failed`, `Terminating` | Where the object is in its lifecycle. |

## Role [#role]

```yaml
apiVersion: funcd.io/v1alpha1
kind: Role
metadata:
  name: object-writer
  namespace: default
  resourceGroup: rg1
spec:
  actions:
    - s3::write
```

| apiVersion | kind |
| --- | --- |
| `funcd.io/v1alpha1` | `Role` |

### `Role.spec` [#rolespec]

| Field | Type and limits | Description |
| --- | --- | --- |
| `actions` | array of string values, required | The actions the role grants, at least one, such as s3::read, kv::write or lake::query. An action that funcd does not know grants nothing. |

## RolesAssignment [#rolesassignment]

```yaml
apiVersion: funcd.io/v1alpha1
kind: RolesAssignment
metadata:
  name: analyst-reads-namespace
  namespace: default
  resourceGroup: rg1
spec:
  principal:
    kind: Identity
    name: analyst
  scope:
    kind: Namespace
  assignments:
    - roleRef:
        kind: BuiltinRole
        name: Blob Data Reader
    - roleRef:
        kind: BuiltinRole
        name: Lake Query Reader
```

| apiVersion | kind |
| --- | --- |
| `funcd.io/v1alpha1` | `RolesAssignment` |

### `RolesAssignment.spec` [#rolesassignmentspec]

| Field | Type and limits | Description |
| --- | --- | --- |
| `assignments` | array of [`RolesAssignment.spec.assignments[]`](#rolesassignmentspecassignments), required | The grants, at least one: each entry grants one role to a principal at a scope. funcd refuses an entry that sets no principal while spec.principal is unset, and likewise for the scope. |
| `principal` | object, [`RolesAssignment.spec.principal`](#rolesassignmentspecprincipal) | The principal of each entry that sets none. |
| `scope` | object, [`RolesAssignment.spec.scope`](#rolesassignmentspecscope) | The scope of each entry that sets none. |

### `RolesAssignment.spec.assignments[]` [#rolesassignmentspecassignments]

| Field | Type and limits | Description |
| --- | --- | --- |
| `principal` | object, [`RolesAssignment.spec.principal`](#rolesassignmentspecprincipal) | Who the entry grants its role to. When unset, spec.principal. |
| `roleRef` | object, [`RolesAssignment.spec.assignments[].roleRef`](#rolesassignmentspecassignmentsroleref), required | The role the entry grants. |
| `scope` | object, [`RolesAssignment.spec.scope`](#rolesassignmentspecscope) | Where the entry's role applies. When unset, spec.scope. |

### `RolesAssignment.spec.assignments[].roleRef` [#rolesassignmentspecassignmentsroleref]

| Field | Type and limits | Description |
| --- | --- | --- |
| `kind` | string, required, one of `BuiltinRole`, `Role` | Where the role comes from: BuiltinRole for one of funcd's built-in roles, Role for a Role of the RolesAssignment's namespace. |
| `name` | string, required | The role's name. A built-in role is one of Blob Data Reader, Blob Data Writer, KV Data Reader, KV Data Writer, SQL Data Reader, SQL Data Writer, Secret Data Reader, Secret Data Writer, Lake Query Reader, Lake Contributor, Function Invoker, Reader, Contributor and Owner; the last three cover Bucket and KV data only. A name that matches no role grants nothing. |

### `RolesAssignment.spec.principal` [#rolesassignmentspecprincipal]

| Field | Type and limits | Description |
| --- | --- | --- |
| `kind` | string, required, one of `Function`, `Job`, `Identity` | The kind of the principal: a Function, a Job, whose runs' workers act as it, or an Identity for a caller outside funcd. |
| `name` | string, required, a DNS-1123 label | The principal's name, in the RolesAssignment's namespace. funcd does not check that it exists. |

### `RolesAssignment.spec.scope` [#rolesassignmentspecscope]

| Field | Type and limits | Description |
| --- | --- | --- |
| `kind` | string, required, one of `Namespace`, `BucketPrefix`, `KVStore`, `Lake`, `SQLDatabase`, `Secret` | What the grant covers: with Namespace, every resource of the RolesAssignment's namespace; with another kind, the one resource that name gives, in that namespace. |
| `name` | string | The resource for each kind: &lt;bucket&gt;/&lt;prefix&gt; for one prefix of a Bucket, &lt;store&gt; for every table of a KVStore or &lt;store&gt;/&lt;table&gt; for one, &lt;lake&gt; for a Lake, &lt;database&gt; for a SQLDatabase and &lt;secret&gt; for a Secret. A Namespace scope covers the whole namespace, whatever its name. |

## Policy [#policy]

```yaml
apiVersion: funcd.io/v1alpha1
kind: Policy
metadata:
  name: analyst-writes-nothing
  namespace: default
  resourceGroup: rg1
spec:
  cedar: |
    forbid(
      principal == Identity::"default/analyst",
      action == Action::"s3::write",
      resource in Bucket::"default/lakehouse"
    );
```

| apiVersion | kind |
| --- | --- |
| `funcd.io/v1alpha1` | `Policy` |

### `Policy.spec` [#policyspec]

| Field | Type and limits | Description |
| --- | --- | --- |
| `cedar` | string, required | One or more Cedar permit or forbid statements, which apply with funcd's built-in rules to each request whose principal and resource are both in the Policy's namespace; a forbid wins over any permit. Each statement names one action funcd knows, such as kv::read, and its principal and resource scopes name only entity types funcd knows and, for a type with a namespace, ids that begin with the Policy's namespace and a slash. funcd refuses text that does not parse, holds no statement or breaks these rules. |

## HTTP API [#http-api]

The table lists each described operation of these kinds, with its method and path. The operation's page in the API reference gives its parameters, its body, its authentication and every answer, with when it happens and what to do.

| Method | Path | Operation |
| --- | --- | --- |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/identities` | [List the Identities of a namespace](/docs/api/security-and-networking/identity/list.md) |
| `POST` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/identities` | [Create an Identity](/docs/api/security-and-networking/identity/create.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/identities/{name}` | [Read an Identity](/docs/api/security-and-networking/identity/get.md) |
| `PUT` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/identities/{name}` | [Replace an Identity](/docs/api/security-and-networking/identity/replace.md) |
| `DELETE` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/identities/{name}` | [Delete an Identity](/docs/api/security-and-networking/identity/delete.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/roles` | [List the Roles of a namespace](/docs/api/security-and-networking/role/list.md) |
| `POST` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/roles` | [Create a Role](/docs/api/security-and-networking/role/create.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/roles/{name}` | [Read a Role](/docs/api/security-and-networking/role/get.md) |
| `PUT` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/roles/{name}` | [Replace a Role](/docs/api/security-and-networking/role/replace.md) |
| `DELETE` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/roles/{name}` | [Delete a Role](/docs/api/security-and-networking/role/delete.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/rolesassignments` | [List the RolesAssignments of a namespace](/docs/api/security-and-networking/rolesassignment/list.md) |
| `POST` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/rolesassignments` | [Create a RolesAssignment](/docs/api/security-and-networking/rolesassignment/create.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/rolesassignments/{name}` | [Read a RolesAssignment](/docs/api/security-and-networking/rolesassignment/get.md) |
| `PUT` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/rolesassignments/{name}` | [Replace a RolesAssignment](/docs/api/security-and-networking/rolesassignment/replace.md) |
| `DELETE` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/rolesassignments/{name}` | [Delete a RolesAssignment](/docs/api/security-and-networking/rolesassignment/delete.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/policies` | [List the Policies of a namespace](/docs/api/security-and-networking/policy/list.md) |
| `POST` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/policies` | [Create a Policy](/docs/api/security-and-networking/policy/create.md) |
| `GET` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/policies/{name}` | [Read a Policy](/docs/api/security-and-networking/policy/get.md) |
| `PUT` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/policies/{name}` | [Replace a Policy](/docs/api/security-and-networking/policy/replace.md) |
| `DELETE` | `/apis/funcd.io/v1alpha1/namespaces/{namespace}/policies/{name}` | [Delete a Policy](/docs/api/security-and-networking/policy/delete.md) |
