Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 9cd87a6

Browse files
mangelajoNickCao
authored andcommitted
Add insecure_tls_config flag
(cherry picked from commit 230516d)
1 parent 3a7e9ec commit 9cd87a6

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from jumpstarter_cli_common.opt import (
77
OutputMode,
88
OutputType,
9+
confirm_insecure_tls,
910
opt_context,
11+
opt_insecure_tls_config,
1012
opt_kubeconfig,
1113
opt_labels,
1214
opt_log_level,
@@ -75,13 +77,15 @@ def print_created_client(client: V1Alpha1Client, output: OutputType):
7577
@opt_labels
7678
@opt_kubeconfig
7779
@opt_context
80+
@opt_insecure_tls_config
7881
@opt_oidc_username
7982
@opt_nointeractive
8083
@opt_output_all
8184
async def create_client(
8285
name: Optional[str],
8386
kubeconfig: Optional[str],
8487
context: Optional[str],
88+
insecure_tls_config: bool,
8589
namespace: str,
8690
labels: list[(str, str)],
8791
save: bool,
@@ -94,6 +98,7 @@ async def create_client(
9498
):
9599
"""Create a client object in the Kubernetes cluster"""
96100
try:
101+
confirm_insecure_tls(insecure_tls_config, nointeractive)
97102
async with ClientsV1Alpha1Api(namespace, kubeconfig, context) as api:
98103
if output is None:
99104
# Only print status if is not JSON/YAML
@@ -113,6 +118,7 @@ async def create_client(
113118
allow_drivers = allow.split(",") if allow is not None and len(allow) > 0 else []
114119
client_config.drivers.unsafe = unsafe
115120
client_config.drivers.allow = allow_drivers
121+
client_config.tls.insecure = insecure_tls_config
116122
ClientConfigV1Alpha1.save(client_config, out)
117123
# If this is the only client config, set it as default
118124
if out is None and len(ClientConfigV1Alpha1.list()) == 1:
@@ -156,13 +162,15 @@ def print_created_exporter(exporter: V1Alpha1Exporter, output: OutputType):
156162
@opt_labels
157163
@opt_kubeconfig
158164
@opt_context
165+
@opt_insecure_tls_config
159166
@opt_oidc_username
160167
@opt_nointeractive
161168
@opt_output_all
162169
async def create_exporter(
163170
name: Optional[str],
164171
kubeconfig: Optional[str],
165172
context: Optional[str],
173+
insecure_tls_config: bool,
166174
namespace: str,
167175
labels: list[(str, str)],
168176
save: bool,
@@ -173,6 +181,7 @@ async def create_exporter(
173181
):
174182
"""Create an exporter object in the Kubernetes cluster"""
175183
try:
184+
confirm_insecure_tls(insecure_tls_config, nointeractive)
176185
async with ExportersV1Alpha1Api(namespace, kubeconfig, context) as api:
177186
if output is None:
178187
click.echo(f"Creating exporter '{name}' in namespace '{namespace}'")
@@ -182,6 +191,7 @@ async def create_exporter(
182191
if output is None:
183192
click.echo("Fetching exporter credentials from cluster")
184193
exporter_config = await api.get_exporter_config(name)
194+
exporter_config.tls.insecure = insecure_tls_config
185195
ExporterConfigV1Alpha1.save(exporter_config, out)
186196
if output is None:
187197
click.echo(f"Exporter configuration successfully saved to {exporter_config.path}")

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/import_res.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import asyncclick as click
44
from jumpstarter_cli_common.opt import (
55
PathOutputType,
6+
confirm_insecure_tls,
67
opt_context,
8+
opt_insecure_tls_config,
79
opt_kubeconfig,
810
opt_namespace,
911
opt_nointeractive,
@@ -45,13 +47,15 @@ def import_res():
4547
@opt_namespace
4648
@opt_kubeconfig
4749
@opt_context
50+
@opt_insecure_tls_config
4851
@opt_output_path_only
4952
@opt_nointeractive
5053
async def import_client(
5154
name: str,
5255
namespace: str,
5356
kubeconfig: Optional[str],
5457
context: Optional[str],
58+
insecure_tls_config: bool,
5559
allow: Optional[str],
5660
unsafe: bool,
5761
out: Optional[str],
@@ -63,6 +67,7 @@ async def import_client(
6367
if out is None and ClientConfigV1Alpha1.exists(name):
6468
raise click.ClickException(f"A client with the name '{name}' already exists")
6569
try:
70+
confirm_insecure_tls(insecure_tls_config, nointeractive)
6671
async with ClientsV1Alpha1Api(namespace, kubeconfig, context) as api:
6772
if unsafe is False and allow is None and nointeractive is False:
6873
unsafe = click.confirm("Allow unsafe driver client imports?")
@@ -74,6 +79,7 @@ async def import_client(
7479
click.echo("Fetching client credentials from cluster")
7580
allow_drivers = allow.split(",") if allow is not None and len(allow) > 0 else []
7681
client_config = await api.get_client_config(name, allow=allow_drivers, unsafe=unsafe)
82+
client_config.tls.insecure = insecure_tls_config
7783
config_path = ClientConfigV1Alpha1.save(client_config, out)
7884
# If this is the only client config, set it as default
7985
if out is None and len(ClientConfigV1Alpha1.list()) == 1:
@@ -100,6 +106,7 @@ async def import_client(
100106
@opt_namespace
101107
@opt_kubeconfig
102108
@opt_context
109+
@opt_insecure_tls_config
103110
@opt_output_path_only
104111
@opt_nointeractive
105112
async def import_exporter(
@@ -108,6 +115,7 @@ async def import_exporter(
108115
out: Optional[str],
109116
kubeconfig: Optional[str],
110117
context: Optional[str],
118+
insecure_tls_config: bool,
111119
output: PathOutputType,
112120
nointeractive: bool,
113121
):
@@ -119,10 +127,12 @@ async def import_exporter(
119127
else:
120128
raise click.ClickException(f'An exporter with the name "{name}" already exists')
121129
try:
130+
confirm_insecure_tls(insecure_tls_config, nointeractive)
122131
async with ExportersV1Alpha1Api(namespace, kubeconfig, context) as api:
123132
if output is None:
124133
click.echo("Fetching exporter credentials from cluster")
125134
exporter_config = await api.get_exporter_config(name)
135+
exporter_config.tls.insecure = insecure_tls_config
126136
config_path = ExporterConfigV1Alpha1.save(exporter_config, out)
127137
if output is None:
128138
click.echo(f"Exporter configuration successfully saved to {config_path}")

packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919

2020
opt_labels = click.option("-l", "--label", "labels", type=(str, str), multiple=True, help="Labels")
2121

22+
opt_insecure_tls_config = click.option("--insecure-tls-config", "insecure_tls_config", is_flag=True, default=False,
23+
help="Disable endpoint TLS verification. This is insecure and should only be used for testing purposes")
24+
25+
def confirm_insecure_tls(insecure_tls_config:bool, nointeractive: bool):
26+
"""Confirm if insecure TLS config is enabled and user wants to continue.
27+
28+
Args:
29+
insecure_tls_config (bool): Insecure TLS config flag requested by the user.
30+
nointeractive (bool): This flag is set to True if the command is run in non-interactive mode.
31+
32+
Raises:
33+
click.Abort: Abort the command if user does not want to continue.
34+
"""
35+
if nointeractive is False and insecure_tls_config:
36+
if not click.confirm("Insecure TLS config is enabled. Are you sure you want to continue?"):
37+
click.echo("Aborting.")
38+
raise click.Abort()
2239

2340
class OutputMode(str):
2441
JSON = "json"

packages/jumpstarter-cli/jumpstarter_cli/login.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncclick as click
22
from jumpstarter_cli_common.config import opt_config
33
from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_oidc
4+
from jumpstarter_cli_common.opt import confirm_insecure_tls, opt_insecure_tls_config, opt_nointeractive
45

56
from jumpstarter.config.client import ClientConfigV1Alpha1, ClientConfigV1Alpha1Drivers
67
from jumpstarter.config.common import ObjectMeta
@@ -24,6 +25,8 @@
2425
"--unsafe", is_flag=True, help="Should all driver client packages be allowed to load (UNSAFE!).", default=None
2526
)
2627
# end client specific
28+
@opt_insecure_tls_config
29+
@opt_nointeractive
2730
@opt_config(allow_missing=True)
2831
async def login( # noqa: C901
2932
config,
@@ -37,27 +40,39 @@ async def login( # noqa: C901
3740
client_id: str,
3841
connector_id: str,
3942
unsafe,
43+
insecure_tls_config: bool,
44+
nointeractive: bool,
4045
allow,
4146
):
4247
"""Login into a jumpstarter instance"""
4348

49+
confirm_insecure_tls(insecure_tls_config, nointeractive)
50+
4451
match config:
4552
case ClientConfigV1Alpha1():
4653
issuer = decode_jwt_issuer(config.token)
4754
case ExporterConfigV1Alpha1():
4855
issuer = decode_jwt_issuer(config.token)
4956
case (kind, value):
5057
if namespace is None:
58+
if nointeractive:
59+
raise click.UsageError("Namespace is required in non-interactive mode.")
5160
namespace = click.prompt("Enter the Jumpstarter exporter namespace")
5261
if name is None:
62+
if nointeractive:
63+
raise click.UsageError("Name is required in non-interactive mode.")
5364
name = click.prompt("Enter the Jumpstarter exporter name")
5465
if endpoint is None:
66+
if nointeractive:
67+
raise click.UsageError("Endpoint is required in non-interactive mode.")
5568
endpoint = click.prompt("Enter the Jumpstarter service endpoint")
5669

5770
if kind.startswith("client"):
5871
if unsafe is None:
5972
unsafe = click.confirm("Allow unsafe driver client imports?")
6073
if unsafe is False and allow == "":
74+
if nointeractive:
75+
raise click.UsageError("Allowed driver packages are required in non-interactive mode.")
6176
allow = click.prompt(
6277
"Enter a comma-separated list of allowed driver packages (optional)", default="", type=str
6378
)
@@ -80,6 +95,8 @@ async def login( # noqa: C901
8095
)
8196

8297
if issuer is None:
98+
if nointeractive:
99+
raise click.UsageError("Issuer is required in non-interactive mode.")
83100
issuer = click.prompt("Enter the OIDC issuer")
84101

85102
oidc = Config(issuer=issuer, client_id=client_id)
@@ -93,6 +110,7 @@ async def login( # noqa: C901
93110
tokens = await oidc.authorization_code_grant()
94111

95112
config.token = tokens["access_token"]
113+
config.tls.insecure = insecure_tls_config
96114

97115
match kind:
98116
case "client":

0 commit comments

Comments
 (0)