Skip to content

Commit 403cca6

Browse files
Remove creation of OAuth resources/logic and remove openshift_oauth option (#480)
* Remove creation of OAuth resources/logic and add annotation * Remove openshift_oauth configuration * Add verify_tls to ClusterConfiguration
1 parent 1497434 commit 403cca6

File tree

7 files changed

+46
-341
lines changed

7 files changed

+46
-341
lines changed

Diff for: src/codeflare_sdk/cluster/cluster.py

+19-29
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
)
3434
from ..utils.kube_api_helpers import _kube_api_error_handling
3535
from ..utils.generate_yaml import is_openshift_cluster
36-
from ..utils.openshift_oauth import (
37-
create_openshift_oauth_objects,
38-
delete_openshift_oauth_objects,
39-
)
36+
4037
from .config import ClusterConfiguration
4138
from .model import (
4239
AppWrapper,
@@ -86,14 +83,16 @@ def _client_headers(self):
8683

8784
@property
8885
def _client_verify_tls(self):
89-
return not self.config.openshift_oauth
86+
if not is_openshift_cluster or not self.config.verify_tls:
87+
return False
88+
return True
9089

9190
@property
9291
def job_client(self):
9392
k8client = api_config_handler() or client.ApiClient()
9493
if self._job_submission_client:
9594
return self._job_submission_client
96-
if self.config.openshift_oauth:
95+
if is_openshift_cluster():
9796
print(k8client.configuration.get_api_key_with_prefix("authorization"))
9897
self._job_submission_client = JobSubmissionClient(
9998
self.cluster_dashboard_uri(),
@@ -191,6 +190,7 @@ def create_app_wrapper(self):
191190
ingress_domain = self.config.ingress_domain
192191
ingress_options = self.config.ingress_options
193192
write_to_file = self.config.write_to_file
193+
verify_tls = self.config.verify_tls
194194
return generate_appwrapper(
195195
name=name,
196196
namespace=namespace,
@@ -213,10 +213,10 @@ def create_app_wrapper(self):
213213
image_pull_secrets=image_pull_secrets,
214214
dispatch_priority=dispatch_priority,
215215
priority_val=priority_val,
216-
openshift_oauth=self.config.openshift_oauth,
217216
ingress_domain=ingress_domain,
218217
ingress_options=ingress_options,
219218
write_to_file=write_to_file,
219+
verify_tls=verify_tls,
220220
)
221221

222222
# creates a new cluster with the provided or default spec
@@ -226,10 +226,6 @@ def up(self):
226226
the MCAD queue.
227227
"""
228228
namespace = self.config.namespace
229-
if self.config.openshift_oauth:
230-
create_openshift_oauth_objects(
231-
cluster_name=self.config.name, namespace=namespace
232-
)
233229

234230
try:
235231
config_check()
@@ -281,11 +277,6 @@ def down(self):
281277
except Exception as e: # pragma: no cover
282278
return _kube_api_error_handling(e)
283279

284-
if self.config.openshift_oauth:
285-
delete_openshift_oauth_objects(
286-
cluster_name=self.config.name, namespace=namespace
287-
)
288-
289280
def status(
290281
self, print_to_console: bool = True
291282
) -> Tuple[CodeFlareClusterStatus, bool]:
@@ -500,26 +491,21 @@ def torchx_config(
500491
return to_return
501492

502493
def from_k8_cluster_object(
503-
rc, mcad=True, ingress_domain=None, ingress_options={}, write_to_file=False
494+
rc,
495+
mcad=True,
496+
ingress_domain=None,
497+
ingress_options={},
498+
write_to_file=False,
499+
verify_tls=True,
504500
):
505501
config_check()
506-
openshift_oauth = False
507502
if (
508503
rc["metadata"]["annotations"]["sdk.codeflare.dev/local_interactive"]
509504
== "True"
510505
):
511506
local_interactive = True
512507
else:
513508
local_interactive = False
514-
if "codeflare.dev/oauth" in rc["metadata"]["annotations"]:
515-
openshift_oauth = (
516-
rc["metadata"]["annotations"]["codeflare.dev/oauth"] == "True"
517-
)
518-
else:
519-
for container in rc["spec"]["headGroupSpec"]["template"]["spec"][
520-
"containers"
521-
]:
522-
openshift_oauth = "oauth-proxy" in container["name"]
523509
machine_types = (
524510
rc["metadata"]["labels"]["orderedinstance"].split("_")
525511
if "orderedinstance" in rc["metadata"]["labels"]
@@ -570,7 +556,7 @@ def from_k8_cluster_object(
570556
ingress_domain=ingress_domain,
571557
ingress_options=ingress_options,
572558
write_to_file=write_to_file,
573-
openshift_oauth=openshift_oauth,
559+
verify_tls=verify_tls,
574560
)
575561
return Cluster(cluster_config)
576562

@@ -655,7 +641,10 @@ def get_current_namespace(): # pragma: no cover
655641

656642

657643
def get_cluster(
658-
cluster_name: str, namespace: str = "default", write_to_file: bool = False
644+
cluster_name: str,
645+
namespace: str = "default",
646+
write_to_file: bool = False,
647+
verify_tls: bool = True,
659648
):
660649
try:
661650
config_check()
@@ -729,6 +718,7 @@ def get_cluster(
729718
ingress_domain=ingress_domain,
730719
ingress_options=ingress_options,
731720
write_to_file=write_to_file,
721+
verify_tls=verify_tls,
732722
)
733723
raise FileNotFoundError(
734724
f"Cluster {cluster_name} is not found in {namespace} namespace"

Diff for: src/codeflare_sdk/cluster/config.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ class ClusterConfiguration:
5252
local_interactive: bool = False
5353
image_pull_secrets: list = field(default_factory=list)
5454
dispatch_priority: str = None
55-
openshift_oauth: bool = False # NOTE: to use the user must have permission to create a RoleBinding for system:auth-delegator
5655
ingress_options: dict = field(default_factory=dict)
5756
ingress_domain: str = None
5857
write_to_file: bool = False
58+
verify_tls: bool = True
59+
60+
def __post_init__(self):
61+
if not self.verify_tls:
62+
print(
63+
"Warning: TLS verification has been disabled - Endpoint checks will be bypassed"
64+
)

Diff for: src/codeflare_sdk/utils/generate_yaml.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ def update_names(yaml, item, appwrapper_name, cluster_name, namespace):
227227
lower_meta["labels"]["workload.codeflare.dev/appwrapper"] = appwrapper_name
228228
lower_meta["name"] = cluster_name
229229
lower_meta["namespace"] = namespace
230+
lower_spec = item.get("generictemplate", {}).get("spec")
231+
if is_openshift_cluster():
232+
cookie_secret_env_var = {
233+
"name": "COOKIE_SECRET",
234+
"valueFrom": {
235+
"secretKeyRef": {
236+
"key": "cookie_secret",
237+
"name": f"{cluster_name}-oauth-config",
238+
}
239+
},
240+
}
241+
lower_spec["headGroupSpec"]["template"]["spec"]["containers"][0]["env"].append(
242+
cookie_secret_env_var
243+
)
230244

231245

232246
def update_labels(yaml, instascale, instance_types):
@@ -585,9 +599,6 @@ def enable_openshift_oauth(user_yaml, cluster_name, namespace):
585599
)
586600
# allows for setting value of Cluster object when initializing object from an existing AppWrapper on cluster
587601
user_yaml["metadata"]["annotations"] = user_yaml["metadata"].get("annotations", {})
588-
user_yaml["metadata"]["annotations"][
589-
"codeflare-sdk-use-oauth"
590-
] = "true" # if the user gets an
591602
ray_headgroup_pod = user_yaml["spec"]["resources"]["GenericItems"][0][
592603
"generictemplate"
593604
]["spec"]["headGroupSpec"]["template"]["spec"]
@@ -620,7 +631,7 @@ def _create_oauth_sidecar_object(
620631
"--upstream=http://localhost:8265",
621632
f"--tls-cert={tls_mount_location}/tls.crt",
622633
f"--tls-key={tls_mount_location}/tls.key",
623-
f"--cookie-secret={b64encode(urandom(64)).decode('utf-8')}", # create random string for encrypting cookie
634+
"--cookie-secret=$(COOKIE_SECRET)",
624635
f'--openshift-delegate-urls={{"/":{{"resource":"pods","namespace":"{namespace}","verb":"get"}}}}',
625636
],
626637
image="registry.redhat.io/openshift4/ose-oauth-proxy@sha256:1ea6a01bf3e63cdcf125c6064cbd4a4a270deaf0f157b3eabb78f60556840366",
@@ -696,10 +707,10 @@ def generate_appwrapper(
696707
image_pull_secrets: list,
697708
dispatch_priority: str,
698709
priority_val: int,
699-
openshift_oauth: bool,
700710
ingress_domain: str,
701711
ingress_options: dict,
702712
write_to_file: bool,
713+
verify_tls: bool,
703714
):
704715
user_yaml = read_template(template)
705716
appwrapper_name, cluster_name = gen_names(name)
@@ -757,7 +768,7 @@ def generate_appwrapper(
757768

758769
delete_route_or_ingress(resources["resources"])
759770

760-
if openshift_oauth:
771+
if is_openshift_cluster():
761772
enable_openshift_oauth(user_yaml, cluster_name, namespace)
762773

763774
directory_path = os.path.expanduser("~/.codeflare/appwrapper/")

0 commit comments

Comments
 (0)