Guest User

Untitled

a guest
Jan 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. [root@ns7loc10 ~]# cat /etc/e-smith/templates/etc/sudoers.d/30nethserver_cockpit_roles/10base
  2. {
  3.  
  4. use strict;
  5. use warnings;
  6. use JSON;
  7. #use esmith::ConfigDB;
  8.  
  9. require "/usr/libexec/nethserver/api/lib/auth_functions.pl";
  10.  
  11. my $jsonFile = '/etc/nethserver/cockpit/authorization/roles.json';
  12. my $data = read_json ($jsonFile);
  13.  
  14. my %controllers = (
  15. "system-users-groups" => ["/usr/libexec/nethserver/api/system-roles/*",
  16. "/usr/libexec/nethserver/api/system-password-policy/read",
  17. "/usr/libexec/nethserver/api/system-accounts-provider/*",
  18. "/usr/libexec/nethserver/api/system-users/*"],
  19. 'system-network' => ["/usr/libexec/nethserver/api/system-routes/*",
  20. "/usr/libexec/nethserver/api/system-proxy/*"],
  21. 'system-dns' => ["/usr/libexec/nethserver/api/system-hosts/*"],
  22. 'system-certificates' => ["/usr/libexec/nethserver/api/system-certificate/*"],
  23. 'system-ssh' => ["/usr/libexec/nethserver/api/system-openssh/*"],
  24. 'system-applications' => ["/usr/libexec/nethserver/api/system-apps/*"],
  25. );
  26.  
  27. foreach my $key (keys %{$data}) {
  28.  
  29. my @systems = @{$data->{$key}->{'system'}};
  30. my @applications = @{$data->{$key}->{'applications'}};
  31. my @roles = ();
  32.  
  33. #Here all default sudo commands
  34. my @commands = (
  35. "/usr/libexec/nethserver/api/system-*/read"
  36. );
  37.  
  38. foreach my $system (@systems){
  39. push @roles, "system-$system";
  40. }
  41.  
  42. foreach my $application (@applications){
  43. push @roles, $application;
  44. }
  45.  
  46. # Hack when the group name gets a space
  47. # for example 'domain admins', visudo do not like it
  48. (my $Cmnd_Alias = $key) =~ s/ //;
  49. $key =~s/ /\\ /;
  50.  
  51. $OUT .= "\n#\n# Role delegations for $key\n#";
  52. $OUT .= "\nCmnd_Alias ". uc $Cmnd_Alias .'= ';
  53.  
  54.  
  55. foreach my $role (@roles) {
  56.  
  57. $role = '*' if ($key eq 'domain admins');
  58.  
  59. if (! exists $controllers{$role}){
  60. push @commands, "/usr/libexec/nethserver/api/$role/*";
  61. } else {
  62. push @commands, @{$controllers{$role}};
  63. }
  64. # we allow all for admins
  65. last if ($key eq 'admins');
  66. }
  67.  
  68. $OUT .= join (', ',@commands);
  69. $OUT .= "\n\n%".$key." ALL=NOPASSWD: ". uc $Cmnd_Alias;
  70. $OUT .= "\nDefaults:%".$key." !requiretty\n";
  71. }
  72. }
Add Comment
Please, Sign In to add comment