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

Feat/password: Add password check on python side before passing to node for unlock #116

Merged
merged 3 commits into from
Oct 26, 2023

Conversation

Hamada-Distributed
Copy link
Contributor

This PR adds the capability for a user to be prompted for a passphrase. Note that a user will always be prompted even if the keystore given is passphraseless unless they specify the keystore_unlocked=True in job.exec.

@wiwichips wiwichips self-requested a review October 25, 2023 15:44
@wiwichips wiwichips added the enhancement New feature or request label Oct 25, 2023
@Hamada-Distributed Hamada-Distributed self-assigned this Oct 25, 2023
@wiwichips
Copy link

At first glance everything looks good!

import time
import numpy as np
from bifrost import dcp

# INPUT SET
input_set = list("\"Un bon MOT ne prouve rien.\"")

# WORK FUNCTION
def work_function(character):
  return character.upper()

# COMPUTE_FOR
job = dcp.compute_for(input_set, work_function)

# EXEC
result_set = job.exec(keystore_unlocked=True)

# DISPLAY RESULTS
print(''.join(result_set))\

properly deploys a job for a bank acct keystore that has an empty string password


stlll looking into it

Copy link

@wiwichips wiwichips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes / nitpicks. Not sure how important they are, feel free to dismiss them and I'll consider the MR good to go:


Is it expected for this code job["payment_account_password"]="123123" to result in the following error:

  • TypeError: Job.__setitem__() takes 2 positional arguments but 3 were given

Not sure hows bifrost 1 handles dot vs key access for dict like objects - PythonMonkey conflates them which is maybe weirder. But I was also surprised to see this error


How do you set the password for a keystore whose password isn't the empty string? Or is that out of the scope of this mr. The following code doesn't work (I think as expected since the keystore is never unlocked?)

import time
import numpy as np
from bifrost import dcp

# INPUT SET
input_set = list("\"Un bon MOT ne prouve rien.\"")

# WORK FUNCTION
def work_function(character):
  return character.upper()

# COMPUTE_FOR
job = dcp.compute_for(input_set, work_function)

# SET PASSWORD
job.payment_account_password="123123"

# EXEC
result_set = job.exec(keystore_unlocked=True)

# DISPLAY RESULTS
print(''.join(result_set))

I get the following output:

State : exec
Passphrase prompt may be hidden because stdout is not tty.

It gets stuck and never deploys. If I try to type the password it doesn't take it in

Do I just need to read it in and then pass it as job_payment_account

@Hamada-Distributed
Copy link
Contributor Author

Is it expected for this code job["payment_account_password"]="123123" to result in the following error:

  • TypeError: Job.__setitem__() takes 2 positional arguments but 3 were given

yes. You are not expected to set the payment_account_password manually or by code.

How do you set the password for a keystore whose password isn't the empty string? Or is that out of the scope of this mr. The following code doesn't work (I think as expected since the keystore is never unlocked?)

import time
import numpy as np
from bifrost import dcp

# INPUT SET
input_set = list("\"Un bon MOT ne prouve rien.\"")

# WORK FUNCTION
def work_function(character):
  return character.upper()

# COMPUTE_FOR
job = dcp.compute_for(input_set, work_function)

# SET PASSWORD
job.payment_account_password="123123"

# EXEC
result_set = job.exec(keystore_unlocked=True)

# DISPLAY RESULTS
print(''.join(result_set))

You should never set the password in plaintext on the job. Instead, try the following:

import time
import numpy as np
from bifrost import dcp
import json
 
# INPUT SET
input_set = list("\"Un bon MOT ne prouve rien.\"")

# WORK FUNCTION
def work_function(character):
  return character.upper()

# COMPUTE_FOR
job = dcp.compute_for(input_set, work_function)

#Load the keystore as a string
with open('PATH_TO_KEYSTORE', 'r') as f:
  account = json.load(f)

# EXEC
result_set = job.exec(payment_account = account )

# DISPLAY RESULTS
print(''.join(result_set))

You'll automatically be asked for the password.

Copy link

@wiwichips wiwichips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome LGTM!

@Hamada-Distributed Hamada-Distributed merged commit 189418e into main Oct 26, 2023
0 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants