Skip to content

Commit 2fe430c

Browse files
update auth to allow for skip_tls
1 parent 8feb136 commit 2fe430c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/codeflare_sdk/cluster/auth.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import abc
2323
import openshift as oc
24+
from openshift import OpenShiftPythonException
2425

2526

2627
class Authentication(metaclass=abc.ABCMeta):
@@ -61,13 +62,25 @@ def __init__(
6162
self.token = token
6263
self.server = server
6364

64-
def login(self):
65+
def login(self, skip_tls=False):
6566
"""
6667
This function is used to login to an OpenShift cluster using the user's API token and API server address.
68+
Depending on the cluster, a user can choose to login in with "--insecure-skip-tls-verify` by setting `skip_tls`
69+
to `True`.
6770
"""
6871
token = self.token
6972
server = self.server
70-
response = oc.invoke("login", [f"--token={token}", f"--server={server}:6443"])
73+
args = [f"--token={token}", f"--server={server}:6443"]
74+
if skip_tls:
75+
args.append("--insecure-skip-tls-verify")
76+
try:
77+
response = oc.invoke("login", args)
78+
except OpenShiftPythonException as osp:
79+
error_msg = osp.result.err()
80+
if "The server uses a certificate signed by unknown authority" in error_msg:
81+
return "Error: certificate auth failure, please set `skip_tls=True` in your cluster config"
82+
else:
83+
return error_msg
7184
return response.out()
7285

7386
def logout(self):

src/codeflare_sdk/cluster/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def up(self):
9595
Applies the AppWrapper yaml, pushing the resource request onto
9696
the MCAD queue.
9797
"""
98-
self.config.auth.login()
98+
self.config.auth.login(self.config.skip_tls)
9999
namespace = self.config.namespace
100100
with oc.project(namespace):
101101
oc.invoke("apply", ["-f", self.app_wrapper_yaml])

src/codeflare_sdk/cluster/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ class ClusterConfiguration:
4848
envs: dict = field(default_factory=dict)
4949
image: str = "ghcr.io/foundation-model-stack/base:ray2.1.0-py38-gpu-pytorch1.12.0cu116-20221213-193103"
5050
auth: Authentication = Authentication()
51+
skip_tls = False

0 commit comments

Comments
 (0)