Tubiteflon

Identity federation

Sooner or later an app needs to call something outside teflon: a bucket in an AWS account, a Databricks workspace, a Snowflake warehouse. The usual answer is a long-lived key stored as a secret, and long-lived keys are the thing that leaks and the thing nobody rotates. Identity federation is the alternative: the app's pods carry a short-lived, verifiable identity, and the external system is configured to trust that identity directly. Nothing is stored, nothing expires in a drawer, and revoking access is a change on the external side.

Teflon creates no external resources. The AWS account or relying party decides whether to trust this app's identity, so pointing an app at someone else's role grants nothing until that role's owner says so.

There are two flavours, and an app can use both.

FlavourForThe app gets
AWS IAM roleS3, DynamoDB, SQS, anything with an AWS SDKCredentials for a role you name, picked up by the SDK's default chain
OIDC audiencesDatabricks, Snowflake, Vault, anything that federates on OIDCA signed JWT per audience, refreshed in a file the app reads

teflon identity show my-app prints what is configured right now.

$ teflon identity show my-app
AWS role:       arn:aws:iam::123456789012:role/my-app-data
OIDC audiences: databricks

AWS IAM roles

Your app's pods can assume one IAM role in any AWS account. Under the hood this is EKS Pod Identity: teflon's cluster has one shared primary role, and when you set a role on your app, teflon registers an association so that pods running as the app's ServiceAccount receive credentials for your role. Recent AWS SDKs find those credentials on their own through the default credential chain, so the app just calls AWS and no code changes.

The handshake is two commands on your side and one paste on the AWS side.

# Point the app at the role. The pods roll immediately.
teflon identity aws set-role my-app arn:aws:iam::123456789012:role/my-app-data

# Print the trust policy that role needs. Available anytime, even before set-role.
teflon identity aws trust-policy my-app

Then whoever administers the AWS account pastes that JSON in as the role's trust policy and attaches whatever permissions policies the app actually needs. That is the whole setup. The two steps are independent and go in either order: the trust policy depends only on the app, so you can print it and hand it off before ever setting a role. Until both the role is set and its trust policy is in place, the app runs without AWS credentials; once both are true it has them.

The ARN must be a plain role ARN of the form arn:aws:iam::<account-id>:role/<name>. teflon identity aws unset-role my-app clears it, and the pods roll back to running without AWS credentials.

What the trust policy pins

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::210987654321:root"
      },
      "Action": ["sts:AssumeRole", "sts:TagSession"],
      "Condition": {
        "StringEquals": {
          "aws:PrincipalTag/eks-cluster-name": "teflon",
          "aws:PrincipalTag/kubernetes-namespace": "teflon-apps",
          "aws:PrincipalTag/kubernetes-service-account": "app-0192f2b0-1234-7abc-8def-0123456789ab"
        },
        "ArnEquals": {
          "aws:PrincipalARN": "arn:aws:iam::210987654321:role/teflon-pod-identity-primary"
        }
      }
    }
  ]
}

Three things make this policy trust exactly one app.

  • The primary role. Only teflon's primary role may assume yours, and only from teflon's AWS account.
  • The session tags. The namespace and ServiceAccount name identify one application. Another app in the same cluster carries different tags and is refused.
  • The cluster name. A second cluster in the same account carrying the same primary role and the same tags is refused unless it has the same name.

EKS stamps these tags on the primary role's session and carries them into the hop to your role, which is why the policy reads them as aws:PrincipalTag. There is deliberately no cluster ARN in the policy. The primary role, the tags, and the cluster name all survive a cluster rebuild, so external trusts never need to change when the cluster does.

The trust policy depends only on the app, not on the role you point it at, so it is available before any role is set and is safe to check into the AWS account's own infrastructure code.

Sharing one role between apps

Nothing stops two apps from pointing at the same role, and teflon makes a separate association for each. But teflon identity aws trust-policy prints a policy for one app, pinning that app's service-account tag with StringEquals. Pasting a second app's policy over the first breaks the first, so to trust both apps the role's owner merges the two into a single condition that lists both service-account tags:

"aws:PrincipalTag/kubernetes-service-account": [
  "app-0192f2b0-1234-7abc-8def-0123456789ab",
  "app-0192f2b0-5678-7abc-8def-0123456789ab"
]

StringEquals against a list means "any of these", so every named app is admitted and the rest of the policy is unchanged.

More than one role for the same app

An app gets exactly one role from teflon, because EKS Pod Identity allows one role per ServiceAccount. That is not a ceiling on what the app can reach: AWS lets one role assume another, so the role teflon hands out becomes the app's home role and the app hops from it to the others.

Point the app at the home role as above. Then every other role the app needs trusts the home role instead of teflon:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::123456789012:role/my-app-data"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

In the app, assume the extra role explicitly and hand its credentials to the client that needs them. Every AWS SDK has a helper for this that refreshes the credentials before they run out:

import boto3
from botocore.credentials import RefreshableCredentials
from botocore.session import get_session

def role_session(role_arn: str) -> boto3.Session:
    sts = boto3.client("sts")  # uses the home role from the default chain

    def refresh():
        creds = sts.assume_role(RoleArn=role_arn, RoleSessionName="my-app")["Credentials"]
        return {
            "access_key": creds["AccessKeyId"],
            "secret_key": creds["SecretAccessKey"],
            "token": creds["SessionToken"],
            "expiry_time": creds["Expiration"].isoformat(),
        }

    session = get_session()
    session._credentials = RefreshableCredentials.create_from_metadata(
        metadata=refresh(), refresh_using=refresh, method="sts-assume-role"
    )
    return boto3.Session(botocore_session=session)

reports = role_session("arn:aws:iam::333333333333:role/my-app-reports").client("s3")

Two things to know.

  • Chained sessions last at most one hour. AWS caps any role assumed from another role at one hour, whatever the role's own maximum says. The SDK helpers refresh on their own, so this only matters if you hand raw credentials to something that does not.
  • The home role needs sts:AssumeRole. Attach a permissions policy to the home role allowing sts:AssumeRole on each extra role's ARN. The extra role's trust policy alone is not enough.

The alternative is to skip the home role and federate straight from teflon's OIDC issuer, described below. An AWS account can register https://auth.tf.int.tubi.io/identity as an IAM OIDC identity provider, and a role can then trust that provider together with one audience and the app's subject. Add one audience per role with teflon identity oidc add, and the app calls sts:AssumeRoleWithWebIdentity with the matching token file. This suits roles in accounts that would rather trust teflon directly than a home role in another account, at the cost of one identity provider registration per account.

Example: calling Bedrock in another account

Say your app wants to call Bedrock, and Bedrock lives in an AWS account that is not teflon's. This is the normal case, and it takes two people: you (the app owner) and whoever administers that other account. Teflon cannot grant access into an account it does not control, so that account has to opt in - which is exactly what keeps the whole thing safe.

First, the Bedrock account's admin stands up the role and its powers. The real trust policy lands in the last step, so the role starts with a locked-down placeholder that lets no one in:

# Create the role with a deny-all placeholder trust; the real one comes last.
aws iam create-role --role-name my-app-bedrock \
  --assume-role-policy-document '{
    "Version": "2012-10-17",
    "Statement": [{ "Effect": "Deny", "Principal": "*", "Action": "sts:AssumeRole" }]
  }'

# Let it invoke Bedrock models.
aws iam put-role-policy --role-name my-app-bedrock \
  --policy-name invoke-bedrock \
  --policy-document '{
    "Version": "2012-10-17",
    "Statement": [{
      "Effect": "Allow",
      "Action": ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"],
      "Resource": "*"
    }]
  }'

Next, you point the app at that role:

teflon identity aws set-role my-app arn:aws:iam::222222222222:role/my-app-bedrock

Finally, print the trust policy and hand the JSON to that account's admin, who swaps it in for the placeholder - opening the door:

# You:
teflon identity aws trust-policy my-app

# The account's admin, with the JSON you handed over:
aws iam update-assume-role-policy --role-name my-app-bedrock \
  --policy-document file://trust-policy.json

That is the whole handshake. The app's pods now carry credentials for that role automatically, so the code just calls Bedrock with no keys and no config:

import boto3

client = boto3.client("bedrock-runtime", region_name="us-east-1")
client.invoke_model(modelId="...", body=...)

Two things bite people, and neither is a teflon problem.

  • Region. Bedrock is regional. Set the client's region (or AWS_REGION) to one where Bedrock is turned on.
  • Model access. Even with the permission, InvokeModel returns 403 until that account has enabled access to the specific model in the Bedrock console.

The same shape works for any AWS service in any account: name a role, hand over the trust policy, let the role's account attach the permissions it is comfortable with.

OIDC audiences

Systems that are not AWS mostly federate on OIDC: you register an issuer, an audience, and a subject with them, and they accept any JWT signed by that issuer that carries those claims. Teflon gives each app a stable subject and mints such tokens on demand.

An audience is a short name for one relying party. Add one and the pods roll with a token for it.

teflon identity oidc add my-app databricks
teflon identity oidc remove my-app databricks

Names are letters, digits, dots, dashes, and underscores, starting with a letter or digit, at most 255 characters. URL-shaped audiences are not supported; a relying party that demands one needs a mapping layer in front of it.

What the app sees

For every audience the pod carries a file and an env var pointing at it.

AudienceToken fileEnv var
databricks/var/run/teflon/tokens/databricks/tokenTEFLON_IDENTITY_TOKEN_FILE_DATABRICKS
vault.prod/var/run/teflon/tokens/vault.prod/tokenTEFLON_IDENTITY_TOKEN_FILE_VAULT_PROD

The env var name is the audience uppercased with every non-alphanumeric character turned into _. The TEFLON_IDENTITY_TOKEN_FILE_ prefix is reserved, so you cannot set an env var or bind a secret under it.

A sidecar in the pod keeps each file fresh. Tokens live 15 minutes and are replaced well before they expire, so read the file every time you need a token rather than caching its contents. Presenting it is up to the relying party's client library; most take a token file path or the token string and exchange it for their own credential.

