Skip to content

Prevent kubectl-us backups from overwriting on filename collisions #2346

Description

@cardoe

Problem

The backup command introduced by #2344 names backup files using the Kubernetes context, backup type, and int(time.time()). Because the timestamp has one-second resolution, concurrent invocations for the same context can choose the same destination filename.

The successful write path uses os.replace(tmp_path, dest), which replaces an existing destination. A later successful backup can therefore silently overwrite an earlier valid backup, despite the code comment stating that an existing same-name backup is never clobbered.

Expected behavior

A successful backup must not overwrite an existing backup file. The command should either generate collision-resistant filenames or fail safely when the destination has already been reserved or exists.

Acceptance criteria

  • Existing completed backups are never silently overwritten.
  • Concurrent invocations cannot claim the same output filename.
  • Tests cover a successful destination-name collision.

Context

Found while reviewing #2344.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions