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

# Identities

> Manage the users and groups that policies, permissions, and logs refer to

## Overview

This page covers how to create and manage identities in Formal.

There are two types of identities in Formal:

* **Users**: Individual human or machine identities
* **Groups**: Collections of users for streamlined permission management

> [!NOTE]
>
> **Native Users are not identities**: Native users are a separate concept from identities.
> While identities (users and groups) represent who is accessing resources through Formal, native users hold
> the credentials Connectors use to authenticate to the underlying resources (databases, servers, etc.).
> To learn more about native users, refer to [our Native Users documentation](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users.md).

## Users

Users represent identities that connect to resources through Formal Connectors. Every query, command, or API call can be attributed to a specific user for auditing and policy enforcement.

### User Types

> [tab] Human Users
>
> **Human Users** are for employees who need direct access to protected resources.
> They can be invited manually but often organizations provision those users via SCIM or SSO (Formal supports JIT provisioning via SSO).
> They can then retrieve their username and access token from the Control Plane to connect through Connectors.
> **Use cases:**
>
> * Engineers querying production databases
> * Analysts accessing data warehouses
> * DevOps teams managing infrastructure via SSH

> [tab] Machine Users
>
> **Machine Users** are for applications, BI tools, and automated systems that
> connect to resources. Unlike human users, machine users don't receive email
> invitations and can have longer-lived credentials.
> **Use cases:**
>
> * Internal applications querying databases
> * BI tools like Looker, Metabase, Tableau
> * CI/CD pipelines accessing infrastructure
> * ETL jobs moving data
> * AI code agents

### Creating Users

**1. Navigate to Users**

