> For the complete documentation index, see [llms.txt](https://docs.cybus.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cybus.io/2-8-0/data-flows/service-commissioning-files/resources/cybus-namespace.md). Agents can also search and read this documentation through its [MCP server](https://docs.cybus.io/~gitbook/mcp).

# Cybus::Namespace

Set the top topic segment, the tree of nodes, and the policies that decide where assets may live and how they are named.

The **Cybus::Namespace** resource declares one Unified Namespace (UNS), such as the namespace of your company or of one site. A [Cybus::Mount](https://docs.cybus.io/2-8-0/data-flows/service-commissioning-files/resources/cybus-mount.md) places assets in its tree. For how the UNS resources work together, see [Namespaces, Models, and Assets](https://docs.cybus.io/2-8-0/unified-namespace/unified-namespace.md).

A namespace usually lives in a service of its own, which other services mount their assets into. Its root is unique across the whole Connectware installation.

## Namespace Properties

| Property                    | Type     | Required     | Default   |
| --------------------------- | -------- | ------------ | --------- |
| [root](#root)               | `string` | **Required** |           |
| [structure](#structure)     | `object` | Optional     |           |
| [policy](#policy)           | `object` | Optional     |           |
| [targetState](#targetstate) | `enum`   | Optional     | `enabled` |

### root

The top topic segment of the namespace. Every topic of the namespace starts with it, and `uns:` paths start with it, as in `uns:factory/hall1`. You can mount assets at the root itself, for example with `uns:factory`, even when the namespace declares no tree.

* **Required**
* Type: `string`
  * Minimum length: 1 character
  * Must not contain `#`, `+`, or `/`
  * Must follow the [naming rules](#naming-rules), including the `naming` policy of the namespace

### structure

The levels and the tree of nodes of the namespace. A namespace with a `root` only is valid.

* **Optional**
* Type: `object`

| Property | Type     | Description                                                                                                                                  |
| -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `levels` | `array`  | Names of the levels, for example `[site, area, line, cell]`. The names are informational.                                                    |
| `tree`   | `object` | The nodes of the namespace as nested keys. Each key is a topic segment. A node without children is an empty object (`{}`) or an empty value. |

The keys of the tree are the topic segments, with no separate display names. They must follow the [naming rules](#naming-rules).

### policy

The rules that govern the namespace.

* **Optional**
* Type: `object`

| Property           | Type     | Allowed values       | Default            | Description                                                                                                                                                                                                                                                                          |
| ------------------ | -------- | -------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `placement`        | `enum`   | `open`, `tree-only`  | `tree-only`        | With `tree-only`, an asset can only be mounted at a node that the tree declares. A mount at a node that does not exist fails the installation. With `open`, a mount may create new branches, and the installation returns a warning that names each undeclared path.                 |
| `modeling`         | `enum`   | `open`, `required`   | `open`             | With `required`, every asset in the namespace must reference a model. An asset that declares its data inline cannot be mounted in it.                                                                                                                                                |
| `naming`           | `string` | A regular expression | `^[a-z0-9_-]+$`    | The pattern that the root, every node name, and every mount key must match. Connectware matches it against the whole segment, as if wrapped in `^(?:...)$`, and an invalid expression fails the installation. Property names have their own rule. See [Naming Rules](#naming-rules). |
| `modelVersioning`  | `enum`   | `strict`, `relaxed`  | `strict`           | See [Model Versioning](#model-versioning).                                                                                                                                                                                                                                           |
| `validation`       | `object` |                      |                    | See [Validation and Undeclared Topics](#validation-and-undeclared-topics).                                                                                                                                                                                                           |
| `undeclaredTopics` | `enum`   | `allow`, `deny`      | Behaves as `allow` | See [Validation and Undeclared Topics](#validation-and-undeclared-topics).                                                                                                                                                                                                           |

#### Model Versioning

With `strict`, a model version cannot change. Installing a model again at the same version with different data properties or attributes fails the installation. The description and the relations may change. To change a model, create a new version.

With `relaxed`, the service that owns a model may change it at the same version. Connectware then provisions every asset that uses the model again. The following rules apply:

* If assets of other services use the model, every namespace where they are mounted needs `relaxed`.
* If no other service uses the model, `relaxed` on a namespace of the owning service is enough.
* If an asset of another service uses the model but is not mounted, the model counts as `strict`, and the change fails.
* Only the service that owns a model can change it.

#### Validation and Undeclared Topics

Connectware stores the following keys at installation time, but does not enforce them. When a namespace declares one of them, the installation succeeds and returns a warning that names the key.

| Property                     | Type      | Allowed values                        | Default            | Description                                                                             |
| ---------------------------- | --------- | ------------------------------------- | ------------------ | --------------------------------------------------------------------------------------- |
| `validation.mode`            | `enum`    | `off`, `log`, `quarantine`, `enforce` | `log`              | How data that does not match its model is handled.                                      |
| `validation.quarantineTopic` | `string`  | A topic without `#` or `+`            |                    | The topic for messages that do not match their model.                                   |
| `validation.trustDataPaths`  | `boolean` | `true`, `false`                       | `false`            | When `true`, the declared writer of a topic skips the payload validation in the broker. |
| `undeclaredTopics`           | `enum`    | `allow`, `deny`                       | Behaves as `allow` | Whether publishing is allowed on topics below the root that no asset owns.              |

### targetState

Whether the resource is active. A disabled namespace keeps its tree, its placements, and the topics of its assets.

* **Optional**
* Type: `enum`
  * Allowed values: `enabled`, `disabled`
* Default: `enabled`

## Naming Rules

The root, the node names, and the mount keys become topic segments, so Connectware checks them when you install the service. With `placement: open`, the same check applies to every segment of a path that the tree does not declare. A segment fails the installation in the following cases:

* It is `set`, `res`, or `_quarantine`. `set` and `res` carry the commands of [writable properties](https://docs.cybus.io/2-8-0/data-flows/service-commissioning-files/resources/cybus-model.md#data).
* It is `!ref`, `!sub`, `!merge`, `<<`, or `__proto__`, which service commissioning files and the resource write API read as tags or special keys.
* It starts with `$`, which is reserved for topics such as `$meta`.
* It contains `+`, `#`, `/`, or a NUL character.
* It is a number, such as `7`, or `true`, `false`, or `null` in any spelling. This applies even when the key is quoted in YAML, so use a name such as `line7`.
* It does not match the `naming` policy of the namespace, which allows lowercase letters, digits, `_`, and `-` by default.

A mount key defaults to the resource ID of the asset. The default `naming` policy allows no uppercase letters. So an asset with a resource ID such as `cncMill01` needs a mount `key`, such as `cnc-mill-01`.

Property names follow a rule of their own instead of the `naming` policy. See [data](https://docs.cybus.io/2-8-0/data-flows/service-commissioning-files/resources/cybus-model.md#data).

## Removing Nodes

Other services can depend on the nodes of a namespace in the following ways:

* A mount of another service is placed at or below a node.
* A role or user of another service holds a [uns: grant](#access-to-the-namespace) on a node path.

While such a dependency exists, an update or deletion of the namespace service fails if it does one of the following:

* Removes or renames the node.
* Changes the root.
* Removes the namespace resource.
* Narrows the `placement` or `naming` policy so that the path of a `uns:` grant no longer resolves.

The error names the services and the path. Disabled services count too. Move or remove the mounts, or remove or change the grants, first.

Renaming only the resource ID of the namespace keeps every path, so it keeps the grants. With `placement: open`, a removed node still resolves, so a `uns:` grant on it does not prevent the removal.

## Access to the Namespace

To grant read access to a subtree, use `uns:<path>` with `context: mqtt` and `operation: read` in the permissions of a [role](https://docs.cybus.io/2-8-0/data-flows/service-commissioning-files/resources/cybus-role.md#resource) or a [user](https://docs.cybus.io/2-8-0/data-flows/service-commissioning-files/resources/cybus-user.md).

## Example

The following namespace declares a factory with halls and the lines below them. It uses the default policies.

{% code title="Namespace service" lineNumbers="true" %}

```yaml
description: Factory namespace

metadata:
  name: factory
  version: 1.0.0

resources:
  factory:
    type: Cybus::Namespace
    properties:
      root: factory
      structure:
        levels:
          - area
          - line
        tree:
          hall1:
            line1: {}
            line2: {}
          hall2: {}
```

{% endcode %}

To set policies, add a `policy` block to the `properties` of the namespace, next to `structure`:

{% code lineNumbers="true" %}

```yaml
factory:
  type: Cybus::Namespace
  properties:
    root: factory
    structure:
      # ...
    policy:
      placement: tree-only
      modeling: required
      naming: '^[a-z0-9_-]+$'
```

{% endcode %}


---

# 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.cybus.io/2-8-0/data-flows/service-commissioning-files/resources/cybus-namespace.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.
