Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/cli-temporary-credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tigrisdata/cli": minor
---

Support temporary credentials. `tigris credentials temporary <bucket> --name <name> --access read|write|readwrite` issues credentials limited to one bucket (or use `--actions` or `--policy`), lasting `--duration` (default 1h). `--export` prints them as shell `export` lines for `eval "$(...)"`, with `--for aws` for the AWS variable names. Issuing needs an access key. Logged in with OAuth, the command offers to create one for the bucket (ReadOnly or ReadWrite, matching what is granted), or to stop so you can log in with an access key.

The CLI now also authenticates with temporary credentials: `AWS_SESSION_TOKEN` or `TIGRIS_STORAGE_SESSION_TOKEN` alongside the matching access key variables, or an AWS profile that holds a session token. Access errors then say the credentials are temporary, and `whoami`, `credentials test` and the access-key and IAM commands explain what temporary credentials can't do instead of failing with "Access Denied".
10 changes: 10 additions & 0 deletions .changeset/iam-temporary-credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@tigrisdata/iam": minor
"@tigrisdata/storage": patch
---

Add `createTemporaryCredentials(name, options)` to `@tigrisdata/iam`. It issues temporary credentials (STS `GetFederationToken`) limited to one bucket, with `access: 'read' | 'write' | 'readwrite'`, exact `actions`, or a full `policy`, and an optional `durationSeconds` (900 to 129600). The result plugs straight into `@tigrisdata/storage`. It needs an access key, as Tigris refuses OAuth sessions here. Set `stsEndpoint` or `TIGRIS_STS_ENDPOINT` to use an STS endpoint other than `https://sts.storage.dev`.

`@tigrisdata/iam` now depends on `@smithy/signature-v4`, `@aws-crypto/sha256-js` and `@aws-sdk/xml-builder` instead of bundling its own copies, which shrinks its build from about 84 KB to 31 KB. Apps that also use `@tigrisdata/storage` share one copy of each.

Errors with an XML body, such as S3 and STS errors, now report the gateway's message instead of just the HTTP status text.
7 changes: 7 additions & 0 deletions .changeset/storage-temporary-credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tigrisdata/storage": minor
---

Accept temporary credentials (STS `GetFederationToken`). Pass `accessKeyId`, `secretAccessKey` and `sessionToken` together, or set `TIGRIS_STORAGE_SESSION_TOKEN` alongside the access key variables, and every call signs the session token in. `copy`, `move` and `updateObject` previously refused a session token without an organization ID. A `credentialProvider` no longer needs `organizationId`, so it can return renewable temporary credentials. A session token passed without its key pair is still an OAuth token.

