Skip to content

fix(k8s): refuse a volume move in a restricted namespace #7451

Not planned

Description

@dan-petty

Problem

devops k8s volume move makes its copy pods run as root, so GNU tar keeps the owners of the files. A namespace with the Pod Security label pod-security.kubernetes.io/enforce: restricted refuses such a pod. The plan does not read that label, so the move pauses Argo CD, makes <claim>-move, and only then fails at the create of <claim>-dst, and undoes its steps.

Evidence of 2026-11-27 on the homelab: devops k8s volume move devops/valkey-data-roadmap --storage-class longhorn stopped at step 2 with pods "valkey-data-roadmap-dst" is forbidden: violates PodSecurity "restricted:latest". The namespace devops enforces restricted. The owner allowed a window of baseline for that one move: Argo CD paused (bootstrap, cluster, base, devops), enforce=baseline from 17:49:01 to 17:49:31 UTC, the move, then restricted again. The data (1.4 MB, files of uid 999, gid 1000) moved with equal digests. k8s/README.md says the namespace must allow root pods, but the command does not check it.

Change

  1. The plan reads the label pod-security.kubernetes.io/enforce of the namespace and refuses a move in a restricted namespace with a problem that names the label and the way out; and
  2. An option to run the copy pods under restricted: as a user and group that the person names (the owner of the data), with runAsNonRoot, no capabilities, seccompProfile: RuntimeDefault and an fsGroup, so tar writes the files with that owner. The plan refuses this option when the source holds files of more than one owner, if it can see that.

Acceptance criteria

  • A failing test first: the plan of a claim in a restricted namespace refuses with that problem and changes nothing.
  • devops ci checks pass.

Related: #7382, #7416, dan-petty/homelab#471.

