From 9da0652bc61b522c5d83d3c71244f21efc5f8478 Mon Sep 17 00:00:00 2001 From: Nigel Foucha Date: Tue, 8 Oct 2019 14:42:26 -0400 Subject: [PATCH] Dynamically load apiserver id from kube config --- config/kube_config.py | 5 +++-- config/kube_config_test.py | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/kube_config.py b/config/kube_config.py index ddfd0b38..00133a83 100644 --- a/config/kube_config.py +++ b/config/kube_config.py @@ -249,12 +249,13 @@ def _refresh_azure_token(self, config): tenant = config['tenant-id'] authority = 'https://login.microsoftonline.com/{}'.format(tenant) context = adal.AuthenticationContext( - authority, validate_authority=True, + authority, validate_authority=True, api_version='1.0' ) refresh_token = config['refresh-token'] client_id = config['client-id'] + apiserver_id = config['apiserver-id'] token_response = context.acquire_token_with_refresh_token( - refresh_token, client_id, '00000002-0000-0000-c000-000000000000') + refresh_token, client_id, apiserver_id) provider = self._user['auth-provider']['config'] provider.value['access-token'] = token_response['accessToken'] diff --git a/config/kube_config_test.py b/config/kube_config_test.py index c8fb7967..2b031083 100644 --- a/config/kube_config_test.py +++ b/config/kube_config_test.py @@ -647,7 +647,7 @@ class TestKubeConfigLoader(BaseTestCase): "auth-provider": { "config": { "access-token": TEST_AZURE_TOKEN, - "apiserver-id": "ApiserverId", + "apiserver-id": "00000002-0000-0000-c000-000000000000", "environment": "AzurePublicCloud", "refresh-token": "refreshToken", "tenant-id": "9d2ac018-e843-4e14-9e2b-4e0ddac75433" @@ -662,7 +662,7 @@ class TestKubeConfigLoader(BaseTestCase): "auth-provider": { "config": { "access-token": TEST_AZURE_TOKEN, - "apiserver-id": "ApiserverId", + "apiserver-id": "00000002-0000-0000-c000-000000000000", "environment": "AzurePublicCloud", "expires-in": "0", "expires-on": "156207275", @@ -679,7 +679,7 @@ class TestKubeConfigLoader(BaseTestCase): "auth-provider": { "config": { "access-token": TEST_AZURE_TOKEN, - "apiserver-id": "ApiserverId", + "apiserver-id": "00000002-0000-0000-c000-000000000000", "environment": "AzurePublicCloud", "expires-in": "0", "expires-on": "2018-10-18 00:52:29.044727", @@ -696,7 +696,7 @@ class TestKubeConfigLoader(BaseTestCase): "auth-provider": { "config": { "access-token": TEST_AZURE_TOKEN, - "apiserver-id": "ApiserverId", + "apiserver-id": "00000002-0000-0000-c000-000000000000", "environment": "AzurePublicCloud", "expires-in": "0", "expires-on": "2018-10-18 00:52", @@ -713,7 +713,7 @@ class TestKubeConfigLoader(BaseTestCase): "auth-provider": { "config": { "access-token": TEST_AZURE_TOKEN, - "apiserver-id": "ApiserverId", + "apiserver-id": "00000002-0000-0000-c000-000000000000", "environment": "AzurePublicCloud", "expires-in": "0", "expires-on": "-1",