1
+ #! /bin/bash
2
+
3
+ # Not intended to be run as a script, but rather as a guide to install smart_proxy_realm_ad_plugin from source code.
4
+ # This script demonstrates how to install smart_proxy_realm_ad_plugin from source code.
5
+ docker run -it ubuntu:22.04
6
+
7
+ # Setup the environment
8
+ apt-get update && apt-get install -y \
9
+ build-essential \
10
+ curl \
11
+ git \
12
+ libssl-dev \
13
+ pkg-config \
14
+ sudo \
15
+ wget \
16
+ jq
17
+
18
+
19
+ # Install ruby-install
20
+ wget https://github.com/postmodern/ruby-install/releases/download/v0.9.3/ruby-install-0.9.3.tar.gz
21
+ tar -xzvf ruby-install-0.9.3.tar.gz
22
+ cd ruby-install-0.9.3/
23
+ make install
24
+
25
+ # Install Ruby
26
+ ruby-install 3.3.4
27
+
28
+ # Add Ruby to the PATH
29
+ export PATH=/usr/local/src/ruby-3.3.4:/usr/local/src/ruby-3.3.4/bin:/opt/rubies/ruby-3.3.4/bin:$PATH
30
+ ruby -v
31
+
32
+ # Clone smart-proxy into ~/smart-proxy
33
+ cd ~
34
+ git clone https://github.com/theforeman/smart-proxy.git
35
+ git clone https://github.com/theforeman/smart_proxy_realm_ad_plugin.git
36
+
37
+ # Install the smart_proxy_realm_ad_plugin from source code
38
+ cd smart_proxy_realm_ad_plugin
39
+
40
+ # Install the dependencies
41
+ apt-get -y install libkrb5-dev libldap-dev ruby-dev libsasl2-dev
42
+ bundle install
43
+ gem build smart_proxy_realm_ad_plugin.gemspec
44
+ gem list| grep radcli
45
+
46
+ # Build the gem
47
+ gem build smart_proxy_realm_ad_plugin.gemspec
48
+ gem install smart_proxy_realm_ad_plugin-0.0.1.gem
49
+
50
+ # Add the plugin to the smart-proxy.
51
+ # This is so that the smart-proxy can load the plugin.
52
+ cd ~ /smart-proxy
53
+
54
+ # Install dependencies for smart-proxy
55
+
56
+ apt-get install -y ruby-libvirt libvirt-dev libsystemd-dev apt-get
57
+ bundle install
58
+
59
+ # Add the plugin to the Gemfile.local.rb so that the smart-proxy can load the plugin.
60
+ echo " gem 'smart_proxy_realm_ad_plugin', :path => '~/smart_proxy_realm_ad_plugin'" >> ./bundler.d/Gemfile.local.rb
61
+
62
+ # Enable the plugin in the smart-proxy.
63
+ cd ~ /smart-proxy
64
+
65
+ # Its a realm plugin, so we need to enable the realm plugin:
66
+ rm -f ~ /smart-proxy/config/settings.d/realm.yml
67
+
68
+ cat > ~ /smart-proxy/config/settings.d/realm.yml << EOF
69
+ ---
70
+ # Can be true, false, or http/https to enable just one of the protocols
71
+ :enabled: true
72
+
73
+ # Available providers:
74
+ # realm_freeipa
75
+ :use_provider: realm_ad
76
+ EOF
77
+
78
+ # We need to create a keytab file for the plugin to work.
79
+ mkdir -p /etc/foreman-proxy
80
+ touch /etc/foreman-proxy/realm_ad.keytab
81
+
82
+ # The plugin requires some configuration to work, this is done in the realm_ad.yml file
83
+ rm -f ~ /smart-proxy/config/settings.d/realm_ad.yml
84
+ cat > ~ /smart-proxy/config/settings.d/realm_ad.yml << EOF
85
+ ---
86
+ # Authentication for Kerberos-based Realms
87
+ :realm: EXAMPLE.COM
88
+
89
+ # Kerberos pricipal used to authenticate against Active Directory
90
+ :principal: realm-proxy@EXAMPLE.COM
91
+
92
+ # Path to the keytab used to authenticate against Active Directory
93
+ :keytab_path: /etc/foreman-proxy/realm_ad.keytab
94
+
95
+ # FQDN of the Domain Controller
96
+ :domain_controller: dc.example.com
97
+
98
+ # Optional: OU where the machine account shall be placed
99
+ #:ou: OU=Linux,OU=Servers,DC=example,DC=com
100
+
101
+ # Optional: Prefix for the computername
102
+ :computername_prefix: 'my_required_for_now_nice_prefix'
103
+
104
+ # Optional: Generate the computername by calculating the SHA256 hexdigest of the hostname
105
+ #:computername_hash: false
106
+
107
+ # Optional: use the fqdn of the host to generate the computername
108
+ #:computername_use_fqdn: false
109
+ EOF
110
+
111
+ cat > ~ /smart-proxy/config/settings.yml << EOF
112
+ :bind_host: ['*']
113
+ :http_port: 8000
114
+ :log_file: /tmp/proxy.log
115
+ :log_level: DEBUG
116
+ EOF
117
+
118
+ # We can now start the smart-proxy using, bundle exec,
119
+ cd ~ /smart-proxy
120
+ rm -f /tmp/proxy.log| touch /tmp/proxy.log
121
+ bundle exec bin/smart-proxy &
122
+ cat /tmp/proxy.log
123
+
124
+ root@40f20ed4b158:~ /smart-proxy# cat /tmp/proxy.log
125
+
126
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/facts.yml. Using default settings.
127
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/dns.yml. Using default settings.
128
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/templates.yml. Using default settings.
129
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/tftp.yml. Using default settings.
130
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/dhcp.yml. Using default settings.
131
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/puppetca.yml. Using default settings.
132
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/puppet.yml. Using default settings.
133
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/bmc.yml. Using default settings.
134
+ # 2024-08-22T21:47:55 [D] 'realm' settings: 'enabled': true, 'use_provider': realm_ad
135
+ # 2024-08-22T21:47:55 [D] 'realm' ports: 'http': true, 'https': true
136
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/logs.yml. Using default settings.
137
+ # 2024-08-22T21:47:55 [D] 'logs' settings: 'enabled': true (default)
138
+ # 2024-08-22T21:47:55 [D] 'logs' ports: 'http': true, 'https': true
139
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/httpboot.yml. Using default settings.
140
+ # 2024-08-22T21:47:55 [W] Couldn't find settings file /root/smart-proxy/config/settings.d/registration.yml. Using default settings.
141
+ # 2024-08-22T21:47:55 [D] Providers ['realm_ad'] are going to be configured for 'realm'
142
+ # 2024-08-22T21:47:55 [D] 'realm_ad' settings: 'computername_prefix': my_required_for_now_nice_prefix, 'computername_use_fqdn': false (default), 'domain_controller': dc.example.com, 'keytab_path': /etc/foreman-proxy/realm_ad.keytab, 'principal': realm-proxy@EXAMPLE.COM, 'realm': EXAMPLE.COM, 'use_provider': realm_ad
143
+ # 2024-08-22T21:47:55 [I] Successfully initialized 'foreman_proxy'
144
+ # 2024-08-22T21:47:55 [I] Successfully initialized 'realm_ad'
145
+ # 2024-08-22T21:47:55 [I] Successfully initialized 'realm'
146
+ # 2024-08-22T21:47:55 [D] Log buffer API initialized, available capacity: 2000/1000
147
+ # 2024-08-22T21:47:55 [I] Successfully initialized 'logs'
148
+ # 2024-08-22T21:47:55 [W] Missing SSL setup, https is disabled.
149
+ # 2024-08-22T21:47:55 [I] Smart proxy has launched on 1 socket(s), waiting for requests
150
+
151
+ # Verify that plugins runs...
152
+
153
+ curl -s -H " Accept: application/json" http://localhost:8000/features| jq
154
+
155
+ # create host
156
+ curl -s -d ' hostname=server1.example.com' http://localhost:8000/realm/EXAMPLE.COM| jq
157
+ curl -d ' hostname=server1.example.com&rebuild=true' http://localhost:8000/realm/EXAMPLE.COM
158
+ curl -XDELETE http://localhost:8000/realm/EXAMPLE.COM/server1
159
+
160
+ # We can find log messages grepping the smart_proxy log file
161
+ cat /tmp/proxy.log | grep realm_ad
0 commit comments