Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kubernetes/config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ def _load_oid_token(self, provider):
return self.token

def _refresh_oidc(self, provider):
config = Configuration()
# host selects the environment proxy (and NO_PROXY match) for the IdP
config = Configuration(host=provider['config']['idp-issuer-url'])

if 'idp-certificate-authority-data' in provider['config']:
cert = base64.b64decode(
Expand Down
27 changes: 27 additions & 0 deletions kubernetes/config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,33 @@ def test_oidc_with_refresh(self, mock_ApiClient, mock_OAuth2Session):
self.assertTrue(loader._load_auth_provider_token())
self.assertEqual("Bearer abc123", loader.token)

@mock.patch('kubernetes.config.kube_config.OAuth2Session.refresh_token')
@mock.patch('kubernetes.config.kube_config.ApiClient')
def test_oidc_refresh_uses_env_proxy_for_issuer(
self, mock_ApiClient, mock_OAuth2Session):
mock_response = mock.MagicMock()
mock_response.status = 200
mock_response.data = json.dumps({
"token_endpoint": "https://example.org/identity/token"
})
mock_ApiClient.return_value.call_api.return_value = mock_response
mock_OAuth2Session.return_value = {"id_token": "abc123",
"refresh_token": "newtoken123"}

proxy = "http://proxy.example.com:3128"
env = {"https_proxy": proxy, "HTTPS_PROXY": proxy,
"no_proxy": "", "NO_PROXY": ""}
with mock.patch.dict(os.environ, env):
loader = KubeConfigLoader(
config_dict=copy.deepcopy(self.TEST_KUBE_CONFIG),
active_context="expired_oidc",
)
self.assertTrue(loader._load_auth_provider_token())

config = mock_ApiClient.call_args.kwargs["configuration"]
self.assertEqual("https://example.org/identity", config.host)
self.assertEqual(proxy, config.proxy)

@mock.patch('kubernetes.config.kube_config.OAuth2Session.refresh_token')
@mock.patch('kubernetes.config.kube_config.ApiClient.call_api')
def test_oidc_with_idp_ca_file_refresh(self, mock_ApiClient, mock_OAuth2Session):
Expand Down