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

Solves #9674 #643

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Solves #9674 #643

wants to merge 9 commits into from

Conversation

piotrbartman
Copy link
Member

@piotrbartman piotrbartman commented Dec 29, 2024

Delete the file and drop-in folder for the denied device interfaces list and move the list to qvm-prefs.

Solves QubesOS/qubes-issues/issues/9674

qubes/api/admin.py Show resolved Hide resolved
self.fire_event_for_permission()

denied = self.dest.devices_denied
return "\n".join(map(repr, DeviceInterface.from_str_bulk(denied)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe assert that there are no newlines in the repr output?

Comment on lines 736 to 752
@staticmethod
def from_str_bulk(interfaces: Optional[str]) -> List["DeviceInterface"]:
interfaces = interfaces or []
return [
DeviceInterface(interfaces[i: i + 7])
for i in range(0, len(interfaces), 7)
]
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest raising a QubesValueError if the size is not a multiple of 8 or if there are invalid characters in the interface name.

@@ -733,6 +733,14 @@ def unknown(cls) -> "DeviceInterface":
"""Value for unknown device interface."""
return cls("?******")

@staticmethod
def from_str_bulk(interfaces: Optional[str]) -> List["DeviceInterface"]:
interfaces = interfaces or []
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
interfaces = interfaces or []
interfaces = interfaces or ""

Fix typing error.

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.

Can the "cleaning" commit be squashed into original adding commit?

self, prop, value,
"Interface code list contains duplicates.")
# block, usb, mic, pci, *
pattern = r"^([bump\*][0123456789\*]{6})*$"
Copy link
Member

Choose a reason for hiding this comment

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

What about hex numbers in interfaces?

Payload:
Encoded device interface (can be repeated without any separator).
If payload is empty, all interfaces are removed.
Copy link
Member

Choose a reason for hiding this comment

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

This invites mistakes... maybe better some magic value like all?

Add device interface(s) to the denied list for the VM.
Payload:
Encoded device interface (can be repeated without any separator).
Copy link
Member

Choose a reason for hiding this comment

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

What is intended behavior on duplicates? IIUC right now if at least one interface you try to add is already on deny list, the whole operation will fail. Is that intentional? IMHO better would be to ignore duplicates (as in - adding interface that is already denied is no-op, but others non-duplicated added at the same time are still added). Excluding duplicates at the client side is racy (somebody can modify the value between client reads it (to exclude duplicates) and writes it back).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this was intentional; I followed the "fail fast" principle. However, now I understand that in the mentioned example, admin methods should be idempotent.
To keep consistency, in the case of removing an interface that is not currently on the list nothing should be done, am I right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think so

def from_str_bulk(interfaces: Optional[str]) -> List["DeviceInterface"]:
interfaces = interfaces or ""
if len(interfaces) % 7 != 0:
QubesValueError(
Copy link
Member

Choose a reason for hiding this comment

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

pylint says: missing raise

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.

Generally looks fine, besides the issue pylint found. And black is not happy...

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 89.83051% with 6 lines in your changes missing coverage. Please review.

Project coverage is 69.71%. Comparing base (3494e02) to head (d3de443).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
qubes/device_protocol.py 78.57% 3 Missing ⚠️
qubes/ext/admin.py 0.00% 2 Missing ⚠️
qubes/vm/qubesvm.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #643      +/-   ##
==========================================
+ Coverage   69.50%   69.71%   +0.20%     
==========================================
  Files          58       58              
  Lines       12468    12498      +30     
==========================================
+ Hits         8666     8713      +47     
+ Misses       3802     3785      -17     
Flag Coverage Δ
unittests 69.71% <89.83%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@marmarek
Copy link
Member

marmarek commented Jan 8, 2025

As previously - can you fold fixes (especially the exception one) into relevant commits?

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