Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 support for freeradius not working #3193

Open
shibumi opened this issue Dec 10, 2019 · 8 comments
Open

Python3 support for freeradius not working #3193

shibumi opened this issue Dec 10, 2019 · 8 comments

Comments

@shibumi
Copy link

@shibumi shibumi commented Dec 10, 2019

Issue type

  • Defect - Unexpected behaviour (obvious or verified by project member).

Defect

It's not possible to build freeradius with python3 support.

How to reproduce the issue

We are desperately trying to build freeradius 3.0.20 with python3 support. First we thought python3 support is already in version 3.0.20, because the website says:

"Add experimental rlm_python3. This should largely work the same as rlm_python, which was Python2 only."

We try to build on Ubuntu 18.04 via the Freeradius debian directory.
Also, we've applied this patch here:

diff --git a/debian/control.in b/debian/control.in
index 6101a55196..ffe8a76526 100644
--- a/debian/control.in
+++ b/debian/control.in
@@ -28,6 +28,7 @@ Build-Depends: @BUILDDEPS@ debhelper (>= 9),
  libmemcached-dev,
  libhiredis-dev,
  python-dev,
+ python3-dev,
  dh-systemd,
  samba-dev | samba4-dev
 Section: net
diff --git a/debian/rules b/debian/rules
index 2bb22ef7a0..c43c443532 100755
--- a/debian/rules
+++ b/debian/rules
@@ -115,6 +115,9 @@ endif
 		--without-rlm_sql_oracle \
 		--without-rlm_sql_unixodbc \
 		--with-systemd \
+		--with-rlm_python3 \
+		--with-rlm-python3-lib-dir="/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu" \
+		--with-rlm-python3-include-dir="/usr/include/python3.6m" \
 		--enable-reproducible-builds
 
 	rm config.guess
diff --git a/src/modules/rlm_python3/configure.ac b/src/modules/rlm_python3/configure.ac
index a00320fda4..243273b6ee 100644
--- a/src/modules/rlm_python3/configure.ac
+++ b/src/modules/rlm_python3/configure.ac
@@ -95,7 +95,7 @@ if test x$with_[]modname != xno; then
 
 		old_CFLAGS=$CFLAGS
 		CFLAGS="$CFLAGS $PY_CFLAGS"
-		smart_try_dir="$PY_PREFIX/include/python$PY_SYS_VERSION"
+		smart_try_dir=$PY_INC_DIR
 		FR_SMART_CHECK_INCLUDE(Python.h)
 		CFLAGS=$old_CFLAGS
 
diff --git a/src/modules/stable b/src/modules/stable
index 0fa9ba7950..afec8ec6a6 100644
--- a/src/modules/stable
+++ b/src/modules/stable
@@ -25,6 +25,7 @@ rlm_passwd
 rlm_perl
 rlm_preprocess
 rlm_python
+rlm_python3
 rlm_radutmp
 rlm_realm
 rlm_rest

Most of the changes are copied by @cipherboy. Thanks a lot btw :)

Freeradius gets build successful, but when I try to actually use python3, I get the following error:

python_function_load - Module 'example' not found
python_error_log:200, Exception type: <class 'ModuleNotFoundError'>, Exception value: No module named 'example'
python_function_load - Failed to import python function 'example.accounting'
python_error_log:188, Unknown error
/etc/freeradius/mods-enabled/python3[9]: Instantiation failed for module "python3"

Our /etc/freeradius/mods-enabled/python3 looks like this:

