Skip to content

Commit dbadc71

Browse files
committed
Install from source script
1 parent 4501849 commit dbadc71

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

hack/install_from_source.sh

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

0 commit comments

Comments
 (0)