Alternatives check of 2026-11-27: partly.
Tool: utkuozdemir/pv-migrate (https://github.com/utkuozdemir/pv-migrate), Apache-2.0, last activity 2026-11-26, maintained.
Reason: Web searches returned no tool that reads a namespace's pod-security enforce label; pv-migrate, the closest, copies PVC data with configurable copy pods, but it has no pre-flight refusal, no plan and no Argo CD pause.

Covers:

  • Moves PVC data between storage classes
  • Runs copy pods from a configurable Helm chart
  • Supports rsync and sshd transfer strategies

Lacks:

  • No read of the namespace pod-security enforce label
  • No plan that refuses before any cluster change
  • No Argo CD pause, move and undo sequence
  • No refusal when source files have several owners

Proposed design

Problem statement

The issue's original plan would build root copy pods. The move now uses pv-migrate. The plan must read the Pod Security enforce label before any change, run pv-migrate as non-root when an fsGroup works, and refuse the other cases. The owner-preserving copy is a separate issue because pv-migrate --non-root does not keep file owners.

Acceptance criteria

Requirement: Restricted refusal makes no change

The plan MUST refuse a move in a namespace that enforces restricted when the copy cannot run, and MUST make no cluster change before the refusal.

Scenario: Restricted namespace without fsGroup

  • WHEN the plan of a claim in a namespace with pod-security.kubernetes.io/enforce: restricted runs and the workload pod template has no fsGroup
  • THEN the new test test_restricted_refusal_changes_nothing asserts the refusal message and that the plan calls no Argo CD pause, no claim create and no workload scale

Requirement: Refuse local-path in a restricted namespace

The plan MUST refuse a move in a restricted namespace when the target storage class does not supply an fsGroup, such as local-path.

Scenario: Local-path target

  • WHEN the plan runs for a restricted namespace and the target class is local-path
  • THEN the test _restricted_on_local_path asserts the refusal message names the label and the way out

Requirement: Refuse a driver without fsGroup

The plan MUST refuse a move in a restricted namespace when the CSI driver of the target class has fsGroupPolicy: None.

Scenario: Driver without fsGroup

  • WHEN the plan runs for a restricted namespace and the CSI driver of the target class has fsGroupPolicy: None
  • THEN the test _restricted_on_a_driver_without_fs_group asserts the refusal message names the label and the way out

Requirement: Run pv-migrate as non-root when fsGroup works

The plan SHALL run pv-migrate with --non-root and --rsync-extra-args=--no-perms when a restricted namespace has a workload fsGroup and a target class fsGroup.

Scenario: Restricted namespace with fsGroup

  • WHEN the plan runs for a restricted namespace with a workload fsGroup and a target class whose driver supplies an fsGroup
  • THEN the plan invokes pv-migrate with --non-root and --rsync-extra-args=--no-perms, and the test asserts those arguments

Requirement: Scoped checks pass

The change MUST pass the repository checks.

Scenario: Scoped k8s checks

  • WHEN the implement job runs uv run devops ci --check --only k8s
  • THEN the command exits 0

Existing Tool Considered

The alternatives check in the issue body records verdict partly for utkuozdemir/pv-migrate (Apache-2.0, maintained). The proposal uses pv-migrate for the copy. It adds the pre-flight read of the label, the refusal before any cluster change, and the --non-root and --no-perms options that pv-migrate lacks. The check in the issue body lists what the tool covers and lacks.

Key questions

  • What does the current volume move do in a namespace that enforces restricted?: The plan reads pod-security.kubernetes.io/enforce before any change. It runs pv-migrate with --non-root and --rsync-extra-args=--no-perms when the workload has an fsGroup and the target class supplies one. It refuses when the workload has no fsGroup, the target class is local-path, or the CSI driver has fsGroupPolicy: None. [sources: k8s/README.md, tests/k8s/test_k8s_volume_move.py]
  • Does pv-migrate --non-root keep the owner and group of each file?: No. pv-migrate --non-root runs as user 10000 and adds --no-o --no-g to rsync. It keeps no owner and no group. The workload reads the files through its fsGroup. [sources: k8s/README.md]
  • Should the plan refuse every move in a restricted namespace or run pv-migrate as non-root when it can?: Run pv-migrate as non-root when the workload and the storage class supply an fsGroup. Refuse only when the copy cannot run under restricted. This avoids a needless stop and uses the open tool. (best practice) [sources: k8s/README.md, AGENTS.md]
    • Rejected: Refuse every restricted move. It stops moves that pv-migrate can run as non-root.
    • Chosen: Run pv-migrate --non-root when fsGroup works and refuse otherwise. It uses the maintained tool and prevents the late failure.
    • Rejected: Build custom copy pods as a named user and group. It builds code that pv-migrate already covers and needs a separate owner decision.
  • Should the issue implement the option to run copy pods as a named user and group under restricted?: No. Defer it. pv-migrate --non-root does not keep file owners, and a custom copy pod would replace the tool. File an issue for the owner-preserving copy. (best practice) [sources: k8s/README.md, AGENTS.md]
    • Rejected: Implement custom copy pods as a named user and group. It builds code that pv-migrate does not support and adds a second copy path.
    • Chosen: Defer the owner-preserving copy and use pv-migrate --non-root with fsGroup. It keeps one copy path and uses the maintained tool.
    • Rejected: Require a baseline window for every owner-preserving move. It weakens the namespace policy and needs a person to change it.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Moved to new items

#7574

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    status/new
    value/medium
    on Nov 27, 2026
  2. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor
  3. added
    effort/medium
    priority/p2-medium
    on Nov 27, 2026
  4. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • pv-migrate securityContext runAsNonRoot fsGroup seccompProfile options, results: 5
    • kubernetes pvc migration tool pod security restricted namespace non-root fsGroup, results: 5
    • kubernetes volume move command restricted namespace, results: 5
    • pv-migrate github, results: 5
    • pod security standards restricted label enforce kubernetes namespace check, results: 5
    • utkuozdemir pv-migrate kubernetes persistent volume migration, results: 5
    • pv-migrate, results: 5
    • kopiur kubectl plugin copy pvc data, results: 5
    • pv-migrate helm chart values securityContext runAsUser runAsGroup, results: 5
    • Kubernetes PVC copy pod runs as non-root fsGroup tool kopiur, results: 5

    Sources:

  5. dan-petty commented on Nov 28, 2026

    @dan-petty
    OwnerAuthor

    Replacement check for #7498 (PR #7518, which replaces the volume move copy with pv-migrate): mostly fixed, in another form.

    1. The plan now reads pod-security.kubernetes.io/enforce of the namespace (_enforces_restricted) before it changes anything. In a restricted namespace it does not refuse every move: the copy runs pv-migrate --non-root, whose pods pass restricted. The plan refuses, with no change, a workload that sets no fsGroup and a class whose volumes get no fsGroup from the kubelet, such as local-path. Each refusal names the label and the way out: give an fsGroup, move to a class such as longhorn, or move while the namespace enforces baseline. Tests: the parametrized refusal test (_restricted_without_fs_group, _restricted_on_local_path, _restricted_on_a_driver_without_fs_group).
    2. The option to run under restricted is automatic, but not as a user that the person names: pv-migrate --non-root runs as user 10000 and keeps no owner and no group (internal/rsync/cmd.go adds --no-o --no-g). The workload reads the files through its fsGroup. A copy as the owner of the data keeps needing a window of baseline, as the evidence of this issue did.

    I leave the issue open for the owner to decide whether this form is enough.

  6. added
    status/ready
    and removed
    status/new
    on Nov 28, 2026
  7. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

  8. dan-petty commented on Nov 29, 2026

    @dan-petty
    OwnerAuthor

    Superseded by PR #7518 (commit 2669c9e0a, closed #7498).

    The volume move plan in src/devops_cli/k8s/volume_move.py already reads pod-security.kubernetes.io/enforce, runs pv-migrate with --non-root and --rsync-extra-args=--no-perms when a workload and storage class fsGroup work, and refuses a restricted namespace without a workload fsGroup, on local-path, or on a CSIDriver with fsGroupPolicy: None before making any cluster change (tests/k8s/test_k8s_volume_move.py:930-954, 1036-1038, 1165-1190). Owner-preserving copy remains tracked in #7574.

  9. removed
    status/ready
    on Nov 29, 2026
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

    effort/mediumpriority/p2-mediumscope/k8ssource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions