You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "amoghrajesh (via GitHub)" <gi...@apache.org> on 2026/04/14 12:17:23 UTC
[PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
amoghrajesh opened a new pull request, #65212:
URL: https://github.com/apache/airflow/pull/65212
<!-- SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICENSE-2.0 -->
<!--
Thank you for contributing!
Please provide above a brief description of the changes made in this pull request.
Write a good git commit message following this guide: http://chris.beams.io/posts/git-commit/
Please make sure that your code changes are covered with tests.
And in case of new features or big changes remember to adjust the documentation.
Feel free to ping (in general) for the review if you do not see reaction for a few days
(72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications.
In case of an existing issue, reference it using one of the following:
* closes: #ISSUE
* related: #ISSUE
-->
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR, please
change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
-->
- [x] Yes - Cursor with Sonnet 4.6
<!--
Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
Reattempt at: https://github.com/apache/airflow/pull/61738/
closes: https://github.com/apache/airflow/pull/61738/
Deferrable tasks on EKS/GKE can run longer than the 15-minute token lifetime issued by exec auth plugins (aws eks get-token, gke-gcloud-auth-plugin). Because `_load_config()` caches the kubeconfig on the first call, subsequent
calls are no operations and the expired token gets reused, causing auth failures.
Attempting to redo the PR by addressing review comments from myself
- Add `_uses_exec_auth()` to detect exec-based auth in the active context user only (not any user in the file), passing
- Skip caching when exec auth is detected; all other auth paths continue to cache as before
---
* Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #65212:
URL: https://github.com/apache/airflow/pull/65212#issuecomment-4250523965
> This PR is different and is a token expiry issue specific to `AsyncKubernetesHook`. On the first `_load_config()` call, the exec plugin runs and obtains a token which is short lived. Because `_config_loaded = True` is set, all future calls return early and do not renew the token resulting to failed auth.
Since this fix is for EKS and GKE I guess we should bump the k8s provider version in these providers?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #65212:
URL: https://github.com/apache/airflow/pull/65212#issuecomment-4250078139
@eladkal I wasn't aware of that one so I investigated a bit.
They are actually distinct issues.
#63610 was trying to fix a race condition, ie: concurrent tasks fighting over the aws cli cache dir, causing `FileExistsError`. A new version of botocore helped solve it because botocore ≥ 1.40.2 seemed to handle it internally.
This PR is different and is a token expiry issue specific to `AsyncKubernetesHook`. On the first `_load_config()` call, the exec plugin runs and obtains a token which is short lived. Because `_config_loaded = True` is set, all future calls return early and do not renew the token resulting to failed auth.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #65212:
URL: https://github.com/apache/airflow/pull/65212#discussion_r3084656865
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -818,6 +818,31 @@ def __init__(
self._event_polling_fallback = False
self._config_loaded = False
+ def _uses_exec_auth(self, kubeconfig_data: dict, context: str | None = None) -> bool:
+ """
+ Detect if the active kubeconfig context uses exec-based authentication.
+
+ Exec plugins return short-lived tokens (EKS, GKE, etc). Only the user
+ tied to the active context is checked.
+ """
+ active_context = context or kubeconfig_data.get("current-context")
+
+ active_user: str | None = None
+ for ctx in kubeconfig_data.get("contexts", []):
+ if ctx.get("name") == active_context:
+ active_user = ctx.get("context", {}).get("user")
+ break
+
+ users = kubeconfig_data.get("users", [])
+ if active_user is not None:
+ for user in users:
+ if user.get("name") == active_user:
+ return "exec" in user.get("user", {})
+ return False
+
+ # fallback to check all users if active context user cannot be resolved; this is a safe fallback since it errs on the side of not caching
+ return any("exec" in u.get("user", {}) for u in users)
+
async def _load_config(self):
"""Load Kubernetes configuration once per hook instance."""
Review Comment:
Valid, made the change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #65212:
URL: https://github.com/apache/airflow/pull/65212#discussion_r3084669434
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -818,6 +818,31 @@ def __init__(
self._event_polling_fallback = False
self._config_loaded = False
+ def _uses_exec_auth(self, kubeconfig_data: dict, context: str | None = None) -> bool:
+ """
+ Detect if the active kubeconfig context uses exec-based authentication.
+
+ Exec plugins return short-lived tokens (EKS, GKE, etc). Only the user
+ tied to the active context is checked.
Review Comment:
Valid, made the changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #65212:
URL: https://github.com/apache/airflow/pull/65212#discussion_r3081674884
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -818,6 +818,31 @@ def __init__(
self._event_polling_fallback = False
self._config_loaded = False
+ def _uses_exec_auth(self, kubeconfig_data: dict, context: str | None = None) -> bool:
+ """
+ Detect if the active kubeconfig context uses exec-based authentication.
+
+ Exec plugins return short-lived tokens (EKS, GKE, etc). Only the user
+ tied to the active context is checked.
+ """
+ active_context = context or kubeconfig_data.get("current-context")
+
+ active_user: str | None = None
+ for ctx in kubeconfig_data.get("contexts", []):
+ if ctx.get("name") == active_context:
+ active_user = ctx.get("context", {}).get("user")
+ break
+
+ users = kubeconfig_data.get("users", [])
+ if active_user is not None:
+ for user in users:
+ if user.get("name") == active_user:
+ return "exec" in user.get("user", {})
+ return False
+
+ # fallback to check all users if active context user cannot be resolved; this is a safe fallback since it errs on the side of not caching
+ return any("exec" in u.get("user", {}) for u in users)
+
async def _load_config(self):
"""Load Kubernetes configuration once per hook instance."""
Review Comment:
The `_load_config()` docstring says the config is loaded "once per hook instance", but with the new exec-auth behavior the config may intentionally be reloaded on every call (since `_config_loaded` stays `False`). Please update the docstring to reflect the new semantics so callers aren’t misled when debugging repeated config loads.
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -846,50 +871,76 @@ async def _load_config(self):
self._config_loaded = True
return
- # If above block does not return, we are not in a cluster.
self._is_in_cluster = False
-
if self.config_dict:
self.log.debug(LOADING_KUBE_CONFIG_FILE_RESOURCE.format("config dictionary"))
- await async_config.load_kube_config_from_dict(self.config_dict, context=cluster_context)
- self._config_loaded = True
- return
+ await async_config.load_kube_config_from_dict(
+ self.config_dict,
+ context=cluster_context,
+ )
+
+ if not self._uses_exec_auth(self.config_dict, context=cluster_context):
+ self._config_loaded = True
+
+ return
if kubeconfig_path is not None:
self.log.debug("loading kube_config from: %s", kubeconfig_path)
+
await async_config.load_kube_config(
config_file=kubeconfig_path,
client_configuration=self.client_configuration,
context=cluster_context,
)
- self._config_loaded = True
- return
+ try:
+ async with aiofiles.open(kubeconfig_path) as f:
+ content = await f.read()
+ data = yaml.safe_load(content)
+
+ if not self._uses_exec_auth(data, context=cluster_context):
+ self._config_loaded = True
+ except Exception as exc:
+ self.log.warning(
+ "Error while parsing kube_config from %s to detect exec auth; "
+ "continuing without caching the config: %s",
+ kubeconfig_path,
+ exc,
+ )
+
+ return
Review Comment:
New exec-auth detection for `kube_config_path` isn’t covered by tests. There are existing tests for loading from `kube_config_path`, but none assert the new caching behavior (`_config_loaded` stays `False` when the active context uses exec, and `True` otherwise). Adding a unit test that writes an exec-based kubeconfig to `tmp_path` and asserts the resulting `_config_loaded` value would prevent regressions.
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -818,6 +818,31 @@ def __init__(
self._event_polling_fallback = False
self._config_loaded = False
+ def _uses_exec_auth(self, kubeconfig_data: dict, context: str | None = None) -> bool:
+ """
+ Detect if the active kubeconfig context uses exec-based authentication.
+
+ Exec plugins return short-lived tokens (EKS, GKE, etc). Only the user
+ tied to the active context is checked.
Review Comment:
`_uses_exec_auth()` docstring says "Only the user tied to the active context is checked", but the implementation falls back to scanning *all* users when the active context/user can’t be resolved. Please document this fallback behavior (and its intent to err on the side of not caching) to keep the docstring accurate.
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -818,6 +818,31 @@ def __init__(
self._event_polling_fallback = False
self._config_loaded = False
+ def _uses_exec_auth(self, kubeconfig_data: dict, context: str | None = None) -> bool:
+ """
+ Detect if the active kubeconfig context uses exec-based authentication.
+
+ Exec plugins return short-lived tokens (EKS, GKE, etc). Only the user
+ tied to the active context is checked.
+ """
+ active_context = context or kubeconfig_data.get("current-context")
+
+ active_user: str | None = None
+ for ctx in kubeconfig_data.get("contexts", []):
+ if ctx.get("name") == active_context:
+ active_user = ctx.get("context", {}).get("user")
+ break
+
+ users = kubeconfig_data.get("users", [])
+ if active_user is not None:
+ for user in users:
+ if user.get("name") == active_user:
+ return "exec" in user.get("user", {})
+ return False
+
+ # fallback to check all users if active context user cannot be resolved; this is a safe fallback since it errs on the side of not caching
+ return any("exec" in u.get("user", {}) for u in users)
Review Comment:
`_uses_exec_auth()` assumes `ctx["context"]` and `user["user"]` are dicts, but kubeconfig YAML can legally contain empty mappings like `context:` / `user:` which `yaml.safe_load` parses as `None`. In that case, `ctx.get("context", {}).get(...)` or `'exec' in user.get('user', {})` will raise (AttributeError/TypeError) and can fail `_load_config()` for exec detection. Consider normalizing with `ctx_context = ctx.get("context") or {}` and `user_spec = user.get("user") or {}` (and similarly in the fallback `any(...)`) so detection is best-effort and never breaks config loading.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh merged PR #65212:
URL: https://github.com/apache/airflow/pull/65212
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #65212:
URL: https://github.com/apache/airflow/pull/65212#issuecomment-4246322298
Isn't that the same issue as https://github.com/apache/airflow/pull/63610 which we concluded as won't fix since the solution is to bump boto version https://github.com/apache/airflow/issues/60943#issuecomment-3785975556 ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #65212:
URL: https://github.com/apache/airflow/pull/65212#discussion_r3084632913
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -884,50 +871,76 @@ async def _load_config(self):
self._config_loaded = True
return
- # If above block does not return, we are not in a cluster.
self._is_in_cluster = False
-
if self.config_dict:
self.log.debug(LOADING_KUBE_CONFIG_FILE_RESOURCE.format("config dictionary"))
- await async_config.load_kube_config_from_dict(self.config_dict, context=cluster_context)
- self._config_loaded = True
- return
+ await async_config.load_kube_config_from_dict(
+ self.config_dict,
+ context=cluster_context,
+ )
+
+ if not self._uses_exec_auth(self.config_dict, context=cluster_context):
+ self._config_loaded = True
+
+ return
if kubeconfig_path is not None:
self.log.debug("loading kube_config from: %s", kubeconfig_path)
+
Review Comment:
Thanks handled.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #65212:
URL: https://github.com/apache/airflow/pull/65212#discussion_r3084665653
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -818,6 +818,31 @@ def __init__(
self._event_polling_fallback = False
self._config_loaded = False
+ def _uses_exec_auth(self, kubeconfig_data: dict, context: str | None = None) -> bool:
+ """
+ Detect if the active kubeconfig context uses exec-based authentication.
+
+ Exec plugins return short-lived tokens (EKS, GKE, etc). Only the user
+ tied to the active context is checked.
+ """
+ active_context = context or kubeconfig_data.get("current-context")
+
+ active_user: str | None = None
+ for ctx in kubeconfig_data.get("contexts", []):
+ if ctx.get("name") == active_context:
+ active_user = ctx.get("context", {}).get("user")
+ break
+
+ users = kubeconfig_data.get("users", [])
+ if active_user is not None:
+ for user in users:
+ if user.get("name") == active_user:
+ return "exec" in user.get("user", {})
+ return False
+
+ # fallback to check all users if active context user cannot be resolved; this is a safe fallback since it errs on the side of not caching
+ return any("exec" in u.get("user", {}) for u in users)
Review Comment:
Valid ask again, made the changes for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #65212:
URL: https://github.com/apache/airflow/pull/65212#issuecomment-4257904792
Do we need to do that since the dependency is optional?
And this is not an interface change but a bug fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #65212:
URL: https://github.com/apache/airflow/pull/65212#discussion_r3084638433
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -884,50 +871,76 @@ async def _load_config(self):
self._config_loaded = True
return
- # If above block does not return, we are not in a cluster.
self._is_in_cluster = False
-
if self.config_dict:
self.log.debug(LOADING_KUBE_CONFIG_FILE_RESOURCE.format("config dictionary"))
- await async_config.load_kube_config_from_dict(self.config_dict, context=cluster_context)
- self._config_loaded = True
- return
+ await async_config.load_kube_config_from_dict(
+ self.config_dict,
+ context=cluster_context,
+ )
+
+ if not self._uses_exec_auth(self.config_dict, context=cluster_context):
+ self._config_loaded = True
+
+ return
Review Comment:
Yeah actually having a new config for this might turn out cleaner. Handling that using a new private class var: `_is_exec_auth`, with an intent to run `_uses_exec_auth` once per instance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #65212:
URL: https://github.com/apache/airflow/pull/65212#discussion_r3080214221
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -884,50 +871,76 @@ async def _load_config(self):
self._config_loaded = True
return
- # If above block does not return, we are not in a cluster.
self._is_in_cluster = False
-
if self.config_dict:
self.log.debug(LOADING_KUBE_CONFIG_FILE_RESOURCE.format("config dictionary"))
- await async_config.load_kube_config_from_dict(self.config_dict, context=cluster_context)
- self._config_loaded = True
- return
+ await async_config.load_kube_config_from_dict(
+ self.config_dict,
+ context=cluster_context,
+ )
+
+ if not self._uses_exec_auth(self.config_dict, context=cluster_context):
+ self._config_loaded = True
+
+ return
Review Comment:
nit: When exec auth is detected, `load_kube_config_from_dict` is called on every `_load_config()` invocation since `_config_loaded` stays False. Should we consider separating config initialised from config cached to avoid redundant loads?
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -884,50 +871,76 @@ async def _load_config(self):
self._config_loaded = True
return
- # If above block does not return, we are not in a cluster.
self._is_in_cluster = False
-
if self.config_dict:
self.log.debug(LOADING_KUBE_CONFIG_FILE_RESOURCE.format("config dictionary"))
- await async_config.load_kube_config_from_dict(self.config_dict, context=cluster_context)
- self._config_loaded = True
- return
+ await async_config.load_kube_config_from_dict(
+ self.config_dict,
+ context=cluster_context,
+ )
+
+ if not self._uses_exec_auth(self.config_dict, context=cluster_context):
+ self._config_loaded = True
+
+ return
if kubeconfig_path is not None:
self.log.debug("loading kube_config from: %s", kubeconfig_path)
+
Review Comment:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #65212:
URL: https://github.com/apache/airflow/pull/65212#issuecomment-4243815783
Adding back same set of reviewers: @shahar1 @potiuk
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #65212:
URL: https://github.com/apache/airflow/pull/65212#issuecomment-4251065704
Thanks for the pointer! These are actually distinct issues:
- **#60943 / #63610** is a *race condition* — concurrent tasks fighting over the AWS CLI cache directory, causing `FileExistsError`. That's resolved by pre-creating the cache dirs (or botocore ≥ 1.40.2 handling it internally).
- **This PR** is a *token expiry* issue specific to `AsyncKubernetesHook`. On the first `_load_config()` call, the exec plugin runs and obtains a short-lived token (15 min for EKS). Because `_config_loaded = True` is set, all future calls return early — the exec plugin is never re-invoked. After 15 minutes, the expired token is reused and auth fails.
Bumping botocore fixes the race condition but not this: the stale-token problem exists regardless of botocore version, as it is Airflow's hook-level caching that suppresses the reload. Deferrable tasks are especially affected since they can be deferred far longer than the token lifetime.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Do not cache kubeconfig for exec based auth in AsyncKubernetesHook [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #65212:
URL: https://github.com/apache/airflow/pull/65212#discussion_r3084663581
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -846,50 +871,76 @@ async def _load_config(self):
self._config_loaded = True
return
- # If above block does not return, we are not in a cluster.
self._is_in_cluster = False
-
if self.config_dict:
self.log.debug(LOADING_KUBE_CONFIG_FILE_RESOURCE.format("config dictionary"))
- await async_config.load_kube_config_from_dict(self.config_dict, context=cluster_context)
- self._config_loaded = True
- return
+ await async_config.load_kube_config_from_dict(
+ self.config_dict,
+ context=cluster_context,
+ )
+
+ if not self._uses_exec_auth(self.config_dict, context=cluster_context):
+ self._config_loaded = True
+
+ return
if kubeconfig_path is not None:
self.log.debug("loading kube_config from: %s", kubeconfig_path)
+
await async_config.load_kube_config(
config_file=kubeconfig_path,
client_configuration=self.client_configuration,
context=cluster_context,
)
- self._config_loaded = True
- return
+ try:
+ async with aiofiles.open(kubeconfig_path) as f:
+ content = await f.read()
+ data = yaml.safe_load(content)
+
+ if not self._uses_exec_auth(data, context=cluster_context):
+ self._config_loaded = True
+ except Exception as exc:
+ self.log.warning(
+ "Error while parsing kube_config from %s to detect exec auth; "
+ "continuing without caching the config: %s",
+ kubeconfig_path,
+ exc,
+ )
+
+ return
Review Comment:
Added a test that does it: `test_load_config_caching_behavior_kube_config_path`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org