Skip to content

fix(k8s): volume move copy pods fail Pod Security restricted #7449

Backlog

Description

@dan-petty

Problem Description

devops k8s volume move cannot move a claim in a namespace that enforces Pod Security restricted. It builds its copy pods itself, with no securityContext. It reads only the image of the copy container from CronJob devops/volume-move (src/devops_cli/k8s/volume_move.py). Namespace devops enforces restricted, so the API server refuses the first copy pod.

Evidence, 2026-11-27 17:32 UTC

dan-petty/homelab#580 gives the claims devops/valkey-data-roadmap and devops/renovate-cache the class longhorn. A bound claim cannot change its class, so each sync of Application devops fails until the data moves. The move stopped at step 2 and undid each step:

$ uv run devops k8s volume move devops/valkey-data-roadmap --storage-class longhorn
The move stopped at step 2: `kubectl create` exited 1: Error from server (Forbidden): error when creating "STDIN": pods "valkey-data-roadmap-dst" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "copy" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "copy" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "copy" ...

Namespaces llm and monitoring enforce privileged, so the earlier moves there passed. The sync of Application devops fails since 17:00 UTC, so no new release of devops-cli reaches the cluster.

Expected Behavior

The copy pods pass Pod Security restricted: runAsNonRoot, allowPrivilegeEscalation: false, capabilities.drop: ["ALL"] and the seccomp profile RuntimeDefault. They run as the user and group of the pod template of the workload that mounts the claim, and the new volume gets the fsGroup of that template, so the copy reads each file and writes it with the same owner. Example: deployment/valkey-roadmap runs as user 999, group 1000, fsGroup 1000. CronJob renovate runs as 12021. The compare of step 6 still finds no difference.

Acceptance Criteria

  • A test: the copy pods of a move in a namespace that enforces restricted have each field that the profile asks for, and the user, group and fsGroup of the workload pod template.
  • A test: a workload whose pod template runs as root keeps the copy pods of today in a namespace that admits them.
  • Pending a person or an agent after the release: uv run devops k8s volume move devops/valkey-data-roadmap --storage-class longhorn ends with no difference in step 6, and the next sync of Application devops succeeds.

Related

Alternatives check of 2026-11-27: none.
Tool: none found.
Reason: Searches found only generic PVC migrators and cluster policy engines, which run their own pods or mutate cluster-side; none gives the CLI's copy pods the restricted fields plus the workload user, group and fsGroup, or fixes the step 6 compare.

Lacks:

  • No library builds a restricted securityContext into a pod manifest the CLI creates
  • No tool derives runAsUser, runAsGroup and fsGroup from the workload pod template
  • No tool adjusts the copy and digest scripts for the provisioner-owned root directory
  • No tool refuses a claim whose workloads set disagreeing user or fsGroup values

Proposed design

Problem statement

Do not rebuild the copy pods: the move now uses pv-migrate --non-root in a restricted namespace. The remaining gate is the live move of devops/valkey-data-roadmap, which waits on dan-petty/devtools#118. The defect is that a claim in a namespace that enforces Pod Security restricted cannot move, because the API server refuses the copy pod. The fix must pass the restricted profile and keep the data readable by the workload.

Acceptance criteria

Requirement: Restricted namespace uses pv-migrate non-root

The move SHALL pass --non-root and --rsync-extra-args=--no-perms to pv-migrate when the namespace enforces Pod Security restricted, which makes pv-migrate give the copy pods the restricted securityContext.

Scenario: Restricted namespace

  • WHEN A test calls pv_migrate_argv with a plan whose non_root is true.
  • THEN The argv contains --non-root and --rsync-extra-args=--no-perms.

Requirement: Non-restricted namespace keeps the root copy

The move SHALL call pv-migrate without --non-root when the namespace does not enforce Pod Security restricted.

Scenario: Non-restricted namespace

  • WHEN A test calls pv_migrate_argv with a plan whose non_root is false.
  • THEN The argv contains no --non-root and no --rsync-extra-args.

