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 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. 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)