1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-18 06:03:39 +03:00
one/share/sudoers/sudo_commands.rb

50 lines
2.0 KiB
Ruby
Raw Normal View History

#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
2023-01-09 12:23:19 +01:00
# Copyright 2002-2023, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
2019-09-30 15:15:42 +02:00
ONE_LOCATION = ENV['ONE_LOCATION']
if !ONE_LOCATION
2019-09-30 15:15:42 +02:00
LIB_LOCATION = '/usr/lib/one'
else
2019-09-30 15:15:42 +02:00
LIB_LOCATION = ONE_LOCATION + '/lib'
end
2019-09-30 15:15:42 +02:00
require 'erb'
require_relative 'sudoers'
2019-09-30 15:15:42 +02:00
sudoers = Sudoers.new LIB_LOCATION
aliases = sudoers.aliases
aliases.reject! {|_k, v| v.empty? }
2019-09-30 15:15:42 +02:00
puts ERB.new(DATA.read, nil, '<>').result(binding)
__END__
2019-09-30 15:15:42 +02:00
Defaults:oneadmin !requiretty
Defaults:oneadmin secure_path = /sbin:/bin:/usr/sbin:/usr/bin
2019-09-30 15:15:42 +02:00
<% cmd_sets = sudoers.cmds.keys.sort %>
<% cmd_sets.each do |k|; l = "ONE_#{k}"; v = aliases[l] %>
<% if !v.nil? %>
Cmnd_Alias <%= l %> = <%= v.join(", ") %>
2019-09-30 15:15:42 +02:00
<% end %>
<% end %>
2019-09-30 15:15:42 +02:00
## Command aliases are enabled individually in dedicated
## sudoers files by each OpenNebula component (server, node).
# oneadmin ALL=(ALL) NOPASSWD: <%= cmd_sets.each.sort.collect{|k| "ONE_#{k}"}.join(", ") %>