One undocumented combination changes meaning: a config with a non-empty `accessKeyId` and `secretAccessKey` plus an OAuth `sessionToken` and `organizationId` used to be sent as OAuth. It is now treated as temporary credentials. Pass an OAuth token without the key pair.
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Non-published apps live in `apps/` (part of the pnpm workspace via the `apps/*`

Shared code lives in [`shared/`](shared) and is imported via the `@shared/*` TS path alias and the matching tsup esbuild alias. It is bundled into each package at build time and is not published as its own package.

`shared/` is bundled, but its third-party imports are not. Every published package that pulls in shared code with a runtime dependency (`@smithy/signature-v4`, `@aws-crypto/sha256-js`, `@aws-sdk/xml-builder`, `dotenv`) lists that dependency in its own `dependencies`, with the same version range as `shared/package.json`. tsup then leaves it external, so an app using several Tigris packages loads one copy. A missing entry makes tsup inline a private copy instead.

Root-level scripts:

- `pnpm build` — build all packages (`pnpm -r run build`)
Expand Down
38 changes: 33 additions & 5 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Run `tigris help` to see all available commands, or `tigris <command> help` for
| `tigris usage` | Show the active organization's usage and charges for a billing month, as on the console's Usage page. Requires OAuth login |
| `tigris update` | Update the CLI to the latest version |
| `tigris logout` | End the current session and clear login state. Credentials saved via 'configure' are kept |
| `tigris credentials` (creds) | Test whether your current credentials can reach Tigris and optionally verify access to a specific bucket |
| `tigris credentials` (creds) | Test whether your current credentials can reach Tigris, and issue temporary credentials limited to one bucket |
| `tigris telemetry` | Show or change whether the CLI sends usage analytics and error reports |
| `tigris ls` (list) | List all buckets (no arguments) or objects under a bucket/prefix path. Accepts bare names or t3:// URIs |
| `tigris mk` (create) | Create a bucket (bare name) or a folder inside a bucket (bucket/folder/ with trailing slash) |
Expand Down Expand Up @@ -222,11 +222,12 @@ tigris logout

### `tigris credentials` (creds)

Test whether your current credentials can reach Tigris and optionally verify access to a specific bucket
Test whether your current credentials can reach Tigris, and issue temporary credentials limited to one bucket

| Command | Description |
| ----------------------------- | ---------------------------------------------------------------------------------------- |
| `tigris credentials test` (t) | Verify that current credentials are valid. Optionally checks access to a specific bucket |
| Command | Description |
| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tigris credentials test` (t) | Verify that current credentials are valid. Optionally checks access to a specific bucket |
| `tigris credentials temporary` (temp) | Issue temporary credentials (an access key ID, secret and session token) limited to one bucket and the actions you choose. They expire on their own and cannot be revoked one by one. They are issued with your access key; logged in with OAuth, you can create one for the bucket |

#### `tigris credentials test` (t)

Expand All @@ -247,6 +248,33 @@ tigris credentials test
tigris credentials test --bucket my-bucket
```

#### `tigris credentials temporary` (temp)

Issue temporary credentials (an access key ID, secret and session token) limited to one bucket and the actions you choose. They expire on their own and cannot be revoked one by one. They are issued with your access key; logged in with OAuth, you can create one for the bucket

```
tigris credentials temporary [bucket] [flags]
```

| Flag | Description |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `-n, --name` | A name for the credentials, shown in their federated user ARN. 2 to 32 characters from letters, digits and _+=,.@- **(required)** |
| `-a, --access` | Grant the read actions, the write actions, or both |
| `--actions` | Comma-separated actions to grant, such as s3:GetObject,s3:ListBucket. Combines with --access |
| `--policy` | Path to a JSON policy to use instead of a bucket with --access or --actions |
| `-d, --duration` | How long the credentials last, from 15m to 36h, e.g. 30m, 1h or 3600 (seconds) (default: 1h) |
| `--export` | Print the credentials as shell "export" lines and nothing else on stdout, for eval "$(tigris credentials temporary ... --export)" |
| `--for` | Which SDK the --export variables are for. tigris writes TIGRIS_STORAGE_*; aws writes AWS_* plus Tigris endpoints and region (default: tigris) |

**Examples:**

```bash
tigris credentials temporary my-bucket --name ci-upload --access write
tigris credentials temporary my-bucket --name reader --actions s3:GetObject,s3:ListBucket --duration 30m
tigris credentials temporary --name custom --policy ./policy.json
eval "$(tigris credentials temporary my-bucket --name ci --access readwrite --export --for aws)"
```

### `tigris telemetry`

Show or change whether the CLI sends usage analytics and error reports
Expand Down
15 changes: 14 additions & 1 deletion packages/cli/src/auth/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { getAuthClient } from './client.js';

export { isFlyOrganization } from './fly.js';

import { getTigrisConfig, resolveAuthMethod } from './provider.js';
import {
getTigrisConfig,
resolveAuthMethod,
usesTemporaryCredentials,
} from './provider.js';
import {
getAwsProfileConfig,
getLoginMethod,
Expand Down Expand Up @@ -60,6 +64,15 @@ export async function getOAuthIAMConfig(context: MessageContext) {
export async function getIAMConfig(context: MessageContext) {
const method = await resolveAuthMethod();

// Tigris refuses IAM calls from temporary credentials. Say so up front
// rather than surface the gateway's bare "Access Denied".
if (usesTemporaryCredentials(method)) {
failWithError(
context,
'You are using temporary credentials, which cannot manage access keys or IAM. Use an access key instead.'
);
}

switch (method.type) {
case 'oauth':
return getOAuthIAMConfig(context);
Expand Down
31 changes: 30 additions & 1 deletion packages/cli/src/auth/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { fromIni } from '@aws-sdk/credential-providers';
import type { RetryConfig } from '@tigrisdata/storage';
import { setUsingTemporaryCredentials } from '@utils/temporary-credentials.js';

import {
DEFAULT_IAM_ENDPOINT,
Expand Down Expand Up @@ -70,7 +71,11 @@ export function getEnvForcePathStyle(): boolean {
// Environment credential helpers
// ---------------------------------------------------------------------------

type EnvCredentials = CredentialsConfig & { source: 'tigris' | 'aws' };
type EnvCredentials = CredentialsConfig & {
source: 'tigris' | 'aws';
/** Set for temporary credentials. */
sessionToken?: string;
};

/**
* Get credentials from environment variables.
Expand All @@ -86,6 +91,7 @@ export function getEnvCredentials(): EnvCredentials | null {
return {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN || undefined,
endpoint,
source: 'aws',
};
Expand All @@ -101,6 +107,7 @@ export function getEnvCredentials(): EnvCredentials | null {
return {
accessKeyId: process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,
secretAccessKey: process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY,
sessionToken: process.env.TIGRIS_STORAGE_SESSION_TOKEN || undefined,
endpoint,
source: 'tigris',
};
Expand Down Expand Up @@ -147,6 +154,8 @@ export type AuthMethod =
profile: string;
accessKeyId: string;
secretAccessKey: string;
/** Set when the profile holds temporary credentials. */
sessionToken?: string;
}
| { type: 'oauth' }
| { type: 'credentials'; accessKeyId: string; secretAccessKey: string }
Expand All @@ -155,6 +164,8 @@ export type AuthMethod =
accessKeyId: string;
secretAccessKey: string;
source: 'tigris' | 'aws';
/** Set for temporary credentials. */
sessionToken?: string;
}
| { type: 'configured'; accessKeyId: string; secretAccessKey: string }
| { type: 'none' };
Expand All @@ -167,6 +178,20 @@ export type AuthMethod =
* per-session override that should win over a previously stored login.
*/
export async function resolveAuthMethod(): Promise<AuthMethod> {
const method = await resolveAuthMethodUnrecorded();
setUsingTemporaryCredentials(usesTemporaryCredentials(method));
return method;
}

/** Whether the method authenticates with temporary credentials. */
export function usesTemporaryCredentials(method: AuthMethod): boolean {
return (
(method.type === 'aws-profile' || method.type === 'environment') &&
!!method.sessionToken
);
}

async function resolveAuthMethodUnrecorded(): Promise<AuthMethod> {
// 1. AWS profile
if (hasAwsProfile()) {
const profile = process.env.AWS_PROFILE || 'default';
Expand All @@ -176,6 +201,7 @@ export async function resolveAuthMethod(): Promise<AuthMethod> {
profile,
accessKeyId: resolved.accessKeyId,
secretAccessKey: resolved.secretAccessKey,
...(resolved.sessionToken && { sessionToken: resolved.sessionToken }),
};
}

Expand All @@ -187,6 +213,7 @@ export async function resolveAuthMethod(): Promise<AuthMethod> {
accessKeyId: envCreds.accessKeyId,
secretAccessKey: envCreds.secretAccessKey,
source: envCreds.source,
...(envCreds.sessionToken && { sessionToken: envCreds.sessionToken }),
};
}

Expand Down Expand Up @@ -312,6 +339,7 @@ async function resolveStorageConfig(options?: {
return {
accessKeyId: method.accessKeyId,
secretAccessKey: method.secretAccessKey,
...(method.sessionToken && { sessionToken: method.sessionToken }),
endpoint:
profileConfig.endpoint ||
getTigrisConfig().endpoint ||
Expand Down Expand Up @@ -367,6 +395,7 @@ async function resolveStorageConfig(options?: {
return {
accessKeyId: method.accessKeyId,
secretAccessKey: method.secretAccessKey,
...(method.sessionToken && { sessionToken: method.sessionToken }),
endpoint: getEnvCredentials()?.endpoint || DEFAULT_STORAGE_ENDPOINT,
};

Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/lib/access-keys/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type CredentialsSdk,
credentialVariables,
gitignoreStatus,
SESSION_TOKEN_VARIABLE,
shellExportLines,
writeDotenv,
} from '@utils/credentials-export.js';
Expand Down Expand Up @@ -128,7 +129,8 @@ export default async function create(options: Record<string, unknown>) {
let envError: NodeJS.ErrnoException | undefined;
if (envPath) {
try {
writeDotenv(envPath, variables);
// A permanent key: drop any token left by temporary credentials.
writeDotenv(envPath, variables, [SESSION_TOKEN_VARIABLE[sdk]]);
} catch (err) {
envError = err instanceof Error ? err : new Error(String(err));
}
Expand Down
Loading