@@ -108,6 +108,13 @@ public final class AuthenticationDetailsFactory
108108 */
109109 public static final Parameter <String > USERNAME = Parameter .create ();
110110
111+ /**
112+ * Timeout in seconds for instance principal authentication.
113+ * Optional – defaults to 5 seconds if not explicitly configured.
114+ */
115+ public static final Parameter <Integer > INSTANCE_PRINCIPAL_TIMEOUT =
116+ Parameter .create ();
117+
111118 /**
112119 * <p>
113120 * An OCI region provided by instances of
@@ -187,7 +194,7 @@ private static AbstractAuthenticationDetailsProvider getAuthenticationDetails(
187194 case CLOUD_SHELL :
188195 return cloudShellAuthentication ();
189196 case INSTANCE_PRINCIPAL :
190- return instancePrincipalAuthentication ();
197+ return instancePrincipalAuthentication (parameterSet );
191198 case RESOURCE_PRINCIPAL :
192199 return resourcePrincipalAuthentication ();
193200 case INTERACTIVE :
@@ -312,7 +319,7 @@ private static AbstractAuthenticationDetailsProvider getAuthenticationDetails(
312319 }
313320
314321 try {
315- return instancePrincipalAuthentication ();
322+ return instancePrincipalAuthentication (parameters );
316323 }
317324 catch (RuntimeException notComputeInstance ) {
318325 previousFailure .addSuppressed (
@@ -332,17 +339,23 @@ private static AbstractAuthenticationDetailsProvider getAuthenticationDetails(
332339 * </p><p>
333340 * It is thought that authentication as an instance principal should not take
334341 * more than a few seconds to complete, so this method will throw an
335- * {@code IllegalStateException} if a timeout of 5 seconds is exceeded.
342+ * {@code IllegalStateException} if the operation exceeds the configured
343+ * timeout (5 seconds by default).
344+ * </p><p>
345+ * The timeout can be overridden using the optional
346+ * {@code INSTANCE_PRINCIPAL_TIMEOUT} parameter (value in seconds), which can
347+ * be provided in the URI query string.
336348 * </p>
337349 * @return Authentication details for an instance principal. Not null.
338350 * @throws IllegalStateException If the current environment is not a compute
339351 * instance.
340352 */
341353 private static InstancePrincipalsAuthenticationDetailsProvider
342- instancePrincipalAuthentication () {
354+ instancePrincipalAuthentication (ParameterSet parameters ) {
355+ int timeoutSeconds = parameters .getOptional (INSTANCE_PRINCIPAL_TIMEOUT );
343356 try {
344357 return InstancePrincipalAuthenticationTask .FUTURE
345- .get (5 , TimeUnit .SECONDS );
358+ .get (timeoutSeconds , TimeUnit .SECONDS );
346359 }
347360 catch (ExecutionException exception ) {
348361 throw new IllegalStateException (
@@ -356,8 +369,8 @@ private static AbstractAuthenticationDetailsProvider getAuthenticationDetails(
356369 }
357370 catch (TimeoutException timeoutException ) {
358371 throw new IllegalStateException (
359- "Authentication as an instance principal did not complete within" +
360- " 5 seconds" ,
372+ "Authentication as an instance principal did not complete within "
373+ + timeoutSeconds + " seconds" ,
361374 timeoutException );
362375 }
363376 }
0 commit comments