Skip to content

Commit eaff9c0

Browse files
google-genai-botDeanChensj
authored andcommitted
feat: Update check-file-contents.yml to check for non-mTLS hardcoded endpoints
Merge 29fcd80 into 104edc8 ORIGINAL_AUTHOR=agrawalradhika-cell <agrawalradhika@google.com> GitOrigin-RevId: 46a8802 Change-Id: I3c6c4e92c92c99567be2bb938e95ae950bbbc634
1 parent 104edc8 commit eaff9c0

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

.github/workflows/check-file-contents.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,37 @@ jobs:
100100
else
101101
echo "✅ No relevant Python files found."
102102
fi
103+
104+
- name: Check for hardcoded googleapis.com endpoints
105+
run: |
106+
git fetch origin ${GITHUB_BASE_REF}
107+
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${GITHUB_BASE_REF}...HEAD | grep -E '\.py$' || true)
108+
if [ -n "$CHANGED_FILES" ]; then
109+
echo "Checking for hardcoded endpoints in: $CHANGED_FILES"
110+
111+
# 1. Identify files containing any googleapis.com URL.
112+
set +e
113+
FILES_WITH_ENDPOINTS=$(grep -lE 'https?://[a-zA-Z0-9.-]+\.googleapis\.com' $CHANGED_FILES)
114+
115+
# 2. From those, identify files that are MISSING the required mTLS version.
116+
if [ -n "$FILES_WITH_ENDPOINTS" ]; then
117+
FILES_MISSING_MTLS=$(grep -L '.mtls.googleapis.com' $FILES_WITH_ENDPOINTS)
118+
fi
119+
set -e
120+
121+
if [ -n "$FILES_MISSING_MTLS" ]; then
122+
echo "❌ Found hardcoded googleapis.com endpoints without mTLS support."
123+
echo "The following files must define both standard and mTLS (.mtls.googleapis.com) endpoints"
124+
echo "to support dynamic endpoint selection as required by security policy:"
125+
echo "$FILES_MISSING_MTLS"
126+
echo ""
127+
echo "To fix this, please follow these steps:"
128+
echo "1. Initialize an AuthorizedSession with your credentials."
129+
echo "2. Use 'mtls.has_default_client_cert_source() from google-auth' to check for available client certificates."
130+
echo "3. If certificates are present, use 'session.configure_mtls_channel()'."
131+
echo "4. Dynamically select the '.mtls.' variant of the endpoint when mTLS is active."
132+
exit 1
133+
else
134+
echo "✅ All hardcoded endpoints have corresponding mTLS definitions or no endpoints found."
135+
fi
136+
fi

0 commit comments

Comments
 (0)