python3 {
	#  Path to the python modules
	#
	#  Note that due to limitations on Python, this configuration
	#  item is GLOBAL TO THE SERVER.  That is, you cannot have two
	#  instances of the python module, each with a different path.
	#
        python_path = ${modconfdir}/${.:name}:/usr/lib/python36.zip:/usr/lib/python3.6:/usr/lib/python3.6/lib-dynload:/usr/local/lib/python3.6/dist-packages:/usr/lib/python3/dist-packages

	module = example

	# Pass all VPS lists as a 6-tuple to the callbacks
	# (request, reply, config, state, proxy_req, proxy_reply)
	# pass_all_vps = no

	# Pass all VPS lists as a dictionary to the callbacks
	# Keys: "request", "reply", "config", "session-state", "proxy-request",
	#       "proxy-reply"
	# This option prevales over "pass_all_vps"
	# pass_all_vps_dict = no

	mod_instantiate = ${.module}
	#func_instantiate = instantiate

	mod_detach = ${.module}
	#func_detach = instantiate

	mod_authorize = ${.module}
	#func_authorize = authorize

	mod_authenticate = ${.module}
	#func_authenticate = authenticate

	mod_preacct = ${.module}
	#func_preacct = preacct

	mod_accounting = ${.module}
	func_accounting = accounting

	mod_checksimul = ${.module}
#	func_checksimul = checksimul

	mod_pre_proxy = ${.module}
	#func_pre_proxy = pre_proxy

	mod_post_proxy = ${.module}
	#func_post_proxy = post_proxy

	mod_post_auth = ${.module}
	#func_post_auth = post_auth

	mod_recv_coa = ${.module}
	#func_recv_coa = recv_coa

	mod_send_coa = ${.module}
	#func_send_coa = send_coa
}

I have an example.py file in the /etc/freeradius/mods-config/python3/ directory, together with a radiusd.py file.

I suggest we have a look on it, because EOL for python2 is 2020-01-01. If you need any help regarding building debian packages or debugging this issue, let me know.

@jpereira

This comment has been minimized.

Copy link
Contributor

@jpereira jpereira commented Dec 10, 2019

It's a known issue. you could find the patch (not merged yet) in:

#3183 - Build issue with rlm_python3
#3185 - Python PATH issue (rlm_python3) Python 3.x
#3184 - Python PATH issue (rlm_python) Python 2.x

@shibumi

This comment has been minimized.

Copy link
Author

@shibumi shibumi commented Dec 10, 2019

@jpereira thanks a lot. Can't wait to try these patches tomorrow.

@jpereira

This comment has been minimized.

Copy link
Contributor

@jpereira jpereira commented Dec 10, 2019

@shibumi The mentioned patches were integrated into v3.0.x branch. therefore, the current code in https://github.com/FreeRADIUS/freeradius-server/tree/v3.0.x/src/modules/rlm_python3 should work with your tests.

  1. The configure option should be: ./configure --with-rlm-python3-config-bin=python3-config

  2. For each mod_$statement, you have to configure also the func_$statement.

e.g: if you want to execute authorize function in example.py.

$ cat raddb/mods-available/python3
python3 {
...
    mod_authorize = ${.module}
    func_authorize = authorize
...
}
$
  1. The recent code in v3.0.x HEAD fixed the Python path, so don't need to put the libraries path. Just where have yours *.py files.

e.g:

$ cat raddb/mods-available/python3
python3 {
...
    python_path = "${modconfdir}/${.:name}:/another/path/if/you/have"
...
}
$
@shibumi

This comment has been minimized.

Copy link
Author

@shibumi shibumi commented Dec 11, 2019

@jpereira Do you plan a release soon? I have discussed this with my colleagues and we've decided to wait for a new release. (At least for production). However I would test this out on one of our testing servers.

@jpereira

This comment has been minimized.

Copy link
Contributor

@jpereira jpereira commented Dec 11, 2019

@shibumi About the next release, probably @alandekok could say something.

Therefore, we appreciate if you could perform some tests. meanwhile, keep us updated with test results.

@shibumi

This comment has been minimized.

Copy link
Author

@shibumi shibumi commented Dec 11, 2019

@alandekok Will there be a freeradius release with python3 before 2020? (Python2 EOL is 2020-01-01)

@alandekok

This comment has been minimized.

Copy link
Member

@alandekok alandekok commented Dec 11, 2019

There is very likely to not be a FR release before 2020. We have pre-releases available on our web site at:

https://networkradius.com/freeradius-developer-builds/

You can download packages for 3.0.21 from that site. The code will become 3.0.21 at some point in the new year.

@shibumi

This comment has been minimized.

Copy link
Author

@shibumi shibumi commented Dec 11, 2019

@alandekok thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.