@@ -42,8 +42,7 @@ export class Compute extends OAuth2Client {
4242 private static readonly EMAIL_REGEX = / ^ [ ^ @ ] + @ [ ^ @ ] + \. [ ^ @ ] + $ / ;
4343 readonly serviceAccountEmail : string ;
4444 scopes : string [ ] ;
45- private rabLookupSkippedWarningLogged = false ;
46- private resolvedServiceAccountEmail ?: string ;
45+ private isNonEmailAccount = false ;
4746
4847 /**
4948 * Google Compute Engine service account credentials.
@@ -145,21 +144,18 @@ export class Compute extends OAuth2Client {
145144
146145 /**
147146 * Returns the regional access boundary lookup URL for the GCE instance.
148- * This implementation resolves the default service account email of the GCE
149- * instance to construct the lookup endpoint.
147+ * This implementation resolves the service account email of the GCE
148+ * instance to construct the lookup endpoint. If the resolved email is invalid
149+ * or not found, it returns `null` to skip the regional access boundary check.
150150 *
151- * @return The regional access boundary URL string.
151+ * @return The regional access boundary URL string, or null if regional access
152+ * boundary checks should be skipped.
152153 * @internal
153154 */
154155 public async getRegionalAccessBoundaryUrl ( ) : Promise < string | null > {
155156 const email = await this . resolveServiceAccountEmail ( ) ;
156- if ( ! email || ! Compute . EMAIL_REGEX . test ( email ) ) {
157- if ( ! this . rabLookupSkippedWarningLogged ) {
158- AuthClient . log . info (
159- `RegionalAccessBoundary: Service account email "${ email } " is not in a valid email format. Skipping regional access boundary lookup.` ,
160- ) ;
161- this . rabLookupSkippedWarningLogged = true ;
162- }
157+ if ( email === null ) {
158+ // This credential corresponds to a non-email account; skip RAB lookup.
163159 return null ;
164160 }
165161 const regionalAccessBoundaryUrl = SERVICE_ACCOUNT_LOOKUP_ENDPOINT . replace (
@@ -172,24 +168,34 @@ export class Compute extends OAuth2Client {
172168 /**
173169 * Resolves the service account email. If the email is set to 'default',
174170 * it fetches the email from the GCE metadata server.
175- * @returns A promise that resolves with the service account email.
171+ * @returns A promise that resolves with the service account email,
172+ * or null if MDS returns an invalid email format
176173 */
177- private async resolveServiceAccountEmail ( ) : Promise < string > {
174+ private async resolveServiceAccountEmail ( ) : Promise < string | null > {
175+ if ( this . isNonEmailAccount ) {
176+ return null ;
177+ }
178+
178179 if ( this . serviceAccountEmail !== 'default' ) {
179180 // If a specific email is provided, return it directly.
180181 return this . serviceAccountEmail ;
181182 }
182183
183- if ( this . resolvedServiceAccountEmail !== undefined ) {
184- return this . resolvedServiceAccountEmail ;
185- }
186-
187184 // Otherwise, fetch the default email from the metadata server.
188185 try {
189186 const email = await gcpMetadata . instance < string > (
190187 'service-accounts/default/email' ,
191188 ) ;
192- this . resolvedServiceAccountEmail = email ;
189+
190+ // If the metadata server returned an non-email format, log a warning only once.
191+ if ( ! email || ! Compute . EMAIL_REGEX . test ( email ) ) {
192+ AuthClient . log . info (
193+ `RegionalAccessBoundary: Service account email "${ email } " is not in a valid email format. Skipping regional access boundary lookup.` ,
194+ ) ;
195+ this . isNonEmailAccount = true ;
196+ return null ;
197+ }
198+
193199 return email ;
194200 } catch ( e ) {
195201 throw new Error (
0 commit comments