# Architecture

Self-managed BYOC is designed to provide a secure, flexible and reliable environment for running your applications, while being managed through the Diagrid control plane. This document provides an overview of the system architecture to help you understand the key components, data flows, dependencies, and infrastructure requirements of a self-managed BYOC deployment.

## Components

A self-managed BYOC deployment consists of the following key components:

- [Agent](#agent)
- [Management Service](#management-service)
- [Gateway](#gateway)
- [Telemetry Collectors](#telemetry-collectors)
- [Diagrid Dapr Control Plane](#diagrid-dapr-control-plane)
- [Diagrid Dapr Servers](#diagrid-dapr-servers)
- [Diagrid Tunneling Service](#diagrid-tunneling-service) (optional)

### Agent

The **Agent** is responsible for managing the lifecycle of all the Diagrid resources within the Kubernetes cluster. It securely connects to the Diagrid control plane using mTLS and SPIFFE based workload identity. Once connected, it installs and manages the Telemetry Collectors, Diagrid Dapr Control Plane and any other configured infrastructure services such as PostgreSQL. The Agent then subscribes to any relevant resource updates from the control plane and ensures the desired state is maintained within the cluster. This includes the provisioning of Diagrid Projects and other related resources.

### Management Service

The **Management Service** serves 3 main purposes:

1. Provides a REST API for access from your private network to view application data.
2. Provides an internal communication channel to allow the Diagrid control plane to securely read and write secrets to your self-managed BYOC region.
3. Provides an internal configuration stream for Diagrid Dapr Servers to dynamically receive updates from the Agent.

The Management Service is not exposed to the public internet and is only accessible from within your private network. It uses reverse tunneling to securely connect to the Diagrid control plane, allowing it to receive configuration updates and securely manage secrets without exposing any endpoints to the public internet.

### Gateway

The **Gateway** is an Envoy control plane that manages access from within your private network to services running within your Diagrid region.

This includes exposing:

- Diagrid Dapr Servers to your applications.
- The Management Service API to the CLI or web UI served from within your private network.
- Workload identity trust anchors for trust distribution
- Diagrid Dapr Control Plane and configuration API for externally running Dapr servers.

### Telemetry Collectors

The **Telemetry Collectors** are responsible for collecting and exporting specific metrics and log data from the Diagrid Dapr Servers. This data is used to provide observability features in the Diagrid control plane. The collectors are Diagrid distributions of the open-source OpenTelemetry Collector project.

### Diagrid Dapr Control Plane

The **Diagrid Dapr Control Plane** is a Diagrid distribution of the Dapr control plane that runs as a shared service within your cluster. It provides the standard Dapr control plane features such as workload identity, configuration management, actor placement and job scheduling to the Diagrid Dapr Servers.

### Diagrid Dapr Servers

The **Diagrid Dapr Servers** are a standalone distribution of the Dapr runtime, packaged similarly to a Dapr sidecar but deployed and scaled independently of your applications. They serve Dapr APIs to your applications, which are deployed separately. The Diagrid Dapr Servers expose the following standard Dapr APIs to your applications:

#### Dapr API Compatibility

- [Conversation](https://docs.dapr.io/reference/api/conversation_api/)
- [Workflows](https://docs.dapr.io/reference/api/workflow_api/)
- [Service invocation](https://docs.dapr.io/reference/api/service_invocation_api/)
- [State management](https://docs.dapr.io/reference/api/state_api/)
- [Pub/Sub](https://docs.dapr.io/reference/api/pubsub_api/)
- [Actors](https://docs.dapr.io/reference/api/actors_api/)
- [Secrets](https://docs.dapr.io/reference/api/secrets_api/)
- [Configuration](https://docs.dapr.io/reference/api/configuration_api/)
- [Bindings](https://docs.dapr.io/reference/api/bindings_api/)
- [Distributed Lock](https://docs.dapr.io/reference/api/distributed_lock_api/)
- [Jobs](https://docs.dapr.io/reference/api/jobs_api/)

### Diagrid Tunneling Service (optional, opt-out)

Diagrid hosts a tunneling service known as `piko` that provides the capability for applications and other clients to securely expose themselves to the Diagrid Dapr Servers directly over a tunnel without the need for additional ingress. This is the capability that powers the `diagrid listen` and `diagrid dev run` commands.

## Networking & Data Flows

Self-managed BYOC is designed to ensure that all application data remains within your private network and is not exposed to Diagrid or the public internet. The Diagrid control plane manages the lifecycle of resources within your Region, but does not have access to any of the application data flowing through the Diagrid Dapr Servers. The Diagrid control plane also does not persist any of the secret resource configuration data, instead it securely stores those within your private installation and only keeps references to resolve them at runtime.

The only endpoint you need to expose from your self-managed BYOC region is the Gateway, which is accessed by your applications and users from within your private network. [Inbound network connections](#inbound-network-connections) lists the hostnames it serves.

**Diagram: A self-managed BYOC region and its connections.** Apps and users reach the region only through the Gateway. The Agent, Management Service and Telemetry Collectors open outbound connections to the control plane; exporting metrics and logs is opt-out.

- **Diagrid**: Control plane
- **Your private network**: Apps & users
  - **Kubernetes cluster**: Management Service, Agent, Telemetry Collectors, Gateway, Dapr control plane
    - **Project namespace (prj-<project-id>)**: Dapr Servers

- Apps & users → Gateway
- Gateway → Management Service
- Gateway → Dapr Servers
- Dapr control plane → Dapr Servers
- Dapr Servers → Telemetry Collectors
- Management Service → Control plane (reverse tunnel, async)
- Agent → Control plane (mTLS)
- Telemetry Collectors → Control plane (metrics, logs, async)

To provide a better user experience, we optionally (opt-out) export the following data from your self-managed BYOC region to the Diagrid control plane:

- Dapr Servers metrics and logs.
- Agent installation metadata such as k8s version.
- Resource installation and lifecycle status and metadata.

### Outbound Network Connections

Self-managed BYOC requires outbound connectivity to the Diagrid control plane. Ensure your network allows access to:

| Domain | Description | Required |
|--------|-------------|----------|
| `login.diagrid.io` | CLI login and authentication (identity provider). | Yes |
| `api.r1.diagrid.io` | Region join (installation only). | Yes |
| `catalyst-cloud.r1.diagrid.io` | Resource configuration updates. | Yes |
| `sentry.r1.diagrid.io` | Workload identity (mTLS). | Yes |
| `trust.r1.diagrid.io` | Trust anchors. A workload that cannot fetch them does not start. | Yes |
| `tunnels.trust.diagrid.io` | OIDC provider for Piko tunnels. | No |
| `client-events.r1.diagrid.io` | Event publishing. | Yes |
| `catalyst-metrics.r1.diagrid.io` | Dapr runtime metrics. | No |
| `catalyst-logs.r1.diagrid.io` | Dapr runtime logs. | No |
| `catalyst-releases.r1.diagrid.io` | The release to install next, when [release availability](./automate-upgrades.mdx#read-the-decision-in-your-cluster) is turned on (mTLS). | No |

You can route these connections through a firewall or an outbound proxy, but only some of them can be TLS-terminated:

- `catalyst-cloud.r1.diagrid.io`, `sentry.r1.diagrid.io` and `catalyst-releases.r1.diagrid.io` carry SPIFFE mTLS. No proxy can re-sign them, so they must pass through uninspected.
- Every other endpoint in the table is ordinary HTTPS and may be terminated by an inspecting proxy, provided Diagrid trusts the CA that proxy re-signs with. Set that CA with the `global.trustedCA` Helm value, either as an inline PEM bundle or as a reference to an existing ConfigMap.
- Container images are pulled by the container runtime rather than by the chart, so `global.trustedCA` does not cover them. A proxy in front of the registry needs its CA in the nodes' own trust store.

`global.trustedCA` adds the CA to the trust store of the agent, management, MCP and gateway control-plane deployments, and of every project sidecar, both OpenTelemetry collectors and the in-region Sentry. The certificates are added to the image's public roots, so public-CA upstreams keep verifying. A rotated bundle takes effect when the pod restarts. See [Proxying Outbound Connections](./reference.md#proxying-outbound-connections) in the Helm Chart Reference for both value forms and the workloads you have to roll after rotating a ConfigMap.

### Inbound network connections

The Diagrid control plane never connects into the region. Your applications and users do, and every connection arrives at one place: the Gateway's `gateway-envoy` Service in the `cra-agent` namespace. The Gateway serves every hostname on the port in the region's ingress (443 in the install guides), and picks the destination from the hostname of each request.

Every hostname is one label under the region's wildcard domain, the domain you give `diagrid region create --ingress "https://*.<domain>:443"`. Below, `<domain>` is that domain without the `*.`:

| Hostname | Used by | Purpose | TLS at the Gateway |
|----------|---------|---------|--------------------|
| `http-prj<project-id>.<domain>` | Your applications | A project's Dapr HTTP API. One per project. | Terminated |
| `grpc-prj<project-id>.<domain>` | Your applications | A project's Dapr gRPC API, and its Temporal API where enabled. One per project. | Terminated |
| `management.<domain>` | Diagrid CLI, Diagrid Web Console | The Management Service API. Not used when the region has [remote CLI and console access](./upgrades-operations.md#remote-cli-and-console-access) turned on. | Terminated |
| `trust.<domain>` | External workloads, automation | The region's trust anchors, served without authentication. Published on the region as `.status.endpoints.trustAnchors`. | Terminated |
| `oidc.<domain>` | Anything that checks a token the region issued | OIDC discovery documents for identities issued in the region. The same documents are also served by the control plane at `.status.endpoints.oidc`. | Terminated |
| `tunnels.<domain>`, `tunnels-proxy.<domain>` | `diagrid listen`, `diagrid dev run` | Tunnels that expose a local app to the project's Dapr servers. | Terminated |
| `health.<domain>` | Your global load balancer or DNS health check | Which region of a [region group](https://docs.diagrid.io/operate/platform-operations/multi-region) accepts writes. Served only by region group members. | Terminated |
| `sentry.<domain>` | `diagrid listen`, `diagrid dev run`, Dapr sidecars that run outside the region | Workload identity. The region's own sidecars use Sentry inside the cluster. | Passed through |
| `xrs.<domain>`, `dapr-api.<domain>`, `dapr-placement.<domain>`, `dapr-scheduler.<domain>`, `dapr-scheduler-server-0.<domain>` to `dapr-scheduler-server-2.<domain>` | Dapr sidecars that run outside the region | Configuration, actor placement and job scheduling, plus one name per scheduler replica. The region's own sidecars reach these services inside the cluster. Not needed when every Dapr server runs in the region. | Passed through |

The project ID is assigned when a project is created, so the project hostnames can't be known in advance. That is why the region needs a wildcard DNS record and a certificate that covers the wildcard. [Ingress and DNS](./ingress-dns.mdx) explains this, the ways to avoid a wildcard, and how to resolve project hostnames inside your cluster.

A region can instead be [served on one hostname](./ingress-dns.mdx#serve-the-region-on-one-hostname) that you choose, such as `catalyst-api.mycompany.com`. Then that hostname is the only one that needs a certificate. It is also the only one that needs a DNS record, unless Dapr sidecars run outside the region: they look up the Dapr services' names, so those names need [DNS records](./ingress-dns.mdx#create-the-record-and-the-certificate), still without a certificate. The Gateway serves every project on it, picked by the App ID's API token, and the management API, trust anchors, OIDC discovery and tunnels under `/diagrid/`. It still passes through the services marked **Passed through** above by their own names, such as `sentry.catalyst-api.mycompany.com`: clients connect to the hostname and send that name in the TLS handshake.

Two things follow from the TLS column:

- **The Gateway's certificate covers the terminated hostnames.** It is the `*.<domain>` certificate you give it in `gateway.tls`. If the region is served on one hostname, it is a certificate for that hostname. If a private CA signed it, see [Private gateway CA](./private-gateway-ca.mdx).
- **Passed-through hostnames need a layer 4 path.** The Gateway routes them by the name in the TLS handshake and forwards the connection unopened to a service that presents its own SPIFFE certificate. A load balancer, firewall or proxy in front of the Gateway must forward TCP without terminating TLS. One that terminates TLS for the other hostnames must leave these alone.

When the region tells clients to use TLS, the Gateway's plain HTTP port answers every request with a redirect to HTTPS.

Unless the region has a managed domain or remote CLI and console access, the Diagrid Web Console calls the Management Service from the user's browser at a Diagrid-owned name, `<hash>.r1.privatediagrid.net`, shown on the region as `.status.endpoints.managementDiagrid`. Diagrid points that name at `management.<domain>`, or at the region's hostname when it is served on one hostname, and issues its certificate, which the Gateway serves alongside yours. So your users' browsers must be able to resolve `management.<domain>`, or the region's one hostname, and reach the Gateway.

### Namespaces

Diagrid uses these namespaces in your cluster. The names are the defaults:

| Namespace | Holds |
|---|---|
| `cra-agent` | The Agent, the Management Service, the Gateway and the telemetry collectors. This is the namespace you install the Helm chart into. |
| `root-dapr-system` | The region's own Dapr control plane, including Sentry. |
| `shared-postgresql`, `shared-kafka`, `shared-ratelimit-redis` | The data stores Diagrid installs for you, when it installs them. |
| `prj-<project-id>` | One project's Dapr Servers. Each project gets its own. |

In a self-managed region you can choose other names, and put everything except the project namespaces into one namespace. Project namespaces keep one each, but you can change how their names start: set `global.namespaces.projectPrefix` to replace `prj-`. Choose before you install: the names are part of each service's identity, so moving an installed region to other namespaces means reinstalling it. See [Installing into other namespaces](./reference.md#installing-into-other-namespaces) in the Helm chart reference.

The guides in this section use the defaults. If you chose other names, use yours in their commands.

### Network Policies

Each project runs in its own dedicated Kubernetes namespace (`prj-<project-id>` by default). Diagrid reconciles a set of Kubernetes `NetworkPolicy` resources in each project namespace to enforce a deny-by-default posture, allowing only the traffic required for Diagrid to operate. By default, Dapr Servers in one project cannot reach workloads in another project's namespace or internal services on your cluster network.

The default posture can be tuned via the following Helm values under `agent.config.project`. See the [Helm Chart Reference](./reference.md#network-policies-projects) for the full set of options and examples:

| Key | Purpose |
|-----|---------|
| `blocked_egress` | CIDRs denied from the Dapr Server egress. Defaults cover RFC1918 and the cloud metadata range (`169.254.0.0/16`). |
| `allowed_egress` | Additive allow rules for Dapr Server egress, by CIDRs and/or namespaces, optionally scoped to ports. Use this to allow traffic to services blocked by blocked_egress rules. |
| `allowed_ingress` | Additive allow rules for ingress into project namespaces. The namespace you installed Diagrid into (`cra-agent` by default) and the `monitoring` namespace are always permitted so management traffic and metrics scraping are never blocked. |
| `disable_network_policies` | Disables network policy creation entirely. Not recommended for production usage. |

Allow rules always win over block rules, so you can punch narrow holes through `blocked_egress` without weakening it. For example, to allow Dapr Servers to reach an internal database:

```yaml
agent:
  config:
    project:
      allowed_egress:
        - name: rds
          cidrs: ["10.4.5.6/32"]
          ports:
            - port: 5432
              protocol: TCP
```

## Security

Diagrid builds on top of the security foundations of Dapr. This includes using mTLS and SPIFFE based workload identity for all communication between Diagrid Dapr Servers, Diagrid Components and the Diagrid control plane.

### Workload Identity

Every Diagrid component and Dapr Server is issued a [SPIFFE](https://spiffe.io/) identity in the form of a short-lived X.509 SVID, signed by a Dapr Sentry and automatically rotated in the background. These identities are what drive mTLS authentication across the system, so every connection — between components, between Dapr Servers, and between the region and the Diagrid control plane — is mutually authenticated using verifiable cryptographic identities rather than shared secrets.

#### Trust domains and sentries

Self-managed BYOC operates two sentries across two trust domains:

- **Dataplane Sentry** — runs inside your cluster as part of the Diagrid Dapr Control Plane. It issues SPIFFE identities under a regional trust domain to in-cluster Diagrid components and Diagrid Dapr Servers. The root of trust for this sentry is owned and managed by the user.
- **Public Sentry** — runs in Diagrid's cloud (`sentry.r1.diagrid.io`) under the `trust.diagrid.io` trust domain. It issues identities to components that communicate with the Diagrid control plane. The root of trust for this sentry is owned and managed by Diagrid.

Components that bridge your private network and the Diagrid control plane — the Agent, Gateway, and Management Service — hold **dual identities**, one from each sentry. The security layer transparently selects the correct credential to present based on the peer's trust domain.

**Diagram: Workload identity across a self-managed BYOC region and the control plane.** The agent, gateway and management service hold identities from both sentries. Diagrid Dapr servers hold only a regional identity.

- **Diagrid**: Control plane, Public Sentry
- **Self-managed BYOC region**: Agent, Management service, Gateway, Dataplane Sentry, Diagrid Dapr servers
- **Any infrastructure**: Application

- Control plane ↔ Agent
- Control plane ↔ Gateway
- Public Sentry ↔ Agent (public identity)
- Public Sentry ↔ Management service
- Public Sentry ↔ Gateway
- Dataplane Sentry ↔ Agent
- Dataplane Sentry ↔ Management service
- Dataplane Sentry ↔ Gateway
- Dataplane Sentry ↔ Diagrid Dapr servers (regional identity)
- Diagrid Dapr servers ↔ Application

The SPIFFE ID format follows the standard `spiffe://<trust-domain>/ns/<namespace>/<identity>` pattern. For example, a Dapr Server in a project receives an identity like `spiffe://<regional-trust-domain>/ns/prj-<project-id>/<app-id>`, where `prj-<project-id>` is the project's namespace (with the default project prefix).

#### Trust anchor distribution

To verify each other's certificates, components maintain three sets of trust anchors, one per trust domain in use:

- **Diagrid CA** — the root CA for identities issued by the Public Sentry. Fetched from `trust.r1.diagrid.io`.
- **Region Host CA** — the root CA for identities issued by the Dataplane Sentry. Distributed in-cluster and served to external clients via the Gateway's trust distribution endpoint.
- **Workload Identity CA** — established per external workload during join, used only to validate the workload's bootstrap certificate.

When a component receives a peer certificate, it looks up the peer's trust domain, finds the matching CA, and validates the signature — allowing the system to recognize multiple authorities without conflating them.

### Regional PKI

The Dataplane Sentry needs an X.509 issuer (CA certificate, CA private key, and root trust anchors) to sign the SPIFFE identities it hands out to in-region components and Diagrid Dapr Servers. This issuer — the **regional PKI** — is the root of trust for every workload identity in your region, so its lifecycle determines how long those identities continue to validate.

There are two ways to provide it.

#### Option 1: Default PKI generated by Sentry

If you do not supply your own PKI, the Dataplane Sentry generates a self-signed root CA and issuer key pair on first boot and persists them as Kubernetes secrets in the Diagrid Dapr Control Plane namespace. No additional configuration is required.

This option is the fastest path to a working region and is appropriate for evaluation, development, and non-production environments. It comes with one important caveat:

:::warning Sentry-generated certificates expire after 1 year and are not automatically renewed
The self-signed issuer is valid for **1 year** from the time Sentry first boots. Diagrid does **not** currently rotate or renew this certificate. When it expires, the Dataplane Sentry can no longer issue valid SVIDs, mTLS handshakes between Diagrid Dapr Servers and other in-region components will start to fail, and recovery requires manual intervention (deleting the existing Sentry secrets and restarting Sentry to regenerate them, which produces a new root and forces every workload to pick up the new trust anchors).

For any environment where you cannot tolerate a hard cutover at the 1-year mark, use Option 2 instead.
:::

#### Option 2: Bring your own PKI

For production, supply your own issuer and trust anchors at region installation time. The Dataplane Sentry loads them on boot and uses them — rather than generating its own — to sign workload SVIDs. With this option, **you own the renewal lifecycle**: Diagrid will not rotate the issuer for you, so you must ensure the issuer certificate is replaced before it expires.

You provide the PKI material as existing Kubernetes resources and point the chart at them via `agent.config.internal_dapr.pki` (see the [Helm Chart Reference](./reference.md#dapr-pki) for the full set of options):

```yaml
agent:
  config:
    internal_dapr:
      pki:
        issuer:
          secret:
            name: dapr-trust-bundle
            namespace: cert-manager
            cert: tls.crt
            key: tls.key
        trust:
          config_map:
            name: dapr-trust-bundle
            namespace: cert-manager
            chain: ca.crt
```

- `pki.issuer.secret` — Kubernetes secret holding the PEM-encoded issuer certificate (`cert`) and private key (`key`) the Sentry will use to sign SVIDs.
- `pki.trust.config_map` — Kubernetes ConfigMap holding the PEM-encoded root CA chain (`chain`) distributed to workloads as the trust anchor.

The agent reads the issuer from this secret when it starts, and installs the Dataplane Sentry with it. To rotate the issuer, update the secret and restart the agent (`kubectl -n cra-agent rollout restart deployment agent`); Sentry then issues SVIDs signed by the new issuer. Changing the trust anchors after the region has joined needs a rejoin through [Diagrid support](mailto:support@diagrid.io).

The recommended way to provision and renew the regional PKI is with [cert-manager](https://cert-manager.io/) and [trust-manager](https://cert-manager.io/docs/trust/trust-manager/), which can issue the CA, populate the secret and ConfigMap above, and renew before expiration automatically. To keep the root CA key out of the cluster and protect the issuer key, see [Protect the regional PKI keys](./protect-pki-keys.mdx).

### Secret Management

In Diagrid, secrets can be handled implicitly or explicitly. By default, if you provide a resource to the Diagrid API with plaintext values in a secret field, the platform will automatically extract the value and store it securely in an internal secret provider. This is transparent to you as the user and does not require any additional configuration. This means that we never store your secret values in our controlplane database and they will always be stored securely within the configured secret provider. However, if you would prefer to explicitly reference secrets from your own secret store, you can do so by creating a Dapr secret store component and using the Dapr secret references in your resource definitions.

If you run self-managed BYOC, you can configure the secret provider the platform uses for handling implicit secrets. By default, we use a Kubernetes secrets provider that stores secrets within your cluster, but you can also choose to use AWS Secrets Manager or PostgreSQL with automated data encryption as your secret provider. See the [Helm Chart Reference](./reference.md#secrets) for the full set of options and configuration details. In a [region group](https://docs.diagrid.io/operate/platform-operations/multi-region), every member must use the PostgreSQL provider and the same key encryption key: secrets are envelope-encrypted, so the rows replicate to a member holding a different key and cannot be decrypted there.

## Dependencies

### Kubernetes

Self-managed BYOC is designed to run on Kubernetes 1.24 or later. It is packaged and distributed as a single Helm chart.

### PostgreSQL

Features such as Managed Workflows, Agents and KV Store rely on PostgreSQL as a backing datastore. This database backs the [managed workflow store](https://docs.diagrid.io/operate/project-operations/managed-services#workflow-store), which every new project in the region uses by default. By default, a PostgreSQL instance will be installed by the Agent into your Kubernetes cluster as part of the installation process. However, this is not suitable for production workloads and we recommend using an external managed PostgreSQL instance for production deployments. Refer to the [Helm Chart Reference](./reference.md) documentation for configuration options to use an external PostgreSQL instance. The members of a [region group](https://docs.diagrid.io/operate/platform-operations/multi-region) share one external cluster, replicated across the regions with a single writer.

### Kafka

Features such as Managed Pub/Sub rely on Kafka as a backing datastore. By default, a lightweight Kafka instance will be installed by the Agent into your Kubernetes cluster as part of the installation process. However, this is not suitable for production workloads and we recommend using an external managed Kafka instance for production deployments. Refer to the [Helm Chart Reference](./reference.md) documentation for configuration options to use an external Kafka instance.
