Temporary credentials travel with requests

Published on , 2410 words, 9 minutes to read

Securing your API keys is an annoying affair. We're all guilty of making one big credential and then reusing it across different agents and services because it's just convenient. Hell, I'm guilty of this even though I have enough SRE experience to know that doing so is a bad idea. What if it was easy to just make temporary credentials that you can use from anywhere and rest easy knowing that they will expire at some point?

This is why we've developed Temporary Credentials. They're like the wristband at a music festival. Our STS endpoint checks your admission ticket (an access key) at the door, gives your agent the wristband, and then it's off to do whatever it wants and can get back into its bucket easily with just the wristband. The catch is that the wristband never stops being tied to your ticket. Every time your agent flashes it, Tigris checks your ticket too, so if you cancel the ticket, every wristband it got you is dead.

Why temporary credentials?

If it's not easy to do things the "right way", people won't do it. They just won't. You can do all the user education you want, but if the UX sucks nobody will take the time to implement it.

Tigris temporary credentials let you just get an access key with a single API call:

Tigris CLI

tigris credentials temporary my-bucket --name ci-upload --access readwrite --duration 1h

--access grants the read actions, the write actions, or both. Use --actions to list exact actions, or --policy for a policy file. See tigris credentials temporary.

JavaScript

import { createTemporaryCredentials } from "@tigrisdata/iam";

const { data: creds, error } = await createTemporaryCredentials("ci-upload", {
  bucket: "my-bucket",
  access: "readwrite", // "read", "write", or "readwrite"
  durationSeconds: 3600,
});
if (error) throw error;

@tigrisdata/iam signs the request with the access key in TIGRIS_STORAGE_ACCESS_KEY_ID and TIGRIS_STORAGE_SECRET_ACCESS_KEY. It returns accessKeyId, secretAccessKey, sessionToken, and expiration.

Already have the AWS SDKs wired up everywhere? Those work too, and I'll get to them further down.

This means that your agent can operate on a bucket fork and then you can be sure that agent never gets access to anything but that fork.

We think that this will let you have better granular workload identity and reduce the splash damage from credential reuse.

Pass-by-value credentials

In programming we have two paradigms for how data propagates through the system: pass by reference and pass by value. Traditionally this means the difference between getting a pointer to a value in memory as a function argument and copying all of the data as a function argument.

This is similar to what you do with an API key lookup in the database. You check if the API key is valid and what user it references.

Most of the time this works well enough. I'd be willing to bet that a lot of you have implemented things like this already. Tigris does it in a global active-active setup where any region can be authoritative for any access key, user, bucket, object, or other primitive. When you create an access key, its record gets stored and replicated, and the key works in every region right away.

That's totally fine when keys are things humans make by hand every so often. It gets silly at machine speed. If every agent run gets its own bucket fork and its own credential, every one of those credentials is another record that has to be stored, replicated to every region, looked up, and cleaned up after the run. That's a lot of bookkeeping for a key that might only live for 15 minutes.

So temporary credentials go the other way: they're passed by value. Minting one stores nothing, so there's nothing to replicate and nothing to clean up, and the credential works in every region the moment you get it. The record that would have gone in the database travels with each request instead, sealed inside the session token.

There's one thing the token doesn't replace, though: the key that issued it. Every request made with a temporary credential is also checked as if that access key made it. This is load-bearing. It's why a temporary credential can never do more than its issuer, and it's how you can kill a whole batch of them by disabling one key.

The meaty innards of a temporary credential

At first glance, what I just said probably sounds a bit insane to you. "What, you just include the database record with the request? How in the seven hells is that secure at all?? Isn't this just a gentrified JWT?" Yeah, it's similar to a JWT, but it's fundamentally misuse resistant in ways that JWTs simply are not.

The trick is that the database record is encrypted by Tigris when you create it, returned as a session token, and then that session token is validated against your temporary credentials before any API calls can happen.

Here's what an example temporary credential keypair looks like:

$ t3 credentials temporary xe-models --name ci-upload --access readwrite --duration 1h --export --for aws
export AWS_ACCESS_KEY_ID='tsid_...'
export AWS_SECRET_ACCESS_KEY='tssec_...'
export AWS_SESSION_TOKEN='tsts1....'
export AWS_ENDPOINT_URL_S3='https://t3.storage.dev'
export AWS_ENDPOINT_URL_IAM='https://iam.storageapi.dev'
export AWS_REGION='auto'

The access key ID and secret access key are used mostly the same way they are in SigV4 auth normally, so we'll just skip over that. The secret access key is derived from the session token with a key that only Tigris holds, so seeing the session token doesn't give you the secret.

Now for the really interesting part: the session token. When you mint one yourself, you'll see a long, very high entropy string (we've cut it short here) that you are undoubtedly going to put through a base64 decoder and xxd only to get random data back. That's because the session token is actually a sealed record, or an encrypted value that gets decrypted by the platform as part of the process of using it. If the decryption fails, the request fails, and forging access to things you shouldn't have access to is impossible unless all of cryptography is broken (in which case we hope Tigris is not high on the list of targets).

The data in the session token

Under the covers, the session token holds the data that would normally go in a FoundationDB record, including but not limited to:

Then you submit the session token with your S3 requests and if all goes well your credential works! If not then your data is secure, even from yourself!

Creating temporary credentials

In order to create one, you poke our new STS endpoint at https://sts.storage.dev and issue a GetFederationToken call with an IAM policy that names one bucket and the actions you want. Every AWS SDK can do this with only the endpoint changed. With the AWS CLI, you can set AWS_ENDPOINT_URL_STS=https://sts.storage.dev instead of passing --endpoint-url:

