> ## 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.

# Migrate from legacy Native Users

> Move Resources from legacy Native Users to new Native Users

## Overview

Legacy Native Users are deprecated. They use identity links and a default flag.
New [Native Users](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users.md) replace
these assignments with a Resource-level CEL expression.

## Migrate to new Native Users

A new version of Native Users is available with typed credentials, hooks, and
default Native User selection. This guide explains how to configure it.

> [tab] Web
>
> > [!NOTE]
> >
> > New Native Users require Connector version 2.17.0 or later. Upgrade every
> > Connector serving this Resource before opting in.
>
> **1. Preview and create new Native Users**
>
> Click the **Preview** button to add new Native Users. Previewed changes are saved,
> but Connectors continue using legacy credentials. Formal does not copy
> legacy secrets into the replacements.
>
> Create one replacement for each legacy Native User:
>
> | Legacy credential | New credential type |
> | - | - |
> | Username and password | **Password** |
> | AWS ambient IAM marker `iam` | **AWS IAM** |
> | AWS IAM role ARN used for authentication | **AWS IAM Role** |
> | GCP IAM marker `iam_gcp` | **GCP IAM** |
> | Azure IAM marker `iam_azure` | **Azure IAM** |
> | Snowflake PEM private key | **Snowflake Key** |
> | SSH key or key and certificate JSON | **SSH Key** |
> | HTTP authentication JSON | Matching **HTTP** credential type |
>
> For an `ENV:<NAME>` secret, choose **Environment Variable** and enter
> `<NAME>`. Do not include the `ENV:` prefix.
>
> > [!NOTE]
> >
> > New Native Users use labels for
> > [explicit Native User selection](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users.md#request-a-native-user-at-connection-time),
> > rather than usernames. If you rely on a specific username for selection,
> > match the new label to the legacy username.
>
> **2. Replace identity links with a default selection**
>
> Legacy identity links do not migrate automatically. Recreate their behavior
> in **Default Native User** with CEL.
>
> Place specific User rules before Group rules, then return the legacy default:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> user.id == "user_01k9fanpwmbsnpn32ep6axj1qr" // alice
>   ? native_users["admin"]
>   : "group_01kzrt34v7c2wv0ygtekyycctr" in user.group_ids // analysts
>     ? native_users["readonly"]
>     : native_users["default"]
> ```
>
> See
> [select a default Native User](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users.md#select-a-default-native-user)
> for supported identity fields and more examples.
>
> **3. Review policies**
>
> New Native Users expose their label through `input.native_user`. Preserve
> legacy usernames as labels to keep these comparisons stable.
>
> Update policies that inspect `input.native_user_assignment`. New Native
> Users return `cel` or `user-requested` instead of legacy assignment values.
>
> **4. Activate and verify**
>
> Click **Opt in**, enter `confirm`, and complete these checks:
>
> 1. Connect without a label and confirm the expected default selection.
> 2. Connect as an identity with a User or Group rule.
> 3. Connect with `@<label>` if clients request Native Users explicitly.
> 4. Confirm the upstream identity and policy result in session logs.
>
> Legacy Native Users remain stored after activation, if a rollback is needed.
>
> **5. Roll back if needed**
>
> To roll back, click **Roll back** and enter `confirm`. The Resource resumes
> using its stored legacy configuration.
>
> New Native Users and their selection remain stored. Fix the configuration,
> then opt in again.

> [tab] Terraform
>
> > [!NOTE]
> >
> > New Native Users require Formal Terraform Provider 4.26.0 or later and
> > Connector version 2.17.0 or later. Upgrade every Connector serving the
> > Resource before opting in.
>
> **1. Add `formal_native_user_v3` resources alongside legacy resources**
>
> Keep every `formal_native_user` and `formal_native_user_link` block. Add
> separate `formal_native_user_v3` replacements. Expand each credential type
> for its before-and-after configuration.
>
> > [!NOTE]
> >
> > New Native Users use labels for
> > [explicit Native User selection](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users.md#request-a-native-user-at-connection-time),
> > rather than usernames. If you rely on a specific username for selection,
> > match the new label to the legacy username.
>
> > [accordion] Password or environment variable
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "read_only" {
> >   resource_id        = formal_resource.database.id
> >   native_user_id     = "readonly"
> >   native_user_secret = "ENV:DB_READONLY_PASSWORD"
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "read_only" {
> >   resource_id = formal_resource.database.id
> >   label       = "readonly"
> >
> >   basic {
> >     username = "readonly"
> >     password {
> >       environment_variable = "DB_READONLY_PASSWORD"
> >     }
> >   }
> > }
> > ```
> >
> > Remove `ENV:` from the V3 `environment_variable` value. To store the
> > password in Formal instead, replace `environment_variable` with
> > `literal`.
>
> > [accordion] AWS ambient IAM
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "aws_ambient" {
> >   resource_id        = formal_resource.database.id
> >   native_user_id     = "iam_database_user"
> >   native_user_secret = "iam"
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "aws_ambient" {
> >   resource_id = formal_resource.database.id
> >   label       = "iam_database_user"
> >
> >   aws_iam {
> >     username = "iam_database_user"
> >   }
> > }
> > ```
>
> > [accordion] AWS IAM role
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "aws_role" {
> >   resource_id        = formal_resource.database.id
> >   native_user_id     = "iam_database_user"
> >   native_user_secret = "arn:aws:iam::123456789012:role/formal-database-access"
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "aws_role" {
> >   resource_id = formal_resource.database.id
> >   label       = "iam_database_user"
> >
> >   aws_iam_role {
> >     username = "iam_database_user"
> >     role     = "arn:aws:iam::123456789012:role/formal-database-access"
> >   }
> > }
> > ```
>
> > [accordion] GCP IAM
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "gcp_iam" {
> >   resource_id        = formal_resource.database.id
> >   native_user_id     = "formal-connector"
> >   native_user_secret = "iam_gcp"
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "gcp_iam" {
> >   resource_id = formal_resource.database.id
> >   label       = "formal-connector"
> >
> >   gcp_iam {
> >     username = "formal-connector"
> >   }
> > }
> > ```
> >
> > Continue using the service account email without the
> > `.gserviceaccount.com` suffix as the username.
>
> > [accordion] Azure IAM
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "azure_iam" {
> >   resource_id        = formal_resource.database.id
> >   native_user_id     = "formal-connector"
> >   native_user_secret = "iam_azure"
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "azure_iam" {
> >   resource_id = formal_resource.database.id
> >   label       = "formal-connector"
> >
> >   azure_iam {
> >     username = "formal-connector"
> >   }
> > }
> > ```
>
> > [accordion] Snowflake private key
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "snowflake" {
> >   resource_id        = formal_resource.snowflake.id
> >   native_user_id     = "FORMAL_CONNECTOR"
> >   native_user_secret = "ENV:SNOWFLAKE_PRIVATE_KEY"
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "snowflake" {
> >   resource_id = formal_resource.snowflake.id
> >   label       = "FORMAL_CONNECTOR"
> >
> >   snowflake_key {
> >     username = "FORMAL_CONNECTOR"
> >     key {
> >       environment_variable = "SNOWFLAKE_PRIVATE_KEY"
> >     }
> >   }
> > }
> > ```
>
> > [accordion] SSH private key and certificate
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "ssh" {
> >   resource_id    = formal_resource.ssh.id
> >   native_user_id = "ubuntu"
> >   native_user_secret = jsonencode({
> >     key  = file("${path.module}/id_rsa")
> >     cert = file("${path.module}/id_rsa-cert.pub")
> >   })
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "ssh" {
> >   resource_id = formal_resource.ssh.id
> >   label       = "ubuntu"
> >
> >   ssh_key {
> >     username = "ubuntu"
> >     key {
> >       literal = file("${path.module}/id_rsa")
> >     }
> >     certificate {
> >       literal = file("${path.module}/id_rsa-cert.pub")
> >     }
> >   }
> > }
> > ```
> >
> > For private-key-only authentication, use the same `ssh_key` block
> > without `certificate`.
>
> > [accordion] HTTP Basic
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "http_basic" {
> >   resource_id    = formal_resource.api.id
> >   native_user_id = "basic-auth"
> >   native_user_secret = jsonencode({
> >     type     = "http"
> >     sub_type = "basic"
> >     http_basic = {
> >       header   = "Authorization"
> >       username = "api_user"
> >       password = "ENV:HTTP_BASIC_PASSWORD"
> >     }
> >   })
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "http_basic" {
> >   resource_id = formal_resource.api.id
> >   label       = "basic-auth"
> >
> >   http_basic {
> >     header   = "Authorization"
> >     username = "api_user"
> >     password {
> >       environment_variable = "HTTP_BASIC_PASSWORD"
> >     }
> >   }
> > }
> > ```
>
> > [accordion] HTTP bearer token
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "http_bearer" {
> >   resource_id    = formal_resource.api.id
> >   native_user_id = "bearer"
> >   native_user_secret = jsonencode({
> >     type     = "http"
> >     sub_type = "bearer_token"
> >     http_bearer_token = {
> >       header = "Authorization"
> >       token  = "ENV:HTTP_BEARER_TOKEN"
> >     }
> >   })
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "http_bearer" {
> >   resource_id = formal_resource.api.id
> >   label       = "bearer"
> >
> >   http_bearer {
> >     header = "Authorization"
> >     token {
> >       environment_variable = "HTTP_BEARER_TOKEN"
> >     }
> >   }
> > }
> > ```
>
> > [accordion] HTTP API key header
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "http_api_key_header" {
> >   resource_id    = formal_resource.api.id
> >   native_user_id = "header-api-key"
> >   native_user_secret = jsonencode({
> >     type     = "http"
> >     sub_type = "api_key"
> >     http_api_key = {
> >       type  = "header"
> >       key   = "X-Api-Key"
> >       value = "ENV:HTTP_API_KEY"
> >     }
> >   })
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "http_api_key_header" {
> >   resource_id = formal_resource.api.id
> >   label       = "header-api-key"
> >
> >   http_api_key_header {
> >     key = "X-Api-Key"
> >     value {
> >       environment_variable = "HTTP_API_KEY"
> >     }
> >   }
> > }
> > ```
>
> > [accordion] HTTP API key query parameter
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "http_api_key_query" {
> >   resource_id    = formal_resource.api.id
> >   native_user_id = "query-api-key"
> >   native_user_secret = jsonencode({
> >     type     = "http"
> >     sub_type = "api_key"
> >     http_api_key = {
> >       type  = "query_params"
> >       key   = "api_key"
> >       value = "ENV:HTTP_API_KEY"
> >     }
> >   })
> > }
> > ```
> >
> > **After**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user_v3" "http_api_key_query" {
> >   resource_id = formal_resource.api.id
> >   label       = "query-api-key"
> >
> >   http_api_key_query {
> >     key = "api_key"
> >     value {
> >       environment_variable = "HTTP_API_KEY"
> >     }
> >   }
> > }
> > ```
>
> > [accordion] Default and identity links
> >
> > **Before**
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_native_user" "readonly" {
> >   resource_id        = formal_resource.database.id
> >   native_user_id     = "readonly"
> >   native_user_secret = "ENV:DB_READONLY_PASSWORD"
> >   use_as_default     = true
> > }
> >
> > resource "formal_native_user_link" "alice" {
> >   native_user_id       = formal_native_user.admin.id
> >   formal_identity_id   = formal_user.alice.id
> >   formal_identity_type = "user"
> > }
> >
> > resource "formal_native_user_link" "dev" {
> >   native_user_id       = formal_native_user.readwrite_all.id
> >   formal_identity_id   = formal_group.dev.id
> >   formal_identity_type = "group"
> > }
> >
> > resource "formal_native_user_link" "sales" {
> >   native_user_id       = formal_native_user.readwrite_sales.id
> >   formal_identity_id   = formal_group.sales.id
> >   formal_identity_type = "group"
> > }
> > ```
> >
> > **After**
> >
> > After creating V3 replacements named `admin`, `readwrite_all`,
> > `readwrite_sales`, and `readonly`, replace the default and links with
> > one selection:
> >
> > ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > resource "formal_resource_native_user_selection" "database" {
> >   resource_id = formal_resource.database.id
> >
> >   cel = <<-CEL
> >     user.id == "${formal_user.alice.id}"
> >       ? "${formal_native_user_v3.admin.id}"
> >       : "${formal_group.dev.id}" in user.group_ids
> >         ? "${formal_native_user_v3.readwrite_all.id}"
> >         : "${formal_group.sales.id}" in user.group_ids
> >           ? "${formal_native_user_v3.readwrite_sales.id}"
> >           : "${formal_native_user_v3.readonly.id}"
> >   CEL
> > }
> > ```
> >
> > The final branch replaces `use_as_default`. Place User rules before
> > Group rules.
>
> Use the
> [default selection examples](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users.md#select-a-default-native-user)
> to translate User and Group links.
>
> Selection CEL has no Resource Hostname object. For a
> `resource_hostname` link, match the machine identity through `user.id`,
> `user.username`, or `user.external_ids`.
>
> Do not use `terraform state mv`. V3 Native Users are separate records with
> new IDs.
>
> **2. Apply the staged configuration**
>
> ```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> terraform plan
> terraform apply
> ```
>
> **Verify:** The plan creates V3 Native Users and the selection. It must not
> destroy legacy resources or enable V3.
>
> **3. Activate V3 in a separate apply**
>
> Change only the mode flag:
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> native_users_v3_enabled = true
> ```
>
> Then apply:
>
> ```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> terraform plan
> terraform apply
> ```
>
> **Verify:** The plan changes the Resource in place. It must not replace the
> Resource or either set of Native Users.
>
> Test default, User, Group, and explicit label selection after activation.
> Confirm the upstream identity and policy result in session logs.
>
> **4. Roll back or remove legacy resources**
>
> To roll back, set `native_users_v3_enabled = false` and apply.
>
> Keep legacy resources in configuration until you no longer need rollback.
> Then remove their `formal_native_user` and `formal_native_user_link` blocks.
>
> Disable termination protection before removing protected legacy resources.
> Run `terraform plan` and confirm that only legacy resources are destroyed.


## Related topics

- [Native Users](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users.md)
- [Kubernetes Operator Custom Resources](https://docs.formal.ai/docs/guides/core-concepts/kubernetes-operator/custom-resources.md)
- [List native users](https://docs.formal.ai/api-reference/corev1nativeuserservice/list-native-users.md)
- [Get native user](https://docs.formal.ai/api-reference/corev1nativeuserservice/get-native-user.md)
- [Create native user](https://docs.formal.ai/api-reference/corev1nativeuserservice/create-native-user.md)


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