(no commit message)
[devwiki.git] / ConfiguringRHEL.mdwn
1 First we need to install and configure moonshot, its dependencies, and a local RADIUS server for testing<br />
2 In a real deployment, a local RADIUS server is not needed, however it simplifies testing if one is available<br />
3 __gss-server__ and __gss-client__ are standard Kerberos diagnostic tools, which give us a lot of information that is helpful for debugging<br />
4 Again, in a real deployment these are not required, but help with testing
5
6 This guide walks through deploying the client, IdP and SP portions of moonshot - depending on your target, some steps may be inappropriate.
7
8 ## Environment
9
10
11 ### SELinux set to permissive
12 Moonshot has a couple of outstanding issues regarding proper labeling of _SELinux_ contexts, causing it to fail when _SELinux_ is enforcing.  This should be resolved soon - change the setting in _/etc/sysconfig/selinux_, or in _/etc/rc.local_:
13
14     echo 0 > /selinux/enforce
15
16 ### EPEL
17 Moonshot needs __EPEL__ for a few extra libraries (as pulling them from a semi-supported repository is preferable to repackaging).<br />
18 The simplest way to install EPEL is:
19
20     rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
21     yum install epel-release
22
23 ## Moonshot Packages
24 The RPM's and SRPM's for moonshot are currently hosted at [[http://project-moonshot.org]] - this may change (and in fact, is quite likely to change) in the future.  The packages are signed.<br />
25 Example _/etc/yum.repos.d/moonshot.repo_
26
27     [moonshot]
28     name=Moonshot RPMs
29     baseurl=http://repository.project-moonshot.org/rpms/centos6/
30     failovermethod=priority
31     enabled=1
32     gpgcheck=1
33     gpgkey=http://repository.project-moonshot.org/rpms/centos6/moonshot.key
34
35
36 After setting up the repository definition, we'll set up a composite ORPS/IdP.
37
38 ##Moonshot IdP
39 To install the diagnostic tools (only needed for testing) and the RADIUSd:
40
41     yum install freeradius krb5-moonshot-devel moonshot-gss-eap
42
43 Once FreeRADIUS is installed, a source of identity needs to be enabled - either the roaming network in the case of an ORPS, or AD/LDAP/etc for an IdP.  For now, we'll just use a flat file.  Open _/etc/raddb/users_ and locate the following fragment:
44
45
46     # This is a complete entry for "steve". Note that there is no Fall-Through
47     # entry so that no DEFAULT entry will be used, and the user will NOT
48     # get any attributes in addition to the ones listed here.
49     #
50     #   steve   Cleartext-Password := "testing"
51     #   Service-Type = Framed-User,
52     #   Framed-Protocol = PPP,
53
54 Uncomment the line beginning __steve__.
55
56 __Chargeable-User-Identity__ is the value used to decide what user account to log in the user as on the SSH server.<br />
57 This value would normally be set by your local RADIUS proxy (ORPS) – so in a real deployment, rather than statically logging the user in as __moonshot__ you may decide to use something like __steve-camford.ac.uk__.<br />
58 If anonymity is required, you could use a Perl or Python script to generate something like __user-789-camford.ac.uk__.<br />
59 The exact value does not matter – only that the mappings are consistent, so that the user gets access to the same local account each time.
60 To allow creation of accounts on demand you could use __LDAP__ – when the ORPS sees a successful authentication, it could trigger a script that creates the desired account in an __LDAP__ domain.
61 It is not guaranteed that __Chargeable-User-Identity__ will be used permanently – in the future a specific RADIUS attribute may be created instead.
62
63 To activate CUI insertion, Edit _/etc/raddb/sites-enabled/default_, and find the post-auth section, and add the following:
64
65     update reply {
66         Chargeable-User-Identity = "moonshot"
67     }
68
69 Note in the case of an ORPS you need to unfilter this attribute in _/etc/raddb/attrs_ to prevent this attribute from being stripped on roaming requests.
70
71 A legacy attribute required for SSH at this time is the user name returned by the IdP.  To make this happen, Edit _/etc/raddb/sites-enabled/inner-tunnel_, find the following and uncomment it:
72
73                 #update outer.reply {
74                 #       User-Name = "%{request:User-Name}"
75                 #}
76
77 Finally, set the EAP type in use by moonshot (EAP-TTLS) by editing _/etc/raddb/eap.conf_ 
78
79     default_eap_type = md5
80
81 becomes:
82
83     default_eap_type = ttls
84
85 Other EAP types should be supported (PEAP and MD5 tested).
86  
87 FreeRADIUS now has a very minimal IdP/ORPS configuration, and can be started with:
88
89     service radiusd restart
90
91 If you encounter any issues, you can run radius in debug mode to see what is going on internally.
92
93     service radiusd stop
94     radiusd -X
95
96 When in debug mode, FreeRADIUS acts as an interactive program, so it should be run on a separate console, or under GNU Screen.
97
98 ##Moonshot Proper
99 First we need a minimal _/etc/radsec.conf_
100
101     
102     realm gss-eap {
103         type = "UDP"
104         timeout = 5
105         retries = 3
106         server {
107             hostname = "127.0.0.1"
108             service = "1812"
109             secret = "testing123"
110         }
111     }
112
113 This tells the moonshot SP where to find a RADIUS server for authentication - in this case, we will use the local server just configured.<br />
114 Moonshot will ultimately use RADSEC for communicating with the radius server – in which case you would use __transport="TCP"__ in _/etc/radsc.conf_<br />
115 Ultimately, the final values depend on the deployment – probably the address, port and secret used by your ORPS.
116
117 ###gss_eap_id
118
119 Next, a file is created in the home directory at _~/.gss\_eap\_id_ – this is the file that moonshot looks in for credentials.
120 The format is very simple – username followed by a password on separate lines.  For now, set it to:
121
122     steve
123     testing
124
125 In a deployment with a GUI, this file is replaced by the Moonshot Identity Selector.  It is conceivable in the future that the Identity Selector GUI will be supplemented with a curses-like UI, or other mechanism allowing console usage.
126
127 ###Shibboleth
128
129 Moonshot uses _libshib_ to parse RADIUS and SAML attributes – SAML assertions can be embedded inside RADIUS responses by the IdP, allowing an ORPS to exercise a very fine-grained authorization policy.
130 In the demo we just use a very simple example – mapping the _Chargeable-User-Identity_ to a local user account, but in a real deployment you could map a SAML attribute to the user account just as easily.
131
132 Delete _/etc/shibboleth/attribute-map.xml_ and replace it with:
133
134     <Attributes xmlns="urn:mace:shibboleth:2.0:attribute-map" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
135         <GSSAPIAttribute name="urn:ietf:params:gss:radius-attribute 89" id="local-login-user"/>
136     </Attributes>
137
138 In this case, 89 corresponds to _Chargeable-User-Identity_, which is mapped to _local-login-user_, which sets the local account that the user will be given access to.
139
140 To load the moonshot extensions, under the root node in _/etc/shibboleth/shibboleth2.xml_, add:
141
142     <Extensions>
143         <Library path="plugins.so" fatal="true"/>
144     </Extensions>
145
146 Further down the same file, find this line:
147
148     <AttributeExtractor type="XML" validate="true" path="attribute-map.xml"/>
149
150 Directly underneath it, add:
151
152     <AttributeExtractor type="GSSAPI" validate="true" path="attribute-map.xml"/>
153
154 Note that this file is sensitive to the order of statements.
155
156 ###/etc/gss/mech
157
158 This file tells moonshot what encryption options are valid for use with GSS.
159
160     #
161     # Sample mechanism glue configuration for EAP GSS mechanism.
162     #
163     # Any encryption type supported by Kerberos can be defined as the
164     # last element of the OID arc.
165     #
166     eap-aes128 1.3.6.1.5.5.15.1.1.17 mech_eap.so
167     eap-aes256 1.3.6.1.5.5.15.1.1.18 mech_eap.so
168    
169 ##Testing Functionality
170
171 As mentioned earlier, we will be using the Kerberos test tools to make sure that things are working.<br />
172 To start the _gss-server_, run:
173
174     /opt/moonshot/sbin/gss-server host@localhost &
175
176 There are two ways to start _gss-client_ – the first specifies an encryption method to use by its OID 1.3.6.1.5.5.15.1.1.18 (as seen in /etc/gss/mech):
177
178     /opt/moonshot/bin/gss-client -mech "{1.3.6.1.5.5.15.1.1.18 }" 127.0.0.1 host@localhost bar
179
180 The second uses __Simple and Protected GSSAPI Negotiation Mechanism (SPNEGO)__<br />
181 This chooses the "best" mutually-agreeable encryption method for between client and server.  To invoke the client using __SPNEGO__, use:
182
183     /opt/moonshot/bin/gss-client -spnego 127.0.0.1 host@localhost bar
184
185 ##Sample Output
186
187     Attribute local-login-user Authenticated Complete
188     
189     moonshot
190     
191     6d6f6f6e73686f74
192     
193     UID: 501
194     Accepted connection: "steve"
195     Sending init_sec_context token (size=150)...continue needed...
196     
197     context flag: GSS_C_MUTUAL_FLAG
198     context flag: GSS_C_REPLAY_FLAG
199     context flag: GSS_C_SEQUENCE_FLAG
200     context flag: GSS_C_CONF_FLAG 
201     context flag: GSS_C_INTEG_FLAG 
202     "steve" to "host/moonbuildcentos.dev.ja.net", lifetime -1, flags 13e, locally initiated, open
203     Name type of source name is { 1 2 840 113554 1 2 1 1 }.
204     Mechanism { 1 3 6 1 5 5 2 } supports 4 names
205       0: { 1 2 840 113554 1 2 1 1 }
206       1: { 1 2 840 113554 1 2 1 2 }
207       2: { 1 2 840 113554 1 2 1 3 }
208       3: { 1 2 840 113554 1 2 1 4 }
209     Received message: "testing"
210     Signature verified.
211     NOOP token
212
213 Running _gss-client_ produces a massive amount of output.<br />
214 The important part is at the end – you should see output similar to what is on the previous slide.<br />
215 If you do not see the line:
216
217     Attribute local-login-user Authenticated Complete
218
219 Then attribute mapping is not functioning properly, and you need to check your shibboleth configuration.
220
221 ##SSH
222 To install moonshot-enabled SSH:
223
224     yum install openssh-moonshot-clients openssh-moonshot-server
225
226 Inside _/etc/ssh/sshd\_config_, and if these values are not set already:<br />
227 Uncomment __UsePrivilegeSeparation__ and set it to __‘no’__
228
229         UsePriviligeSeparation no
230
231 Uncomment __GSSAPIAuthentication__ and set it to __‘yes’__
232
233         GSSAPIAuthentication yes
234
235 Uncomment __GSSAPIKeyExchange__ and set it to __‘yes’__
236
237         GSSAPIKeyExchange yes
238
239 Inside _/etc/ssh/ssh\_config_ and if these values are not set already:<br />
240 Uncomment __GSSAPIAuthentication__ and set it to __‘yes’__
241
242         GSSAPIAuthentication yes
243
244 Uncomment __GSSAPIKeyExchange__ and set it to __‘yes’__
245
246         GSSAPIKeyExchange yes
247
248 ###Running SSH
249
250 Finally, we need to start sshd on a seperate port:
251
252     /opt/moonshot/sbin/sshd –p 2222
253
254 At this time we do not recommend running __openssh-moonshot__ as the systemwide SSH client or server – it should be installed alongside the the standard SSH client and server.<br />
255 Also note, that sshd must be invoked with its full path, i.e. _/opt/moonshot/sbin/sshd._
256
257 Finally, try connecting with the following:
258
259     /opt/moonshot/bin/ssh –p 2222 –l "" 127.0.0.1
260
261 With any luck, magic happens and you are logged in as the user specified in your _Chargeable-User-Identity_!<br />
262 After successfully logging in, don’t forget to type __exit__ to end the SSH session and return to the root shell.<br />
263 Note in the SSH client command, the option __-l ""__ – this signifies that no username is to be sent to the SSH server. 
264
265 ##Common Issues:
266
267 ###If you see:
268
269     connecting to server: Connection refused
270
271 _gss-server_ is not running – start it again, and check its output for any reasons why it doesn't stay running
272
273 ###If you see:
274
275     GSS-API error initializing context: Unspecified GSS failure.  Minor code may provide more information
276     GSS-API error initializing context: SPNEGO cannot find mechanisms to negotiate
277     reading token flags: 0 bytes read
278
279 Then _/etc/gss/mech_ is invalid or missing
280
281 ###If you see:
282
283     Sending init_sec_context token (size=101)...continue needed...
284     CTRL-EVENT-EAP-STARTED EAP authentication started
285     GSS-API error accepting context: Unspecified GSS failure.  Minor code may provide more information
286     GSS-API error accepting context: 
287     Sending init_sec_context token (size=43)...continue needed...
288     GSS-API error initializing context: Unspecified GSS failure.  Minor code may provide more information
289     GSS-API error initializing context: SPNEGO failed to negotiate a mechanism
290
291 Your RADIUS server may not be running, or malfunctioning, run it in debug mode (as mentioned earlier) to find out why.
292
293 ###If you see:
294
295         Segmentation fault
296
297 Then _~/.gss\_eap\_id_ is invalid or missing
298
299 ###If you see:
300
301         CTRL-EVENT-EAP-METHOD EAP vendor 0 method 4 (MD5) selected
302
303 Then you have not correctly set the _default\_eap\_type_ on the RADIUS server.
304
305 ###If you see:
306
307     GSS-API error gss_pname_to_uid: Unspecified GSS failure.  Minor code may provide more information
308     GSS-API error gss_pname_to_uid: Unknown error
309
310 Then there is not a local user that matches your Chargeable-User-Identity
311
312 ###If you see…
313
314     /opt/moonshot/bin/gss-client: relocation error: /opt/moonshot/bin/gss-client: symbol gss_acquire_cred_with_password, version gssapi_krb5_2_MIT not defined in file libgssapi_krb5.so.2 with link time reference
315
316 Then LD_LIBRARY_PATH is not properly set
317
318
319 ##Remote IdP
320 This is left for an exercise for the user - at this stage it should just be a case of changing _/etc/radsec.conf_ to point at the right RADIUSd