Go to [Users](https://app.formal.ai/users) in the Control Plane

**2. Click Create User**

Select **Create User**

**3. Select Identity Type**

Choose **Human** or **Machine**

**4. Provide user information**

* **Name**: Full name or application name - **Email**: For human users
  (receives credentials) - **Temporary**: (Optional) Set expiration time for
  temporary access - **Groups**: (Optional) Add to groups

> [!TIP]
>
> Temporary users are automatically deleted after the specified time—perfect for
> contractors or time-limited access grants.

### Access Tokens

Formal decouples credentials from underlying resources, enabling each user to have their own set of short-lived, rotating credentials.

#### Token Validity

How long an access token lasts depends on the kind of user:

| Token | Validity |
| - | - |
| **Access Token** in the Control Plane | Your organization's setting, **7 days** by default |
| Machine user access token | 10 years or until refreshed |

#### Configuring Token Validity

To adjust the validity period for your organization, contact Formal support. Organization administrators are authorized to make this request.

### Accessing Formal Credentials

1. Navigate to [the Control Plane](https://app.formal.ai)
2. In the sidebar footer, click **Access Token**
3. Copy your credentials (username and access token)

![Access credentials in Control Plane](https://mintcdn.com/formal/z9GNtynV1YHUDYCN/assets/images/credentials.png?fit=max\&auto=format\&n=z9GNtynV1YHUDYCN\&q=85\&s=197a0605e08a20de29b65e5647921e39)

#### Passing Formal Credentials

Connect to resources using your Formal credentials:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
# PostgreSQL example
psql -h connector.joinformal.com -p 5432 \
  -U "idp:formal:human:alice@example.com" \
  -d production_db

# Password: <your access token from Control Plane>
```

#### Using Hashed Access Tokens

Some database clients limit password length, and Formal access tokens typically exceed it. Use a hashed token, a shortened form of your access token, with these clients.

To obtain a hashed token:

1. Navigate to [the Control Plane](https://app.formal.ai)
2. In the sidebar footer, click **Access Token**
3. Click **Show SHA-256 Hash** to view your hashed token
4. Copy the hashed token for use with restricted clients

> [!WARNING]
>
> Hashed tokens have the same access level as your full access token. Treat them with the same security precautions and never share them.

### Using End User Identities

There may be times when a machine identity interacting with the Connector is itself making requests on behalf of *end users*. For example, you may
want to control access to a Retool dashboard. Various technologies support the notion of *end user identities* where the machine user can map a request
to a separate Formal user identity. For more information on how to specify the end user, refer to the resource page for that particular technology.

> [!NOTE]
>
> End user identities do not require the machine identity to have access to the end user identity's access token. As a result,
> when looking at end user identities, the machine identity needs to be trusted when writing policies against end users.

**External IDs** solve this by mapping end-user identities from external systems to Formal users:

**1. Add External ID to Human User**

Map the user's ID in your BI tool (e.g., Looker user ID 12345) to their
Formal user

**2. Configure your application**

Update your application to propagate the end-user ID when connecting through
Formal. Formal provides SDKs to simplify this:

* [formal-sqlcommenter for Python/Django](https://pypi.org/project/formal-sqlcommenter/)
* Built-in integrations for Metabase, Looker, and more

**3. Verify attribution**

Check [Logs](https://docs.formal.ai/docs/guides/observability/logs.md) to confirm queries are
attributed to the correct end user

This enables accurate auditing and per-user policy enforcement even when using shared application credentials.

## Groups

Groups allow you to apply policies and native user assignments to multiple users simultaneously, streamlining permission management.

> [card] Simplify Policy Management
>
> Write policies once for a group instead of per-user

> [card] Consistent Access
>
> Ensure all group members have the same permissions

> [card] Native User Mapping
>
> Assign database credentials at the group level

> [card] Flexible Membership
>
> Users can belong to multiple groups

### Creating Groups

**1. Navigate to Groups**

Go to [Groups](https://app.formal.ai/groups) in the Control Plane

**2. Click Create Group**

Click **Create Group**

**3. Name the group**

Choose a descriptive name (e.g., "Engineering Team", "Analytics", "External
Contractors")

**4. Add members**

Select users to add to the group

### Managing Group Membership

**1. Open group details**

Click on a group in the Groups list

**2. Add or remove users**

Click **+ Add Member** to add users, or remove existing members from the
group details page

> [!NOTE]
>
> A user can be part of multiple groups. Their effective permissions are the
> union of all group policies plus any user-specific policies.

## Best Practices

> [accordion] Use Groups for Team-Based Access
>
> Create groups that match your organizational structure (teams, departments,
> roles). This makes policy management scalable as your organization grows.

> [accordion] Leverage Temporary Users for Contractors
>
> Set expiration dates for external contractors or time-limited access needs.
> Formal automatically cleans up expired users.

> [accordion] Implement External IDs for BI Tools
>
> Ensure end-user accountability even when using shared application credentials.
> This is critical for compliance and security auditing.

> [accordion] Use Machine Users for Applications
>
> Never share human user credentials with applications. Create dedicated machine
> users for each application or service.

> [accordion] Minimize Direct User Assignments
>
> Select Native Users by group in the [Default Native User](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users.md#select-a-default-native-user)
> CEL expression (for example, `"admins" in user.groups`) rather than per-user
> rules. This reduces configuration complexity.

## Configuration

> [tab] Control Plane
>
> Manage users and groups through the Control Plane at:
>
> * [Users](https://app.formal.ai/users)
> * [Groups](https://app.formal.ai/groups)

> [tab] Terraform
>
> ```hcl theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
> # Create users
> resource "formal_user" "alice" {
>   name  = "Alice Smith"
>   email = "alice@example.com"
>   type  = "human"
> }
>
> resource "formal_user" "bi_tool" {
>   name = "Looker Application"
>   type = "machine"
> }
>
> # Create groups
> resource "formal_group" "engineering" {
>   name = "Engineering Team"
> }
>
> # Add users to groups
> resource "formal_group_user_link" "alice_eng" {
>   group_id = formal_group.engineering.id
>   user_id  = formal_user.alice.id
> }
> ```

## Understanding Identities in Logs

Individual logs will specify which identity was used. If a formal identity was used,
the resulting `user` field will have `user.type` equal to `formal`. In addition,
`user.formal` will be populated with the identity. `user.formal.type` will specify whether the identity will be `human` or `machine`.

If a Formal identity is not specified, `user.formal` will be empty and `user.type` will be `native`.

## Next Steps

> [card] [Assign Native Users](https://docs.formal.ai/docs/guides/core-concepts/resources#native-users)
>
> Map Formal users to resource credentials

> [card] [Write Policies](https://docs.formal.ai/docs/guides/policies/introduction.md)
>
> Control access based on users and groups

> [card] [Configure External IDs](#external-ids-and-identity-propagation)
>
> Enable end-user attribution for BI tools

> [card] [Monitor Sessions](https://docs.formal.ai/docs/guides/observability/sessions.md)
>
> See what users are accessing in real-time


## Related topics

- [List the identity provider's groups](https://docs.formal.ai/api-reference/corev1directorysyncservice/list-the-identity-providers-groups.md)
- [Connect a directory to its identity provider](https://docs.formal.ai/api-reference/corev1directorysyncservice/connect-a-directory-to-its-identity-provider.md)
- [Update a directory's identity provider connection](https://docs.formal.ai/api-reference/corev1directorysyncservice/update-a-directorys-identity-provider-connection.md)
- [Delete a directory's identity provider connection](https://docs.formal.ai/api-reference/corev1directorysyncservice/delete-a-directorys-identity-provider-connection.md)
- [Get a directory's identity provider connection](https://docs.formal.ai/api-reference/corev1directorysyncservice/get-a-directorys-identity-provider-connection.md)


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