<div dir="ltr"><div>Hi everyone.<br><br>First of all, sorry if my email is very long, I am just trying not to leave any important details out. :)<br><br>In my Company, I'd like to setup a freeradius based wifi authentication following the same principle:<br>
First check if a user is using the Company's laptop (or phone) by checking a list of MAC addresses. If the device is in the list, let the user authenticate through LDAP and get a VLAN depending on the user's group; if it's not present, authenticate the user against ldap, but assign the user to a "public" VLAN, which cannot reach our internal servers.<br>
This is basically to take care of users who connect to our network with their own devices, on which we don't have control and that could spread all sorts of malware in the internal network.<br><br>So far, I managed to do the dynamic VLAN assignment, but cannot seem to get it to work together with the MAC checking.<br>
I can get an auth to be refused if the MAC is not listed in the authorized_macs file, but can't quite put the two things together. Perhaps I am a bit confused with regards to where to put the MAC check. For now, I just managed to get the check to work only on the authorization phase in sites-enabled/default, but then the VLAN assignment, which is done in the internal-tunnel, seems to overwrite my changes.<br>
So I tried to put the MAC check in the post-auth section in the default file, but the MAC check doesn't seem to ever work.<br><br>Here are the relevant config files:<br><br>Radius version:<br>2.1.10+dfsg-2+squeeze1 (running on Debian)<br>
<br>--- policy.conf<br>(...)<br>    rewrite_calling_station_id {<br>            if (Calling-Station-Id =~ /([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})/i){<br>                    update request {<br>
                        Calling-Station-Id := "%{1}-%{2}-%{3}-%{4}-%{5}-%{6}"<br>                    }<br>            }<br>            else {<br>                    noop<br>            }<br>    }<br>       <br>}<br>
<br><br>--- modules/files:<br>(...)<br>files authorized_macs {<br>        key = "%{tolower:%{Calling-Station-ID}}"<br>        usersfile = ${confdir}/authorized_macs<br>        compat = no<br>}<br><br>---authorized_macs<br>
e8-99-c4-a2-39-36<br>  Reply-Message = "Device with MAC Address %{Calling-Station-Id} authorized for network access"<br><br>--- sites-available/default<br>authorize {<br>    preprocess<br>    auth_log<br>    suffix<br>
    eap {<br>        ok = return<br>    }<br>    expiration<br>    logintime<br>    pap<br>}<br>authenticate {<br>    Auth-Type PAP {<br>        pap<br>    }<br>    eap<br>}<br>preacct {<br>    preprocess<br>    acct_unique<br>
    suffix<br>}<br>accounting {<br>    sql {<br>        fail = 1<br>    }<br>}<br>session {<br>    radutmp<br>    sql {<br>        fail = 1<br>    }<br>}<br>post-auth {<br>        rewrite_calling_station_id<br>        authorized_macs<br>
        if (!ok) {<br>        update reply {<br>        Tunnel-Type = VLAN<br>            Tunnel-Medium-Type = IEEE-802<br>            Tunnel-Private-Group-Id = 36<br>            }<br>        }<br>    sql {<br>        fail = 1<br>
    }<br>    exec<br>    Post-Auth-Type REJECT {<br>        attr_filter.access_reject<br>    }<br>}<br>pre-proxy {<br>}<br>post-proxy {<br>    eap<br>}<br><br>--- sites-available/inner-tunnel<br>authorize {<br>    preprocess<br>
    auth_log<br>    suffix<br>    eap {<br>        ok = return<br>    }<br>    expiration<br>    logintime<br>    pap<br>}<br>authenticate {<br>    Auth-Type PAP {<br>        pap<br>    }<br>    eap<br>}<br>preacct {<br>    preprocess<br>
    acct_unique<br>    suffix<br>}<br>accounting {<br>    sql {<br>        fail = 1<br>    }<br>}<br>session {<br>    radutmp<br>    sql {<br>        fail = 1<br>    }<br>}<br>post-auth {<br>        rewrite_calling_station_id<br>
        authorized_macs<br>        if (!ok) {<br>        update reply {<br>        Tunnel-Type = VLAN<br>            Tunnel-Medium-Type = IEEE-802<br>            Tunnel-Private-Group-Id = 36<br>            }<br>        }<br>
    sql {<br>        fail = 1<br>    }<br>    exec<br>    Post-Auth-Type REJECT {<br>        attr_filter.access_reject<br>    }<br>}<br>pre-proxy {<br>}<br>post-proxy {<br>    eap<br>}<br><br>And here is an authentication example, with a device not listed in authorized_macs:<br>
