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

PAM module in virtualenv #2

Open
mrvanes opened this issue Jun 7, 2018 · 4 comments
Open

PAM module in virtualenv #2

mrvanes opened this issue Jun 7, 2018 · 4 comments

Comments

@mrvanes
Copy link
Contributor

mrvanes commented Jun 7, 2018

What would the PAM configuration line look like if the python PAM module is developed in a virtualenv?

@mrvanes
Copy link
Contributor Author

mrvanes commented Jun 7, 2018

To answer my own question:
auth optional pam_env.so envfile=/lib/security/pam_websso/env
where /lib/security/pam_websso/env contains a single line
PATH=/lib/security/pam_websso/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
seems to do the trick

Or, add
#!/usr/bin/env /lib/security/pam_websso/bin/python
at the top of the module

@mrvanes mrvanes closed this as completed Jun 7, 2018
@mrvanes
Copy link
Contributor Author

mrvanes commented Jun 11, 2018

It turns out I was testing (pamtester) from an activated virtualenv which was sufficient to let pamtester succeed. It still fails from a clean env using any combination of the above tests, so I still don't have a way to start the virtualenv from within pam-python. For now, I'll install the required modules system wide.

@mrvanes mrvanes reopened this Jun 11, 2018
@hmoffatt
Copy link

hmoffatt commented Dec 9, 2019

It fails because your script is not being run as a program (using the interpreter specified by the #! line) - the python interpreter is actually embedded in this module.

You just need to add the virtualenv path to sys.path before importing the other modules. Something like this:

import os.path
import sys

activate_this = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'venv/bin/activate_this.py')
exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this))

@mrvanes
Copy link
Contributor Author

mrvanes commented Dec 9, 2019

Wow, thx. It's been a while since I worked on this (the proof of concept module works) but I'll keep this in mind if and when the module will be deployed in the wild!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants