Skip to content

Commit

Permalink
Fix redirect failures from apache client 5.x (#5996)
Browse files Browse the repository at this point in the history
This commit changes the underlying http client used by the RestTemplate in the
Container Image Registry component from Apache Http Client to Reactor Netty.

Our upgrade to Spring Boot 3.x brought with it an update from 4.x to 5.x for the
Apache Http client. The 5.x line removes support for dropping  headers - which
is a requirement of this component.

Moving to Reactor Netty solves the redirect issue while also greatly reducing the
complexity of this code.

Fixes #5989
  • Loading branch information
corneil authored Nov 7, 2024
1 parent 59b5ba3 commit 08c082d
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 311 deletions.
4 changes: 4 additions & 0 deletions spring-cloud-dataflow-configuration-metadata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.dataflow.container.registry.authorization;

import java.util.Collections;
import java.util.Map;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureWebClient;
import org.springframework.cloud.dataflow.configuration.metadata.ApplicationConfigurationMetadataResolverAutoConfiguration;
import org.springframework.cloud.dataflow.configuration.metadata.container.DefaultContainerImageMetadataResolver;
import org.springframework.cloud.dataflow.container.registry.ContainerRegistryAutoConfiguration;
import org.springframework.cloud.dataflow.container.registry.ContainerRegistryConfiguration;
import org.springframework.cloud.dataflow.container.registry.ContainerRegistryProperties;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

import static org.assertj.core.api.Assertions.assertThat;

/**
* This test is aimed at performing a manual test against a deployed container registry;
* In order to invoke this test populate the fields of DropAuthorizationHeaderOnContainerTestManual.TestApplication
* named registryDomainName, registryUser, registrySecret and imageNameAndTag
*
* The image should be one built with spring-boot:build-image or paketo so that is has a label named 'org.springframework.boot.version'
* For docker hub use:
* registryDomainName="registry-1.docker.io",
* registryUser="docker user"
* registrySecret="docker access token"
* imageNameAndTag="springcloudstream/s3-sink-rabbit:5.0.0"
*
* @author Corneil du Plessis
*/
public class DropAuthorizationHeaderOnContainerTestManual {

private static final String registryDomainName = "registry-1.docker.io";
private static final String registryUser = "<docker-user>";
private static final String registrySecret = "<docker-access-token>";
private static final String imageNameAndTag = "springcloudstream/s3-sink-rabbit:5.0.0";

private AnnotationConfigApplicationContext context;

@AfterEach
void clean() {
if (context != null) {
context.close();
}
context = null;
}

@Test
void testContainerImageLabels() {
context = new AnnotationConfigApplicationContext(TestApplication.class);
DefaultContainerImageMetadataResolver imageMetadataResolver = context.getBean(DefaultContainerImageMetadataResolver.class);
Map<String, String> imageLabels = imageMetadataResolver.getImageLabels(registryDomainName + "/" + imageNameAndTag);
System.out.println("imageLabels:" + imageLabels.keySet());
assertThat(imageLabels).containsKey("org.springframework.boot.version");
}

@Import({ContainerRegistryAutoConfiguration.class, ApplicationConfigurationMetadataResolverAutoConfiguration.class})
@AutoConfigureWebClient
static class TestApplication {

@Bean
@Primary
ContainerRegistryProperties containerRegistryProperties() {
ContainerRegistryProperties properties = new ContainerRegistryProperties();
ContainerRegistryConfiguration registryConfiguration = new ContainerRegistryConfiguration();
registryConfiguration.setRegistryHost(registryDomainName);
registryConfiguration.setAuthorizationType(ContainerRegistryConfiguration.AuthorizationType.dockeroauth2);
registryConfiguration.setUser(registryUser);
registryConfiguration.setSecret(registrySecret);
properties.setRegistryConfigurations(Collections.singletonMap(registryDomainName, registryConfiguration));

return properties;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
* @author Adam J. Weigold
* @author Corneil du Plessis
*/
//TODO: Boot3x followup
@Disabled("TODO: Boot3x `org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [no body]` is thrown by REST Template")
public class DropAuthorizationHeaderOnSignedS3RequestRedirectStrategyTest {
@RegisterExtension
public final static S3SignedRedirectRequestServerResource s3SignedRedirectRequestServerResource =
Expand Down
4 changes: 4 additions & 0 deletions spring-cloud-dataflow-container-registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down
Loading

0 comments on commit 08c082d

Please sign in to comment.