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

# Native Users

> Configure the credentials that Connectors use for upstream resources

## Overview

Native Users define how a Connector authenticates to an upstream Resource.
Formal identities never need to know or send these upstream credentials.

> [!NOTE]
>
> This guide documents Native Users supported by Connector 2.17.0 and later.
> If your Resource still uses legacy Native Users, see the
> [migration guide](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users-legacy).

## How Native Users work

Each Native User has three important properties:

* A **label** identifies the Native User within its Resource.
* A **credential type** defines how the Connector authenticates upstream.
* A **credential source** supplies static values or runs a hook at connection time.

You can configure a default Native User selection for each Formal identity.
The selection returns a Native User, usually by its label.

A user can instead request a Native User by appending `@<label>` to their Formal
username. The requested Native User takes precedence over the default selection.

## Supported credential types

The Control Plane shows only the credential types supported by the Resource:

| Credential type | `user_type` | Connector behavior |
| - | - | - |
| Passthrough | `passthrough` | Forwards the client's own credentials |
| Password | `basic` | Sends an upstream username and password |
| SSH Key | `ssh_key` | Uses an SSH username, private key, and optional certificate |
| Snowflake Key | `snowflake_key` | Uses a Snowflake username and private key |
| AWS IAM | `aws_iam` | Uses the Connector's ambient AWS credentials |
| AWS IAM Role | `aws_iam_role` | Assumes a specified AWS role |
| GCP IAM | `gcp_iam` | Uses the Connector's ambient GCP service account |
| Azure IAM | `azure_iam` | Uses the Connector's ambient Microsoft Entra identity |
| Kubeconfig Path | `kubernetes_path` | Reads a kubeconfig file on the Connector |
| Kubeconfig | `kubernetes_inline` | Uses an inline kubeconfig document |
| HTTP Basic | `http_basic` | Injects Basic credentials into a named header |
| HTTP Bearer | `http_bearer` | Injects a bearer token into a named header |
| API Key (Header) | `http_api_key_header` | Injects an API key into a named header |
| API Key (Query) | `http_api_key_query` | Injects an API key into a query parameter |
| Linked Account (HTTP Basic) | `linked_http_basic` | Injects Basic credentials into a named header, with the user's [linked](https://docs.formal.ai/docs/guides/core-concepts/resources/oauth.md) upstream account token as the password |
| Linked Account (HTTP Bearer) | `linked_http_bearer` | Injects the user's [linked](https://docs.formal.ai/docs/guides/core-concepts/resources/oauth.md) upstream account token as a bearer token into a named header |

