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

Gml 1660 support jwt token auth in py tiger graph #224

Merged
merged 27 commits into from
Jun 12, 2024

Conversation

luzhoutg
Copy link
Contributor

No description provided.

@luzhoutg luzhoutg added the enhancement New feature or request label May 10, 2024
Copy link
Collaborator

@parkererickson-tg parkererickson-tg left a comment

Choose a reason for hiding this comment

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

Version should not be a connection parameter, we should be able to use the function to get it dynamically.

@luzhoutg
Copy link
Contributor Author

Yes, just switch to getVer() to get the version dynamically.

Copy link
Contributor

@billshitg billshitg left a comment

Choose a reason for hiding this comment

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

Have we tested the jwt token authentication with restpp?

@@ -124,6 +126,14 @@ def __init__(self, host: str = "http://127.0.0.1", graphname: str = "MyGraph",
else:
self.authHeader = {"Authorization": "Basic {0}".format(self.base64_credential)}

# If JWT token is provided, set authMode to "token", and overwrite authMode = "pwd" for GSQL authentication as well if version is newer than 4.1.0
if jwtToken:
dbVersion = self.getVer()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This version check will fail since version relies on token auth, and the auth header has not yet been defined.

if jwtToken:
dbVersion = self.getVer()
if StrictVersion(dbVersion) >= StrictVersion("4.1.0"):
self.authMode = "token"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This self.authMode variable isn't used anywhere, why are we setting it?

@luzhoutg
Copy link
Contributor Author

Thanks Parker for the comments. I will modify the PR and test it today.

@luzhoutg
Copy link
Contributor Author

luzhoutg commented May 24, 2024

  1. move getVersion() and getVer() from pyTigerGraphUtils to pyTigerGraphBase
  2. use getVer() and _get() schema of a graph in pyTigerGraphBase to check restpp and gsql authentication respectively
  3. tested on 3.10.1 using jwt token for restpp authentication successfully
  4. waiting for patch to test gsql authentication

Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be disabled such that our other tests don't fail... @billshitg, do you have thoughts on how to support this test in the future?

@@ -42,6 +43,7 @@ def make_connection(graphname: str = None):
certPath=server_config["certPath"],
sslPort=server_config["sslPort"],
gcp=server_config["gcp"],
jwtToken=server_config["jwtToken"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we support this in our current testing pipeline?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we need to modify the config file to add the jwtToken field but set it to empty str to avoid actually using it now.

Meanwhile, we need to figure out with QE team how to config the DB to use jwtToken

Copy link
Contributor

Choose a reason for hiding this comment

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

Just double check here: does server_config contains this key "jwtToken"? I don't see the config file modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I just add the jwtToken to the config file and set it to empty.

Just double check here: does server_config contains this key "jwtToken"? I don't see the config file modified.


# TODO Remove apiToken parameter
# if apiToken:
# warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we remove this deprecation warning but keep the apiToken parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was trying to clean up the code. There are several deprecation warnings other than "apiToken" parameter. I can add the deprecation warning back.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The apiToken parameter is used for CoPilot

try:
logger.debug(f"Attempting to get schema with URL: {self.gsUrl + '/gsqlserver/gsql/schema?graph=' + self.graphname}")
logger.debug(f"Using auth header: {self.authHeader}")
self._get(self.gsUrl + "/gsqlserver/gsql/schema?graph=" + self.graphname, authMode="token")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to use graphname here? Might cause issue when there is no graph in the database

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The graphname is a required field accoroding to https://docs.tigergraph.com/tigergraph-server/current/api/built-in-endpoints#_show_graph_schema_metadata. We don't have a package to test on the GSQL auth yet. So if there no graph in the database, it could cause issue. might need to change to another function for validation after testing on.

self.authHeader = {'Authorization': 'Basic {0}'.format(self.base64_credential)}
_headers = self.authHeader
authMode = 'pwd'
# If JWT token is provided, always use jwtToken as token
Copy link
Contributor

Choose a reason for hiding this comment

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

Is jwtToken also used when authMode is pwd?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently no, still use pwd. in the init, if the db doesn't support jwt, it will raise an error asking users to use username and password.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how we can test this file in our CICD pipeline. Will need to talk to our QE team to find out how we can configure the DB to use the JWT token auth.

@parkererickson
Copy link
Contributor

parkererickson commented May 24, 2024 via email

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1062/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1063/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1066/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1067/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1068/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1070/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1072/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1075/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1076/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1077/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1078/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1079/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: FAILURE, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1080/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

Unit Test: SUCCESS, e2e Test: SKIPPED, Jenkins_job:http://192.168.99.101:30080/job/mlwb_build/1081/

Copy link
Collaborator

@qe-tigergraph qe-tigergraph left a comment

Choose a reason for hiding this comment

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

QE Approved


def _requestJWTToken(self):
# Define the URL
url = f"{self.conn.host}:{self.conn.gsPort}/gsqlserver/requestjwttoken"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we make the jwt request endpoint as a utility function?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. Maybe we should add it to the GSQL integration plan?

Copy link
Contributor Author

@luzhoutg luzhoutg Jun 12, 2024

Choose a reason for hiding this comment

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

That is a good idea. I will create another PR for this.

@@ -42,6 +43,7 @@ def make_connection(graphname: str = None):
certPath=server_config["certPath"],
sslPort=server_config["sslPort"],
gcp=server_config["gcp"],
jwtToken=server_config["jwtToken"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Just double check here: does server_config contains this key "jwtToken"? I don't see the config file modified.

@luzhoutg luzhoutg merged commit 26919bd into master Jun 12, 2024
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.

5 participants