> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes Operator Custom Resources

> Reference for the Formal Kubernetes Operator CRDs

## FormalResource

Registers an in-cluster service as a Formal resource.

```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
apiVersion: joinformal.com/v1
kind: FormalResource
metadata:
  name: orders-database
spec:
  technology: postgres
  hostname: postgres.default.svc.cluster.local
  port: 5432
```

### Spec

| Field | Type | Required | Description |
| - | - | - | - |
| `technology` | string | Yes | Protocol type (`postgres`, `mysql`, `mongodb`, `http`, etc.) |
| `hostname` | string | Yes | In-cluster hostname of the backend service |
| `port` | int | Yes | Port of the backend service |
| `spaceId` | string | No | ID of the [Space](https://docs.formal.ai/docs/guides/core-concepts/spaces.md) to assign the resource to |
| `tls` | object | No | TLS configuration for the backend connection |

### TLS Configuration

```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
spec:
  tls:
    mode: verify-full
    minVersion: "TLSv1.2"
    caSecretRef:
      name: my-ca-secret
      key: ca.crt
```

| Field | Type | Required | Description |
| - | - | - | - |
| `tls.mode` | string | Yes | `disable`, `insecure-skip-verify`, `insecure-verify-ca-only` (verifies the chain but not the hostname), or `verify-full` |
| `tls.minVersion` | string | No | Minimum TLS version: `TLSv1.2` or `TLSv1.3` |
| `tls.caSecretRef.name` | string | No | Kubernetes Secret containing the CA certificate |
| `tls.caSecretRef.key` | string | No | Key within the Secret |

`tls.mode` is required whenever you set `tls`.

***

## FormalListener

Creates a listener on an existing Formal connector with routing rules.

```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
apiVersion: joinformal.com/v1
kind: FormalListener
metadata:
  name: postgres
spec:
  connectorId: connector_abc123
  name: postgres
  port: 5432
  rules:
    - type: technology
      technology: postgres
```

### Spec

| Field | Type | Required | Description |
| - | - | - | - |
| `connectorId` | string | Yes | ID of the Formal connector |
| `name` | string | Yes | Display name of the listener |
| `port` | int | Yes | Port the listener binds to on the connector |
| `rules` | list | No | Routing rules for the listener |

### Rules

Each rule routes traffic to one or more resources:

| Field | Type | Required | Description |
| - | - | - | - |
| `type` | string | Yes | `resource` or `technology` |
| `resourceRef` | string | No | Name of a FormalResource in the same namespace (for `resource` rules) |
| `technology` | string | No | Technology name (for `technology` rules) |

When using `resource` rules, the operator resolves the `resourceRef` to the Formal resource ID automatically.

> [!NOTE]
>
> The connector itself is not managed by the operator. Create the connector via
> [Terraform](https://docs.formal.ai/docs/guides/configuration/terraform.md) or the [Control Plane](https://app.formal.ai/connectors), then reference its ID in
> FormalListener resources.

***

## FormalNativeUser

Creates a legacy Native User on a Formal Resource. Credentials come from a
Kubernetes Secret.

> [!NOTE]
>
> This CRD supports only legacy Native Users, which are deprecated. See the
> [migration guide](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users-legacy)
> to move to new Native Users.

```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
apiVersion: joinformal.com/v1
kind: FormalNativeUser
metadata:
  name: orders-database-default
spec:
  resourceRef: orders-database
  type: basic
  useAsDefault: true
  secretRef:
    name: postgres-credentials
    keys:
      username: username
      password: password
```

### Spec

| Field | Type | Required | Description |
| - | - | - | - |
| `resourceRef` | string | Yes | Name of a FormalResource in the same namespace |
| `type` | string | Yes | See [supported types](#supported-types) below |
| `useAsDefault` | bool | No | Whether this is the default native user for the resource |
| `identityLinks` | list | No | See [identity links](#identity-links) below |

> [!NOTE]
>
> Only one FormalNativeUser per FormalResource can set `useAsDefault`. When several do, the oldest one wins and the others report `Ready=False` with reason `DefaultConflict`. The operator reapplies `useAsDefault` on every reconcile, so a default changed outside Kubernetes (for example in the Formal console) is reverted.

> [!NOTE]
>
> The operator watches referenced Secrets. When a Secret is updated, the
> operator automatically propagates the new credentials to Formal.

### Supported Types

#### `basic`

Username and password credentials, sourced from a Kubernetes Secret.

| Field | Type | Required | Description |
| - | - | - | - |
| `secretRef.name` | string | Yes | Name of the Kubernetes Secret |
| `secretRef.keys.username` | string | Yes | Key in the Secret containing the username |
| `secretRef.keys.password` | string | Yes | Key in the Secret containing the password |

#### `iam`

Cloud IAM authentication.

| Field | Type | Required | Description |
| - | - | - | - |
| `iam.cloudProvider` | string | Yes | Cloud provider (`aws` or `gcp`) |
| `iam.username` | string | Yes | IAM username for authentication |
| `iam.role` | string | No | IAM role ARN or identifier (if omitted, uses the environment's ambient IAM credentials) |

#### `kubernetes`

Kubernetes authentication via kubeconfig.

| Field | Type | Required | Description |
| - | - | - | - |
| `kubernetes.kubeconfigEnv` | string | Yes | Environment variable name containing kubeconfig |

#### `ssh_key`

SSH key authentication, with the private key sourced from a Kubernetes Secret.

| Field | Type | Required | Description |
| - | - | - | - |
| `sshKey.username` | string | Yes | SSH username |
| `sshKey.secretRef.name` | string | Yes | Secret containing the private key |
| `sshKey.secretRef.key` | string | Yes | Key within the Secret |

#### `snowflake_key`

Snowflake key-pair authentication, with the private key sourced from a Kubernetes Secret.

| Field | Type | Required | Description |
| - | - | - | - |
| `snowflakeKey.username` | string | Yes | Snowflake username |
| `snowflakeKey.secretRef.name` | string | Yes | Secret containing the private key |
| `snowflakeKey.secretRef.key` | string | Yes | Key within the Secret |

#### `http_basic`

HTTP Basic authentication, with credentials sourced from a Kubernetes Secret.

| Field | Type | Required | Description |
| - | - | - | - |
| `httpBasic.header` | string | Yes | HTTP header name (e.g., `Authorization`) |
| `httpBasic.secretRef.name` | string | Yes | Name of the Kubernetes Secret |
| `httpBasic.secretRef.keys.username` | string | Yes | Key in the Secret containing the username |
| `httpBasic.secretRef.keys.password` | string | Yes | Key in the Secret containing the password |

#### `http_bearer`

HTTP Bearer token authentication, with the token sourced from a Kubernetes Secret.

| Field | Type | Required | Description |
| - | - | - | - |
| `httpBearer.header` | string | Yes | HTTP header name (e.g., `Authorization`) |
| `httpBearer.secretRef.name` | string | Yes | Secret containing the token |
| `httpBearer.secretRef.key` | string | Yes | Key within the Secret |

#### `http_api_key`

HTTP API key authentication, with the value sourced from a Kubernetes Secret.

| Field | Type | Required | Description |
| - | - | - | - |
| `httpApiKey.location` | string | Yes | `header` or `query_parameter` |
| `httpApiKey.key` | string | Yes | Header or query parameter name |
| `httpApiKey.secretRef.name` | string | Yes | Secret containing the API key value |
| `httpApiKey.secretRef.key` | string | Yes | Key within the Secret |

### Identity Links

`identityLinks` binds Formal identities to the native user. Each entry is resolved by name against the Formal control plane:

| Field | Type | Required | Description |
| - | - | - | - |
| `type` | string | Yes | `user`, `group`, or `resource_hostname` |
| `name` | string | Yes | Name of the identity to link (see resolution rules below) |
| `terminationProtection` | bool | No | If `true`, the link cannot be deleted |

Resolution rules per `type`:

* `group`: matched against `Group.name`
* `user`: matched against `User.db_username`
* `resource_hostname`: matched against `ResourceHostname.name` within the parent resource

Links not present in `identityLinks` on reconcile are removed, so the spec is the source of truth.

```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
spec:
  resourceRef: orders-database
  type: basic
  secretRef:
    name: postgres-credentials
    keys:
      username: username
      password: password
  identityLinks:
    - type: group
      name: db-readers
    - type: group
      name: orders-admins
      terminationProtection: true
```

***

## FormalPolicy

Creates and manages a Formal policy from Rego code.

```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
apiVersion: joinformal.com/v1
kind: FormalPolicy
metadata:
  name: data-eng-postgres-read
spec:
  description: Read-only Postgres access for the data-eng team
  status: active
  terminationProtection: false
  code: |
    package formal.v2

    import future.keywords.if
    import future.keywords.in

    session := {
      "action": "block",
      "type": "block_with_formal_message",
      "reason": "Access restricted to the data-eng team"
    } if {
      input.resource.technology == "postgres"
      input.resource.tags["team"] == "data-eng"
      not "data-eng" in input.user.groups
    }

    request := {
      "action": "block",
      "type": "block_with_formal_message",
      "reason": "Read-only access for the data-eng team"
    } if {
      input.resource.tags["team"] == "data-eng"
      input.query.statement_type != "SELECT"
    }
```

### Spec

| Field | Type | Required | Description |
| - | - | - | - |
| `description` | string | Yes | Description shown for the policy |
| `status` | string | Yes | Policy mode: `draft`, `dry-run`, or `active` |
| `code` | string | Yes | Policy logic written in Rego |
| `terminationProtection` | bool | No | Prevents policy deletion when `true`; defaults to `false` |

The operator uses `metadata.name` as the Formal policy name.
It synchronizes spec changes and stores the Formal policy ID in `status.policyId`.
If the policy is deleted in Formal, the operator recreates it during reconciliation.

Deleting the custom resource also deletes the policy from Formal.
Disable `terminationProtection` before deleting a protected policy.

**Verify:**

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
kubectl get formalpolicy data-eng-postgres-read \
  -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}{"\n"}'
# Expected: True
```

***

## FormalConnectorHostname

Sets the hostname of an existing Formal connector. A [Formal-Managed](https://docs.formal.ai/docs/guides/core-concepts/connectors/tls.md#formal-managed) hostname takes a `dnsRecord`, and Formal issues its TLS certificate. A [Customer-Managed](https://docs.formal.ai/docs/guides/core-concepts/connectors/tls.md#customer-managed) hostname takes a `secretRef` to a Kubernetes Secret holding the certificate, such as one issued by [cert-manager](https://cert-manager.io).

```yaml theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
apiVersion: joinformal.com/v1
kind: FormalConnectorHostname
metadata:
  name: main-connector
spec:
  connectorId: connector_abc123
  hostname: main.connectors.example.com
  secretRef:
    name: connector-tls
    keys:
      certificate: tls.crt
      privateKey: tls.key
```

### Spec

| Field | Type | Required | Description |
| - | - | - | - |
| `connectorId` | string | Yes | ID of the Formal connector. Immutable. |
| `hostname` | string | Yes | Hostname clients use to reach the connector. Immutable. |
| `dnsRecord` | string | No | Formal-Managed only: hostname of the load balancer the hostname points to |
| `secretRef.name` | string | No | Customer-Managed only: name of the Kubernetes Secret |
| `secretRef.keys.certificate` | string | Yes | Key in the Secret containing the PEM certificate full chain |
| `secretRef.keys.privateKey` | string | Yes | Key in the Secret containing the PEM private key |
| `terminationProtection` | bool | No | Prevents hostname deletion when `true`; defaults to `false` |

Set exactly one of `dnsRecord` or `secretRef`. A Formal-Managed hostname becomes `Ready` once Formal has issued its certificate and created its DNS record.

> [!NOTE]
>
> The operator watches the referenced Secret. When the certificate is renewed, the operator uploads it to Formal.

If the connector already has this hostname, the operator adopts it. Deleting the custom resource also deletes the hostname from Formal.


## Related topics

- [Kubernetes Operator](https://docs.formal.ai/docs/changelog/kubernetes-operator.md)
- [Formal Kubernetes Operator](https://docs.formal.ai/docs/guides/core-concepts/kubernetes-operator/introduction.md)
- [Deploy the Kubernetes Operator](https://docs.formal.ai/docs/guides/core-concepts/kubernetes-operator/deployment.md)
- [Formal Control Plane](https://docs.formal.ai/docs/guides/control-plane/overview.md)
- [Connector Hostname and TLS](https://docs.formal.ai/docs/guides/core-concepts/connectors/tls.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.