AWS CLI

aws sts get-federation-token \
  --endpoint-url https://sts.storage.dev \
  --region auto \
  --name ci-upload \
  --duration-seconds 3600 \
  --policy '{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": ["s3:GetObject", "s3:PutObject", "s3:ListBucket"],
        "Resource": ["arn:aws:s3:::my-bucket", "arn:aws:s3:::my-bucket/*"]
      }
    ]
  }'

JavaScript

import { GetFederationTokenCommand, STSClient } from "@aws-sdk/client-sts";

const policy = {
  Version: "2012-10-17",
  Statement: [
    {
      Effect: "Allow",
      Action: ["s3:GetObject", "s3:PutObject", "s3:ListBucket"],
      Resource: ["arn:aws:s3:::my-bucket", "arn:aws:s3:::my-bucket/*"],
    },
  ],
};

const sts = new STSClient({
  endpoint: "https://sts.storage.dev",
  region: "auto",
});

const { Credentials: creds } = await sts.send(
  new GetFederationTokenCommand({
    Name: "ci-upload",
    DurationSeconds: 3600,
    Policy: JSON.stringify(policy),
  })
);

Python

import json

import boto3

policy = {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": ["s3:GetObject", "s3:PutObject", "s3:ListBucket"],
            "Resource": ["arn:aws:s3:::my-bucket", "arn:aws:s3:::my-bucket/*"],
        }
    ],
}

sts = boto3.client("sts", endpoint_url="https://sts.storage.dev", region_name="auto")
creds = sts.get_federation_token(
    Name="ci-upload",
    DurationSeconds=3600,
    Policy=json.dumps(policy),
)["Credentials"]

Go

import (
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/sts"
)

const policy = `{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:PutObject", "s3:ListBucket"],
      "Resource": ["arn:aws:s3:::my-bucket", "arn:aws:s3:::my-bucket/*"]
    }
  ]
}`

cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
	log.Fatal(err)
}

stsClient := sts.NewFromConfig(cfg, func(o *sts.Options) {
	o.BaseEndpoint = aws.String("https://sts.storage.dev")
	o.Region = "auto"
})

out, err := stsClient.GetFederationToken(ctx, &sts.GetFederationTokenInput{
	Name:            aws.String("ci-upload"),
	DurationSeconds: aws.Int32(3600),
	Policy:          aws.String(policy),
})
if err != nil {
	log.Fatal(err)
}
creds := out.Credentials

What you get back is an access key ID, a secret access key, and a session token. Use them like any other credential, just with the session token set next to the other two. The docs have examples of using them with each SDK.

Here's a couple infrastructure prompt ideas on how you can use this:

Personally I think the coolest application for this is having credentials constantly rolling so that your services never have persistent Tigris credentials, but they have to constantly request new ones. It's a lot like SSH certificates if you've ever dealt with those.

The price of stateless

In my experience, this works pretty great. Your credentials automatically self-terminate, and when one leaks anyway, the blast radius is one bucket for however long that credential has left to live.

The main tradeoff you make here is that temporary credentials can't be arbitrarily revoked, like with presigned URLs. Once you mint them, they are valid until they expire or the access key that minted them is disabled or deleted. In the worst possible scenario, you disable or delete the access key that minted all your credentials. That kills the leaked ones, but it also kills every other credential that key ever minted.

None of this is instant, either. It takes about 10 minutes to reach every credential the key minted. I'd reach for disabling the key over deleting it, because you can turn a disabled key back on once the fire is out. If you only take some permissions away from the issuing key, its credentials lose that access within 30 minutes.

We think about this as an explicit tradeoff between latency, simplicity, and security. If you want to use this in your stack, please ask a security expert (or your AI agent with a skill that acts like one) to talk you through the advantages and disadvantages of this for your use case.

In practice credentials being locked down to a single bucket for a set expiry time isn't that bad of an issue, but again this depends on the paranoia level of your use case.

Then there's the fine print:

The policy you mint a temporary credential with can grant these IAM actions:

Read actionsWrite actions
s3:GetObjects3:PutObject
s3:GetObjectVersions3:DeleteObject
s3:GetObjectTaggings3:DeleteObjectVersion
s3:GetObjectVersionTaggings3:PutObjectTagging
s3:GetObjectAttributess3:DeleteObjectTagging
s3:ListBuckets3:PutObjectVersionTagging
s3:ListBucketVersionss3:DeleteObjectVersionTagging
s3:GetBucketLocations3:AbortMultipartUpload
s3:GetBucketVersionings3:ListMultipartUploadParts
s3:ListBucketMultipartUploads

These are actions, not individual S3 API calls, and one action can cover several calls. s3:PutObject, for example, covers copies and the whole multipart upload flow: creating the upload, uploading parts, and completing it.

In practice, this matches about 99% of the most common API calls. If you need to do something outside this list, please reach out to us so we can learn more about your use case!

Let us know how it works for you!

Temporary credentials are our first step towards making Tigris authentication work for you instead of having to work around it for your needs. We really hope that you enjoy them and would love to hear what you build!

We're going to continue working on making Tigris better for everyone. Check out our Discord community to talk with other users and share in your victories. We'll cheer along with you!

Stay safe all! Happy holidays and happy new year!

Hand your agents a wristband, not the main keypair

Mint short-lived, bucket-scoped credentials with one API call. They work in every region the moment you make them and expire on their own.

Read the temporary credentials docs


Facts and circumstances may have changed since publication. Please contact me before jumping to conclusions if something seems wrong or unclear.

Tags: