qubes-issues icon indicating copy to clipboard operation
qubes-issues copied to clipboard

Avoid creating too-similar VM labels

Open marmarek opened this issue 9 years ago • 1 comments

If we in practice want to allow creating custom labels, it would be nice to avoid them being too similar. Some PoC:

https://github.com/QubesOS/qubes-core-admin/pull/95#discussion_r106681789

import math

GAMMA = 2.2
#THRESHOLD = 

def hex_to_float(color, gamma=1.0):
  return tuple((int(color[i:i+2], 0x10) / 255.0) ** gamma for i in range(0, len(color), 2))

untrusted_r, untrusted_g, untrusted_b = hex_to_float(untrusted_color, gamma=GAMMA)
for label in existing_labels:
  r, g, b = hex_to_float(label.color, gamma=GAMMA)
  # approximate the colour distance as Euclidean distance in linear (gamma-expanded) space
  if math.sqrt((r - untrusted_r) ** 2 + (g - untrusted_g) ** 2 + (b - untrusted_b) ** 2) < THRESHOLD:
    raise qubes.exc.QubesValueError('colour too similar to an existing one')

marmarek avatar Mar 28 '17 13:03 marmarek

Should this be enforcing and forbidding or just a warning to end user? I know some users who are very much into dark themes are creating Labels in multiple shades of gray/dark via my Label Creation CLI tool (I am working on the Python port of it). If limit is going to be enforced, should the end tool do it or the admin API will do it?

But yes. Random colors and tinting the Qute Sushi icons with them makes it evident that many are going to be virtually identical:

qute-sushi

alimirjamali avatar Jun 11 '24 12:06 alimirjamali

If we in practice want to allow creating custom labels, it would be nice to avoid them being too similar.

I suggest another alternative. Instead of forbidding users to create too similar label (colors), we could provide an API call to compare the new value with the existing ones. And gives the green light or return a list of too similar existing labels. It could be named as admin.label.Similar with threshold as argument and 0xRRGGBB as inside parameter. And if it does not return the value, the front-end utility knows that it would be safe to create it. Otherwise it shows the conflicting labels to user from the API call's returned value.

And even if too similar, the way that currently icon preference of each qube is bind to its label justifies fairly similar colors. As in theory with alternative effect to tint, the label icon could be superimposed on top-left-bottom of the running app icon/Appmenu icon to signify its source qube. And for the border, we could apply specific border effect to labels (like solid-line, dash-dot, dot-dot, ...) with fairly similar label color to differentiate them from each other even though the label color would be similar.

alimirjamali avatar Mar 14 '25 16:03 alimirjamali

Instead of forbidding users to create too similar label (colors), we could provide an API call to compare the new value with the existing ones.

If not blocking, there is IMO no reason to have this logic on the backend side. It can be a frontend that fetches existing colors and compare it there. This gives a bit more flexibility of what can be done.

marmarek avatar Mar 14 '25 17:03 marmarek

I agree, the backend should be able to do any case. Only Qube Manager or any front should handle this feature or safety guard.

fepitre avatar Mar 14 '25 17:03 fepitre