Skip to content

Commit 7c2bd45

Browse files
VDK-Plugin: Oauth plugin (#3410)
Added oauth plugin --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent cda0d0f commit 7c2bd45

File tree

9 files changed

+285
-5
lines changed

9 files changed

+285
-5
lines changed

projects/vdk-core/src/vdk/internal/builtin_plugins/config/vdk_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,19 @@ def vdk_configure(self, config_builder: ConfigurationBuilder) -> None:
162162
)
163163
config_builder.add(
164164
TEAM_CLIENT_ID,
165-
"",
165+
None,
166166
True,
167167
"The Team's oAuth Client Id to use in authentication operations.",
168168
)
169169
config_builder.add(
170170
TEAM_CLIENT_SECRET,
171-
"",
171+
None,
172172
True,
173173
"The Team's oAuth Client Secret to use in authentication operations",
174174
)
175175
config_builder.add(
176176
TEAM_OAUTH_AUTHORIZE_URL,
177-
"",
177+
None,
178178
True,
179179
"The URL for Team's oAuth authorization",
180180
)

projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/kerberos_configuration.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
KEYTAB_REALM = "KEYTAB_REALM"
1919
KERBEROS_KDC_HOST = "KERBEROS_KDC_HOST"
2020
KRB_AUTH_FAIL_FAST = "KRB_AUTH_FAIL_FAST"
21-
2221
API_SERVER_KERBEROS_SERVICE_NAME = "API_SERVER_KERBEROS_SERVICE_NAME"
22+
DISABLE_KERBEROS_LOGIN = "DISABLE_KERBEROS_LOGIN"
2323

2424

2525
class KerberosPluginConfiguration:
@@ -87,6 +87,9 @@ def auth_fail_fast(self) -> bool:
8787
def api_server_kerberos_service_name(self) -> str:
8888
return self.__config.get_value(API_SERVER_KERBEROS_SERVICE_NAME)
8989

90+
def disable_kerberos_plugin(self):
91+
return self.__config.get_value(DISABLE_KERBEROS_LOGIN).lower() == "true"
92+
9093

9194
def add_definitions(config_builder: ConfigurationBuilder) -> None:
9295
config_builder.add(
@@ -152,3 +155,8 @@ def add_definitions(config_builder: ConfigurationBuilder) -> None:
152155
(for example, '[email protected]').
153156
""",
154157
)
158+
config_builder.add(
159+
key=DISABLE_KERBEROS_LOGIN,
160+
default_value=False,
161+
description="To enable/disable kerberos login.",
162+
)

projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/kerberos_plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def vdk_initialize(self, context: CoreContext) -> None:
5959
kerberos_configuration = KerberosPluginConfiguration(
6060
None, None, context.configuration
6161
)
62+
if kerberos_configuration.disable_kerberos_plugin():
63+
return
6264
if (
6365
kerberos_configuration.keytab_filename()
6466
and kerberos_configuration.keytab_principal()
@@ -79,6 +81,9 @@ def initialize_job(self, context: JobContext) -> None:
7981
kerberos_configuration = KerberosPluginConfiguration(
8082
context.name, str(context.job_directory), context.core_context.configuration
8183
)
84+
if kerberos_configuration.disable_kerberos_plugin():
85+
return
86+
8287
self.__attempt_kerberos_authentication(kerberos_configuration)
8388

8489

projects/vdk-plugins/vdk-kerberos-auth/tests/test_kerberos.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_no_authentication(self):
4141
{
4242
"VDK_KRB_AUTH_FAIL_FAST": "true",
4343
"VDK_LOG_EXECUTION_RESULT": "True",
44+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
4445
},
4546
):
4647
result: Result = self.__runner.invoke(
@@ -53,7 +54,11 @@ def test_no_authentication(self):
5354
def test_invalid_authentication_mode(self):
5455
with mock.patch.dict(
5556
os.environ,
56-
{"VDK_KRB_AUTH": "invalid", "VDK_KRB_AUTH_FAIL_FAST": "true"},
57+
{
58+
"VDK_KRB_AUTH": "invalid",
59+
"VDK_KRB_AUTH_FAIL_FAST": "true",
60+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
61+
},
5762
):
5863
result: Result = self.__runner.invoke(
5964
["run", jobs_path_from_caller_directory("test-job")]
@@ -71,6 +76,7 @@ def test_kinit_authentication(self):
7176
"VDK_KRB_AUTH_FAIL_FAST": "true",
7277
"VDK_KRB5_CONF_FILENAME": krb5_conf_filename,
7378
"VDK_LOG_EXECUTION_RESULT": "True",
79+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
7480
},
7581
):
7682
result: Result = self.__runner.invoke(
@@ -86,6 +92,7 @@ def test_kinit_authentication_cli_command_no_auth(self):
8692
{
8793
"VDK_KRB_AUTH": "",
8894
"VDK_KRB_AUTH_FAIL_FAST": "true",
95+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
8996
},
9097
):
9198
result: Result = self.__runner.invoke(["my-echo", "hi"])
@@ -106,6 +113,7 @@ def test_kinit_authentication_cli_command(self):
106113
"VDK_KEYTAB_FOLDER": str(pathlib.Path(data_job_path).parent),
107114
"VDK_KEYTAB_FILENAME": "test-job.keytab",
108115
"VDK_KEYTAB_PRINCIPAL": "pa__view_test-job",
116+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
109117
},
110118
):
111119
result: Result = self.__runner.invoke(["my-echo", "hi"])
@@ -125,6 +133,7 @@ def test_minikerberos_authentication_cli_command(self):
125133
"VDK_KEYTAB_FOLDER": str(get_caller_directory().joinpath("jobs")),
126134
"VDK_KEYTAB_FILENAME": "test-job.keytab",
127135
"VDK_KEYTAB_PRINCIPAL": "pa__view_test-job",
136+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
128137
},
129138
):
130139
result: Result = self.__runner.invoke(["my-echo", "hi"])
@@ -140,6 +149,7 @@ def test_minikerberos_authentication_cli_command_no_keytab_file(self):
140149
"VDK_KRB_AUTH_FAIL_FAST": "true",
141150
"VDK_KRB5_CONF_FILENAME": krb5_conf_filename,
142151
"VDK_KEYTAB_PRINCIPAL": "pa__view_test-job",
152+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
143153
},
144154
):
145155
result: Result = self.__runner.invoke(["my-echo", "hi"])
@@ -161,6 +171,7 @@ def test_kinit_authentication_with_wrong_credentials(self):
161171
"different_principal.keytab"
162172
)
163173
),
174+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
164175
},
165176
):
166177
result: Result = self.__runner.invoke(["run", data_job_path])
@@ -181,6 +192,7 @@ def test_kinit_authentication_error_fail_fast_is_false(self):
181192
"VDK_KEYTAB_FILENAME": str(
182193
pathlib.Path(data_job_path).parent.joinpath("non_existent.keytab")
183194
),
195+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
184196
},
185197
):
186198
result: Result = self.__runner.invoke(["run", data_job_path])
@@ -198,6 +210,7 @@ def test_kinit_authentication_with_missing_keytab(self):
198210
"VDK_KRB5_CONF_FILENAME": krb5_conf_filename,
199211
"VDK_KEYTAB_FOLDER": str(pathlib.Path(data_job_path).parent),
200212
"VDK_KEYTAB_FILENAME": "non_existent.keytab",
213+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
201214
},
202215
):
203216
result: Result = self.__runner.invoke(["run", data_job_path])
@@ -216,6 +229,7 @@ def test_minikerberos_authentication(self):
216229
"VDK_KERBEROS_KDC_HOST": "localhost",
217230
"VDK_KRB5_CONF_FILENAME": krb5_conf_filename,
218231
"VDK_LOG_EXECUTION_RESULT": "True",
232+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
219233
},
220234
):
221235
result: Result = self.__runner.invoke(
@@ -237,6 +251,7 @@ def test_minikerberos_authentication_with_wrong_credentials(self):
237251
"VDK_KRB5_CONF_FILENAME": krb5_conf_filename,
238252
"VDK_KEYTAB_FOLDER": str(pathlib.Path(data_job_path).parent),
239253
"VDK_KEYTAB_FILENAME": "different_principal.keytab",
254+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
240255
},
241256
):
242257
result: Result = self.__runner.invoke(["run", data_job_path])
@@ -257,6 +272,7 @@ def test_minikerberos_authentication_with_missing_keytab(self):
257272
"VDK_KEYTAB_FILENAME": str(
258273
pathlib.Path(data_job_path).parent.joinpath("non_existent.keytab")
259274
),
275+
"VDK_DISABLE_KERBEROS_LOGIN": "False",
260276
},
261277
):
262278
result: Result = self.__runner.invoke(["run", data_job_path])
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
The plugin provides Oauth authentication on data job startup.
3+
4+
# Usage
5+
6+
To install the plugin, run:
7+
8+
```bash
9+
pip install vdk-oauth-auth
10+
```
11+
12+
## Configuration
13+
14+
The following environment variables can be used to configure this plugin:
15+
16+
| name | description |
17+
|----------------------|-----------------------------------------------|
18+
| `TEAM_CLIENT_ID` | Client id to fetch access token from CSP. |
19+
| `TEAM_CLIENT_SECRET` | Client secret to fetch access token from CSP. |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
docker<7
2+
docker-compose
3+
4+
5+
# install earlier version due to https://github.com/yaml/pyyaml/issues/601
6+
PyYAML==5.3.1
7+
8+
vdk-test-utils
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2023-2024 Broadcom
2+
# SPDX-License-Identifier: Apache-2.0
3+
import pathlib
4+
5+
import setuptools
6+
7+
8+
__version__ = "0.3.0"
9+
10+
setuptools.setup(
11+
name="vdk-oauth-auth",
12+
version=__version__,
13+
url="https://github.com/vmware/versatile-data-kit",
14+
description="Versatile Data Kit SDK plugin adds Oauth support.",
15+
long_description=pathlib.Path("README.md").read_text(),
16+
long_description_content_type="text/markdown",
17+
install_requires=[
18+
"vdk-core",
19+
],
20+
package_dir={"": "src"},
21+
packages=setuptools.find_namespace_packages(where="src"),
22+
entry_points={"vdk.plugin.run": ["vdk-oauth-auth = vdk.plugin.oauth.oauth_plugin"]},
23+
classifiers=[
24+
"Development Status :: 4 - Beta",
25+
"License :: OSI Approved :: Apache Software License",
26+
"Programming Language :: Python :: 3.7",
27+
"Programming Language :: Python :: 3.8",
28+
"Programming Language :: Python :: 3.9",
29+
"Programming Language :: Python :: 3.10",
30+
"Programming Language :: Python :: 3.11",
31+
"Programming Language :: Python :: 3.12",
32+
],
33+
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2024-2025 Broadcom
2+
# SPDX-License-Identifier: Apache-2.0
3+
from vdk.internal.core.config import Configuration
4+
from vdk.internal.core.config import ConfigurationBuilder
5+
6+
CLIENT_ID = "CLIENT_ID"
7+
CLIENT_SECRET = "CLIENT_SECRET"
8+
TEAM_CLIENT_ID = "TEAM_CLIENT_ID"
9+
TEAM_CLIENT_SECRET = "TEAM_CLIENT_SECRET"
10+
CONTROL_SERVICE_REST_API_URL = "CONTROL_SERVICE_REST_API_URL"
11+
API_TOKEN_AUTHORIZATION_URL = "API_TOKEN_AUTHORIZATION_URL"
12+
TEAM_OAUTH_AUTHORIZE_URL = "TEAM_OAUTH_AUTHORIZE_URL"
13+
CSP_ACCESS_TOKEN = "CSP_ACCESS_TOKEN"
14+
DISABLE_OAUTH_LOGIN = "DISABLE_OAUTH_LOGIN"
15+
Team = "TEAM"
16+
17+
18+
class OauthPluginConfiguration:
19+
def __init__(
20+
self,
21+
config: Configuration,
22+
):
23+
self.__config = config
24+
25+
def team(self):
26+
return self.__config.get_value(Team)
27+
28+
def team_client_id(self):
29+
return self.__config.get_value(TEAM_CLIENT_ID)
30+
31+
def team_client_secret(self):
32+
return self.__config.get_value(TEAM_CLIENT_SECRET)
33+
34+
def control_service_rest_api_url(self):
35+
return self.__config.get_value(CONTROL_SERVICE_REST_API_URL)
36+
37+
def api_token_authorization_url(self):
38+
return self.__config.get_value(API_TOKEN_AUTHORIZATION_URL)
39+
40+
def team_oauth_authorize_url(self):
41+
return self.__config.get_value(TEAM_OAUTH_AUTHORIZE_URL)
42+
43+
def csp_access_token(self):
44+
return self.__config.get_value(CSP_ACCESS_TOKEN)
45+
46+
def disable_oauth_plugin(self):
47+
return self.__config.get_value(DISABLE_OAUTH_LOGIN).lower() == "true"
48+
49+
50+
def add_definitions(config_builder: ConfigurationBuilder) -> None:
51+
config_builder.add(
52+
key=DISABLE_OAUTH_LOGIN,
53+
default_value=False,
54+
description="To enable/disable oauth login.",
55+
)

0 commit comments

Comments
 (0)