Skip to content

feat(k8s): preserve file owners in a restricted volume move #7574

Backlog

Description

@devops-cli-service

Split from #7451.

The move in a restricted namespace uses pv-migrate --non-root. That mode runs as user 10000 and keeps no owner and no group. The workload reads the files through its fsGroup. The issue asked for an option to run the copy as a user and group that a person names, with runAsNonRoot, no capabilities, seccompProfile: RuntimeDefault and an fsGroup, so tar writes the files with that owner. This part is deferred because pv-migrate does not support a named user with owner preservation. A custom copy pod would replace pv-migrate and needs a separate decision. Acceptance criteria: The plan offers an option to run the copy as a named user and group under restricted. The copy pod sets runAsNonRoot: true, drops all capabilities, sets seccompProfile: RuntimeDefault, and sets an fsGroup. The plan refuses the option when the source has files of more than one owner, if it can see that. A test proves the copy preserves the owner and group of a file in a restricted namespace.

Proposed design

Problem statement

A move in a restricted namespace runs pv-migrate with --non-root as user 10000. That copy keeps no owner and no group. Each workload reads the files only through its fsGroup. The issue adds an option that runs the copy as a named user and group under restricted. Then tar writes each file with that owner and that group.

Acceptance criteria

Requirement: Copy as a named user and group

The volume move command SHALL accept --copy-as-user and --copy-as-group and SHALL copy a claim under restricted with a dedicated Job that runs as that pair.

Scenario: The rendered copy Job

  • WHEN uv run pytest tests/k8s/test_k8s_volume_move.py -k restricted_copy_named_user runs
  • THEN the rendered Job sets runAsUser to 1000, runAsGroup to 1000 and fsGroup to 1000.

Requirement: The copy pod meets the restricted profile

The copy pod MUST set runAsNonRoot: true, MUST drop every capability, MUST set seccompProfile: RuntimeDefault, MUST set allowPrivilegeEscalation: false and MUST keep a read-only root filesystem with an emptyDir at /tmp.

Scenario: The rendered pod and container security context

  • WHEN uv run pytest tests/k8s/test_k8s_volume_move.py -k restricted_copy_security_context runs
  • THEN each field of the pod and the container matches that profile and the container mounts an emptyDir at /tmp.

Requirement: The copy keeps the owner and the group

The copy Job MUST run GNU tar as the named user and group and MUST NOT try to change the owner or the mode of the destination root folder.

Scenario: The rendered copy command

  • WHEN uv run pytest tests/k8s/test_k8s_volume_move.py -k restricted_copy_keeps_owner runs
  • THEN the rendered command holds tar -x --no-overwrite-dir and no --same-owner.

Requirement: Refuse a source of another owner

The plan MUST refuse the option when the source claim holds a file whose owner or group differs from the named pair.

Scenario: A source file of user 1001

  • WHEN uv run pytest tests/k8s/test_k8s_volume_move.py -k restricted_copy_refuses_other_owner runs
  • THEN the plan exits with a message that names the other owner and it creates no copy Job.

Requirement: The option applies only under restricted

The plan MUST refuse the option in a namespace that does not enforce restricted.

Scenario: A namespace at baseline

  • WHEN uv run pytest tests/k8s/test_k8s_volume_move.py -k restricted_copy_requires_restricted runs
  • THEN the plan exits with a message that names baseline and says that pv-migrate keeps the owners there.

Requirement: Pending a person after the merge

A person MUST show on a restricted namespace that a moved file keeps its owner and its group.

Scenario: A live move of a test claim

  • WHEN the pull request is merged and a test claim moves with --copy-as-user 1000 --copy-as-group 1000
  • THEN a pod with fsGroup 1000 runs ls -ln on the destination and shows 1000 1000 for each copied file.

Existing Tool Considered

No alternatives check has run on this issue. GNU tar is the open copy tool that the option uses: it creates each file as the user that runs it, so a run as the named user keeps that owner. pv-migrate, the copy tool in use, has no option for a named user and group: --non-root runs as user 10000 and keeps no owner and no group (k8s/README.md:124). The change builds a small copy Job around tar: about 30k tokens to build, about 5k tokens for each later change to keep and fix, and about 2 days of elapsed time.