(...)<br><br>rad_recv: Access-Request packet from host 192.168.59.202 port 32769, id=129, length=345<br>    User-Name = "fabrizio.vecchi"<br>    Calling-Station-Id = "60-fa-cd-47-1a-44"<br>    Called-Station-Id = "24-01-c7-28-aa-d0:MindCandyAuth"<br>
    NAS-Port = 1<br>    Cisco-AVPair = "audit-session-id=ca3ba8c0000000dede1c5852"<br>    NAS-IP-Address = 192.168.59.202<br>    NAS-Identifier = "Cisco_6e:1f:4f"<br>    Airespace-Wlan-Id = 5<br>    Service-Type = Framed-User<br>
    Framed-MTU = 1300<br>    NAS-Port-Type = Wireless-802.11<br>    Tunnel-Type:0 = VLAN<br>    Tunnel-Medium-Type:0 = IEEE-802<br>    Tunnel-Private-Group-Id:0 = "36"<br>    EAP-Message = 0x0206005f15800000005517030100506509e5008fb8b33c992bdddc007472c4f5d210aa8d535f74724cccc1bc99c4cb8785066c7ef4f262c470986626e1d31efc71f0d3b42b80663afc9fdc68715d1ee49c02af509c6b12de0bca5bf5501cba<br>
    State = 0xf1f3e6cbf5f5f3adc22ef694ca5dfcba<br>    Message-Authenticator = 0xeff670953d883040f13b8dfc42d39849<br># Executing section authorize from file /etc/freeradius/sites-enabled/default<br>+- entering group authorize {...}<br>
