Repository navigation
Fix race condition in AWS CLI cache creation during parallel KubernetesPodOperator auth (#60943) - #61935
Fix race condition in AWS CLI cache creation during parallel KubernetesPodOperator auth (#60943)#61935Vamsi-klu wants to merge 1 commit into
Conversation
…esPodOperator auth (apache#60943) Pre-create ~/.aws/cli/cache directory in KubernetesHook.get_conn() to prevent a FileExistsError race condition when multiple KPO tasks authenticate via `aws eks get-token` concurrently on the same Celery worker. Older botocore versions (<1.40.2) call os.makedirs() without exist_ok=True, causing intermittent task failures before pod creation. closes: apache#60943
| # authentication (e.g. ``aws eks get-token``). Pre-creating it avoids the race. | ||
| # See: https://github.com/apache/airflow/issues/60943 | ||
| # https://github.com/boto/botocore/commit/f1c1bc90 | ||
| _AWS_CLI_CACHE_DIR = os.path.join(os.path.expanduser("~"), ".aws", "cli", "cache") |
There was a problem hiding this comment.
Similar like my comments in #61936: Why are there AWS specifc changes made in K8s standard package? If AWS specific they should land in AWS provider.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
@o-nikolas / @eladkal same here - any guidance from your experience?
There was a problem hiding this comment.
Same answer as here
I think I prefer 1 or 3, I don't like the complication of 2 for such a small usecase
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
|
I do not see any changes, is there a new PR? Or forgot to push? Can same approach also be made for #61936 (comment) ? |
|
@Vamsi-klu This PR has been converted to draft because it does not yet meet our Pull Request quality criteria. Issues found:
What to do next:
Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. If you have questions, feel free to ask on the Airflow Slack. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
This comment was marked as spam.
This comment was marked as spam.
|
closing in favor of #63610 |
Summary
~/.aws/cli/cachedirectory inKubernetesHook.get_conn()to prevent aFileExistsErrorrace condition when multiple KPO tasks authenticate viaaws eks get-tokenconcurrently on the same Celery workeros.makedirs()withoutexist_ok=True, causing intermittent task failures before pod creationRoot Cause
When parallel KubernetesPodOperator tasks invoke exec-based EKS authentication on the same worker, the AWS CLI races to create
~/.aws/cli/cache. The losing process getsFileExistsError(errno 17), which surfaces as a 403 Forbidden from the Kubernetes API — the task fails before the pod is even created.Fixed upstream in botocore 1.40.2, but this defensive fix protects users on older versions.
Why this approach (and not something else)
We considered several alternatives before landing on defensive directory pre-creation:
generic_api_retryTRANSIENT_STATUS_CODESwould mask real auth failures and add retry latency to every legitimate 403. Distinguishing transient exec-auth 403s from real permission denials is not reliably possible — the Kubernetes client's ExecProvider silently swallows the subprocess error and proceeds with a bad token, so the 403 looks identical to a genuine RBAC denial.threading.Lockaround config loadingaws eks get-token) runs lazily during the first API call, not duringconfig.load_kube_config(). A lock around config loading wouldn't prevent the race. Locking around every API call would serialize all K8s operations — unacceptable for performance.botocore >= 1.40.2as a dependencyWhy pre-creation wins:
os.makedirs(..., exist_ok=True)call — the exact same fix botocore 1.40.2 applied, just done earlier in the call chainexist_ok=Trueis inherently safe for concurrent invocations — no race between our pre-creation and the AWS CLIChanges
hooks/kubernetes.py: Added_ensure_exec_plugin_cache_dirs()function called fromget_conn()before any kube config loading. Usesos.makedirs(..., exist_ok=True)to pre-create the cache directory.test_kubernetes.py: 3 new test cases verifying directory creation, idempotency, and integration withget_conn().closes: #60943
Test plan