> For the complete documentation index, see [llms.txt](https://docs.onyxia.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onyxia.sh/admin-doc/namespaces-and-permissions.md). Agents can also search and read this documentation through its [MCP server](https://docs.onyxia.sh/~gitbook/mcp).

# Namespaces and Permissions

Use `onyxia.api.regions[].services` to choose where Onyxia deploys users' services, and with which Kubernetes identity.

The Onyxia Helm chart reads this configuration to:

* grant Onyxia API the Kubernetes permissions it needs, and nothing more;
* deploy the onboarding when a namespace has to be created for each user and group.

The chart only reads the first region.

## Onyxia API and the Onboarding

Two components of Onyxia act on the cluster:

* **Onyxia API** ([`InseeFrLab/onyxia-api`](https://github.com/InseeFrLab/onyxia-api), Java) runs Helm to install, upgrade and uninstall the users' services. It only works in namespaces that already exist, so the identity it uses needs the rights to create every resource of the catalog charts in them.
* **The onboarding** ([onyxia-datalab/onyxia-backend](https://github.com/onyxia-datalab/onyxia-backend/), Go) creates the namespaces of users and groups, with their resource quotas, their annotations and the resources listed in `namespaceResources`. It never installs services.

When a user selects a project, Onyxia Web calls `POST /api/onboarding`, once per browser session. When the onboarding is deployed, the chart routes `/api/onboarding` to it, and the rest of `/api` to Onyxia API.

Onyxia API used to create the namespaces itself (`allowNamespaceCreation`). This is deprecated: keeping the two components apart means that the one running the users' charts cannot create namespaces or grant permissions, and the one granting permissions does not run the users' charts.

## Single Namespace

By default, every user deploys their services in the namespace where Onyxia is installed. This suits a datalab for a single team, or a region dedicated to one project.

{% code title="apps/onyxia/values.yaml" %}

```yaml
onyxia:
  api:
    regions:
      - {
          "id": "default",
          "services": {
            "type": "KUBERNETES"
          }
        }
```

{% endcode %}

Here, the chart binds the Onyxia API service account to the `admin` ClusterRole with a `RoleBinding` in the release namespace. It creates nothing at the cluster level, so you can install Onyxia without cluster-admin rights. The onboarding is not deployed.

## One Namespace per User and Group

Set `singleNamespace` to `false` to give each user and each group their own namespace:

{% code title="apps/onyxia/values.yaml" %}

```yaml
onyxia:
  api:
    regions:
      - {
          "id": "default",
          "services": {
            "type": "KUBERNETES",
            "singleNamespace": false
          }
        }
```

{% endcode %}

Here, a user `alice` deploys in `user-alice`, and the members of the group `datascience` deploy in `projet-datascience`. Use `namespacePrefix` and `groupNamespacePrefix` to change these prefixes.

The chart:

* sets `authenticationMode` to `serviceAccountInTargetNamespace` in the region passed to Onyxia API, unless you set another mode;
* deploys the onboarding and routes `/api/onboarding` to it;
* creates a `ClusterRole` and a `ClusterRoleBinding` that only allow Onyxia API to impersonate the `onyxia-local` service account.

The chart creates cluster-scoped resources, so installing it requires cluster-admin rights.

### How `serviceAccountInTargetNamespace` Works

Onyxia API never deploys services with its own identity:

1. When a user selects a project, the onboarding creates its namespace, then creates in it the `onyxia-local` service account and a `RoleBinding` granting it `admin`.
2. When the user launches a service, Onyxia API runs Helm as `system:serviceaccount:user-alice:onyxia-local`.

Onyxia API can only impersonate service accounts named `onyxia-local`, and each of them only has rights in its own namespace. A flaw in Onyxia API therefore cannot reach other namespaces such as `kube-system`, unlike with `serviceAccount` authentication, where Onyxia API is `cluster-admin`.

The onboarding is not `admin` either. It can create namespaces, resource quotas, service accounts and role bindings, and it may only bind the `admin` ClusterRole.

Since the onboarding creates the namespaces, Onyxia API does not create any in this mode: it disables `allowNamespaceCreation` and logs a warning.

### Resources Created in Each Namespace

The onboarding creates the resources listed in `onyxia.onboarding.env.onboarding.namespaceResources`. The chart's default:

{% code title="apps/onyxia/values.yaml" %}

```yaml
onyxia:
  onboarding:
    env:
      onboarding:
        namespaceResources:
          - |
            apiVersion: v1
            kind: ServiceAccount
            metadata:
              name: onyxia-local
          - |
            apiVersion: rbac.authorization.k8s.io/v1
            kind: RoleBinding
            metadata:
              name: onyxia-local
            subjects:
              - kind: ServiceAccount
                name: onyxia-local
                namespace: ${onyxia.namespace}
            roleRef:
              apiGroup: rbac.authorization.k8s.io
              kind: ClusterRole
              name: admin
```

{% endcode %}

Here, `${onyxia.namespace}` is replaced with the namespace being provisioned.

To give the services less than `admin`, bind another ClusterRole in the `RoleBinding`, for example `onyxia-services`. The onboarding is only allowed to bind `admin`, so also replace `admin` in the last rule of `onyxia.onboarding.clusterRole.rules`:

{% code title="apps/onyxia/values.yaml" %}

```yaml
onyxia:
  onboarding:
    clusterRole:
      rules:
        # ...the other default rules of the chart
        - apiGroups: ["rbac.authorization.k8s.io"]
          resources: ["clusterroles"]
          verbs: ["bind"]
          resourceNames: ["onyxia-services"]
```

{% endcode %}

{% hint style="warning" %}
`rules` and `namespaceResources` replace the chart's lists. Copy every default entry from the chart's `values.yaml`, not only the ones you change. If you add other kinds of resources to `namespaceResources`, grant the onboarding the matching `create` and `patch` verbs.
{% endhint %}

## Other Authentication Modes

Set `authenticationMode` explicitly to use another identity:

* `serviceAccount`: Onyxia API uses its own service account. In single namespace, this is the default. In multi namespace, the chart binds it to `cluster-admin`: prefer `serviceAccountInTargetNamespace`.
* `impersonate`: Onyxia API runs Helm as the user (`--kube-as-user`). Grant the users the rights they need in their namespaces, and Onyxia API the `impersonate` verb on `users` and `groups`.
* `tokenPassthrough`: Onyxia API sends the user's access token to the Kubernetes API server, which must trust your OIDC provider. Grant the users the rights they need in their namespaces.

With `impersonate` and `tokenPassthrough`, the chart cannot guess the permissions to grant and creates none: configure them with the chart values below.

## Configuration Reference

The following type describes the `services` fields of a region that this page relies on:

```typescript
type Services = {
  /**
   * true:  every user deploys in the Onyxia namespace.
   * false: one namespace per user and per group.
   * Default: true
   */
  singleNamespace?: boolean;

  /**
   * Identity Onyxia API uses to deploy the services.
   * Default: "serviceAccount" in single namespace,
   * "serviceAccountInTargetNamespace" in multi namespace (set by the chart).
   */
  authenticationMode?:
    | "serviceAccount"
    | "serviceAccountInTargetNamespace"
    | "impersonate"
    | "tokenPassthrough";

  /**
   * Service account impersonated in the target namespace with
   * serviceAccountInTargetNamespace authentication.
   * Default: "onyxia-local"
   */
  targetNamespaceServiceAccount?: string;

  /** Default: "user-" */
  namespacePrefix?: string;

  /** Default: "projet-" */
  groupNamespacePrefix?: string;
};
```

The chart derives the following values from the region. Leave them to `null` to keep the derived value, or set them to `true` or `false` to force it:

```typescript
type ChartValues = {
  onboarding: {
    /** Derived: true in multi namespace. */
    enabled: boolean | null;
  };
  api: {
    /** RoleBinding in the release namespace. */
    roleBinding: Binding & {
      /** Derived: true in single namespace with serviceAccount authentication. */
      create: boolean | null;
    };
    /** ClusterRole granting the impersonation of targetNamespaceServiceAccount. */
    clusterRole: {
      /** Derived: true with serviceAccountInTargetNamespace authentication. */
      create: boolean | null;
      name?: string;
      rules: PolicyRule[];
    };
    clusterRoleBinding: Binding & {
      /**
       * Derived: true with serviceAccountInTargetNamespace authentication,
       * or in multi namespace with serviceAccount authentication.
       */
      create: boolean | null;
    };
  };
};

type Binding = {
  name?: string;
  /**
   * ClusterRole to bind.
   * Default: api.clusterRole when the chart creates it, otherwise
   * admin for roleBinding and cluster-admin for clusterRoleBinding.
   */
  clusterRoleName?: string;
};
```

## Operational Requirements

* In multi namespace, installing the chart requires cluster-admin rights.
* The name `onyxia-local` must be the same in `targetNamespaceServiceAccount`, in `onyxia.onboarding.env.onboarding.namespaceResources` and in the `resourceNames` of `onyxia.api.clusterRole.rules`. Otherwise, launching a service fails with a `forbidden` error.
* Users can only launch services in a namespace once the onboarding has created `onyxia-local` in it. This applies to namespaces created before the onboarding was deployed.
* The ClusterRole bound to `onyxia-local` must allow every resource that the catalog charts create.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.onyxia.sh/admin-doc/namespaces-and-permissions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
