5959from __future__ import annotations
6060
6161import argparse
62- import hashlib
6362import json
6463import os
65- import socket
66- import ssl
6764import sys
6865from dataclasses import dataclass , field
6966from pathlib import Path
8481OIDC_AUDIENCE = "aws.workload.identity"
8582STATIC_AWS_VARS = ("AWS_ACCESS_KEY_ID" , "AWS_SECRET_ACCESS_KEY" , "AWS_SESSION_TOKEN" )
8683
84+ # Placeholder thumbprint sent to AWS when creating the OIDC provider. AWS's
85+ # `CreateOpenIDConnectProvider` accepts a `ThumbprintList` parameter that
86+ # was historically expected to be the SHA1 hash of the provider's TLS
87+ # certificate. Since July 2023 AWS no longer validates this value for
88+ # providers backed by Amazon Trust Services CAs (which app.terraform.io
89+ # is) — the cert chain is validated at runtime against the ATS root CAs.
90+ # Any 40-char hex string is accepted in the field.
91+ # See: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html
92+ #
93+ # Sending a placeholder removes the need for this script to make a TLS
94+ # connection to app.terraform.io and SHA1-hash the leaf cert — both of
95+ # which trip CodeQL's py/insecure-protocol and py/weak-sensitive-data-hashing
96+ # rules even though neither is a security concern in this context.
97+ OIDC_PROVIDER_THUMBPRINT_PLACEHOLDER = "0" * 40
98+
8799
88100# ---------------------------------------------------------------------------
89101# CLI
@@ -258,16 +270,6 @@ def parse_args(argv: list[str] | None = None) -> Args:
258270# ---------------------------------------------------------------------------
259271
260272
261- def _terraform_thumbprint () -> str :
262- ctx = ssl .create_default_context ()
263- with socket .create_connection ((OIDC_PROVIDER_URL , 443 ), timeout = 10 ) as sock :
264- with ctx .wrap_socket (sock , server_hostname = OIDC_PROVIDER_URL ) as ssock :
265- cert = ssock .getpeercert (binary_form = True )
266- # AWS API expects SHA1; this is not used as a security primitive (since
267- # July 2023 AWS validates the certificate chain, not the thumbprint).
268- return hashlib .sha1 (cert ).hexdigest () # noqa: S324
269-
270-
271273def ensure_identity_provider (iam ) -> tuple [str , bool ]:
272274 """Return (OIDC provider ARN, was_created). Idempotent: reuses any
273275 existing provider for the same URL rather than recreating it.
@@ -285,7 +287,7 @@ def ensure_identity_provider(iam) -> tuple[str, bool]:
285287 resp = iam .create_open_id_connect_provider (
286288 Url = expected_url ,
287289 ClientIDList = [OIDC_AUDIENCE ],
288- ThumbprintList = [_terraform_thumbprint () ],
290+ ThumbprintList = [OIDC_PROVIDER_THUMBPRINT_PLACEHOLDER ],
289291 )
290292 return resp ["OpenIDConnectProviderArn" ], True
291293
0 commit comments