Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QWT support #181

Merged
merged 47 commits into from
Mar 8, 2025
Merged

Add QWT support #181

merged 47 commits into from
Mar 8, 2025

Conversation

omeg
Copy link
Member

@omeg omeg commented Feb 10, 2025

Copy link
Member

@marmarek marmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a full review yet, but I think I captured main point here already.

set -efo pipefail

# shellcheck source=SCRIPTDIR/qubes.WinSign.common
. /etc/qubes-rpc/qubes.WinSign.common
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better not hardcode the path here. Especially, it's convenient to install the RPC files in /usr/local/etc/qubes-rpc in a specific AppVM.
You can use $(dirname "$0") to find the directory.

Similar comment to all the other services too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


echo "[*] Copying the final iso from '${DISPVM}' to '${OUTPUT}'..."

shell_call "${DISPVM}" "cat ~/win-build.iso" | cat > "${OUTPUT}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why extra cat?

Suggested change
shell_call "${DISPVM}" "cat ~/win-build.iso" | cat > "${OUTPUT}"
shell_call "${DISPVM}" "cat ~/win-build.iso" > "${OUTPUT}"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

key_name=sign_key_name,
)

dvm.kill()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If starting dvm fails, this will fail too (UnboundLocalError: cannot access local variable 'dvm' where it is not associated with a value). Either move starting dvm before the try part, or initialize the variable early (with None?) and check for it here.
But also, it looks like the dvm start can be moved much later? Currently it's at the start of the build, but it's used only after the build - so, if you move it later, you can save starting it in case of build failure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

qubes.WinSign.CreateKey +Qubes__Windows__Tools work-qubesos vault-sign allow
qubes.WinSign.DeleteKey +Qubes__Windows__Tools work-qubesos vault-sign allow
qubes.WinSign.GetCert +Qubes__Windows__Tools work-qubesos vault-sign allow
qubes.WinSign.Sign +Qubes__Windows__Tools work-qubesos vault-sign allow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing policy for the timestamp service

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

admin.vm.property.Get * work-qubesos win-build allow target=dom0
admin.vm.device.block.Attach * work-qubesos win-build allow target=dom0

qubes.WinSign.QueryKey +Qubes__Windows__Tools work-qubesos vault-sign allow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally for builder-specific services we use qubesbuilder. prefix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +296 to +163
def run(
self,
cmd: List[str],
copy_in: List[Tuple[Path, PurePath]] = None,
copy_out: List[Tuple[PurePath, Path]] = None,
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support building in DispVM, this should be able to create and start new DispVM first and kill it at the end.
It does mean fresh DispVM for each component - is that a problem? In other words - are there some hidden assumption about reusing the same VM (like, depending on some files being present from previous build)?

For development builds it probably make sense to retain option to reuse the same VM over and over, so the DispVM case can be under some config option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be a DispVM all the time, for development I usually just do local builds without the builder.

Comment on lines 27 to 28
from qubesadmin import Qubes
from qubesadmin.devices import DeviceAssignment, UnknownDevice
from qubesadmin.exc import DeviceAlreadyAttached, QubesException
from qubesadmin.utils import encode_for_vmexec
from qubesadmin.vm import DispVM, QubesVM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to use qubes-builderv2 outside of Qubes VM too. It doesn't need to support building Windows code there, but it shouldn't crash on ImportError. I think there need to be try / except ImportError somewhere, that will catch it nicely. I have an idea where - see separate comment.

@@ -31,6 +31,7 @@
from qubesbuilder.executors.container import ContainerExecutor
from qubesbuilder.executors.local import LocalExecutor
from qubesbuilder.executors.qubes import LinuxQubesExecutor
from qubesbuilder.executors.windows import WindowsExecutor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can catch ImportError here, and set some variable like windows_executor_available = False

@@ -575,6 +576,8 @@ def get_executor(options):
executor = LocalExecutor(**executor_options) # type: ignore
elif executor_type == "qubes":
executor = LinuxQubesExecutor(**executor_options) # type: ignore
elif executor_type == "windows":
executor = WindowsExecutor(**executor_options) # type: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here throw an exception if windows_executor_available is false.

from qubesbuilder.config import Config
from qubesbuilder.distribution import QubesDistribution
from qubesbuilder.executors import ExecutorError
from qubesbuilder.executors.windows import WindowsExecutor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And similarly this (and the qubesadmin imports above) can be problematic. It wants either some wrapping here (and raise an exception early in run if qubesadmin is not available), or changing PluginManager so that plugin import error is not fatal. IMO the first option is better if wouldn't clutter the code too much.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW several CI tests that are unrelated to QWT fail due to importing qubesadmin. That could be a good check if it works as expected - tests not related to QWT should pass even if qubesadmin cannot be imported.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the qubesadmin dependency.

Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
@marmarek
Copy link
Member

It has conflicts now... @fepitre in the meantime added most of the cross-distribution dependencies that will be needed for building iso+rpm (remaining part is in #185, but that shouldn't conflict anymore, I hope).

omeg added 15 commits February 26, 2025 18:57
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Add option to not ask user to enable network discovery

Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
…age options

Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 34.53510% with 345 lines in your changes missing coverage. Please review.

Project coverage is 74.79%. Comparing base (1987baa) to head (4916714).
Report is 54 commits behind head on main.

Files with missing lines Patch % Lines
qubesbuilder/plugins/build_windows/__init__.py 21.93% 153 Missing ⚠️
qubesbuilder/executors/windows.py 22.60% 89 Missing ⚠️
qubesbuilder/executors/qubes.py 44.31% 49 Missing ⚠️
qubesbuilder/plugins/source_windows/__init__.py 42.10% 22 Missing ⚠️
qubesbuilder/executors/qrexec.py 70.68% 17 Missing ⚠️
qubesbuilder/plugins/__init__.py 46.15% 7 Missing ⚠️
qubesbuilder/config.py 33.33% 4 Missing ⚠️
qubesbuilder/distribution.py 60.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #181      +/-   ##
==========================================
- Coverage   78.74%   74.79%   -3.95%     
==========================================
  Files          47       51       +4     
  Lines        5388     5865     +477     
==========================================
+ Hits         4243     4387     +144     
- Misses       1145     1478     +333     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marmarek
Copy link
Member

Can you squash the fixup commits (just do git rebase -i --autosquash)

omeg added 9 commits February 27, 2025 15:56
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
omeg added 8 commits February 27, 2025 15:57
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
…utor

Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
@omeg omeg marked this pull request as ready for review February 27, 2025 15:36
@tlaurion
Copy link

tlaurion commented Feb 28, 2025

Amazing work @omeg ! Can't wait to test testing packages. Also really interesting piece of work in terms of complex qubes-builderv2 for a learner. Thanks!

@marmarek
Copy link
Member

marmarek commented Mar 4, 2025

I reviewed this as of 5f3210a, and generally looks good, I'll re-test it again and if all good should be good for merging. There are a couple of TODO comments - are planning to handle them now, or leave for later (I'm fine with either)?

@omeg
Copy link
Member Author

omeg commented Mar 4, 2025

I reviewed this as of 5f3210a, and generally looks good, I'll re-test it again and if all good should be good for merging. There are a couple of TODO comments - are planning to handle them now, or leave for later (I'm fine with either)?

I think we can merge, the remaining TODOs are minor improvements that don't impact functionality.

Copy link
Member

@marmarek marmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this version, using window-ssh executor I needed to attach EWDK myself. I think it was done automatically before. Since the lifetime of this VM is outside of the builder control (right?) this step needs to be documented. In theory it's one time thing (persistent attach), but the loop device needs to be re-created after each work-qubesos VM restart (or added to rc.local...). But if it can be automated, even better.

