symat commented on code in PR #77163:
URL: https://github.com/apache/airflow/pull/77163#discussion_r4643545969


##########
providers/amazon/src/airflow/providers/amazon/aws/hooks/eks.py:
##########
@@ -669,11 +669,10 @@ def generate_config_file(
         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 needs the regional STS endpoint, which botocore uses by default 
since 1.40. Do not set
+        # AWS_STS_REGIONAL_ENDPOINTS here: the environment is shared by every 
trigger in the triggerer.
+        sts_endpoint = 
StsHook(region_name=session.region_name).conn_client_meta.endpoint_url

Review Comment:
   Good catch, thanks!!
   I didn't test the legacy case against EKS, and looking into it, it would 
break. (at least in some of the regions) 
   
   `eks_get_token` signs with the cluster's region, so for a cluster in, e.g., 
`us-west-2` or `eu-west-1` with `legacy` set, STS answers  
_SignatureDoesNotMatch_  and EKS rejects the token. Clusters in `us-east-1`, 
and regions that never had a global mapping, would keep working AFAIU. (I 
haven't tested it)
   
   I'll try and fix this in a different way: keep the regional endpoint forced, 
but scoped to the STS session the hook creates, instead of the process 
environment: `set_config_variable("sts_regional_endpoints", "regional")` on 
that botocore session. It is a bit hacky (reaching into boto's session), but I 
don't really see an other relatively easy solution. WDYT? This should fix the 
race condition issue and keep the previous behaviour. I'll start testing it on 
on my cluster today. 
   
   Note: I haven't tested, but the `AwsEksExecutor` seems to have the same  
_SignatureDoesNotMatch_  issue now with `legacy`, we might want to fix it too 
(either in this PR or in a different one)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to