From ee2eb14f99ad6c53d525fe0493183ecf3cd29ba7 Mon Sep 17 00:00:00 2001 From: whowes Date: Wed, 18 Nov 2026 14:45:27 +0000 Subject: [PATCH 1/2] test: ignore the JDK_JAVA_OPTIONS notice in skaffold mojo tests --- .../tools/jib/maven/skaffold/PackageGoalsMojoTest.java | 7 ++++--- .../cloud/tools/jib/maven/skaffold/SyncMapMojoTest.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/skaffold/PackageGoalsMojoTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/skaffold/PackageGoalsMojoTest.java index dbd80d4e77..4db559be67 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/skaffold/PackageGoalsMojoTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/skaffold/PackageGoalsMojoTest.java @@ -52,9 +52,10 @@ private void verifyGoals(Path projectRoot, String profilesString, String... expe verifier.verifyErrorFreeLog(); Path logFile = Paths.get(verifier.getBasedir()).resolve(verifier.getLogFileName()); List log = Files.readAllLines(logFile, StandardCharsets.UTF_8); - if (log.size() != 0 && log.get(0).startsWith("Picked up JAVA_TOOL_OPTIONS:")) { - log.remove(0); - } + log.removeIf( + line -> + line.startsWith("Picked up JAVA_TOOL_OPTIONS:") + || line.startsWith("NOTE: Picked up JDK_JAVA_OPTIONS:")); Assert.assertEquals(Arrays.asList(expectedGoals), log); } diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/skaffold/SyncMapMojoTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/skaffold/SyncMapMojoTest.java index 31001fe075..14aad3ac8e 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/skaffold/SyncMapMojoTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/skaffold/SyncMapMojoTest.java @@ -68,9 +68,10 @@ private static String getSyncMapJson(Path projectRoot, String module, String pom throws VerificationException, IOException { Path logFile = runBuild(projectRoot, module, pomXml); List outputLines = Files.readAllLines(logFile, StandardCharsets.UTF_8); - if (outputLines.size() != 0 && outputLines.get(0).startsWith("Picked up JAVA_TOOL_OPTIONS:")) { - outputLines.remove(0); - } + outputLines.removeIf( + line -> + line.startsWith("Picked up JAVA_TOOL_OPTIONS:") + || line.startsWith("NOTE: Picked up JDK_JAVA_OPTIONS:")); Assert.assertEquals(3, outputLines.size()); // we expect ["\n", "", ""] Assert.assertEquals("BEGIN JIB JSON: SYNCMAP/1", outputLines.get(1)); return outputLines.get(2); // this is the JSON output From 04ca380bcbfe204ceaf69dae2dc17f8881f02555 Mon Sep 17 00:00:00 2001 From: whowes Date: Wed, 11 Nov 2026 03:20:39 +0000 Subject: [PATCH 2/2] fix: do not send OAuth2 refresh tokens over plain HTTP unless sendCredentialsOverHttp is set --- jib-core/CHANGELOG.md | 1 + .../tools/jib/http/FailoverHttpClient.java | 6 ++++ .../google/cloud/tools/jib/http/Request.java | 24 +++++++++++++ .../jib/registry/RegistryAuthenticator.java | 2 +- .../jib/http/FailoverHttpClientTest.java | 34 +++++++++++++++++++ .../registry/RegistryAuthenticatorTest.java | 20 +++++++++++ jib-gradle-plugin/CHANGELOG.md | 1 + jib-maven-plugin/CHANGELOG.md | 1 + 8 files changed, 88 insertions(+), 1 deletion(-) diff --git a/jib-core/CHANGELOG.md b/jib-core/CHANGELOG.md index 7d94150be4..23112e3457 100644 --- a/jib-core/CHANGELOG.md +++ b/jib-core/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Changed ### Fixed +- fix: do not send OAuth2 refresh tokens over plain HTTP unless `sendCredentialsOverHttp` is set ## 0.28.2 diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/http/FailoverHttpClient.java b/jib-core/src/main/java/com/google/cloud/tools/jib/http/FailoverHttpClient.java index f7e1f5daa2..2eea20695c 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/http/FailoverHttpClient.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/http/FailoverHttpClient.java @@ -325,6 +325,12 @@ private Response call( boolean retryOnIoException) // See https://github.com/GoogleContainerTools/jib/issues/3424 throws IOException { boolean clearAuthorization = !isHttpsProtocol(url) && !sendAuthorizationOverHttp; + if (clearAuthorization && request.hasCredentialBody()) { + throw new SSLException( + "credentials not sent over insecure HTTP connection: " + + url + + "; use HTTPS or set the 'sendCredentialsOverHttp' system property to true"); + } HttpHeaders requestHeaders = clearAuthorization diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/http/Request.java b/jib-core/src/main/java/com/google/cloud/tools/jib/http/Request.java index fc5a766ccb..31fa6e5e14 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/http/Request.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/http/Request.java @@ -30,6 +30,9 @@ public class Request { /** The HTTP request body. */ @Nullable private final HttpContent body; + /** Whether the HTTP request body carries credentials. */ + private final boolean credentialBody; + /** HTTP connection and read timeout. */ @Nullable private final Integer httpTimeout; @@ -37,6 +40,7 @@ public static class Builder { private final HttpHeaders headers = new HttpHeaders().setAccept("*/*"); @Nullable private HttpContent body; + private boolean credentialBody; @Nullable private Integer httpTimeout; public Request build() { @@ -96,6 +100,21 @@ public Builder setHttpTimeout(@Nullable Integer httpTimeout) { */ public Builder setBody(@Nullable HttpContent httpContent) { this.body = httpContent; + this.credentialBody = false; + return this; + } + + /** + * Sets a body that carries credentials. {@link FailoverHttpClient} sends such a request over + * plain HTTP only if sending credentials over HTTP is enabled, and otherwise throws {@link + * javax.net.ssl.SSLException}. + * + * @param httpContent the body content + * @return this + */ + public Builder setCredentialBody(HttpContent httpContent) { + this.body = httpContent; + this.credentialBody = true; return this; } } @@ -107,6 +126,7 @@ public static Builder builder() { private Request(Builder builder) { this.headers = builder.headers; this.body = builder.body; + this.credentialBody = builder.credentialBody; this.httpTimeout = builder.httpTimeout; } @@ -119,6 +139,10 @@ HttpContent getHttpContent() { return body; } + boolean hasCredentialBody() { + return credentialBody; + } + @Nullable Integer getHttpTimeout() { return httpTimeout; diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryAuthenticator.java b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryAuthenticator.java index 0fc0a219da..3259be9cc6 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryAuthenticator.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryAuthenticator.java @@ -272,7 +272,7 @@ private Authorization authenticate( if (isOAuth2Auth(credential)) { String parameters = getAuthRequestParameters(credential, repositoryScopes); - requestBuilder.setBody( + requestBuilder.setCredentialBody( new BlobHttpContent(Blobs.from(parameters), MediaType.FORM_DATA.toString())); } else if (credential != null) { requestBuilder.setAuthorization( diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/http/FailoverHttpClientTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/http/FailoverHttpClientTest.java index b46267d96d..8668054de1 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/http/FailoverHttpClientTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/http/FailoverHttpClientTest.java @@ -329,6 +329,40 @@ public void testGet_originalRequestHeaderUntouchedWhenClearingHeader() throws IO "Basic ZmFrZS11c2VybmFtZTpmYWtlLXNlY3JldA==", request.getHeaders().getAuthorization()); } + @Test + public void testPost_doNotSendCredentialBodyOverHttp() throws IOException { + FailoverHttpClient insecureHttpClient = newHttpClient(true, false); + Request request = + Request.builder() + .setCredentialBody(new BlobHttpContent(Blobs.from("crepecake"), "fake.content.type")) + .build(); + + Mockito.when(mockHttpRequest.execute()).thenThrow(new ConnectException()); + + SSLException exception = + Assert.assertThrows( + SSLException.class, + () -> insecureHttpClient.post(new URL("https://insecure"), request)); + assertThat(exception).hasMessageThat().contains("sendCredentialsOverHttp"); + + verifyCapturedUrls("https://insecure"); + } + + @Test + public void testPost_sendCredentialBodyOverHttp() throws IOException { + FailoverHttpClient insecureHttpClient = newHttpClient(true, true); + Request request = + Request.builder() + .setCredentialBody(new BlobHttpContent(Blobs.from("crepecake"), "fake.content.type")) + .build(); + + try (Response response = insecureHttpClient.post(new URL("http://plain.http"), request)) { + // intentionally empty + } + + verifyCapturedUrls("http://plain.http"); + } + @Test public void testShutDown() throws IOException { FailoverHttpClient secureHttpClient = newHttpClient(false, false); diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java index 0ce5be3dba..89260b83c2 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/registry/RegistryAuthenticatorTest.java @@ -315,6 +315,26 @@ public void testAuthorizationCleared() throws RegistryAuthenticationFailedExcept } } + @Test + public void testAuthenticate_oauth2RefreshTokenNotSentOverHttp() + throws IOException, InterruptedException, GeneralSecurityException, URISyntaxException, + RegistryAuthenticationFailedException { + try (TestWebServer server = new TestWebServer(false)) { + RegistryAuthenticator authenticator = + RegistryAuthenticator.fromAuthenticationMethod( + "Bearer realm=\"" + server.getEndpoint() + "\"", + registryEndpointRequestProperties, + "user-agent", + new FailoverHttpClient(true, false, ignored -> {})) + .get(); + + Assert.assertThrows( + RegistryAuthenticationFailedException.class, + () -> authenticator.authenticatePull(Credential.from("", "oauth2_token"))); + assertThat(server.getInputRead()).isEmpty(); + } + } + @Test public void testAuthenticationResponseTemplate_readsToken() throws IOException { String input = "{\"token\":\"test_value\"}"; diff --git a/jib-gradle-plugin/CHANGELOG.md b/jib-gradle-plugin/CHANGELOG.md index 0916ff372c..f50546634e 100644 --- a/jib-gradle-plugin/CHANGELOG.md +++ b/jib-gradle-plugin/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Changed ### Fixed +- fix: do not send OAuth2 refresh tokens over plain HTTP unless `sendCredentialsOverHttp` is set ## 3.5.4 diff --git a/jib-maven-plugin/CHANGELOG.md b/jib-maven-plugin/CHANGELOG.md index 4e613dafd2..ac8a9ca017 100644 --- a/jib-maven-plugin/CHANGELOG.md +++ b/jib-maven-plugin/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Changed ### Fixed +- fix: do not send OAuth2 refresh tokens over plain HTTP unless `sendCredentialsOverHttp` is set ## 3.5.2