This is an automated email from the ASF dual-hosted git repository.

o-nikolas 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 ec2bd5eafe1 Fix EksPodOperator auth failing when the connection sets 
endpoint_url (#77419)
ec2bd5eafe1 is described below

commit ec2bd5eafe17052d752ca72c0cfdc4ed534f8ac5
Author: Ramit Kataria <[email protected]>
AuthorDate: Wed Nov 25 09:54:55 2026 -0700

    Fix EksPodOperator auth failing when the connection sets endpoint_url 
(#77419)
    
    Since #77163, EksHook.generate_config_file takes the STS URL for the
    kubeconfig from the hook's own connection. The lookup it used falls back
    to the connection-wide endpoint_url. On a connection that points
    endpoint_url at an EKS endpoint (FIPS, or an interface VPC endpoint with
    private DNS off), that EKS URL became the STS URL, and EKS answered every
    request from EksPodOperator with 401 Unauthorized. Before that change the
    STS URL was resolved through aws_default, so those connections worked.
    The regression is not in a released provider version yet.
    
    The connection-wide endpoint_url on an EKS connection is meant for the
    EKS API, and EKS only accepts tokens signed for an STS hostname. The
    kubeconfig therefore uses a custom STS endpoint only when it is set under
    service_config, the same way the STS client for assume role and test
    connection ignores the connection-wide endpoint_url. The endpoint_url
    precedence rules in the AWS connection docs now list this client too.
    
    Reproduced against an EKS cluster in us-west-2 with endpoint_url set to
    https://fips.eks.us-west-2.amazonaws.com on the connection: the hook from
    before the regression authenticates and the current hook gets 401. A
    connection that sets the same URL under service_config.eks, which gives
    the STS URL this change restores, authenticates.
---
 providers/amazon/docs/connections/aws.rst          |  6 +++--
 .../src/airflow/providers/amazon/aws/hooks/eks.py  |  4 ++-
 .../amazon/tests/unit/amazon/aws/hooks/test_eks.py | 29 ++++++++++++++++------
 3 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/providers/amazon/docs/connections/aws.rst 
b/providers/amazon/docs/connections/aws.rst
index 6902c7b2b06..328ebeb13dc 100644
--- a/providers/amazon/docs/connections/aws.rst
+++ b/providers/amazon/docs/connections/aws.rst
@@ -362,8 +362,10 @@ For enforce to default ``botocore``/``boto3`` behaviour 
you might set value to `
 The precedence rules are as follows:
 
   1. ``endpoint_url`` specified per service level.
-  2. ``endpoint_url`` specified in root level of connection extra. Please note 
that **sts** client which are
-     uses in assume role or test connection do not use global parameter.
+  2. ``endpoint_url`` specified in root level of connection extra. Please note 
that the **sts** clients
+     used for assume role, for test connection, and by
+     :class:`~airflow.providers.amazon.aws.hooks.eks.EksHook` to build the 
kubeconfig for
+     :class:`~airflow.providers.amazon.aws.operators.eks.EksPodOperator` do 
not use the global parameter.
   3. Default ``botocore``/``boto3`` behaviour
 
 
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 06511d8a32e..23c3cecb3c3 100644
--- a/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py
+++ b/providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py
@@ -674,7 +674,9 @@ class EksHook(AwsBaseHook):
         session._session.set_config_variable("sts_regional_endpoints", 
"regional")
         sts_client = session.client(
             "sts",
-            endpoint_url=self.conn_config.get_service_endpoint_url("sts"),
+            # sts_connection_assume skips the connection-wide endpoint_url, 
which on an EKS connection is
+            # an EKS endpoint, and EKS rejects tokens signed for a non-STS 
host.
+            endpoint_url=self.conn_config.get_service_endpoint_url("sts", 
sts_connection_assume=True),
             config=self.config,
             verify=self.verify,
         )
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 1877f6945f1..df08f8f9c34 100644
--- a/providers/amazon/tests/unit/amazon/aws/hooks/test_eks.py
+++ b/providers/amazon/tests/unit/amazon/aws/hooks/test_eks.py
@@ -1382,14 +1382,27 @@ class TestEksHook:
         assert f"--sts-url '{regional_sts_url}'" in command_arg
         assert os.environ["AWS_STS_REGIONAL_ENDPOINTS"] == "legacy"
 
+    @pytest.mark.parametrize(
+        ("extra", "expected_sts_endpoint"),
+        [
+            pytest.param(
+                {"service_config": {"sts": {"endpoint_url": 
"https://sts-fips.us-west-2.amazonaws.com"}}},
+                "https://sts-fips.us-west-2.amazonaws.com";,
+                id="sts-service-config",
+            ),
+            pytest.param(
+                {"endpoint_url": "https://fips.eks.us-west-2.amazonaws.com"},
+                "https://sts.us-west-2.amazonaws.com";,
+                id="connection-wide-endpoint-url-is-not-used",
+            ),
+        ],
+    )
     @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"}}},
-        )
+    def test_generate_config_file_uses_sts_endpoint_of_hook_connection(
+        self, mock_conn, mock_get_connection, extra, expected_sts_endpoint
+    ):
+        mock_get_connection.return_value = Connection(conn_id="eks_conn", 
conn_type="aws", extra=extra)
         mock_conn.return_value.describe_cluster.return_value = {
             "cluster": {"certificateAuthority": {"data": "test-cert"}, 
"endpoint": "test-endpoint"}
         }
@@ -1403,8 +1416,8 @@ class TestEksHook:
             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
+        sts_url = 
f"{expected_sts_endpoint}/?Action=GetCallerIdentity&Version=2011-06-15"
+        assert f"--sts-url '{sts_url}'" in command_arg
         mock_get_connection.assert_called_with("eks_conn")
 
     def test_command_template_captures_stderr_separately(self):

Reply via email to