SELF=$(qubesdb-read /name)
read -r -a result <<< "$(qrexec_call "${SELF}" admin.vm.property.Get+default_dispvm)"
dispvm_template="${result[2]}" # default=False type=vm vm-name
DISPVM=$(qrexec_call "$dispvm_template" admin.vm.CreateDisposable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DISPVM=$(qrexec_call "$dispvm_template" admin.vm.CreateDisposable)
DISPVM=$(qrexec_call "dom0" admin.vm.CreateDisposable)

Doing the call to dom0 makes it use default_dispvm, so you can save one call. And admin.vm.property.Get in the policy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

set -efo pipefail

# shellcheck source=SCRIPTDIR/qubesbuilder.WinSign.common
. "$(dirname "$0")/qubes.WinSign.common"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
. "$(dirname "$0")/qubes.WinSign.common"
. "$(dirname "$0")/qubesbuilder.WinSign.common"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

admin.vm.device.block.Available * work-qubesos work-qubesos allow target=dom0

admin.vm.Start * work-qubesos win-build allow target=dom0
admin.vm.CurrentState * work-qubesos win-build allow target=dom0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be unused.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing policy for qubesbuilder.WinFileCopyIn and qubesbuilder.WinFileCopyOut

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

what="copy-in",
vm=self.dispvm,
service=f"{self.copy_in_service}+{encoded_dst_path}",
args=["/usr/lib/qubes/qfile-agent", str(src)],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest for windows adding --ignore-symlinks, or ignore them at the receiver side. At least for me it choked on them (I did have some in one of the repos).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you added the parameter, but it isn't actually used in the command...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed.

Comment on lines 127 to 133
qrexec_call(
log=log,
what="remove vm",
vm=vm,
service="admin.vm.Remove",
ignore_errors=True,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kill on a DispVM implicitly remove it already. In practice this one is harmless, but results in a warning, as the target VM doesn't exist at this point anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dispvm is created in a stopped state (to attach EWDK) so Kill doesn't do anything if there's some error during this phase. I guess I can only call Remove if Kill fails...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Yes, doing Remove if Kill fails with QubesVMNotStartedError (or maybe simply any error) is a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved dispvm removal.

@omeg
Copy link
Member Author

omeg commented Mar 5, 2025

With this version, using window-ssh executor I needed to attach EWDK myself. I think it was done automatically before. Since the lifetime of this VM is outside of the builder control (right?) this step needs to be documented. In theory it's one time thing (persistent attach), but the loop device needs to be re-created after each work-qubesos VM restart (or added to rc.local...). But if it can be automated, even better.

I followed @fepitre suggestion that in the SSH case the Windows worker could be any (even non-Qubes) Windows machine. Maybe I should add a config option to auto attach EWDK in the common (Qubes VM) case?

@omeg
Copy link
Member Author

omeg commented Mar 5, 2025

Or even better, try to attach EWDK if the current ewdk path option is specified.

Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
@omeg
Copy link
Member Author

omeg commented Mar 5, 2025

I've added ssh-vm parameter in the config that, if set, will cause the SSH executor to auto-start the vm and auto-attach EWDK to it. If the parameter is not present, it's assumed all configuration was done manually.

"
}

if ! OPTS=$(getopt -o hi:o: --long help,iso,output: -n "$0" -- "$@"); then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ! OPTS=$(getopt -o hi:o: --long help,iso,output: -n "$0" -- "$@"); then
if ! OPTS=$(getopt -o hi:o: --long help,iso:,output: -n "$0" -- "$@"); then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

SCRIPT_DIR=$(readlink -f "${SCRIPT_DIR}")

echo "[*] Setting up a loop device for the ISO..."
LODEV=$(losetup -f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also this sometimes needs sudo (if there are no free devices and one needs to be created)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

omeg added 6 commits March 7, 2025 21:24
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Also support auto-starting a SSH qube and attaching EWDK to it.

Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
Signed-off-by: Rafał Wojdyła <omeg@invisiblethingslab.com>
@marmarek marmarek merged commit ed3319c into QubesOS:main Mar 8, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants