Skip to content

Fix exec-plugin cache dir race condition in KubernetesHook - #63610

Closed
Vamsi-klu wants to merge 2 commits into
apache:mainfrom
Vamsi-klu:fix/k8s-exec-plugin-cache-dir-race
Closed

Vamsi-klu wants to merge 2 commits into
apache:mainfrom
Vamsi-klu:fix/k8s-exec-plugin-cache-dir-race

Conversation

@Vamsi-klu

@Vamsi-klu Vamsi-klu commented Mar 14, 2026 •

Copy link
Copy Markdown

Summary

Pre-create cache directories used by exec-based authentication plugins before
establishing the Kubernetes API connection in KubernetesHook.get_conn().

When multiple tasks run concurrently on the same Celery worker, each may invoke
an exec-based credential plugin (e.g., AWS IAM authenticator) in parallel. Some
plugin implementations create their cache directories with os.makedirs()
without exist_ok=True, which causes a FileExistsError race condition when
two processes attempt the creation simultaneously.

This fix defensively pre-creates known cache directories so they already exist
by the time any exec plugin runs.

Co-contributors: @codingrealitylabs @girlcoder-gaming

closes: #60943

Test plan

  • test_creates_cache_dirs — verifies directories are created when missing
  • test_no_error_when_dir_already_exists — verifies no error when dirs already exist
  • test_get_conn_calls_ensure_cache_dirs — verifies get_conn() calls the pre-creation function
  • Ruff lint and format pass
  • All tests pass locally

Note: This fix was originally included in PR #62656 (structlog serialization fix) by mistake.
It has been split out into its own PR as requested by reviewers.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Claude Opus 4.6)

Generated-by: Claude Code (Claude Opus 4.6) following the guidelines

@boring-cyborg boring-cyborg Bot added area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues labels Mar 14, 2026
@Vamsi-klu

This comment was marked as spam.

@Vamsi-klu

This comment was marked as spam.

@jscheffl

Copy link
Copy Markdown
Contributor

We had a discussion about this topic recently in another PR... need to take a look for this. We do not want to have provider (=aws) specific code in the generic CNCF provider.

@jscheffl

Copy link
Copy Markdown
Contributor

Ah, it was this here: #61936

@Vamsi-klu

This comment was marked as spam.

@jscheffl jscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you request feedback: Then like in the previous PR this is a race condition specifically as needed for AWS credentials. Can you therefore please make this into the AWS specific provider package? I think the generic CNCF provider (in my view) should be neutral to any potential race condition of a specific other provider feature.

I assume it migt be best in EcsHook as the right place.

Pre-create ~/.aws/cli/cache in EksHook.generate_config_file() to
prevent a FileExistsError when parallel tasks on the same Celery
worker invoke aws eks get-token simultaneously. Older botocore
versions call os.makedirs() without exist_ok=True, causing a race.

The fix lives in the Amazon provider (not the CNCF Kubernetes
provider) because the race condition is specific to the AWS CLI
cache directory.

closes: apache#60943
@Vamsi-klu
Vamsi-klu force-pushed the fix/k8s-exec-plugin-cache-dir-race branch from 6e84965 to 09eee0a Compare March 17, 2026 06:04
@Vamsi-klu
Vamsi-klu requested a review from o-nikolas as a code owner March 17, 2026 06:04
@Vamsi-klu

This comment was marked as spam.

@Vamsi-klu
Vamsi-klu requested a review from jscheffl March 17, 2026 06:10

@jscheffl jscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for the rework.

Would kindly request one of the AWS provider maintainers for another pair of eyes.

@Vamsi-klu

This comment was marked as spam.

@jscheffl

Copy link
Copy Markdown
Contributor

I think you should not call for reviews on individual contributors. This limits your visibility. While Jarek is one of the most active this is a change rather in AWS territory, so I did not merge looking for some AWS maintainer review.

@o-nikolas Can you make a review?

@eladkal

eladkal commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

The comment in #60943 (comment) suggest this issue is already resolved in botocore 1.40.2
Since we have

"botocore>=1.41.0",

I don't understand what are we fixing here?

I am aware that previous attempts were to fix the issue in K8s provider (for users who use newer versions of k8s provider with older versions of amazon provider) but since that approach was a no go I don't understand the benefit of this PR

@o-nikolas

Copy link
Copy Markdown
Contributor

Agreed with @eladkal here, I'll close this one unless @Vamsi-klu would like to make another argument as to why we need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race Condition in AWS CLI Cache Creation During Parallel KubernetesPodOperator Authentication

4 participants