Skip to content

Instantly share code, notes, and snippets.

@angely-dev
Created October 14, 2021 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angely-dev/3d3de098c4ae81807ad565358ed63ffa to your computer and use it in GitHub Desktop.
Save angely-dev/3d3de098c4ae81807ad565358ed63ffa to your computer and use it in GitHub Desktop.
Force accept a RADIUS user, using FreeRADIUS and a custom module (UNLANG).
#
# /etc/freeradius/policy.d/force_accept
#
# Force accept a user.
#
# Two scenarios:
# - the user does NOT exist in the database => trigger FORCE-ACCEPT-USERNAME-NOT-FOUND
# - the user does exist but password is incorrect => trigger FORCE-ACCEPT-PASSWORD-INCORRECT
#
# This can be implemented with two modules, called at different sections in the FreeRADIUS sequence.
# (This may also be implemented with a single module for refactoring concern.)
#
force_accept_username_not_found {
#
# MANDATORY: set Auth-Type to Accept.
# Optional: set Tmp-String-0 for logging purpose (used in radiusd.conf:msg_goodpass).
#
update control {
&Auth-Type := Accept
&Tmp-String-0 := "FORCE-ACCEPT-USERNAME-NOT-FOUND"
}
#
# Optional: add some attributes for the NAS.
#
update reply {
&Cisco-AVPair += "ip:vrf-id=FORCE-ACCEPT-USERNAME-NOT-FOUND-VRF"
&Cisco-AVPair += "ip:addr-pool=FORCE-ACCEPT-USERNAME-NOT-FOUND-POOL"
&Cisco-AVPair += "ip:ip-unnumbered=Loopback0"
}
#
# Optional: tell we updated some attributes (good practice).
#
updated
}
force_accept_password_incorrect {
#
# Optional: set Auth-Type to Accept (for refactoring concern if you prefer a single module).
# Optional: set Tmp-String-0 for logging purpose (used in radiusd.conf:msg_goodpass).
#
update control {
# &Auth-Type := Accept
&Tmp-String-0 := "FORCE-ACCEPT-PASSWORD-INCORRECT"
}
#
# RADIUS attributes from radreply are fetched BEFORE the authentication checking,
# so it may be needed to remove them and (optionally) to add some attributes for the NAS.
#
update reply {
# Remove
&Framed-IP-Address !* ANY
&Framed-IP-Netmask !* ANY
&Cisco-AVPair !* ANY
# Add
&Cisco-AVPair += "ip:vrf-id=FORCE-ACCEPT-PASSWORD-INCORRECT-VRF"
&Cisco-AVPair += "ip:addr-pool=FORCE-ACCEPT-PASSWORD-INCORRECT-POOL"
&Cisco-AVPair += "ip:ip-unnumbered=Loopback1"
}
#
# MANDATORY: "pap" and "chap" modules need "ok" status to be returned.
#
ok
}
@angely-dev
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment