admin.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Wojtek Porczyk <woju@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, see <http://www.gnu.org/licenses/>.
  19. import qubes.api
  20. import qubes.ext
  21. class AdminExtension(qubes.ext.Extension):
  22. # pylint: disable=too-few-public-methods
  23. @qubes.ext.handler(
  24. 'mgmt-permission:admin.vm.tag.Set',
  25. 'mgmt-permission:admin.vm.tag.Remove')
  26. def on_tag_set_or_remove(self, vm, event, arg, **kwargs):
  27. '''Forbid changing specific tags'''
  28. # pylint: disable=no-self-use,unused-argument
  29. if arg.startswith('created-by-'):
  30. raise qubes.api.PermissionDenied()
  31. # TODO create that extension in the first place