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

# Create a trust rule

> Creates a trust rule that lets matching tokens act as a service account.

> [!NOTE]
>
> [Workload identity federation](https://docs.baseten.co/organization/workload-identity.md) is in **Private Preview**.


## OpenAPI

````yaml post /v1/access/trust_rules
openapi: 3.1.0
info:
  description: REST API for management of Baseten resources
  title: Baseten management API
  version: 1.0.0
servers:
  - url: https://api.baseten.co
security:
  - BearerAuth: []
paths:
  /v1/access/trust_rules:
    post:
      summary: Creates a trust rule
      description: >-
        Creates a rule that lets tokens from an identity provider act as a
        service account. Organization admins can create rules for any service
        account, team admins for their own team's. An organization API key
        manager key can't target organization accounts.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAccessTrustRuleRequestV1'
        required: true
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccessTrustRuleV1'
      x-codeSamples:
        - lang: bash
          source: |-
            curl --request POST \
            --url https://api.baseten.co/v1/access/trust_rules \
            --header "Authorization: Bearer $BASETEN_API_KEY" \
            --data '{
              "name": "models-main-deploy",
              "identity_provider_id": "abcd1234",
              "service_account_id": "wxyz5678",
              "condition": "claims.repository_owner_id == '12345' && claims.sub == 'repo:acme/models:ref:refs/heads/main'",
              "audience": "https://api.baseten.co"
            }'
        - lang: python
          source: |-
            import requests
            import os
            API_KEY = os.environ.get("BASETEN_API_KEY", "<YOUR_API_KEY>")
            url = "https://api.baseten.co/v1/access/trust_rules"

            headers = {"Authorization": f"Bearer {API_KEY}"}

            response = requests.request(
                "POST",
                url,
                headers=headers,
                json={'name': 'models-main-deploy', 'identity_provider_id': 'abcd1234', 'service_account_id': 'wxyz5678', 'condition': "claims.repository_owner_id == '12345' && claims.sub == 'repo:acme/models:ref:refs/heads/main'", 'audience': 'https://api.baseten.co'}
            )

            print(response.text)
components:
  schemas:
    CreateAccessTrustRuleRequestV1:
      additionalProperties: false
      description: Request to create a trust rule.
      properties:
        name:
          description: Name, unique in the organization. Can be changed later.
          maxLength: 255
          minLength: 1
          title: Name
          type: string
        description:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Optional description
          title: Description
        identity_provider_id:
          description: Whose tokens the rule accepts. Can't be changed.
          title: Identity Provider Id
          type: string
        service_account_id:
          description: The service account its tokens act as. Can be changed later.
          title: Service Account Id
          type: string
        condition:
          description: >-
            A CEL expression over the token's `claims` that must evaluate to
            true. It must pin a specific `claims.sub` in a top-level `&&`
            clause, plus any provider-required checks. Up to 4,096 characters.
            Can be changed later.
          examples:
            - >-
              claims.repository_owner_id == '12345' &&
              claims.sub.startsWith('repo:acme/models:') && claims.ref ==
              'refs/heads/main'
          title: Condition
          type: string
        audience:
          description: >-
            The token's `aud` must equal this, or contain it when `aud` is a
            list. Up to 1,024 characters. Can be changed later.
          title: Audience
          type: string
        max_access_token_lifetime_seconds:
          default: 3600
          description: >-
            Longest lifetime of a token the rule issues, 60 to 3600 seconds. Can
            be changed later.
          maximum: 3600
          minimum: 60
          title: Max Access Token Lifetime Seconds
          type: integer
      required:
        - name
        - identity_provider_id
        - service_account_id
        - condition
        - audience
      title: CreateAccessTrustRuleRequestV1
      type: object
    AccessTrustRuleV1:
      description: Which tokens from an identity provider may act as a service account.
      properties:
        id:
          description: Trust rule ID. Workloads pass it when they exchange a token.
          title: Id
          type: string
        name:
          description: Name, unique in the organization
          title: Name
          type: string
        description:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Description
          title: Description
        identity_provider_id:
          description: The identity provider whose tokens it accepts
          title: Identity Provider Id
          type: string
        identity_provider_name:
          description: Name of the identity provider
          title: Identity Provider Name
          type: string
        service_account_id:
          description: The service account its tokens act as
          title: Service Account Id
          type: string
        service_account_name:
          description: Name of the service account
          title: Service Account Name
          type: string
        team_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            The service account's team. Null for an organization service
            account.
          title: Team Id
        team_name:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            Name of the service account's team. Null for an organization service
            account.
          title: Team Name
        condition:
          description: >-
            A CEL expression over the token's `claims` that must evaluate to
            true. It must pin a specific `claims.sub` in a top-level `&&`
            clause, plus any provider-required checks. Up to 4,096 characters.
          examples:
            - >-
              claims.repository_owner_id == '12345' &&
              claims.sub.startsWith('repo:acme/models:') && claims.ref ==
              'refs/heads/main'
          title: Condition
          type: string
        audience:
          description: >-
            The token's `aud` must equal this, or contain it when `aud` is a
            list. Up to 1,024 characters.
          title: Audience
          type: string
        max_access_token_lifetime_seconds:
          description: Longest lifetime of a token the rule issues, in seconds
          title: Max Access Token Lifetime Seconds
          type: integer
        last_used_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          default: null
          description: >-
            Last time a request authenticated with a token the rule issued, to
            within an hour. Null until the first.
          title: Last Used At
        created_by:
          description: ID of the user who created the rule
          title: Created By
          type: string
        created_at:
          description: Time the rule was created
          format: date-time
          title: Created At
          type: string
        updated_at:
          description: Time the rule was last updated
          format: date-time
          title: Updated At
          type: string
      required:
        - id
        - name
        - identity_provider_id
        - identity_provider_name
        - service_account_id
        - service_account_name
        - condition
        - audience
        - max_access_token_lifetime_seconds
        - created_by
        - created_at
        - updated_at
      title: AccessTrustRuleV1
      type: object
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Send `Authorization: Bearer <api_key>`. The legacy `Authorization:
        Api-Key <api_key>` scheme is also accepted.

````