Skip to content

Commit

Permalink
[sdk cli] add extra header for cli
Browse files Browse the repository at this point in the history
In some cases, it may need extra header to handle the API calls.
Directly add `header_name` and `header_value` props in
`.config/kfp/context.json` and pass the name/value pair
to APIClient.

Here is one of the use cases:
if the service is protected by istio RBAC and need JWT header
for authentication, you can specify the JWT id-token in
the .config/kfp/context.json with these two new props.
The id-token would be carried in the specified header name.
Then the API call can be properly authentiecated and checked
if the user has the permission to access the service.
  • Loading branch information
yhwang committed Sep 21, 2020
1 parent 68c528e commit 4512da4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sdk/python/kfp/_client.py
Expand Up @@ -125,15 +125,19 @@ def __init__(self, host=None, client_id=None, namespace='kubeflow', other_client
config = self._load_config(host, client_id, namespace, other_client_id, other_client_secret, existing_token, proxy, ssl_ca_cert)
# Save the loaded API client configuration, as a reference if update is
# needed.
self._load_context_setting_or_default()
self._existing_config = config
api_client = kfp_server_api.api_client.ApiClient(config, cookie=cookies)
if cookies is None:
cookies = self._context_setting.get('client_authentication_cookie')
api_client = kfp_server_api.api_client.ApiClient(config, cookie=cookies,
header_name=self._context_setting.get('client_authentication_header_name'),
header_value=self._context_setting.get('client_authentication_header_value'))
_add_generated_apis(self, kfp_server_api, api_client)
self._job_api = kfp_server_api.api.job_service_api.JobServiceApi(api_client)
self._run_api = kfp_server_api.api.run_service_api.RunServiceApi(api_client)
self._experiment_api = kfp_server_api.api.experiment_service_api.ExperimentServiceApi(api_client)
self._pipelines_api = kfp_server_api.api.pipeline_service_api.PipelineServiceApi(api_client)
self._upload_api = kfp_server_api.api.PipelineUploadServiceApi(api_client)
self._load_context_setting_or_default()

def _load_config(self, host, client_id, namespace, other_client_id, other_client_secret, existing_token, proxy, ssl_ca_cert):
config = kfp_server_api.configuration.Configuration()
Expand Down

0 comments on commit 4512da4

Please sign in to comment.