Skip to content
Merged
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
14 changes: 10 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ Follow these rules unless `docs/priciples.md` is updated:
root to become readable through the public Drive9 CLI. It must retain the
resource and local credentials when waiting fails.
- `ti fs delete-file-system` is asynchronous. After Drive9 accepts deletion,
output status is `deleting`, not `deleted`.
output status is `deleting`, not `deleted`. It always requires both
`--file-system-id` and `--confirm-file-system-name`; the confirmation must
equal the target File System display name (or its ID when the backend keeps
no display name), is checked before profile and credential loading, and is
matched against the remote display name before the irreversible delete
request. Deletion has no backend recovery period.
- `ti fs mount-file-system` and `ti fs-vault mount-vault` are background-only
public commands. They wait for readiness, return a structured result, and
persist a local mount locator for the matching unmount command. Do not expose
Expand Down Expand Up @@ -588,8 +593,8 @@ Implemented command behavior:
- `ti fs enable-file-system-token --file-system-id <file-system-id> --token-id <token-id>`
- `ti fs delete-file-system-token --file-system-id <file-system-id> --token-id <token-id>`
- `ti fs refresh-file-system-token --file-system-id <file-system-id>`
- `ti fs delete-file-system --file-system-id <file-system-id>`
- `ti fs delete-file-system --file-system-id <file-system-id> --dry-run`
- `ti fs delete-file-system --file-system-id <file-system-id> --confirm-file-system-name <display-name>`
- `ti fs delete-file-system --file-system-id <file-system-id> --confirm-file-system-name <display-name> --dry-run`
- `ti fs list-file-systems`
- `ti fs list-regions`
- `ti fs list-regions --output text`
Expand Down Expand Up @@ -1014,7 +1019,8 @@ can therefore use an existing resource with only a canonical region and FS
token; the ID is derived in memory from the token. Do not persist ephemeral
flag/environment credentials or create a synthetic `[env]` profile. `ti fs create-file-system`, remote list/describe, and
`ti fs delete-file-system` remain TiDB Cloud-authenticated. Delete requires an
ID but does not require a locally stored owner token.
ID and an explicit display-name confirmation but does not require a locally
stored owner token.

Filesystem token generate/list/enable/disable/delete commands also use only
TiDB Cloud public/private keys and always require an explicit File System ID.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ ti fs generate-file-system-scoped-token \

`TI_FS_TOKEN` may contain either token kind. Scoped tokens work only for allowed paths and operations and can self-refresh; they cannot generate child tokens or manage token inventory. Explicit `--fs-token` takes precedence over the environment. Token list, enable, disable, and delete use an explicit/environment owner token when present, otherwise they use configured TiDB Cloud API keys. With owner Bearer authentication, enable and disable apply only to scoped targets; TiDB Cloud credentials can manage either token kind. Because the token JWT does not expose its kind or scopes, the FS backend is the final permission authority.

An owner FS token authorizes Filesystem use and token management, but it is not a TiDB Cloud administrative credential. Creating, listing, describing, and deleting Filesystem resources require TiDB Cloud API keys. In particular, `ti fs delete-file-system` always requires an explicit `--file-system-id`; `TI_FS_TOKEN` cannot select or authorize deletion of the Filesystem itself. For token list, enable, disable, and delete commands, `--file-system-id` is required only when the command uses TiDB Cloud API keys. When an owner token is supplied through `--fs-token` or `TI_FS_TOKEN`, `ti` derives the Filesystem ID from that token.
An owner FS token authorizes Filesystem use and token management, but it is not a TiDB Cloud administrative credential. Creating, listing, describing, and deleting Filesystem resources require TiDB Cloud API keys. In particular, `ti fs delete-file-system` always requires an explicit `--file-system-id` plus `--confirm-file-system-name` matching the target Filesystem display name; deletion is asynchronous and irreversible because the backend keeps no recovery period, and `TI_FS_TOKEN` cannot select or authorize deletion of the Filesystem itself. For token list, enable, disable, and delete commands, `--file-system-id` is required only when the command uses TiDB Cloud API keys. When an owner token is supplied through `--fs-token` or `TI_FS_TOKEN`, `ti` derives the Filesystem ID from that token.