++[preprocess] returns ok<br>[auth_log]     expand: /var/log/freeradius/radacct/%{Client-IP-Address}/auth-detail-%Y%m%d -> /var/log/freeradius/radacct/<a href="http://192.168.59.202/auth-detail-20131011">192.168.59.202/auth-detail-20131011</a><br>
[auth_log] /var/log/freeradius/radacct/%{Client-IP-Address}/auth-detail-%Y%m%d expands to /var/log/freeradius/radacct/<a href="http://192.168.59.202/auth-detail-20131011">192.168.59.202/auth-detail-20131011</a><br>[auth_log]     expand: %t -> Fri Oct 11 17:12:54 2013<br>
++[auth_log] returns ok<br>[suffix] No '@' in User-Name = "fabrizio.vecchi", looking up realm NULL<br>[suffix] No such realm "NULL"<br>++[suffix] returns noop<br>[eap] EAP packet type response id 6 length 95<br>
[eap] Continuing tunnel setup.<br>++[eap] returns ok<br>Found Auth-Type = EAP<br># Executing group from file /etc/freeradius/sites-enabled/default<br>+- entering group authenticate {...}<br>[eap] Request found, released from the list<br>
[eap] EAP/ttls<br>[eap] processing type ttls<br>[ttls] Authenticate<br>[ttls] processing EAP-TLS<br>  TLS Length 85<br>[ttls] Length Included<br>[ttls] eaptls_verify returned 11<br>[ttls] eaptls_process returned 7<br>[ttls] Session established.  Proceeding to decode tunneled attributes.<br>
[ttls] Got tunneled request<br>    User-Name = "fabrizio.vecchi"<br>    User-Password = <password><br>    FreeRADIUS-Proxied-To = 127.0.0.1<br>[ttls] Sending tunneled request<br>    User-Name = "fabrizio.vecchi"<br>
    User-Password = <password><br>    FreeRADIUS-Proxied-To = 127.0.0.1<br>    Calling-Station-Id = "60-fa-cd-47-1a-44"<br>    Called-Station-Id = "24-01-c7-28-aa-d0:MindCandyAuth"<br>    NAS-Port = 1<br>
    Cisco-AVPair = "audit-session-id=ca3ba8c0000000dede1c5852"<br>    NAS-IP-Address = 192.168.59.202<br>    NAS-Identifier = "Cisco_6e:1f:4f"<br>    Airespace-Wlan-Id = 5<br>    Service-Type = Framed-User<br>
    Framed-MTU = 1300<br>    NAS-Port-Type = Wireless-802.11<br>    Tunnel-Type:0 = VLAN<br>    Tunnel-Medium-Type:0 = IEEE-802<br>    Tunnel-Private-Group-Id:0 = "36"<br>server inner-tunnel {<br># Executing section authorize from file /etc/freeradius/sites-enabled/inner-tunnel<br>
+- entering group authorize {...}<br>++[control] returns notfound<br>[eap] No EAP-Message, not doing EAP<br>++[eap] returns noop<br>++[files] returns noop<br>[ldap] performing user authorization for fabrizio.vecchi<br>[ldap]     expand: %{Stripped-User-Name} -><br>
[ldap]     ... expanding second conditional<br>[ldap]     expand: %{User-Name} -> fabrizio.vecchi<br>[ldap]     expand: (uid=%{%{Stripped-User-Name}:-%{User-Name}}) -> (uid=fabrizio.vecchi)<br>[ldap]     expand: c=gb,dc=mindcandy,dc=com -> c=gb,dc=mindcandy,dc=com<br>
  [ldap] ldap_get_conn: Checking Id: 0<br>  [ldap] ldap_get_conn: Got Id: 0<br>  [ldap] attempting LDAP reconnection<br>  [ldap] (re)connect to <a href="http://192.168.50.41:389">192.168.50.41:389</a>, authentication 0<br>
  [ldap] bind as cn=admin,dc=mindcandy,dc=com/4kaZi638uSFurX to <a href="http://192.168.50.41:389">192.168.50.41:389</a><br>  [ldap] waiting for bind result ...<br>  [ldap] Bind was successful<br>  [ldap] performing search in c=gb,dc=mindcandy,dc=com, with filter (uid=fabrizio.vecchi)<br>
[ldap] Added User-Password = {SSHA}mhuhx35skdNyJ7BrJuviLnMt2iDI3lFs in check items<br>[ldap] No default NMAS login sequence<br>[ldap] looking for check items in directory...<br>  [ldap] userPassword -> Password-With-Header == "{SSHA}mhuhx35skdNyJ7BrJuviLnMt2iDI3lFs"<br>
  [ldap] sambaNtPassword -> NT-Password == 0x3730424545463943433843443839414435374133463731413541354446333742<br>[ldap] looking for reply items in directory...<br>[ldap] user fabrizio.vecchi authorized to use remote access<br>
  [ldap] ldap_release_conn: Release Id: 0<br>++[ldap] returns ok<br>[pap] Normalizing NT-Password from hex encoding<br>[pap] Normalizing SSHA1-Password from base64 encoding<br>[pap] Normalizing SSHA1-Password from base64 encoding<br>
++[pap] returns updated<br>Found Auth-Type = PAP<br># Executing group from file /etc/freeradius/sites-enabled/inner-tunnel<br>+- entering group PAP {...}<br>[pap] login attempt with password <password><br>[pap] Using NT encryption.<br>
[pap]     expand: %{User-Password} -> <password><br>[pap] NT-Hash of <password> = 70beef9cc8cd89ad57a3f71a5a5df37b<br>[pap]     expand: %{mschap:NT-Hash %{User-Password}} -> 70beef9cc8cd89ad57a3f71a5a5df37b<br>
[pap] User authenticated successfully<br>++[pap] returns ok<br># Executing section post-auth from file /etc/freeradius/sites-enabled/inner-tunnel<br>+- entering group post-auth {...}<br>[sql]     expand: %{User-Name} -> fabrizio.vecchi<br>
[sql] sql_set_user escaped user --> 'fabrizio.vecchi'<br>[sql]     expand: %{User-Password} -> <password><br>[sql]     expand: INSERT INTO radpostauth                           (username, pass, reply, authdate)                           VALUES (                           '%{User-Name}',                           '%{%{User-Password}:-%{Chap-Password}}',                           '%{reply:Packet-Type}', '%S') -> INSERT INTO radpostauth                           (username, pass, reply, authdate)                           VALUES (                           'fabrizio.vecchi',                           '<password>',                           'Access-Accept', '2013-10-11 17:12:54')<br>
rlm_sql (sql) in sql_postauth: query is INSERT INTO radpostauth                           (username, pass, reply, authdate)                           VALUES (                           'fabrizio.vecchi',                           '<password>',                           'Access-Accept', '2013-10-11 17:12:54')<br>
rlm_sql (sql): Reserving sql socket id: 3<br>rlm_sql (sql): Released sql socket id: 3<br>++[sql] returns ok<br>++[ldap] returns noop<br>++? if (LDAP-Group == "cn=dept_tech_corporate_it,ou=Groups,c=gb,dc=mindcandy,dc=com")<br>
  [ldap] Entering ldap_groupcmp()<br>    expand: c=gb,dc=mindcandy,dc=com -> c=gb,dc=mindcandy,dc=com<br>    expand: (|(&(objectClass=GroupOfNames)(member=%{control:Ldap-UserDn}))(&(objectClass=GroupOfUniqueNames)(uniquemember=%{control:Ldap-UserDn}))) -> (|(&(objectClass=GroupOfNames)(member=uid\3dfabrizio.vecchi\2cou\3dPeople\2cc\3dgb\2cdc\3dmindcandy\2cdc\3dcom))(&(objectClass=GroupOfUniqueNames)(uniquemember=uid\3dfabrizio.vecchi\2cou\3dPeople\2cc\3dgb\2cdc\3dmindcandy\2cdc\3dcom)))<br>
  [ldap] ldap_get_conn: Checking Id: 0<br>  [ldap] ldap_get_conn: Got Id: 0<br>  [ldap] performing search in cn=dept_tech_corporate_it,ou=Groups,c=gb,dc=mindcandy,dc=com, with filter (|(&(objectClass=GroupOfNames)(member=uid\3dfabrizio.vecchi\2cou\3dPeople\2cc\3dgb\2cdc\3dmindcandy\2cdc\3dcom))(&(objectClass=GroupOfUniqueNames)(uniquemember=uid\3dfabrizio.vecchi\2cou\3dPeople\2cc\3dgb\2cdc\3dmindcandy\2cdc\3dcom)))<br>
rlm_ldap::ldap_groupcmp: User found in group cn=dept_tech_corporate_it,ou=Groups,c=gb,dc=mindcandy,dc=com<br>  [ldap] ldap_release_conn: Release Id: 0<br>? Evaluating (LDAP-Group == "cn=dept_tech_corporate_it,ou=Groups,c=gb,dc=mindcandy,dc=com") -> TRUE<br>
++? if (LDAP-Group == "cn=dept_tech_corporate_it,ou=Groups,c=gb,dc=mindcandy,dc=com") -> TRUE<br>++- entering if (LDAP-Group == "cn=dept_tech_corporate_it,ou=Groups,c=gb,dc=mindcandy,dc=com") {...}<br>
+++[reply] returns noop<br>++- if (LDAP-Group == "cn=dept_tech_corporate_it,ou=Groups,c=gb,dc=mindcandy,dc=com") returns noop<br>++ ... skipping elsif for request 5: Preceding "if" was taken<br>++ ... skipping elsif for request 5: Preceding "if" was taken<br>
++ ... skipping elsif for request 5: Preceding "if" was taken<br>++ ... skipping elsif for request 5: Preceding "if" was taken<br>++ ... skipping else for request 5: Preceding "if" was taken<br>
} # server inner-tunnel<br>[ttls] Got tunneled reply code 2<br>    Tunnel-Type:0 = VLAN<br>    Tunnel-Medium-Type:0 = IEEE-802<br>    Tunnel-Private-Group-Id:0 = "40"<br>[ttls] Got tunneled Access-Accept<br>[eap] Freeing handler<br>
++[eap] returns ok<br># Executing section post-auth from file /etc/freeradius/sites-enabled/default<br>+- entering group post-auth {...}<br>++- entering policy rewrite_calling_station_id {...}<br>+++? if (Calling-Station-Id =~ /([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})/i)<br>
? Evaluating (Calling-Station-Id =~ /([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})/i) -> TRUE<br>+++? if (Calling-Station-Id =~ /([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})/i) -> TRUE<br>
+++- entering if (Calling-Station-Id =~ /([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})/i) {...}<br>    expand: %{1}-%{2}-%{3}-%{4}-%{5}-%{6} -> 60-fa-cd-47-1a-44<br>
++++[request] returns noop<br>+++- if (Calling-Station-Id =~ /([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})/i) returns noop<br>+++ ... skipping else for request 5: Preceding "if" was taken<br>
++- policy rewrite_calling_station_id returns noop<br>[authorized_macs]     expand: %{Calling-Station-ID} -> 60-fa-cd-47-1a-44<br>[authorized_macs]     expand: %{tolower:%{Calling-Station-ID}} -> 60-fa-cd-47-1a-44<br>
++[authorized_macs] returns noop<br>++? if (!ok)<br>? Evaluating !(ok) -> TRUE<br>++? if (!ok) -> TRUE<br>++- entering if (!ok) {...}<br>+++[reply] returns noop<br>++- if (!ok) returns noop<br>[sql]     expand: %{User-Name} -> fabrizio.vecchi<br>
[sql] sql_set_user escaped user --> 'fabrizio.vecchi'<br>[sql]     expand: %{User-Password} -><br>[sql]     ... expanding second conditional<br>[sql]     expand: %{Chap-Password} -><br>[sql]     expand: INSERT INTO radpostauth                           (username, pass, reply, authdate)                           VALUES (                           '%{User-Name}',                           '%{%{User-Password}:-%{Chap-Password}}',                           '%{reply:Packet-Type}', '%S') -> INSERT INTO radpostauth                           (username, pass, reply, authdate)                           VALUES (                           'fabrizio.vecchi',                           '',                           'Access-Accept', '2013-10-11 17:12:54')<br>
rlm_sql (sql) in sql_postauth: query is INSERT INTO radpostauth                           (username, pass, reply, authdate)                           VALUES (                           'fabrizio.vecchi',                           '',                           'Access-Accept', '2013-10-11 17:12:54')<br>
rlm_sql (sql): Reserving sql socket id: 2<br>rlm_sql (sql): Released sql socket id: 2<br>++[sql] returns ok<br>++[exec] returns noop<br>Sending Access-Accept of id 129 to 192.168.59.202 port 32769<br>    Tunnel-Type:0 = VLAN<br>
    Tunnel-Medium-Type:0 = IEEE-802<br>    Tunnel-Private-Group-Id:0 = "40"<br>    MS-MPPE-Recv-Key = 0x0b1d759946c02f9063b69141cdebfd8a229d7d996fdea460aa1fb4e11182270a<br>    MS-MPPE-Send-Key = 0x62814f3d40bc9b08d2661cbc70a93c836f1e8f453e22ee77d3ad3f78dd2432f0<br>
    EAP-Message = 0x03060004<br>    Message-Authenticator = 0x00000000000000000000000000000000<br>    User-Name = "fabrizio.vecchi"<br>Finished request 5.<br>Going to the next request<br>Waking up in 4.8 seconds.<br>
<br>As you can see, the device wasn't listed in the file, the authentication went fine, saying that the tunnel that I should get has ID 40, but that wasn't overwritten by the authorized_macs check...<br><br>Any pointers would be greatly appreciated.<br>
<br>Thank you so much for your help.<br></div>Fabrizio<br></div>