This is an automated email from the ASF dual-hosted git repository.
vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new d406d086ead Stop deferred EksPodOperator tasks failing when they start
together (#77163)
d406d086ead is described below
commit d406d086eadbdd07344f4ae14d688d5c3121fe15
Author: Mate Szalay-Beko <[email protected]>
AuthorDate: Fri Nov 20 21:08:54 2026 +0100
Stop deferred EksPodOperator tasks failing when they start together (#77163)
* Stop deferred EksPodOperator tasks failing when they start together
The triggerer runs all triggers in one process, and while a trigger waits
for a sync connection lookup it lets other triggers run. EksHook set
AWS_STS_REGIONAL_ENDPOINTS for the whole process around such a lookup in
generate_config_file and deleted it afterwards, so when two EksPodTriggers
overlapped, the second delete raised KeyError and the task failed. It also
removed a value the user had set themselves.
botocore already resolves the regional STS endpoint by default, which
AwsEksExecutor relies on as well.
* Force regional STS per session in EksHook kubeconfig
With sts_regional_endpoints=legacy the kubeconfig got the global STS
endpoint, which rejects tokens signed for regions other than us-east-1.
Setting it on the hook's own session keeps the environment shared by all
triggers untouched and uses the EKS connection's STS settings instead of
aws_default.
---
.../src/airflow/providers/amazon/aws/hooks/eks.py | 17 +++++---
.../amazon/tests/unit/amazon/aws/hooks/test_eks.py | 48 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py
b/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py
index 70409e3b62e..06511d8a32e 100644
--- a/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py
+++ b/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py
@@ -32,7 +32,6 @@ from functools import partial
from botocore.exceptions import ClientError
from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
-from airflow.providers.amazon.aws.hooks.sts import StsHook
from airflow.utils import yaml
DEFAULT_PAGINATION_TOKEN = ""
@@ -669,11 +668,17 @@ class EksHook(AwsBaseHook):
cluster_cert = cluster["cluster"]["certificateAuthority"]["data"]
cluster_ep = cluster["cluster"]["endpoint"]
- os.environ["AWS_STS_REGIONAL_ENDPOINTS"] = "regional"
- try:
- sts_url =
f"{StsHook(region_name=session.region_name).conn_client_meta.endpoint_url}/?Action=GetCallerIdentity&Version=2011-06-15"
- finally:
- del os.environ["AWS_STS_REGIONAL_ENDPOINTS"]
+ # eks_get_token signs the URL with the cluster region, which the
global STS endpoint rejects outside
+ # us-east-1, so force the regional endpoint on this session even if
the user configured "legacy".
+ # Not through the environment variable: the environment is shared by
every trigger in the triggerer.
+ session._session.set_config_variable("sts_regional_endpoints",
"regional")
+ sts_client = session.client(
+ "sts",
+ endpoint_url=self.conn_config.get_service_endpoint_url("sts"),
+ config=self.config,
+ verify=self.verify,
+ )
+ sts_url =
f"{sts_client.meta.endpoint_url}/?Action=GetCallerIdentity&Version=2011-06-15"
cluster_config = {
"apiVersion": "v1",
diff --git a/providers/amazon/tests/unit/amazon/aws/hooks/test_eks.py
b/providers/amazon/tests/unit/amazon/aws/hooks/test_eks.py
index 26c35383f0a..1877f6945f1 100644
--- a/providers/amazon/tests/unit/amazon/aws/hooks/test_eks.py
+++ b/providers/amazon/tests/unit/amazon/aws/hooks/test_eks.py
@@ -18,6 +18,7 @@
from __future__ import annotations
import json
+import os
import subprocess
import sys
from contextlib import AbstractContextManager
@@ -58,6 +59,7 @@ from moto.eks.models import (
NODEGROUP_NOT_FOUND_MSG,
)
+from airflow.models.connection import Connection
from airflow.providers.amazon.aws.hooks.eks import COMMAND, EksHook
from unit.amazon.aws.utils.eks_test_constants import (
@@ -1359,6 +1361,52 @@ class TestEksHook:
if expected_region_args:
assert expected_region_args in command_arg
+ @mock.patch.object(EksHook, "conn", new_callable=PropertyMock)
+ def
test_generate_config_file_uses_regional_sts_and_keeps_environment(self,
mock_conn, monkeypatch):
+ """The kubeconfig gets the regional STS endpoint even with "legacy",
and the environment is unchanged."""
+ monkeypatch.setenv("AWS_STS_REGIONAL_ENDPOINTS", "legacy")
+ mock_conn.return_value.describe_cluster.return_value = {
+ "cluster": {"certificateAuthority": {"data": "test-cert"},
"endpoint": "test-endpoint"}
+ }
+ hook = EksHook(aws_conn_id=None, region_name="us-west-2")
+
+ with hook.generate_config_file(
+ eks_cluster_name="test-cluster",
+ pod_namespace="ns",
+ credentials_file="/tmp/test_credentials.aws_creds",
+ ) as config_file:
+ config = yaml.safe_load(Path(config_file).read_text())
+
+ command_arg = config["users"][0]["user"]["exec"]["args"][1]
+ regional_sts_url =
"https://sts.us-west-2.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15"
+ assert f"--sts-url '{regional_sts_url}'" in command_arg
+ assert os.environ["AWS_STS_REGIONAL_ENDPOINTS"] == "legacy"
+
+ @mock.patch.object(EksHook, "get_connection")
+ @mock.patch.object(EksHook, "conn", new_callable=PropertyMock)
+ def test_generate_config_file_uses_sts_endpoint_of_hook_connection(self,
mock_conn, mock_get_connection):
+ mock_get_connection.return_value = Connection(
+ conn_id="eks_conn",
+ conn_type="aws",
+ extra={"service_config": {"sts": {"endpoint_url":
"https://sts-fips.us-west-2.amazonaws.com"}}},
+ )
+ mock_conn.return_value.describe_cluster.return_value = {
+ "cluster": {"certificateAuthority": {"data": "test-cert"},
"endpoint": "test-endpoint"}
+ }
+ hook = EksHook(aws_conn_id="eks_conn", region_name="us-west-2")
+
+ with hook.generate_config_file(
+ eks_cluster_name="test-cluster",
+ pod_namespace="ns",
+ credentials_file="/tmp/test_credentials.aws_creds",
+ ) as config_file:
+ config = yaml.safe_load(Path(config_file).read_text())
+
+ command_arg = config["users"][0]["user"]["exec"]["args"][1]
+ fips_sts_url =
"https://sts-fips.us-west-2.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15"
+ assert f"--sts-url '{fips_sts_url}'" in command_arg
+ mock_get_connection.assert_called_with("eks_conn")
+
def test_command_template_captures_stderr_separately(self):
"""Verify COMMAND keeps stderr out of stdout while preserving
errors."""
# Verify stderr is not merged with stdout (the core correctness
requirement)