project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] Cross-cluster migration: token auth hits "does not look like a valid user name", password auth needs User.Modify

Open sumpfgottheit opened this issue 1 week ago • 3 comments

Hey there! 👋 Thanks for taking the time to report this bug — we appreciate it!

Please keep in mind: PegaProx is developed and maintained entirely by volunteers in our free time. We do our best, but we can't work magic 🪄 — please be patient, we'll get to your issue as soon as we can.

Want to help keep PegaProx alive?

  • ⭐ Star the project — it's free and helps a lot!
  • 💖 Become a Sponsor — helps us dedicate more time to development
  • 🤝 Contributing code or docs is always welcome too!

Describe the bug

Cross-cluster migration against a target cluster that is added with API-token auth fails before the copy starts:

Could not create API token on target cluster:
{"message": "value 'pegaprox@pve!pegaprox' does not look like a valid user name\n", "data": null}

Cause: create_api_token writes self.config.user into the token path. With token auth that field holds the full token id (core/manager.py:1670, _using_api_token = '!' in self.config.user; the two fields are joined to token-id=secret at 1722-1733), so the token id lands in the segment PVE validates as user@realm (core/manager.py:14700-14701; PVE API2/User.pm:782, AccessControl.pm:2406-2409, Auth/Plugin.pm:140-144).

Adding the target with a password does not help either. PegaProx then mints its own management token on the first successful connect (_try_create_api_token, call at core/manager.py:1850-1851, guarded by not self.config.api_token_user and ha.is_active(); HA counts as active on a standalone install) and switches the session to token auth (1942-1986, session rebuild at 1127-1135). From then on the migration's own mint (14705, privsep: 0) runs as the token identity, and PVE refuses token-minted tokens:

# PVE/API2/User.pm, generate_token
check => ['or', ['userid-param', 'self'], ['userid-group', ['User.Modify']]],
description => "... An API token does not count as its owning user.",

A token session is never self, so the request needs User.Modify on /access/groups (or on a group of that user), and because $authuser ne $userid for a token session it also needs Realm.AllocateUser on /access/realm/<realm> plus Permissions.Modify on / (API2/User.pm:141-145, 770-777, 821-824; RPCEnvironment.pm:484-494, 568-606). The role from the permissions docs holds none of those — and it should not, Permissions.Modify on / lets an identity grant itself anything.

So with the documented role the documented auth mode for this feature cannot work. Cross-cluster replication (api/vms.py:10316), cross-cluster load balancing (background/cross_cluster_lb.py:158) and Site Recovery (background/site_recovery.py:371) take the same path as the manual migration (api/vms.py:15244).

Suggested fix

The transfer needs a credential for the target, not a new token. When the manager already authenticates with a token, reuse it — branch after the connection setup, where the token is loaded:

def create_api_token(self, token_name='pegaprox-migrate', expire=0):
    ...
    if self._using_api_token and self._api_token:
        tid, _, secret = self._api_token.partition('=')
        return {'success': True, 'token_id': tid, 'token_value': secret,
                'token_name': tid.split('!')[-1], 'reused': True}

reused has to be honoured by every cleanup path: the immediate deletes (api/vms.py:15352, 15358) and all deferred ones — api/vms.py:15299-15303 and 10453, background/cross_cluster_lb.py:197, background/site_recovery.py:429,436 — which all end in core/transfer_net.py:402-420 (_drop_token), the natural place for the check. UPID polling and its return value (core/transfer_net.py:361-399) must stay, and the UI info text should say "reused" (api/vms.py:15325). Without it every run ends with a delete into the void and the warning "… is still on the target cluster …, delete it there" (transfer_net.py:418-419).

Steps to Reproduce

  1. Add three standalone PVE nodes as separate clusters, each with token auth: user = pegaprox@pve!pegaprox, password field = token secret. Give the identity the role from https://docs.pegaprox.com/configuration/proxmox-permissions/ plus Sys.Incoming on /.
  2. Pick a stopped guest on one node → Migrate → choose the other cluster, a target node and a target storage.
  3. The request returns the error above; no copy starts, nothing is half-moved.

Variant: add the target cluster with user + password instead. The migration then fails one step later with 403, because the temporary token is minted with the token identity.

Expected behavior

Either the copy runs, or the feature refuses with a message a user can act on ("cross-cluster migration needs a password login for the target cluster", or "the role is missing Sys.Incoming/…"). A JSON 500 carrying a PVE parser error does not tell the user what to change.

Environment

  • PegaProx Version: 1.5.0 (ghcr.io/pegaprox/pegaprox)
  • Installation Method: Docker
  • OS: Rocky Linux 9 (container host); PVE 9.2.32 on the managed nodes
  • Browser: n/a — reproduced through the UI and directly against the API
  • Behind Reverse Proxy? Caddy
  • UI? Modern Layout

Logs

2026-11-24T16:53:19+01:00 [PegaProx_pve02] Could not create API token on target cluster: {"message": "value 'pegaprox@pve!pegaprox' does not look like a valid user name\n", "data": null}
2026-11-24T16:54:31+01:00 [PegaProx_pve02] Could not create API token on target cluster: {"message": "value 'pegaprox@pve!pegaprox' does not look like a valid user name\n", "data": null}

Workaround that works today, if it helps other users: qm remote-migrate <vmid> <target-vmid> 'apitoken=PVEAPIToken=<user>@pve!<token>=<secret>,host=<target>' --target-storage <storage> --target-bridge <bridge> on the source node (target needs Sys.Incoming on / and VM.Allocate, PVE API2/Qemu.pm:6868-6873).

Screenshots

Not applicable — the failure is a JSON error response.

Checklist

  • [x] I have searched existing issues to make sure this is not a duplicate
  • [x] I am using the latest version of PegaProx
  • [x] I've put enough in here that someone can start on it without asking me three questions first
  • [x] I understand PegaProx is maintained by volunteers in their free time. Nobody is on call, and writing URGENT doesn't get anyone out of bed 🪄

sumpfgottheit avatar Nov 24 '26 19:11 sumpfgottheit

Hey, thanks for digging this deep. Your reading checks out: with token auth the token id ends up in the /access/users/{user}/token path, and once a password cluster has switched to its own management token, PVE won't let that token mint another one without User.Modify. That's in 1.5.0 and still on Testing.

Reusing the cluster's existing token instead of minting a temporary one is the obvious direction, but it hands a long-lived credential to the transfer instead of a throwaway one, so we want to settle that part before building it. Thanks also for posting the qm remote-migrate route for anyone who runs into this in the meantime.

Marcus

mkellermann97 avatar Nov 25 '26 08:11 mkellermann97

This is fixed on Testing and will be in the next release. The temporary token is now made by the target's own account through a password login, so a target added with a password works with the documented role, and the cluster's own long-lived token is never handed to the source node.

A target added with only an API token can't do that, since PVE won't let a token make another one. It now gets a 409 telling you to add the cluster with the account's password instead of the parser error, so your qm remote-migrate route stays the way to go for token-only targets.

Marcus

mkellermann97 avatar Nov 25 '26 16:11 mkellermann97

Released with 1.5.1. The temporary token of a cross-cluster move is made by the target's own account now, and a target that can't make one (token-only login, two-factor) tells you what to change instead of a 500.

Thanks again for the report!

Nico

MrMasterbay avatar Nov 26 '26 16:11 MrMasterbay