What the relying party pins

$ teflon identity federation-info my-app
Federation info for 'my-app'
Issuer:    https://auth.tf.int.tubi.io/identity
Subject:   system:serviceaccount:teflon-apps:app-0192f2b0-1234-7abc-8def-0123456789ab
Audiences: databricks

{
  "keys": [ ... ]
}

Create the relying party's federation policy with those three values: the issuer, the audience you added, and the subject. -o json prints the same thing for scripts.

The issuer serves a standard discovery document at <issuer>/.well-known/openid-configuration and its keys at <issuer>/jwks, so most relying parties need nothing more than the issuer URL. Where the relying party cannot reach the issuer, the printed JWKS is the same document, ready to paste inline.

The issuer and its keys belong to teflon, not to the cluster, so they survive a cluster rebuild and a relying party pins them once. Signing keys do rotate. The JWKS may list more than one key during a rotation and every token names its key by kid, so a verifier that re-fetches the JWKS on an unknown kid never notices; one that pinned a single key by hand will.

Example: reading from Databricks

Say your app wants to query a Databricks workspace. Like the Bedrock example, this takes two people: you (the app owner) and a Databricks account admin. Databricks calls this workload identity federation: a service principal that trusts a specific issuer, audience, and subject instead of holding a client secret.

First, the Databricks admin creates (or picks) a service principal for the app and grants it whatever the app actually needs: workspace access, CAN USE on a SQL warehouse, table grants. Two IDs come out of this step and the app needs both later:

  • the numeric service principal ID, which the federation policy commands take
  • the application ID, a UUID, which the app presents as client_id when it exchanges tokens

Next, you add the audience and print the federation info:

teflon identity oidc add my-app databricks
teflon identity federation-info my-app

Hand the printed issuer, subject, and audience to the admin. They create a federation policy on the service principal from those three values:

databricks account service-principal-federation-policy create 5581763342009999 --json '{
  "oidc_policy": {
    "issuer": "https://auth.tf.int.tubi.io/identity",
    "audiences": ["databricks"],
    "subject": "system:serviceaccount:teflon-apps:app-0192f2b0-1234-7abc-8def-0123456789ab"
  }
}'

The audiences list is not optional here. Databricks defaults it to the service principal's application ID, and teflon's token says databricks, so the two must be spelled to match. Databricks fetches teflon's keys from the issuer's discovery document on its own; nothing else needs to be pasted.

That is the whole handshake. The pod now carries a fresh teflon token at the path in TEFLON_IDENTITY_TOKEN_FILE_DATABRICKS, and the Databricks SDK knows how to exchange a token file for its own OAuth token:

import os
from databricks.sdk import WorkspaceClient

client = WorkspaceClient(
    host="https://my-workspace.cloud.databricks.com",
    client_id="a2222dd9-33f6-455e-8888-999fbbd77900",  # the service principal's application ID
    auth_type="file-oidc",
    oidc_token_filepath=os.environ["TEFLON_IDENTITY_TOKEN_FILE_DATABRICKS"],
)

for warehouse in client.warehouses.list():
    print(warehouse.name)

The SDK re-reads the file and re-exchanges whenever its Databricks token runs out, so the 15-minute teflon token lifetime is invisible to the app.

Without an SDK, the exchange is one HTTP call, the OAuth token-exchange grant from RFC 8693:

curl --request POST https://my-workspace.cloud.databricks.com/oidc/v1/token \
  --data "client_id=a2222dd9-33f6-455e-8888-999fbbd77900" \
  --data "subject_token=$(cat "$TEFLON_IDENTITY_TOKEN_FILE_DATABRICKS")" \
  --data 'subject_token_type=urn:ietf:params:oauth:token-type:jwt' \
  --data 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
  --data 'scope=all-apis'

The response carries an access_token to send as a Bearer header on any Databricks API, and it expires when the teflon token it was exchanged from does, so repeat the exchange rather than caching it for long.

Two things bite people, and neither is a teflon problem.

  • Wrong ID. The policy command wants the numeric service principal ID; the exchange wants the application ID (a UUID). Mixing them up gives an unhelpful invalid_request.
  • No workspace access. A valid exchange still returns 403 on every call until the service principal has been added to the workspace and granted permissions there.

Snowflake, Vault, and other OIDC relying parties follow the same shape: add an audience named for them, hand over the federation info, and let their side pin the issuer, audience, and subject. Only the last step differs, because each client library has its own way of taking a token file.

In the console

The app detail page has an Identity federation card on its Integrations tab, showing the current role and audiences at a glance, with a Manage identity federation link.

That opens the app's identity page, which is the console's version of everything above. The AWS IAM role card has the field that sets or clears the role and, below it, the trust policy with the three pinned pieces called out and a Copy JSON button. The OIDC federation card lists the audiences with add and remove controls and, below it, the federation info with its own Copy JSON button for the JWKS.

Only the app's owner sees the controls. Anyone else who can reach the app sees the same values read-only, which is enough to hand an AWS admin or a relying party's admin what they need to paste.