Requirement: Restricted move refuses a workload without fsGroup

plan_volume_move SHALL refuse a restricted-namespace move when a workload pod template sets no fsGroup.

Scenario: Workload without fsGroup

  • WHEN A test calls _non_root_problems with a workload state whose fs_group is None and a target class whose fs_group is true.
  • THEN The result contains the message volume_move_restricted_no_fs_group for that workload.

Requirement: Restricted move refuses a class without fsGroup

plan_volume_move SHALL refuse a restricted-namespace move when the target class cannot give the fsGroup to its files.

Scenario: Class with no fsGroup

  • WHEN A test calls _non_root_problems with a workload state whose fs_group is 1000 and a _TargetClass whose fs_group is false.
  • THEN The result contains the message volume_move_restricted_class for the target class.

Requirement: Pending a person after the merge

The move SHALL finish a live move of devops/valkey-data-roadmap to class longhorn with no difference in step 6, and the next sync of Application devops SHALL succeed.

Scenario: Live move after release

  • WHEN A person runs uv run devops k8s volume move devops/valkey-data-roadmap --storage-class longhorn after the release.
  • THEN Step 6 reports no difference and the next sync of Application devops succeeds.

Existing Tool Considered

The alternatives check of 2026-11-27 in the issue body gives the verdict none and names no tool. The repository already uses pv-migrate for the copy (#7518). The proposal keeps pv-migrate with --non-root and --rsync-extra-args=--no-perms in a restricted namespace, and refuses a move when the workload has no fsGroup or the target class gives no fsGroup. It builds no copy code.

Key questions

  • How does the move make the copy pods pass Pod Security restricted?: The move passes --non-root and --rsync-extra-args=--no-perms to pv-migrate when the namespace enforces restricted. pv-migrate v3.8.0 then gives the sshd and rsync pods the restricted securityContext. (best practice) [sources: src/devops_cli/k8s/volume_move.py, tests/k8s/test_k8s_volume_move.py]
    • Chosen: Use pv-migrate --non-root. pv-migrate is already the copy tool, and its non-root values meet the restricted profile.
    • Rejected: Build the copy pod securityContext in the CLI. The repository replaced its own copy pods with pv-migrate in refactor(k8s): replace the volume move copy with pv-migrate #7518; building them again adds code that the tool covers.
    • Rejected: Use a Pod Security exception. It lowers a security threshold, which only the owner can allow.
  • How does the workload read a copy whose files keep no owner?: The workload reads the copy through its fsGroup. The plan refuses a restricted-namespace move when a workload sets no fsGroup, or when the target class cannot give the fsGroup to its files. (best practice) [sources: src/devops_cli/k8s/volume_move.py, src/devops_cli/lang/en/messages.py, tests/k8s/test_k8s_volume_move.py]
    • Chosen: Require a workload fsGroup and a class that applies it. pv-migrate --non-root adds --no-o --no-g to rsync, so the fsGroup is the only way the workload gets access.
    • Rejected: Run the copy as the workload user and group. The pv-migrate rsync and sshd images have only user 10000; a workload runAsUser does not work.
    • Rejected: Copy as root with a Pod Security exception. It lowers a security threshold.
  • What does the move do in a namespace that does not enforce restricted?: The move calls pv-migrate without --non-root. The copy runs as root and rsync -a keeps each owner. (best practice) [sources: src/devops_cli/k8s/volume_move.py, tests/k8s/test_k8s_volume_move.py]
    • Chosen: Run as root when the namespace admits it. The root copy keeps file owners and the namespace does not refuse it.
    • Rejected: Always run --non-root. It drops owners where the namespace would allow root, and the issue asks to keep the old copy for a root workload.
  • Does the repository need a new copy tool?: No. The repository already uses pv-migrate for the copy. The alternatives check of 2026-11-27 in the issue body gives the verdict none for the original need. The proposal keeps pv-migrate and adds no copy code. [sources: src/devops_cli/k8s/volume_move.py]

Fit

Fits in one pull request.

Suspected block

The live move waits on dan-petty/devtools#118, which adds pv-migrate to the devtools image.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
    • Priority: The Argo CD sync of Application devops fails, blocking all devops-cli releases to the cluster.
  3. added
    priority/p0-critical
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 27, 2026
  4. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor

    Stop: a non-root copy cannot pass step 5 or step 6 (evidence, 2026-11-27)

    I did not build this item and I opened no pull request. With copy pods that run as the workload user, the copy of step 5 fails, and the compare of step 6 cannot find "no difference". To continue, the compare must change, or the copy must run as root. The owner must make this decision.

    Test. I ran GNU tar 1.35 of the copy image (debian:trixie-slim@sha256:8aa5a7bf…, the image of CronJob devops/volume-move) and the digest script of the move (CONST_K8S_VOLUME_MOVE_DIGEST_SCRIPT) in rootless podman, on a temporary volume. I made no write to the cluster.

    • Old volume, as local-path makes it: the setup script of ConfigMap local-path-storage/local-path-config runs mkdir -m 0777 -p "$VOL_DIR" as root, so the root directory is d 777 0:0. The volumes of devops/valkey-data-roadmap and devops/renovate-cache are hostPath volumes, so the kubelet applies no fsGroup to them. The test files belong to user 999, group 1000.
    • New volume, as Longhorn makes it: mkfs makes the root directory 0755 0:0. CSIDriver driver.longhorn.io has fsGroupPolicy: ReadWriteOnceWithFSType, and class longhorn has fsType: ext4, so the kubelet applies the fsGroup 1000: the root directory becomes 2775 0:1000.
    • Copy: the same user as the decision of this item (user 999, group 1000, supplementary group 1000), all capabilities dropped, no-new-privileges.
    Copy user Root directory of the new volume Exit code of tar -x Compare of step 6
    root, default capabilities (the copy pods of today) 0755 0:0 0 equal
    999:1000, no capabilities 2775 0:1000 (fsGroup) 2 different
    999:1000, no capabilities, tar --no-overwrite-dir 2775 0:1000 (fsGroup) 2 different
    999:1000, no capabilities 0755 0:0 (no fsGroup) 2 no data written (Cannot mkdir: Permission denied)

    Errors of the non-root extract:

    tar: .: Cannot utime: Operation not permitted
    tar: .: Cannot change mode to rwxrwxrwx: Operation not permitted
    tar: Exiting with failure status due to previous errors
    

    Metadata lines (%y %m %U:%G %P) that are different on the two sides:

    source                       destination
    d 777 0:0                    d 2775 0:1000          (the root directory)
    d 700 999:1000 private       d 2700 999:1000 private
    d 700 999:1000 d700          d 2700 999:1000 d700
    

    The count, the bytes, the content digest and the owner, group and mode of each file were equal. A file dated 2020-01-02 kept that date (the compare does not check mtime).

    Cause. Only the owner of a file, or a process with CAP_FOWNER and CAP_CHOWN, can change the mode, the time and the owner of the file. Root owns the root directory of the new volume. Pod Security restricted refuses user 0 and each added capability except NET_BIND_SERVICE. Thus a non-root copy cannot give the new root directory the owner 0:0 and the mode 0777 of the old root directory, and tar exits 2 when it tries. Also, each new directory gets the setgid bit from the fsGroup root directory. In the test, the directories with mode 700 kept that bit (2700); the directories with mode 711, 750, 755 and 775 did not.

    Options (each one needs a decision of the owner):

    1. Change the move for a non-root copy: leave the root directory out of the archive and out of the metadata digest (the provisioner, mkfs and the kubelet set it, not the workload), and make the mode of each new directory equal to the mode on the source (the copy user owns these directories). This changes the compare.
    2. Keep the compare and copy as root. Namespace devops enforces restricted, so this needs a change of a Pod Security label or of an admission policy.
    3. Unblock the sync of Application devops now: put the class of the two claims back to local-path in the environment repository until a move can run. The class change of the bound claims is the cause of the failed sync.
    Script to do the test again

    Write the digest script first: uv run python -c "from devops_cli.config.constants import CONST_K8S_VOLUME_MOVE_DIGEST_SCRIPT as s; open('digest.sh','w').write(s)". Then run the script with no variables (the non-root copy), with EXTRACT_FLAGS=--no-overwrite-dir, with COPY_USER=0:0 CAP_FLAGS= DST_FSGROUP= (the copy of today), and with DST_FSGROUP=.

    #!/usr/bin/env bash
    # Round trip of the volume move copy (#7449) in the copy image, on a podman volume.
    # Phase "setup" runs as root and builds:
    #   /w/src  as local-path makes a volume (mkdir -m 0777 as root) with files of the workload user
    #   /w/dst  as a new ext4 volume after the kubelet applies fsGroup 1000 (root 0755 -> 2775 :1000)
    # Phase "copy" runs tar as the copy user; phase "digest" prints the digest and the metadata lines.
    set -u
    IMAGE='docker.io/library/debian:trixie-slim@sha256:8aa5a7bf5a1955bddbe7d74fcdd0b91ab30e74362a8b73af672b0481b35b44a0'
    HERE="$(cd "$(dirname "$0")" && pwd)"
    VOL="vm7449-trip"
    EXTRACT_FLAGS="${EXTRACT_FLAGS:-}"
    COPY_USER="${COPY_USER:-999:1000}"
    DST_FSGROUP="${DST_FSGROUP-1000}"
    CAP_FLAGS="${CAP_FLAGS---cap-drop ALL --security-opt no-new-privileges}"
    
    podman volume rm -f "$VOL" >/dev/null 2>&1
    podman volume create "$VOL" >/dev/null
    
    podman run --rm -v "$VOL:/w" -e DST_FSGROUP="$DST_FSGROUP" "$IMAGE" bash -euc '
      mkdir -m 0777 /w/src
      setpriv --reuid=999 --regid=1000 --groups=1000 bash -euc "
        cd /w/src
        umask 022
        printf data > dump.rdb; chmod 0640 dump.rdb; touch -d 2020-01-02T03:04:05 dump.rdb
        mkdir appendonlydir; printf aof > appendonlydir/a.aof; chmod 0600 appendonlydir/a.aof
        mkdir -m 0700 private; printf p > private/key
        ln -s dump.rdb link
        truncate -s 8M sparse.bin
        printf x > exec.sh; chmod 0755 exec.sh
        for m in 700 711 750 755 775 2775; do mkdir d\$m; chmod \$m d\$m; printf f > d\$m/f; done
      "
      mkdir /w/dst; mkdir -m 0700 /w/dst/lost+found
      if [ -n "$DST_FSGROUP" ]; then chgrp 1000 /w/dst /w/dst/lost+found
      chmod 2775 /w/dst; chmod 2770 /w/dst/lost+found; else chmod 0755 /w/dst; fi
    '
    
    echo "== copy as ${COPY_USER} with extract flags [${EXTRACT_FLAGS}]"
    podman run --rm -v "$VOL:/w" --user "$COPY_USER" --group-add 1000 $CAP_FLAGS \
      --security-opt no-new-privileges -e EXTRACT_FLAGS="$EXTRACT_FLAGS" "$IMAGE" bash -c '
      id
      tar -C /w/src --numeric-owner --sparse -cpf - . | tar -C /w/dst --numeric-owner $EXTRACT_FLAGS -xpf -
      echo "exit codes: ${PIPESTATUS[*]}"
    '
    
    echo "== digest and metadata, read as ${COPY_USER}"
    podman run --rm -v "$VOL:/w" -v "$HERE/digest.sh:/digest.sh:ro" --user "$COPY_USER" \
      --group-add 1000 $CAP_FLAGS "$IMAGE" bash -c '
      for side in src dst; do
        echo "-- $side"; bash -c "$(cat /digest.sh)" digest /w/$side | sed -n "1,4p"
        (cd /w/$side && find . -path ./lost+found -prune -o -printf "%y %m %U:%G %TY-%Tm-%Td %P\n" | LC_ALL=C sort)
      done
    '
    podman volume rm -f "$VOL" >/dev/null
  5. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor

    Cannot be built as written: a non-root copy in a restricted namespace cannot set the mode of the new root directory, and the metadata compare of step 6 then differs (evidence: #7449 (comment)). The owner chooses between a change of the compare, a root copy with a Pod Security exception, or no move for this claim.

  6. added
    status/new
    and removed
    status/in-progress
    on Nov 27, 2026
  7. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  8. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor

    Update 2026-11-27 19:22 UTC: this item no longer blocks Application devops. The two claims were made again with the class longhorn at about 17:49 UTC, not by a move (the new pod of valkey-roadmap started then). The owner then confirmed this choice over a move: valkey-roadmap holds only the brain index, which ADR 0023 rates as derived data. Both claims are now longhorn and Bound, the old local-path volume of valkey-data-roadmap is kept as Released, and the Application is Synced and Healthy at v0.228.2 since 18:28 UTC.

    The defect stays: volume move cannot move a claim in a namespace that enforces restricted. Priority goes from P0 to P2. The choice between the options of the evidence comment stays with the owner.

  9. added
    priority/p2-medium
    and removed
    priority/p0-critical
    on Nov 27, 2026
  10. 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:

    • Kubernetes pod securityContext restricted fields library generate pod spec python, results: 5
    • open source tool migrate PVC data between storage classes pod securityContext, results: 5
    • pvc-migrator kubernetes storage class migration github, results: 5
    • Kyverno mutate pod add restricted securityContext policy, results: 5
    • kubectl pvc migrator plugin change storage class copy data, results: 5
    • kubernetes-sigs volume populator copy PVC data new storage class, results: 5
    • github pvc migrator tool "storage class" copy pods runAsNonRoot, results: 5
    • pv-migrate utkuozdemir kubernetes persistent volume migrate, results: 5
    • pod security standards restricted securityContext seccompProfile RuntimeDefault capabilities drop ALL example pod yaml, results: 5
    • pv-migrate, results: 5

    Sources:

  11. 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): partly fixed. The copy passes Pod Security restricted, but the files do not keep their owner.

    • The move makes no copy pods of its own now. The copy is pv-migrate --strategies clusterip. When the namespace has pod-security.kubernetes.io/enforce: restricted, the move adds --non-root. In pv-migrate v3.8.0, applyNonRootValues (internal/strategy/strategy.go:226) gives the sshd and rsync pods runAsNonRoot: true, user and group 10000, allowPrivilegeEscalation: false, capabilities.drop: [ALL], seccompProfile: RuntimeDefault and fsGroup: 10000. The test test_a_namespace_that_enforces_restricted_copies_with_non_root checks that the call ends with --non-root.
    • In a namespace that does not enforce restricted, pv-migrate runs as root and rsync -a keeps each owner (test_a_namespace_that_does_not_enforce_restricted_copies_as_root).
    • Not as the issue asks: the pods do not run as the user and group of the workload. --non-root adds --no-o --no-g to rsync (internal/rsync/cmd.go), and the rsync and sshd images have only user 10000 in /etc/passwd, which OpenSSH needs, so a runAsUser of the workload does not work. The workload reads the copy through its fsGroup. So the plan refuses a move in a restricted namespace when a workload sets no fsGroup, or when the class gives no fsGroup to its files (no CSIDriver, or fsGroupPolicy: None, such as local-path).
    • Pending a person: the live move of the acceptance criteria, after the devtools image has pv-migrate (feat(image): add pv-migrate devtools#118).
  12. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

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/mediumowner/agentpriority/p2-mediumscope/k8ssource/agentstatus/newtype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions