Skip to content

Commit

Permalink
pybridge: Fix superuser startup vs. package reloading race
Browse files Browse the repository at this point in the history
When the superuser bridge gets auto-started via the init message or the
integration tests, it can happen that loading the packages and manifests
finishes after the superuser bridge already runs. That bridge previously
had the name "init", and once packages finished loading, set_config()
stopped that "init" bridge as it is not decleared by the manifests
(usually "sudo" and "pkexec"). That led to the session sometimes not
being privileged.

This was particularly prone to happen in the "devel" scenario where the
packages are much larger and processing took much longer.

Avoid that by setting `self.current` to the correct requested name right
from the start.

Fixes #19014
  • Loading branch information
martinpitt committed Jun 26, 2023
1 parent cf0e7b1 commit 4a20522
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cockpit/superuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,19 @@ async def go(self, name: str, responder: ferny.InteractionResponder) -> None:
except KeyError as exc:
raise bus.BusError('cockpit.Superuser.Error', f'Unknown superuser bridge type "{name}"') from exc

self.current = 'init'
self.current = name
self.peer = SuperuserPeer(self.router, config, responder)
self.peer.add_done_callback(self.peer_done)

try:
await self.peer.start(init_host=self.router.init_host)
except asyncio.CancelledError:
self.current = None
raise bus.BusError('cockpit.Superuser.Error.Cancelled', 'Operation aborted') from None
except (OSError, PeerError) as exc:
self.current = None
raise bus.BusError('cockpit.Superuser.Error', str(exc)) from exc

self.current = name

def set_configs(self, configs: List[Dict[str, object]]):
logger.debug("set_configs() with %d items", len(configs))
self.superuser_configs = {}
Expand Down

0 comments on commit 4a20522

Please sign in to comment.