# Create a RolesAssignment

URL: /docs/api/security-and-networking/rolesassignment/create

`POST /apis/funcd.io/v1alpha1/namespaces/{namespace}/rolesassignments`

## Authentication

One of:

- `bearer`: A credential of funcd's config, sent as Authorization: Bearer followed by its token.
- `apiKey`: A credential of funcd's config, sent in the X-Api-Key header.

## Parameters

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `namespace` | path | string, required | The object's namespace. |
| `dryRun` | query | boolean | Admit the write and store nothing. |

## Body

`RolesAssignment` as `application/json`, required.

```json
{
  "additionalProperties": false,
  "properties": {
    "apiVersion": {
      "type": "string"
    },
    "kind": {
      "type": "string"
    },
    "metadata": {
      "additionalProperties": false,
      "properties": {
        "creationTimestamp": {
          "description": "When funcd created the object.",
          "format": "date-time",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$",
          "patternDescription": "an RFC3339 UTC timestamp with exactly 3 fractional digits (2026-10-07T20:03:35.965Z)",
          "type": "string"
        },
        "deletionTimestamp": {
          "description": "When funcd held the object at its deletion: an object of an Engineless add-on kind with deletion: delete stays, deleting, until its Function has destroyed what it holds. funcd sets it on no other object, and a write keeps it.",
          "format": "date-time",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$",
          "patternDescription": "an RFC3339 UTC timestamp with exactly 3 fractional digits (2026-10-07T20:03:35.965Z)",
          "type": "string"
        },
        "finalizers": {
          "description": "funcd does not read it.",
          "items": {
            "type": "string"
          },
          "type": [
            "array",
            "null"
          ]
        },
        "generateName": {
          "description": "A prefix from which funcd makes the name, adding a random suffix, when a create leaves name empty.",
          "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
          "type": "string"
        },
        "generation": {
          "description": "Set by funcd: 1 when the object is created, then one more each time its spec changes.",
          "format": "int64",
          "type": "integer"
        },
        "name": {
          "description": "The object's name, unique among the objects of its kind in its namespace. A create may leave it empty and set generateName instead.",
          "maxLength": 63,
          "minLength": 1,
          "pattern": "^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$",
          "type": "string"
        },
        "namespace": {
          "description": "The namespace the object belongs to. A cluster-scoped kind has none.",
          "maxLength": 63,
          "minLength": 1,
          "pattern": "^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$",
          "type": "string"
        },
        "ownerReferences": {
          "description": "The objects that own this one. funcd deletes an owned object when its owner goes.",
          "items": {
            "additionalProperties": false,
            "properties": {
              "blockOwnerDeletion": {
                "description": "funcd does not read it.",
                "type": "boolean"
              },
              "controller": {
                "description": "Whether this owner is the one that manages the object.",
                "type": "boolean"
              },
              "kind": {
                "description": "The kind of the object it names.",
                "type": "string"
              },
              "name": {
                "description": "The name of the object it names.",
                "maxLength": 63,
                "minLength": 1,
                "pattern": "^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$",
                "type": "string"
              },
              "namespace": {
                "description": "The namespace of the object it names.",
                "maxLength": 63,
                "minLength": 1,
                "pattern": "^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$",
                "type": "string"
              },
              "uid": {
                "description": "The owner's unique ID.",
                "type": "string"
              }
            },
            "required": [
              "uid",
              "kind",
              "name"
            ],
            "type": "object"
          },
          "type": [
            "array",
            "null"
          ]
        },
        "resourceGroup": {
          "description": "The resource group the object belongs to, within its namespace.",
          "maxLength": 63,
          "minLength": 1,
          "pattern": "^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$",
          "type": "string"
        },
        "resourceVersion": {
          "description": "An opaque version of the stored object, which funcd sets. An update that sends it gets a conflict when the object changed since; compare it for equality only.",
          "type": "string"
        },
        "tags": {
          "additionalProperties": {
            "type": "string"
          },
          "description": "Labels on the object, as keys and values.",
          "type": "object"
        },
        "uid": {
          "description": "The object's unique ID, which funcd sets when it creates the object.",
          "type": "string"
        }
      },
      "type": "object"
    },
    "spec": {
      "additionalProperties": false,
      "properties": {
        "assignments": {
          "description": "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.",
          "items": {
            "additionalProperties": false,
            "properties": {
              "principal": {
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "description": "The kind of the principal: a Function, a Job, whose runs' workers act as it, or an Identity for a caller outside funcd.",
                    "enum": [
                      "Function",
                      "Job",
                      "Identity"
                    ],
                    "type": "string"
                  },
                  "name": {
                    "description": "The principal's name, in the RolesAssignment's namespace. funcd does not check that it exists.",
                    "maxLength": 63,
                    "minLength": 1,
                    "pattern": "^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$",
                    "type": "string"
                  }
                },
                "required": [
                  "kind",
                  "name"
                ],
                "type": "object",
                "description": "Who the entry grants its role to. When unset, spec.principal."
              },
              "roleRef": {
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "description": "Where the role comes from: BuiltinRole for one of funcd's built-in roles, Role for a Role of the RolesAssignment's namespace.",
                    "enum": [
                      "BuiltinRole",
                      "Role"
                    ],
                    "type": "string"
                  },
                  "name": {
                    "description": "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.",
                    "type": "string"
                  }
                },
                "required": [
                  "kind",
                  "name"
                ],
                "type": "object",
                "description": "The role the entry grants."
              },
              "scope": {
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "description": "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.",
                    "enum": [
                      "Namespace",
                      "BucketPrefix",
                      "KVStore",
                      "Lake",
                      "SQLDatabase",
                      "Secret"
                    ],
                    "type": "string"
                  },
                  "name": {
                    "description": "The resource for each kind: <bucket>/<prefix> for one prefix of a Bucket, <store> for every table of a KVStore or <store>/<table> for one, <lake> for a Lake, <database> for a SQLDatabase and <secret> for a Secret. A Namespace scope covers the whole namespace, whatever its name.",
                    "type": "string"
                  }
                },
                "required": [
                  "kind"
                ],
                "type": "object",
                "description": "Where the entry's role applies. When unset, spec.scope."
              }
            },
            "required": [
              "roleRef"
            ],
            "type": "object"
          },
          "type": [
            "array",
            "null"
          ]
        },
        "principal": {
          "additionalProperties": false,
          "properties": {
            "kind": {
              "description": "The kind of the principal: a Function, a Job, whose runs' workers act as it, or an Identity for a caller outside funcd.",
              "enum": [
                "Function",
                "Job",
                "Identity"
              ],
              "type": "string"
            },
            "name": {
              "description": "The principal's name, in the RolesAssignment's namespace. funcd does not check that it exists.",
              "maxLength": 63,
              "minLength": 1,
              "pattern": "^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$",
              "type": "string"
            }
          },
          "required": [
            "kind",
            "name"
          ],
          "type": "object",
          "description": "The principal of each entry that sets none."
        },
        "scope": {
          "additionalProperties": false,
          "properties": {
            "kind": {
              "description": "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.",
              "enum": [
                "Namespace",
                "BucketPrefix",
                "KVStore",
                "Lake",
                "SQLDatabase",
                "Secret"
              ],
              "type": "string"
            },
            "name": {
              "description": "The resource for each kind: <bucket>/<prefix> for one prefix of a Bucket, <store> for every table of a KVStore or <store>/<table> for one, <lake> for a Lake, <database> for a SQLDatabase and <secret> for a Secret. A Namespace scope covers the whole namespace, whatever its name.",
              "type": "string"
            }
          },
          "required": [
            "kind"
          ],
          "type": "object",
          "description": "The scope of each entry that sets none."
        }
      },
      "required": [
        "assignments"
      ],
      "type": "object"
    }
  },
  "required": [
    "metadata",
    "spec",
    "apiVersion",
    "kind"
  ],
  "type": "object"
}
```