> [tab] Web
>
> ## Create a Native User
>
> 1. Go to **Resources** and open your Resource.
>
>    ![Resources list with a Resource ready to open](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/native_user1.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=df525a533918f8c12be630e4708b0151)
> 2. Select **Authentication**.
> 3. Click **Add User**.
>
>    ![Authentication tab with the Native Users section and Add User button](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/native_user2.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=a730fbbf5bb9db59396e5c871d6e0c1c)
> 4. Select a credential type.
>
>    ![Add Native User credential type picker](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/native_user3.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=2b4dab8fdc133b114381f0bdc71096ae)
> 5. Enter a unique **Label**.
> 6. Choose **Static** or **Hook** as the credential source.
> 7. Configure the credential fields and termination protection.
> 8. Click **Create**.
>
> For static secrets, choose **Value** to store an encrypted value in Formal.
> Choose **Environment Variable** to resolve it on the Connector. Choose
> **Secret Manager** to have the Connector fetch it from AWS Secrets Manager,
> GCP Secret Manager, or Azure Key Vault with its own cloud credentials. See
> [Secret manager references](#secret-manager-references) for the accepted
> formats.
>
> Enter only the environment variable name, such as
> `ANALYTICS_READONLY_PASSWORD`. Do not use the legacy `ENV:` prefix.
>
> **Verify:** Confirm that the Native User appears under **Native Users** with
> the expected label, credential type, and authentication source.
>
> ### Resolve credentials with a hook
>
> Choose **Hook** when credentials must be generated or fetched at connection
> time. The hook runs on the Connector after policy allows the connection.
>
> Select the credential type before writing the hook. The hook must return that
> type's exact credential shape.
>
> Allowlist every environment variable the hook reads. Access each value through
> the hook's `env` argument.
>
> Add a named entry under **Secrets** for each
> [secret manager reference](#secret-manager-references) the hook needs. The
> Connector fetches them before the hook runs and passes them as the fourth
> argument, so the hook reads `secrets["NAME"]`. Names use letters, digits, and
> underscores, and cannot start with a digit. The hook does not run if a secret
> cannot be fetched.
>
> The `input` argument contains the Resource and the label of the Native User
> the hook produces credentials for:
>
> ```ts theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> type HookNativeUserInput = {
>   resource: {
>     id: string;
>     name: string;
>     technology: string;
>     hostname: string;
>     port: number;
>     environment: string;
>     provider: string;
>   };
>   native_user: string;
> };
> ```
>
> For HTTP Resources, `input` is the request's
> [policy input](https://docs.formal.ai/docs/guides/policies/evaluation.md#request-stage) instead, as
> request policies see it. It has no `hooks` and no request body fields, such
> as `http.body` and `http.json`. Use `input.llm.model` to pick a key by the
> requested model. It is empty when the request has no model, such as on
> WebSocket upgrades.
>
> Health checks and data discovery run the same hook with no request, so they
> pass only `resource` and `native_user`. Treat every other field as optional,
> and fall back to a default credential when it is missing.
>
> Hook input on other Resources does not include the Formal identity. Use the
> [default selection](#select-a-default-native-user) to choose credentials by
> identity there.
>
> #### Hook examples
>
> The editor provides `HookNativeUserInput`, `HookNativeUserEnvironment`,
> `HookNativeUserSecrets`, and `HookNativeUserOutput` types for your selected
> credential type.
>
> > [accordion] Read a database password from the Connector
> >
> > Select **Password** and allowlist `DATABASE_PASSWORD`.
> >
> > ```ts theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > export default async function credentials(
> >   input: HookNativeUserInput,
> >   env: HookNativeUserEnvironment,
> > ): Promise<HookNativeUserOutput> {
> >   const password = env["DATABASE_PASSWORD"];
> >   if (!password) {
> >     throw new Error("DATABASE_PASSWORD is not set");
> >   }
> >
> >   return {
> >     username: input.native_user,
> >     password,
> >   };
> > }
> > ```
>
> > [accordion] Fetch database credentials from Vault
> >
> > Select **Password**. Allowlist the `vault.example.com` network host and
> > the `VAULT_TOKEN` environment variable.
> >
> > ```ts theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > export default async function credentials(
> >   _input: HookNativeUserInput,
> >   env: HookNativeUserEnvironment,
> > ): Promise<HookNativeUserOutput> {
> >   const token = env["VAULT_TOKEN"];
> >   if (!token) {
> >     throw new Error("VAULT_TOKEN is not set");
> >   }
> >
> >   const response = await fetch(
> >     "https://vault.example.com/v1/database/creds/readonly",
> >     {
> >       headers: { "x-vault-token": token },
> >     },
> >   );
> >   if (!response.ok) {
> >     throw new Error(`Vault returned ${response.status}`);
> >   }
> >
> >   const result = (await response.json()) as {
> >     data?: { username?: string; password?: string };
> >   };
> >   if (!result.data?.username || !result.data.password) {
> >     throw new Error("Vault returned invalid credentials");
> >   }
> >
> >   return {
> >     username: result.data.username,
> >     password: result.data.password,
> >   };
> > }
> > ```
>
> > [accordion] Mint an HTTP bearer token
> >
> > Select **HTTP Bearer**. Allowlist the `auth.example.com` network host.
> > Allowlist the `OAUTH_CLIENT_ID` and `OAUTH_CLIENT_SECRET` environment
> > variables.
> >
> > ```ts theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> > export default async function credentials(
> >   _input: HookNativeUserInput,
> >   env: HookNativeUserEnvironment,
> > ): Promise<HookNativeUserOutput> {
> >   const clientId = env["OAUTH_CLIENT_ID"];
> >   const clientSecret = env["OAUTH_CLIENT_SECRET"];
> >   if (!clientId || !clientSecret) {
> >     throw new Error("OAuth client credentials are not set");
> >   }
> >
> >   const body = [
> >     "grant_type=client_credentials",
> >     `client_id=${encodeURIComponent(clientId)}`,
> >     `client_secret=${encodeURIComponent(clientSecret)}`,
> >   ].join("&");
> >   const response = await fetch("https://auth.example.com/oauth/token", {
> >     method: "POST",
> >     headers: { "content-type": "application/x-www-form-urlencoded" },
> >     body,
> >   });
> >   if (!response.ok) {
> >     throw new Error(`OAuth server returned ${response.status}`);
> >   }
> >
> >   const result = (await response.json()) as { access_token?: string };
> >   if (!result.access_token) {
> >     throw new Error("OAuth server did not return an access token");
> >   }
> >
> >   return {
> >     header: "Authorization",
> >     token: result.access_token,
> >   };
> > }
> > ```
>
> Network access is denied unless you allowlist the destination hostname.
> See [Hooks](https://docs.formal.ai/docs/guides/policies/hooks.md) for network and runtime limits.
>
> ### Rotate or edit credentials
>
> Select a Native User to open its details. You can rename its label or change
> termination protection.
>
> Use **Update Credentials** to rotate static credentials. You cannot change a
> Native User's credential type or switch between static and hook sources.
> Create another Native User for those changes.
>
> ![Native User details with credential and termination protection settings](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/native_user4.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=1d73b872b65cab4d18ce20fcca43f9b1)
>
> ## Select a default Native User
>
> **Default Native User** maps a Formal identity to a Native User. Reference
> a Native User by its label with `native_users["<label>"]`.
>
> > [!NOTE]
> >
> > Selecting by label requires Connector version 2.25.3 or later.
>
> ![Default Native User CEL expression editor](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/native_user5.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=ebe7ccc7a01205cf56d48bc684625007)
>
> Return one label to use the same Native User for everyone:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> native_users["readonly"]
> ```
>
> Use a conditional expression to select by identity:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> "admins" in user.groups
>   ? native_users["admin"]
>   : native_users["readonly"]
> ```
>
> To inject a credential for one group and let everyone else use their own,
> point the other branch at a Passthrough Native User:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> "platform" in user.groups
>   ? native_users["shared-token"]
>   : native_users["passthrough"]
> ```
>
> The `user` object supports these fields:
>
> | Field | Type |
> | - | - |
> | `user.id` | String |
> | `user.email` | String |
> | `user.username` | String |
> | `user.type` | String |
> | `user.external_ids` | List of strings |
> | `user.groups` | List of strings |
> | `user.group_ids` | List of strings |
>
> `native_users` maps each of the Resource's Native User labels to its ID.
>
> Each result branch must be a `native_users` lookup with a literal label of
> one of the Resource's Native Users, or a literal Native User ID. Computed
> lookups such as `native_users[user.username]` are rejected.
>
> Click **Save** after the editor shows **Valid CEL**.
>
> **Verify:** Connect without an `@<label>` suffix and confirm the expected
> upstream credential identity appears in the session log.
>
> ### Require an explicit selection
>
> Leave **Default Native User** unset to require clients to request a label.
> HTTP Resources instead proceed without injected credentials, except those
> with linked accounts, which refuse the request.
>
> A CEL branch can return an empty string to reject matching identities:
>
> ```cel theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> user.type == "machine"
>   ? native_users["service-account"]
>   : ""
> ```
>
> This rejection also applies when the client requests a label explicitly.

> [tab] Terraform
>
> ## Create a Native User
>
> Define each Native User with a typed credential block:
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> resource "formal_resource" "database" {
>   name       = "analytics-postgres"
>   hostname   = "analytics.internal"
>   technology = "postgres"
>   port       = 5432
> }
>
> resource "formal_native_user_v3" "admin" {
>   resource_id = formal_resource.database.id
>   label       = "admin"
>
>   basic {
>     username = "app_admin"
>     password {
>       environment_variable = "ANALYTICS_ADMIN_PASSWORD"
>     }
>   }
> }
>
> resource "formal_native_user_v3" "read_only" {
>   resource_id = formal_resource.database.id
>   label       = "read-only"
>
>   basic {
>     username = "app_readonly"
>     password {
>       environment_variable = "ANALYTICS_READONLY_PASSWORD"
>     }
>   }
> }
>
> resource "formal_resource_native_user_selection" "database" {
>   resource_id = formal_resource.database.id
>
>   cel = <<-CEL
>     "admins" in user.groups
>       ? "${formal_native_user_v3.admin.id}"
>       : "${formal_native_user_v3.read_only.id}"
>   CEL
> }
> ```
>
> An `environment_variable` value names an environment variable on the
> Connector. A `literal` value stores the secret in Terraform state. A
> `secret_manager` block holds exactly one of `aws_secret { arn }`,
> `gcp_secret { name }`, or `azure_secret { url }`, in the
> [formats below](#secret-manager-references):
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> password {
>   secret_manager {
>     aws_secret {
>       arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:analytics-admin-AbCdEf"
>     }
>   }
> }
> ```
>
> **Verify:**
>
> ```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> terraform plan
> terraform apply
> ```
>
> Confirm that the plan creates two `formal_native_user_v3` resources and one
> `formal_resource_native_user_selection`.
>
> ### Use a hook
>
> Hooks run on the Connector at connection time. Declare the output shape and
> allowlist each environment variable:
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> resource "formal_native_user_v3" "dynamic" {
>   resource_id = formal_resource.database.id
>   label       = "dynamic"
>
>   hook {
>     output_type               = "basic"
>     allowlisted_env_variables = ["FORMAL_ENV_USER", "FORMAL_ENV_PASSWORD"]
>     code                      = <<-TYPESCRIPT
>       export default async function (_input, env) {
>         return {
>           username: env.FORMAL_ENV_USER,
>           password: env.FORMAL_ENV_PASSWORD,
>         };
>       }
>     TYPESCRIPT
>   }
> }
> ```

## Secret manager references

A secret manager reference points at a secret the Connector fetches at
connection time. The Connector authenticates with its own cloud identity, so
grant that identity read access to each secret. Formal stores only the
reference, never the secret value.

| Secret manager | Format | Example |
| - | - | - |
| AWS Secrets Manager | `arn:<partition>:secretsmanager:<region>:<account-id>:secret:<name>-<suffix>` | `arn:aws:secretsmanager:us-east-1:123456789012:secret:db-password-AbCdEf` |
| GCP Secret Manager | `projects/<project>/secrets/<secret>/versions/<version>` or `projects/<project>/locations/<location>/secrets/<secret>/versions/<version>` | `projects/my-project/secrets/db-password/versions/latest` |
| Azure Key Vault | `https://<vault-name>.vault.azure.net/secrets/<name>[/<version>]` | `https://my-vault.vault.azure.net/secrets/db-password` |

**AWS Secrets Manager:** Use the full secret ARN, including the six-character
suffix AWS appends to the secret name. The account ID must be 12 digits. To
select a JSON key or a version, use the extended form ECS task definitions use,
`<arn>:<json-key>:<version-stage>:<version-id>`, leaving unused fields empty.
Set a version stage or a version ID, not both. Without either, the Connector
reads `AWSCURRENT`. For example,
`arn:aws:secretsmanager:us-east-1:123456789012:secret:db-AbCdEf:password::`
reads the `password` key of the current version.

**GCP Secret Manager:** Use the secret version's resource name. The version can
be a number or `latest`. Use the `locations/<location>` form for regional
secrets.

**Azure Key Vault:** Use the secret identifier URL. Omit the version to read the
latest version. Vaults in the Azure China and Azure US Government clouds use the
`vault.azure.cn` and `vault.usgovcloudapi.net` hosts.

## Request a Native User at connection time

Append `@<label>` to the Formal username:

```text theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
<formal_username>@<native_user_label>
```

For example:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
psql \
  --host "<CONNECTOR_HOSTNAME>" \
  --port 5432 \
  --dbname "<DATABASE_NAME>" \
  --username "idp:formal:human:john@example.com@read-only"
```

The label selects the Native User. It does not need to match the upstream
username.

An explicit request takes precedence over the assigned default. Use policies to
restrict overrides and privileged labels.

## Control explicit overrides with policies

Native Users expose both the requested Native User and assigned default to
policies. Each object contains `id`, `label`, and `user_type`.

This session policy blocks an explicit request that differs from the assigned
default:

```rego theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
package formal.v2

import future.keywords.if

default session := {"action": "allow"}

session := {
  "action": "block",
  "type": "block_with_formal_message",
  "message": "This Native User is not assigned to your identity"
} if {
  input.native_user_assignment == "user-requested"
  input.native_user_selection.requested.id != input.native_user_selection.assigned.id
}
```

See [policy evaluation](https://docs.formal.ai/docs/guides/policies/evaluation.md#native-users) for the
complete input shape.

## Understand Native Users in logs

For Formal-authenticated sessions, `user.formal.native` contains the selected
Native User's upstream username when applicable.

When a client connects directly with Resource credentials, `user.type` is
`native`. Formal identity fields and `user.formal.native` are absent.


## Related topics

- [Policy Evaluation](https://docs.formal.ai/docs/guides/policies/evaluation.md)
- [RDP](https://docs.formal.ai/docs/guides/core-concepts/resources/rdp.md)
- [MariaDB](https://docs.formal.ai/docs/guides/core-concepts/resources/mariadb.md)
- [Redshift](https://docs.formal.ai/docs/guides/core-concepts/resources/redshift.md)
- [Glossary](https://docs.formal.ai/docs/glossary/index.md)


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