Skip to content
This repository was archived by the owner on Dec 31, 2019. It is now read-only.

More resilient IP detection #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/security/cyclone_pam.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import random
from datetime import datetime
import Queue
import requests
from jose import jwt

BASE_URI = 'https://federation.cyclone-project.eu/auth/realms/master/protocol/openid-connect'
Expand Down Expand Up @@ -183,7 +184,19 @@ def start_server(pamh, argv):
# create main uri using random generated port
global PORT
PORT = server.server_address[1]
host_ip = socket.getfqdn()
host_ip = None
#Get ip for openstack clouds
try:
host_ip = requests.get("http://169.254.169.254/latest/meta-data/public-ipv4").text
except Exception:
pass
if host_ip is None or host_ip == "":
try:
host_ip = requests.get("http://169.254.169.254/latest/meta-data/local-ipv4").text
except Exception:
pass
if host_ip is None or host_ip == "":
host_ip = socket.gethostbyname(socket.getfqdn())
global MY_URI
MY_URI = 'http://{0}:{1}'.format(host_ip, str(PORT))
try:
Expand Down Expand Up @@ -258,7 +271,7 @@ def check_whitelist(user_data, user, pamh):
if email == str(user_data['email']):
return pamh.PAM_SUCCESS

pamh.conversation(pamh.Message(pamh.PAM_PROMPT_ECHO_ON, 'ERROR: Your user cannot login as' + user))
pamh.conversation(pamh.Message(pamh.PAM_PROMPT_ECHO_ON, 'ERROR: Your user cannot login as ' + user))
return pamh.PAM_USER_UNKNOWN


Expand Down