Filesystem AI provider configuration is optional. Without it, existing create, mount, file, search, layer, vault, journal, and Git workflows continue to work normally. Organization administrators can inspect or customize image, audio, and video extraction and OpenAI-compatible 1024-dimension embedding for an explicit Filesystem ID:

Expand Down Expand Up @@ -371,7 +371,7 @@ ti fs enable-file-system-token
ti fs disable-file-system-token
ti fs delete-file-system-token
ti fs refresh-file-system-token
ti fs delete-file-system
ti fs delete-file-system --file-system-id <file-system-id> --confirm-file-system-name <display-name>
ti fs list-file-systems
ti fs describe-file-system
ti fs describe-file-system-extract-configuration
Expand Down
14 changes: 12 additions & 2 deletions docs/present.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export FILE_SYSTEM_ID="$(bin/ti fs create-file-system \
--wait \
--query file_system_id \
--output text)"
export FILE_SYSTEM_NAME="$(bin/ti fs describe-file-system \
--file-system-id "$FILE_SYSTEM_ID" \
--query display_name \
--output text)"

bin/ti fs list-file-systems --output text
bin/ti fs describe-file-system \
Expand Down Expand Up @@ -373,11 +377,17 @@ bin/ti fs-vault delete-secret \
rm -f /tmp/ti-demo-token.txt
```

删除 Filesystem 资源及其本地 credential entry:
删除 Filesystem 资源及其本地 credential entry。删除是异步且不可恢复的,因此必须用 `--confirm-file-system-name` 重复目标 Filesystem 的 display name;dry-run 只校验本地参数,真实执行会先读取远端 display name 再比对:

```bash
bin/ti fs delete-file-system \
--file-system-id "$FILE_SYSTEM_ID"
--file-system-id "$FILE_SYSTEM_ID" \
--confirm-file-system-name "$FILE_SYSTEM_NAME" \
--dry-run

bin/ti fs delete-file-system \
--file-system-id "$FILE_SYSTEM_ID" \
--confirm-file-system-name "$FILE_SYSTEM_NAME"
```

删除演示 cluster:
Expand Down
37 changes: 30 additions & 7 deletions e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func TestHelpAndVersion(t *testing.T) {

deleteFileSystem := runTI(t, bin, "fs", "delete-file-system", "help")
deleteFileSystem.wantExitCode(0)
deleteFileSystem.wantStdoutContains("--file-system-id")
deleteFileSystem.wantStdoutContains("--file-system-id <string> (required)")
deleteFileSystem.wantStdoutContains("--confirm-file-system-name <string> (required)")
deleteFileSystem.wantStdoutNotContains("--file-system-name")
deleteFileSystem.wantStdoutNotContains("--confirm-file-system-name")
createFileSystem := runTI(t, bin, "fs", "create-file-system", "help")
createFileSystem.wantExitCode(0)
createFileSystem.wantStdoutContains("[--display-name <string>]")
Expand Down Expand Up @@ -210,9 +210,9 @@ func TestErrorsAreRenderedAtCLIBoundary(t *testing.T) {
unknown.wantExitCode(2)
unknown.wantStderrContains(`ti [ERROR]: unknown command "missing-command" for "ti db"`)

removedConfirmation := runTI(t, bin, "fs", "delete-file-system", "--file-system-id", "tenant-workspace", "--confirm-file-system-name", "workspace")
removedConfirmation.wantExitCode(2)
removedConfirmation.wantStderrContains(`unknown flag: --confirm-file-system-name`)
missingDeleteConfirmation := runTI(t, bin, "fs", "delete-file-system", "--file-system-id", "tenant-workspace")
missingDeleteConfirmation.wantExitCode(2)
missingDeleteConfirmation.wantStderrContains("--confirm-file-system-name is required")

releaseServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/releases/latest" {
Expand Down Expand Up @@ -1051,8 +1051,31 @@ func TestFSRemoteInventoryAndIDCredentialSelectionAcrossCommandFamilies(t *testi
}

deleteScratch := runTIWithInput(t, bin, "", append(baseEnv, "TI_FS_TOKEN="+drive9TestToken("tenant-aws-us-west-2")), "--profile", "stage", "--region", "aws-us-west-2", "fs", "delete-file-system", "--file-system-id", "tenant-aws-us-west-2")
deleteScratch.wantExitCode(0)
deleteScratch.wantStdoutContains(`"status": "deleting"`)
deleteScratch.wantExitCode(2)
deleteScratch.wantStderrContains("--confirm-file-system-name is required")
if got := westControl.requestCount(); got != requestsBeforeTokenOnlyDelete {
t.Fatalf("unconfirmed delete sent a remote request: before=%d after=%d", requestsBeforeTokenOnlyDelete, got)
}

mismatchedDelete := runTIWithInput(t, bin, "", append(baseEnv, "TI_FS_TOKEN="+drive9TestToken("tenant-aws-us-west-2")), "--profile", "stage", "--region", "aws-us-west-2", "fs", "delete-file-system", "--file-system-id", "tenant-aws-us-west-2", "--confirm-file-system-name", "agent-workspace")
mismatchedDelete.wantExitCode(2)
mismatchedDelete.wantStderrContains(`--confirm-file-system-name "agent-workspace" does not match the target file system display name "tenant-aws-us-west-2"`)
if westControl.hasRequest(http.MethodDelete, "/v1/admin/tenants/tenant-aws-us-west-2") {
t.Fatalf("mismatched confirmation deleted the file system: %#v", westControl.requests)
}

requestsBeforeDeleteDryRun := westControl.requestCount()
deleteDryRun := runTIWithInput(t, bin, "", append(baseEnv, "TI_FS_TOKEN="+drive9TestToken("tenant-aws-us-west-2")), "--profile", "stage", "--region", "aws-us-west-2", "fs", "delete-file-system", "--file-system-id", "tenant-aws-us-west-2", "--confirm-file-system-name", "tenant-aws-us-west-2", "--dry-run")
deleteDryRun.wantExitCode(0)
deleteDryRun.wantStdoutContains(`"delete_confirmation"`)
deleteDryRun.wantStdoutContains(`"dry_run": true`)
if got := westControl.requestCount(); got != requestsBeforeDeleteDryRun {
t.Fatalf("delete dry-run sent a remote request: before=%d after=%d", requestsBeforeDeleteDryRun, got)
}

confirmedDelete := runTIWithInput(t, bin, "", append(baseEnv, "TI_FS_TOKEN="+drive9TestToken("tenant-aws-us-west-2")), "--profile", "stage", "--region", "aws-us-west-2", "fs", "delete-file-system", "--file-system-id", "tenant-aws-us-west-2", "--confirm-file-system-name", "tenant-aws-us-west-2")
confirmedDelete.wantExitCode(0)
confirmedDelete.wantStdoutContains(`"status": "deleting"`)
afterDelete := runTIWithInput(t, bin, "", baseEnv, "--profile", "stage", "fs", "list-file-systems")
afterDelete.wantExitCode(0)
afterDelete.wantStdoutContains(`"file_system_id": "tenant-aws-us-east-1"`)
Expand Down
59 changes: 52 additions & 7 deletions e2e/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (
const defaultLiveProfile = "live-e2e"

var (
liveFSResourceMu sync.Mutex
liveFSResourceAutoCreatedID string
liveFSTokenAutoCreatedID string
liveFSTokenAutoFileSystemID string
liveFSSelectedID string
liveProfileConfigureMu sync.Mutex
liveFSResourceMu sync.Mutex
liveFSResourceAutoCreatedID string
liveFSResourceAutoCreatedName string
liveFSTokenAutoCreatedID string
liveFSTokenAutoFileSystemID string
liveFSSelectedID string
liveProfileConfigureMu sync.Mutex
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -117,6 +118,7 @@ func TestLiveFSRemoteInventoryLifecycle(t *testing.T) {
}
liveFSResourceMu.Lock()
liveFSResourceAutoCreatedID = created.FileSystemID
liveFSResourceAutoCreatedName = created.DisplayName
liveFSSelectedID = created.FileSystemID
liveFSResourceMu.Unlock()

Expand Down Expand Up @@ -297,6 +299,7 @@ func TestLiveFSCommandSurface(t *testing.T) {
bin := tiBinary(t)
profileName := liveProfileName(t)
selected := ensureLiveFSResource(t, bin, profileName)
selectedDisplayName := liveFSDisplayName(t, bin, profileName, selected)
testLiveHelpCommands(t, bin, [][]string{
{"fs", "help"},
{"fs", "create-file-system", "help"}, {"fs", "import-file-system-token", "help"}, {"fs", "list-file-systems", "help"},
Expand All @@ -323,7 +326,7 @@ func TestLiveFSCommandSurface(t *testing.T) {
})
testLiveMutatingDryRuns(t, bin, profileName, [][]string{
{"fs", "create-file-system", "--display-name", "ti-e2e-dry-run", "--label", "environment=test", "--wait"},
{"fs", "delete-file-system", "--file-system-id", selected.FSTenantID},
{"fs", "delete-file-system", "--file-system-id", selected.FSTenantID, "--confirm-file-system-name", selectedDisplayName},
{"fs", "update-file-system-extract-configuration", "--file-system-id", selected.FSTenantID, "--media-type", "image", "--enabled", "false"},
{"fs", "update-file-system-embedding-configuration", "--file-system-id", selected.FSTenantID, "--enabled", "false"},
{"fs", "create-layer", "--layer-id", "layer-1", "--base-root-path", "/workspace", "--layer-name", "dev"},
Expand Down Expand Up @@ -2347,11 +2350,13 @@ func ensureLiveFSResource(t *testing.T, bin, profileName string) *config.Profile
create.wantStdoutContains(`"status": "ready"`)
var created struct {
FileSystemID string `json:"file_system_id"`
DisplayName string `json:"display_name"`
}
if err := json.Unmarshal([]byte(create.stdout), &created); err != nil || created.FileSystemID == "" {
t.Fatalf("decode created live fs resource: %v", err)
}
liveFSResourceAutoCreatedID = created.FileSystemID
liveFSResourceAutoCreatedName = created.DisplayName
liveFSSelectedID = created.FileSystemID
selected := resolveLiveFSResourceByID(t, profile, created.FileSystemID)
return selected
Expand Down Expand Up @@ -2497,6 +2502,7 @@ func cleanupAutoCreatedLiveFSResource() {
"--profile", profileName,
"fs", "delete-file-system",
"--file-system-id", fileSystemID,
"--confirm-file-system-name", liveFSConfirmName(fileSystemID),
)
output, err := cmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -2532,12 +2538,51 @@ func releaseAutoCreatedLiveFSResource(t *testing.T, bin, profileName string) {
"--profile", profileName,
"fs", "delete-file-system",
"--file-system-id", fileSystemID,
"--confirm-file-system-name", liveFSConfirmName(fileSystemID),
)
result.wantExitCode(0)
liveFSResourceAutoCreatedID = ""
liveFSResourceAutoCreatedName = ""
liveFSSelectedID = ""
}

// liveFSDisplayName reads the authoritative display name of the selected live
// File System so destructive-command tests can pass the exact confirmation.
func liveFSDisplayName(t *testing.T, bin, profileName string, profile *config.Profile) string {
t.Helper()
args := []string{"--profile", profileName}
if profile.FSPlacementRegionCode != "" {
args = append(args, "--region", profile.FSPlacementRegionCode)
}
args = append(args, "fs", "describe-file-system", "--file-system-id", profile.FSTenantID)
result := runTI(t, bin, args...)
result.wantExitCode(0)
var described struct {
DisplayName string `json:"display_name"`
}
if err := json.Unmarshal([]byte(result.stdout), &described); err != nil {
t.Fatalf("decode live fs describe result: %v\n%s", err, result.stdout)
}
// The backend falls back to the File System ID when no display name is set,
// and delete-file-system confirms that same effective name, so a File System
// without a display name must be confirmed by its ID instead of failing.
if name := strings.TrimSpace(described.DisplayName); name != "" {
return name
}
return profile.FSTenantID
}

// liveFSConfirmName returns the delete confirmation for an FS the suite
// created itself. The create response reports the authoritative display name;
// an empty value means the backend kept no display name, so the effective name
// is the File System ID.
func liveFSConfirmName(fileSystemID string) string {
if name := strings.TrimSpace(liveFSResourceAutoCreatedName); name != "" {
return name
}
return fileSystemID
}

func liveProfileName(t *testing.T) string {
t.Helper()
profileName := liveProfileNameFromEnv()
Expand Down
45 changes: 38 additions & 7 deletions internal/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1642,11 +1642,17 @@ func newFSUpdateFileSystemEmbeddingConfigurationCommand(info version.Info) *cobr

func newFSDeleteFileSystemCommand(info version.Info) *cobra.Command {
cmd := newControlPlaneCommand(controlPlaneCommandSpec{
Use: "delete-file-system",
Short: "Delete a file system from TiDB Cloud.",
Use: "delete-file-system",
Short: "Delete a file system from TiDB Cloud.",
Long: "Delete a file system from TiDB Cloud. Deletion is asynchronous and irreversible: the backend keeps no recovery period, so the command requires " +
"--confirm-file-system-name to repeat the target file system display name exactly. Read it with ti fs describe-file-system first.",
Mutation: mutatingCommand,
Permission: authz.FSVolumeDelete,
Run: func(ctx commandContext) (any, error) {
confirmName, err := fsDeleteFileSystemConfirmation(ctx)
if err != nil {
return nil, err
}
service, profile, err := fsTIServiceAndProfile(ctx)
if err != nil {
return nil, err
Expand All @@ -1656,11 +1662,16 @@ func newFSDeleteFileSystemCommand(info version.Info) *cobra.Command {
return nil, err
}
return service.DeleteFileSystem(ctx.cmd.Context(), tifs.DeleteFileSystemOptions{
Profile: profile,
FileSystemID: fileSystemID,
Profile: profile,
FileSystemID: fileSystemID,
ConfirmFileSystemName: confirmName,
})
},
DryRun: func(ctx commandContext) (dryrun.Result, error) {
confirmName, err := fsDeleteFileSystemConfirmation(ctx)
if err != nil {
return dryrun.Result{}, err
}
service, profile, err := fsTIServiceAndProfile(ctx)
if err != nil {
return dryrun.Result{}, err
Expand All @@ -1670,16 +1681,36 @@ func newFSDeleteFileSystemCommand(info version.Info) *cobra.Command {
return dryrun.Result{}, err
}
return service.DryRunDeleteFileSystem(ctx.cmd.Context(), ctx.CommandPath(), tifs.DeleteFileSystemOptions{
Profile: profile,
FileSystemID: fileSystemID,
Profile: profile,
FileSystemID: fileSystemID,
ConfirmFileSystemName: confirmName,
})
},
}, info)
cmd.Flags().String("file-system-id", "", "The file system ID. FS tokens cannot select or authorize file system deletion.")
markUsageRequired(cmd, "file-system-id")
cmd.Flags().String("confirm-file-system-name", "", "The target file system display name. The value must match the remote display name exactly; deletion is irreversible.")
markUsageRequired(cmd, "file-system-id", "confirm-file-system-name")
return cmd
}

// fsDeleteFileSystemConfirmation enforces the explicit ID and confirmation
// requirements before profile and credential loading, so missing flags are
// usage errors instead of authentication errors.
func fsDeleteFileSystemConfirmation(ctx commandContext) (string, error) {
fileSystemID, err := ctx.StringFlag("file-system-id")
if err != nil {
return "", err
}
confirmName, err := ctx.StringFlag("confirm-file-system-name")
if err != nil {
return "", err
}
if err := tifs.ValidateDeleteFileSystemInputs(fileSystemID, confirmName); err != nil {
return "", err
}
return confirmName, nil
}

func newFSImportFileSystemTokenCommand(info version.Info) *cobra.Command {
cmd := newControlPlaneCommand(controlPlaneCommandSpec{
Use: "import-file-system-token",
Expand Down
Loading
Loading