Key questions

  • What does a move do today in a namespace that enforces restricted?: pv-migrate gets --non-root and runs as user 10000. It keeps no owner and no group, and rsync gets --no-perms. Each workload reads the files through its fsGroup, and the plan refuses a workload with no fsGroup. [sources: k8s/README.md:124, src/devops_cli/k8s/volume_move.py:1544, tests/k8s/test_k8s_volume_move.py]
  • How does the copy keep the owner and the group of each file under restricted?: A dedicated copy Job runs GNU tar as the named user and group, with fsGroup set to the named group. A non-root process owns each file that it creates, so a run as the named user keeps that owner. The setgid bit that the kubelet sets on each folder of an fsGroup volume gives the named group to each new file. (best practice) [sources: k8s/README.md:124, src/devops_cli/k8s/volume_move.py, tests/k8s/test_k8s_volume_move.py]
    • Chosen: A dedicated copy Job runs tar as the named user and group. It is the only option that sets the user, and a non-root process owns each file that it creates, so the owner and the group stay.
    • Rejected: pv-migrate with a named user and group. --non-root fixes user 10000 and keeps no owner and no group (k8s/README.md:124).
    • Rejected: pv-migrate as root. A restricted namespace refuses a pod that runs as root.
  • Which security context does the copy pod set?: The pod sets runAsNonRoot: true, runAsUser and runAsGroup to the named pair, and fsGroup to the named group. The container sets allowPrivilegeEscalation: false, drops every capability, sets seccompProfile: RuntimeDefault, keeps a read-only root filesystem and mounts an emptyDir at /tmp. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md:37, k8s/devops/cronjob-runner.yaml, k8s/README.md:124]
    • Chosen: The full restricted profile with an emptyDir at /tmp. The restricted admission policy refuses a pod without these fields, and a read-only root filesystem needs a scratch folder for tar.
    • Rejected: Only runAsNonRoot and runAsUser. The restricted policy also asks for a seccomp profile, no capability and no privilege escalation, so the pod would be refused.
  • How does the plan know that the source files have more than one owner?: A pre-flight Job with the same security context runs find on the source and prints each distinct %U:%G pair. The plan refuses the option when a pair differs from the named pair, and when the listing cannot run. (best practice) [sources: k8s/README.md:124, src/devops_cli/k8s/volume_move.py]
    • Chosen: A pre-flight listing Job runs find on the source. It shows the owners before the move starts, so the plan refuses a source that the named user cannot copy.
    • Rejected: The person declares the owner of the source. The plan cannot check the declaration, and the copy fails at the first file of another owner.
    • Rejected: No check of the owners. User 10000 cannot read a file that only its owner can read, so the copy fails and the move undoes its steps (k8s/README.md:124).
  • When does the option apply?: Only when the namespace enforces restricted. Under baseline pv-migrate already keeps the owner and the group, so the plan refuses the option there. (best practice) [sources: k8s/README.md:124, src/devops_cli/k8s/volume_move.py:1544]
    • Chosen: Only under restricted. pv-migrate keeps the owners under baseline, so the option adds no value and hides a wrong namespace.
    • Rejected: Under each enforcement level. A copy as the named user keeps the mode of the destination root folder, so a baseline move would lose the behavior that root keeps today.
  • Where do the move and its messages live?: src/devops_cli/k8s/volume_move.py holds the plan and the copy, src/devops_cli/lang/en/messages.py holds its messages, and tests/k8s/test_k8s_volume_move.py holds its tests. [sources: src/devops_cli/k8s/volume_move.py, src/devops_cli/lang/en/messages.py, tests/k8s/test_k8s_volume_move.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/feature
    scope/k8s
    source/agent
    status/new
    value/medium
    effort/high
    on Nov 28, 2026
  2. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    ContributorAuthor
  3. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    ContributorAuthor

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

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/highpriority/p2-mediumscope/k8ssource/agentstatus/newtype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions