admin.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2.1 of the License, or (at your option) any later version.
  11. #
  12. # This library 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 GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  19. import qubes.api
  20. import qubes.ext
  21. import qubes.vm.adminvm
  22. class AdminExtension(qubes.ext.Extension):
  23. # pylint: disable=too-few-public-methods
  24. @qubes.ext.handler(
  25. 'admin-permission:admin.vm.tag.Set',
  26. 'admin-permission:admin.vm.tag.Remove')
  27. def on_tag_set_or_remove(self, vm, event, arg, **kwargs):
  28. '''Forbid changing specific tags'''
  29. # pylint: disable=no-self-use,unused-argument
  30. if arg.startswith('created-by-') and \
  31. not isinstance(vm, qubes.vm.adminvm.AdminVM):
  32. raise qubes.api.PermissionDenied(
  33. 'changing this tag is prohibited by {}.{}'.format(
  34. __name__, type(self).__name__))
  35. # TODO create that tag here (need to figure out how to pass mgmtvm name)