-
Notifications
You must be signed in to change notification settings - Fork 75
[#517] allow generating a pam-password based .irodsA if not pre-existing #620
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from irods import (env_filename_from_keyword_args, derived_auth_filename) | ||
import irods.client_configuration as cfg | ||
import irods.password_obfuscation as obf | ||
import irods.helpers as h | ||
import getpass | ||
import os | ||
import sys | ||
|
||
def write_native_credentials_to_secrets_file(password, **kw): | ||
env_file = env_filename_from_keyword_args(kw) | ||
auth_file = derived_auth_filename(env_file) | ||
old_mask = None | ||
try: | ||
old_mask = os.umask(0o77) | ||
open(auth_file,'w').write(obf.encode(password)) | ||
finally: | ||
if old_mask is not None: | ||
os.umask(old_mask) | ||
|
||
return True | ||
|
||
def write_pam_credentials_to_secrets_file( password ,**kw): | ||
s = h.make_session() | ||
s.pool.account.password = password | ||
with cfg.loadlines( [dict(setting='legacy_auth.pam.password_for_auto_renew',value=None), | ||
dict(setting='legacy_auth.pam.store_password_to_environment',value=False)] ): | ||
to_encode = s.pam_pw_negotiated | ||
if to_encode: | ||
open(s.pool.account.derived_auth_file,'w').write(obf.encode(to_encode[0])) | ||
return True | ||
return False | ||
|
||
if __name__ == '__main__': | ||
vector = { | ||
'pam_password': write_pam_credentials_to_secrets_file, | ||
'native': write_native_credentials_to_secrets_file | ||
} | ||
|
||
if sys.argv[1] in vector: | ||
vector[sys.argv[1]](getpass.getpass(prompt=f'{sys.argv[1]} password: ')) | ||
else: | ||
print('did not recognize authentication scheme argument',file = sys.stderr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
irods/test/scripts/test002_write_native_credentials_to_secrets_file.bats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Test creation of .irodsA for iRODS native authentication using the free function, | ||
# irods.client_init.write_pam_credentials_to_secrets_file | ||
|
||
. "$BATS_TEST_DIRNAME"/test_support_functions | ||
PYTHON=python3 | ||
|
||
# Setup/prerequisites are same as for login_auth_test. | ||
# Run as ubuntu user with sudo; python_irodsclient must be installed (in either ~/.local or a virtualenv) | ||
# | ||
|
||
ALICES_OLD_PAM_PASSWD="test123" | ||
ALICES_NEW_PAM_PASSWD="new_pass" | ||
|
||
setup() | ||
{ | ||
setup_pam_login_for_alice "$ALICES_OLD_PAM_PASSWD" | ||
} | ||
|
||
teardown() | ||
{ | ||
finalize_pam_login_for_alice | ||
test_specific_cleanup | ||
} | ||
|
||
@test create_secrets_file { | ||
|
||
# Old .irodsA is already created, so we delete it and alter the pam password. | ||
sudo chpasswd <<<"alice:$ALICES_NEW_PAM_PASSWD" | ||
rm -f ~/.irods/.irodsA | ||
$PYTHON -c "import irods.client_init; irods.client_init.write_pam_credentials_to_secrets_file('$ALICES_NEW_PAM_PASSWD')" | ||
|
||
# Define the core Python to be run, basically a minimal code block ensuring that we can authenticate to iRODS | ||
# without an exception being raised. | ||
|
||
local SCRIPT=" | ||
import irods.test.helpers as h | ||
ses = h.make_session() | ||
ses.collections.get(h.home_collection(ses)) | ||
print ('env_auth_scheme=%s' % ses.pool.account._original_authentication_scheme) | ||
" | ||
OUTPUT=$($PYTHON -c "$SCRIPT") | ||
# Assert passing value | ||
[ $OUTPUT = "env_auth_scheme=pam_password" ] | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
irods/test/scripts/test003_write_pam_credentials_to_secrets_file.bats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Test creation of .irodsA for iRODS pam_password authentication using the free function, | ||
# irods.client_init.write_native_credentials_to_secrets_file | ||
|
||
. "$BATS_TEST_DIRNAME"/test_support_functions | ||
PYTHON=python3 | ||
|
||
# Setup/prerequisites are same as for login_auth_test. | ||
# Run as ubuntu user with sudo; python_irodsclient must be installed (in either ~/.local or a virtualenv) | ||
# | ||
|
||
@test create_irods_secrets_file { | ||
|
||
rm -fr ~/.irods | ||
mkdir ~/.irods | ||
cat > ~/.irods/irods_environment.json <<-EOF | ||
{ "irods_host":"$(hostname)", | ||
"irods_port":1247, | ||
"irods_user_name":"rods", | ||
"irods_zone_name":"tempZone" | ||
} | ||
EOF | ||
$PYTHON -c "import irods.client_init; irods.client_init.write_native_credentials_to_secrets_file('rods')" | ||
|
||
# Define the core Python to be run, basically a minimal code block ensuring that we can authenticate to iRODS | ||
# without an exception being raised. | ||
|
||
local SCRIPT=" | ||
import irods.test.helpers as h | ||
ses = h.make_session() | ||
ses.collections.get(h.home_collection(ses)) | ||
print ('env_auth_scheme=%s' % ses.pool.account._original_authentication_scheme) | ||
" | ||
OUTPUT=$($PYTHON -c "$SCRIPT") | ||
# Assert passing value | ||
[ $OUTPUT = "env_auth_scheme=native" ] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.