RunicGuestOptions record

Namespace Runic.Application.Views.Desktop in Runic.Application.Views.Desktop 0.23.0

public sealed record RunicGuestOptions : IEquatable<RunicGuestOptions>

Inherits or implements IEquatable.

Runs a Runic Desktop application in hosted mode: another Runic application, the host, started it and shows its Windows in native windows of its own (the Runic host protocol, runic-host/1). Pass it as RunicDesktopHostOptions.Guest to RunicDesktopHost.Run.

Remarks

The application decides when it can be hosted: it defines its own parameter, such as a hidden command hosted, and runs hosted mode only on that path. Runic defines no well-known flag and no environment variable for it, so an application without that code path cannot be hosted:

if (args is ["hosted"])
{
    try
    {
        return RunicDesktopHost.Run(provider, new DesktopHostOptions(),
            new RunicDesktopHostOptions { Guest = RunicGuestOptions.FromStandardInput() },
            async host =>
            {
                // When the host goes away while the Window opens, the open throws; Run then returns 0.
                await using var window = await host.OpenWindowAsync<MainWindow>();
                await window.WaitForCloseAsync();
                return 0;
            });
    }
    catch (RunicHostedApplicationException) { return 1; } // Not started by a host; the reason is on standard error.
}

In hosted mode Run starts no window toolkit loop and never shows a window of its own. Before the body runs, it reads the host's offer from standard input, opens the host channel on a loopback listener of its own, writes its address and key to standard output and waits for the host to connect and prove itself; a failure throws RunicHostedApplicationException without running the body. Each Window then opens in a window of the host: its page is served as in serve-only mode, the host's window loads it with a one-time launch address, and the Window's IRunicWindowPresentation and close go through the host. Platform services that need the native window, such as file dialogs, report OwnerUnavailable, as in serve-only mode.

When the host goes away (standard input ends or the channel closes) or asks to shut down, the Windows close, DesktopHost.ShutdownRequested is cancelled and Run returns when the body does; a body that has not returned 10 seconds later ends the process. A Window that is opening or opens after the host went away fails with a RunicWindowConfigurationException of code hosted-host-gone; when the body ends with it, or with an OperationCanceledException, after the host went away, Run returns 0, since the host going away is the normal end of a hosted application. A request to the host that has had no reply within 30 seconds reports a failure. Recent documents report BackendUnavailable in hosted mode, as in serve-only mode. A hosted application does not claim ApplicationInstance: each host session has a guest process of its own.

Any process of the same user that knows the parameter can host the application; RunicGuestOptions.AcceptHost is a product filter, not a security boundary. Hosted mode refuses to start when the process runs as another user than its parent, or cannot show that it does (on Linux and macOS its real and effective user ids, on Windows its token's user). It also refuses when the process runs elevated, unless RunicGuestOptions.AllowElevatedHost and the host's RunicGuestStartInfo.AllowElevatedGuest allow the one elevated pair: a parent that runs elevated as the same user. The protocol is experimental; see docs/experimental.md.

Properties

AcceptHost

public Func<RunicHostInfo, bool>? AcceptHost { get; init; }

Decides whether to be hosted by the host the offer names; null, the default, accepts every host. A host it declines gets the refusal host-not-accepted, and Run throws.

Remarks

The name and version are what the host says about itself: a filter for the product, not a credential.

AllowComponentEmbedding

public Func<RunicHostInfo, bool>? AllowComponentEmbedding { get; init; }

Decides whether the host the offer names may show this application's Windows as components in its own pages (trusted component mode, region-component/1); null, the default, allows no host.

Remarks

In component mode the host page loads the guest's component build, an ES module that the component build target of @runic-artifex/vite-plugin-runic writes to _runic_component/, into its own document, and the component connects to this application with a token that the host hands to its page. Host page and component then share one JavaScript realm: the guest's code can read the host page and use its Bridge, and the host page holds the guest's token and can act as the guest's page. Allow it only for hosts of the same vendor, whose pages you trust as your own. The host must opt in too, with RunicHostedWindowDecision.EmbedComponent.

Like RunicGuestOptions.AcceptHost, the decision reads what the host says about itself: it is a filter for the product, not a security boundary. When it returns false, the guest does not list region-component/1, and a component attach is refused with embedding-unsupported; the host can still show the Window in a frame. An application that runs elevated offers component mode only where Runic checks that its loopback peers are elevated too (elevated-peer admission); on macOS it never does.

AllowElevatedHost

public bool AllowElevatedHost { get; init; }

Whether the application, when it runs elevated, accepts a host that runs elevated as the same user; false, the default, refuses hosted mode whenever the process runs elevated (guest-elevated).

Remarks

For administrative tools whose host and guest both need administrator rights, such as an installer that hosts a check tool. It has no effect on a process that does not run elevated. With true, a process that runs elevated (an elevated token on Windows, an effective user id 0 on Linux and macOS) is hosted only when all of these hold, and refuses otherwise:

  • The host's offer allows an elevated guest (RunicGuestStartInfo.AllowElevatedGuest); otherwise guest-elevated.
  • Its parent process is the process that started it, not a newer one that reused a gone parent's id, and runs as the same user (the token's user on Windows; the real and effective user ids on Linux and macOS); otherwise guest-other-user.
  • That parent runs elevated (Windows: its token is elevated, or its integrity level is High or above; Linux and macOS: its effective user id is 0); otherwise guest-elevated-host-not-elevated.

The application checks its parent's token or user ids itself; nothing the host says counts as evidence. Processes of the same user that do not run elevated cannot read the channel's secrets or the Windows' launch addresses, but they can still connect to its loopback listeners, see the screen and read the clipboard; an elevating launcher that relays another process's standard input and output, such as sudo, makes that process the host. Start the application only from a location that only administrators can change. The residual risks are in docs/security.md, "Hosted application windows".

ApplicationId

public string? ApplicationId { get; init; }

The application's identity the host may key what it keeps about it by, such as saved window placements, in reverse-DNS form like com.example.tool; null, the default, tells the host none.

ApplicationName

public string? ApplicationName { get; init; }

The application's name the host sees; null, the default, is the entry assembly's name.

ApplicationVersion

public string? ApplicationVersion { get; init; }

The application's version the host sees; null, the default, is the entry assembly's informational version without build metadata.

StartTimeout

public TimeSpan StartTimeout { get; init; }

How long the hosted start may take, from Run to the host's authenticated hello: 30 seconds by default.

Exceptions

ArgumentOutOfRangeException

The value is not positive.

Methods

FromStandardInput

public static RunicGuestOptions FromStandardInput()

Hosted mode over the process's standard input and standard output, which the host piped when it started the application.

Returns

The options; Run reads standard input only when it starts.