Repository navigation
Description
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_userruns - THEN the rendered Job sets
runAsUserto 1000,runAsGroupto 1000 andfsGroupto 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_contextruns - THEN each field of the pod and the container matches that profile and the container mounts an
emptyDirat/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_ownerruns - THEN the rendered command holds
tar -x --no-overwrite-dirand 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_ownerruns - 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_restrictedruns - THEN the plan exits with a message that names
baselineand 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
fsGroup1000 runsls -lnon the destination and shows1000 1000for 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-rootand runs as user 10000. It keeps no owner and no group, and rsync gets--no-perms. Each workload reads the files through itsfsGroup, and the plan refuses a workload with nofsGroup. [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, withfsGroupset 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 anfsGroupvolume 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-rootfixes user 10000 and keeps no owner and no group (k8s/README.md:124). - Rejected: pv-migrate as root. A
restrictednamespace refuses a pod that runs as root.
- Which security context does the copy pod set?: The pod sets
runAsNonRoot: true,runAsUserandrunAsGroupto the named pair, andfsGroupto the named group. The container setsallowPrivilegeEscalation: false, drops every capability, setsseccompProfile: RuntimeDefault, keeps a read-only root filesystem and mounts anemptyDirat/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
emptyDirat/tmp. Therestrictedadmission policy refuses a pod without these fields, and a read-only root filesystem needs a scratch folder for tar. - Rejected: Only
runAsNonRootandrunAsUser. Therestrictedpolicy also asks for a seccomp profile, no capability and no privilege escalation, so the pod would be refused.
- Chosen: The full restricted profile with an
- How does the plan know that the source files have more than one owner?: A pre-flight Job with the same security context runs
findon the source and prints each distinct%U:%Gpair. 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
findon 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).
- Chosen: A pre-flight listing Job runs
- When does the option apply?: Only when the namespace enforces
restricted. Underbaselinepv-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 underbaseline, 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
baselinemove would lose the behavior that root keeps today.
- Chosen: Only under
- Where do the move and its messages live?:
src/devops_cli/k8s/volume_move.pyholds the plan and the copy,src/devops_cli/lang/en/messages.pyholds its messages, andtests/k8s/test_k8s_volume_move.pyholds 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
devops-cli-service commentedon Nov 28, 2026
Both deal with running copy pods under Pod Security restricted, but #7449 adds a basic securityContext to pass the policy while the candidate adds a named user and group option to preserve file ownership.devops-cli-service commentedon Nov 28, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.