Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,12 @@ public Mono<Void> pushManifest(PushApplicationManifestRequest request) {

@Override
public Mono<Void> pushManifestV3(PushManifestV3Request request) {
// Don't send docker credentials in the apply_manifest body, they end up in the
// audit.app.apply_manifest event. createPackage sends them separately.
ManifestV3 manifestForApply = stripDockerCredentials(request.getManifest());
byte[] manifestSerialized;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ApplicationManifestUtilsV3.write(baos, request.getManifest());
ApplicationManifestUtilsV3.write(baos, manifestForApply);
manifestSerialized = baos.toByteArray();
} catch (IOException e) {
throw new RuntimeException("Could not serialize manifest", e);
Expand Down Expand Up @@ -1227,6 +1230,30 @@ private static String cleanName(ApplicationManifest manifest) {
return manifest.getName().replaceAll("\\.", "");
}

static ManifestV3 stripDockerCredentials(ManifestV3 manifest) {
List<ManifestV3Application> applications =
manifest.getApplications().stream()
.map(
app -> {
if (app.getDocker() == null
|| app.getDocker().getPassword() == null) {
return app;
}
Docker docker =
Docker.builder()
.from(app.getDocker())
.username(null)
.password(null)
.build();
return ManifestV3Application.builder()
.from(app)
.docker(docker)
.build();
})
.collect(Collectors.toList());
return ManifestV3.builder().from(manifest).applications(applications).build();
}

private static BiFunction<String, String, String> collectStates() {
return (totalState, instanceState) -> {
if ("RUNNING".equals(instanceState) || "RUNNING".equals(totalState)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cloudfoundry.operations.applications;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -148,6 +149,52 @@ void testWithMetadataOnlyAnnotation() throws IOException {
assertSerializeDeserialize(manifest);
}

@Test
void testDockerPasswordRoundTrips() throws IOException {
ManifestV3 manifest =
ManifestV3.builder()
.application(
ManifestV3Application.builder()
.name("test-app")
.docker(
Docker.builder()
.image("my-registry/my-image:latest")
.username("user")
.password("secret")
.build())
.build())
.build();

assertSerializeDeserialize(manifest);
}

@Test
void stripDockerCredentials() {
ManifestV3 manifest =
ManifestV3.builder()
.application(
ManifestV3Application.builder()
.name("test-app")
.docker(
Docker.builder()
.image("my-registry/my-image:latest")
.username("user")
.password("secret")
.build())
.build())
.build();

Docker docker =
DefaultApplications.stripDockerCredentials(manifest)
.getApplications()
.get(0)
.getDocker();

assertEquals("my-registry/my-image:latest", docker.getImage());
assertNull(docker.getUsername());
assertNull(docker.getPassword());
}

private void assertSerializeDeserialize(ManifestV3 manifest) throws IOException {
Path file = Files.createTempFile("test-manifest-", ".yml");
ApplicationManifestUtilsV3.write(file, manifest);
Expand Down
Loading