Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure ArcGIS Server to use Active Directory #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cookbooks/arcgis-server/attributes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
server['web_context_url'] = 'https://' + node['arcgis']['server']['domain_name'] + '/' + node['arcgis']['server']['wa_name']
server['admin_username'] = 'admin'
server['admin_password'] = 'changeit'
server['active_directory_username'] = node['arcgis']['run_as_user']
server['active_directory_password'] = node['arcgis']['run_as_password']
server['active_directory_groups_administer'] = 'changeit'
server['active_directory_groups_publisher'] = 'changeit'
server['managed_database'] = ''
server['replicated_database'] = ''
server['keystore_file'] = ''
Expand All @@ -46,6 +50,7 @@
server['configure_autostart'] = true
server['install_system_requirements'] = true
server['use_join_site_tool'] = false
server['configure_active_directory'] = false

unless node['arcgis']['server']['authorization_file'].nil?
server['cached_authorization_file'] = ::File.join(Chef::Config[:file_cache_path],
Expand Down
50 changes: 50 additions & 0 deletions cookbooks/arcgis-server/libraries/server_admin_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,56 @@ def update_system_properties(properties)

validate_response(response)
end

def set_identity_store_to_windows(admin_user, admin_user_password)
request = Net::HTTP::Post.new(URI.parse(@server_url + '/admin/security/config/updateIdentityStore').request_uri)

request.add_field('Referer', 'referer')

token = generate_token()

userStoreConfig = {
'type' => "WINDOWS",
'properties' => {
'adminUser' => admin_user,
'adminUserPassword' => admin_user_password
}
}

roleStoreConfig = {
'type' => "WINDOWS",
'properties' => {
'adminUser' => admin_user,
'adminUserPassword' => admin_user_password
}
}

request.set_form_data('userStoreConfig' => userStoreConfig.to_json,
'roleStoreConfig' => roleStoreConfig.to_json,
'token' => token,
'f' => 'json')

response = send_request(request, @server_url)

validate_response(response)
end

def assign_privileges(rolename, privilege)
request = Net::HTTP::Post.new(URI.parse(@server_url + '/admin/security/roles/assignPrivilege').request_uri)

request.add_field('Referer', 'referer')

token = generate_token()

request.set_form_data('rolename' => rolename,
'privilege' => privilege,
'token' => token,
'f' => 'json')

response = send_request(request, @server_url)

validate_response(response)
end

private

Expand Down
49 changes: 49 additions & 0 deletions cookbooks/arcgis-server/providers/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,55 @@
end
end

action :set_identity_store_to_windows do
if node['platform'] == 'windows'
begin
admin_client = ArcGIS::ServerAdminClient.new(@new_resource.server_url,
@new_resource.username,
@new_resource.password)

admin_client.wait_until_available

Chef::Log.info('Setting ArcGIS Server Identity Store to Windows (Active Directory)...')

admin_client.set_identity_store_to_windows(@new_resource.active_directory_username,
@new_resource.active_directory_password)

admin_client.wait_until_available
rescue Exception => e
Chef::Log.error "Failed to set ArcGIS Server Identity Store to Windows (Active Directory). " + e.message
raise e
end
end
end

action :assign_privileges do
if node['platform'] == 'windows'
begin
admin_client = ArcGIS::ServerAdminClient.new(@new_resource.server_url,
@new_resource.username,
@new_resource.password)

admin_client.wait_until_available

Chef::Log.info('Assigning privileges to Active Directory groups...')

@new_resource.roles_administer.each do |admin_role|
admin_client.assign_privileges(admin_role,"ADMINISTER")
end

@new_resource.roles_publisher.each do |publisher_role|
admin_client.assign_privileges(publisher_role,"PUBLISH")
end

admin_client.wait_until_available
rescue Exception => e
Chef::Log.error "Failed to set ArcGIS Server Identity Store to Windows (Active Directory). " + e.message
raise e
end
end
end

private

def generate_admin_token(install_dir, expiration)
Expand Down
40 changes: 40 additions & 0 deletions cookbooks/arcgis-server/recipes/server_active_directory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Cookbook Name:: arcgis-server
# Recipe:: server_active_directory
#
# Copyright 2015 Esri
#
# 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.
#

if node['platform'] == 'windows'
arcgis_server_server 'Couple ArcGIS Server with Active Directory' do
server_url node['arcgis']['server']['url']
username node['arcgis']['server']['admin_username']
password node['arcgis']['server']['admin_password']
active_directory_username node['arcgis']['server']['active_directory_username']
active_directory_password node['arcgis']['server']['active_directory_password']
only_if { node['arcgis']['server']['configure_active_directory'] }
action :set_identity_store_to_windows
end

arcgis_server_server 'Assign ArcGIS Server roles to Active Directory groups' do
server_url node['arcgis']['server']['url']
username node['arcgis']['server']['admin_username']
password node['arcgis']['server']['admin_password']
roles_administer node['arcgis']['server']['active_directory_groups_administer']
roles_publisher node['arcgis']['server']['active_directory_groups_publisher']
only_if { node['arcgis']['server']['configure_active_directory'] }
action :assign_privileges
end
end
8 changes: 7 additions & 1 deletion cookbooks/arcgis-server/resources/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

actions :system, :install, :uninstall, :update_account, :stop, :start,
:configure_autostart, :authorize, :create_site, :join_site,
:join_cluster, :configure_https, :register_database, :federate
:join_cluster, :configure_https, :register_database, :federate,
:set_identity_store_to_windows, :assign_privileges

attribute :setup, :kind_of => String
attribute :product_code, :kind_of => String
Expand All @@ -42,6 +43,11 @@
attribute :portal_password, :kind_of => String
attribute :username, :kind_of => String
attribute :password, :kind_of => String
attribute :active_directory_username, :kind_of => String
attribute :active_directory_password, :kind_of => String
attribute :roles_administer, :kind_of => Array
attribute :roles_publisher, :kind_of => Array
attribute :configure_active_directory, :kind_of => [TrueClass, FalseClass], :default => false
attribute :server_directories_root, :kind_of => String
attribute :config_store_connection_string, :kind_of => String
attribute :config_store_connection_secret, :kind_of => String
Expand Down
3 changes: 3 additions & 0 deletions roles/webgis-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"server":{
"admin_username":"admin",
"admin_password":"changeit",
"configure_active_directory":true,
"active_directory_groups_administer":["MyDomain\\AGS-Admins1", "MyDomain\\AGS-Admins2"],
"active_directory_groups_publisher":["MyDomain\\AGS-Users1", "MyDomain\\AGS-Users2"],
"setup":"C:\\ArcGIS\\10.5\\Server\\Setup.exe",
"authorization_file":"C:\\ArcGIS\\10.5\\Authorization_Files\\Server.prvc",
"keystore_file":"C:\\keystore\\mydomain_com.pfx",
Expand Down