## Answers

| Status | Problem type | When | What to do |
| --- | --- | --- | --- |
| 200 |  | OK |  |
| 400 | `urn:funcd:problem:invalid` | A field breaks a rule that the schema cannot hold, which the detail names. | Correct the field that the detail names. |
| 400 | `urn:funcd:problem:invalid` | The body's metadata.namespace is not the namespace of the path. | Send the object to the path of its own namespace. |
| 400 | `about:blank` | The body is missing or is not JSON. | Send a JSON body. |
| 401 | `urn:funcd:problem:unauthorized` | The request carries no bearer token or API key, or one that funcd does not know. | Send a credential of funcd's config as a bearer token in the Authorization header, or in X-Api-Key. |
| 403 | `urn:funcd:problem:forbidden` | The credential's role or namespaces do not allow it to create a RolesAssignment in the namespace. | Use a credential whose role allows it, such as a developer of the namespace or an admin. |
| 409 | `urn:funcd:problem:conflict` | A RolesAssignment of that name already exists in the namespace. | Choose another name, or replace the existing RolesAssignment. |
| 413 | `urn:funcd:problem:payload-too-large` | The body is larger than 1 MiB. | Send a smaller body. |
| 415 | `about:blank` | The Content-Type of the body is not JSON. | Send the body as application/json. |
| 422 | `about:blank` | The query holds a parameter that the operation does not take. | Send only the parameters that the operation lists. |
| 422 | `about:blank` | The dryRun parameter is neither true nor false. | Send dryRun=true, or leave it out. |
| 422 | `about:blank` | The namespace in the path is not a DNS-1123 label. | Use at most 63 lowercase letters, digits and hyphens, starting and ending with a letter or a digit. |
| 422 | `about:blank` | The body breaks the schema: a field that it does not know, of the wrong type or past its limits. | Correct the field at the location that the detail gives. |