diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java index ec4e7a0d6d..8aab3b7b5b 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java @@ -685,9 +685,12 @@ public Mono pushManifest(PushApplicationManifestRequest request) { @Override public Mono 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); @@ -1227,6 +1230,30 @@ private static String cleanName(ApplicationManifest manifest) { return manifest.getName().replaceAll("\\.", ""); } + static ManifestV3 stripDockerCredentials(ManifestV3 manifest) { + List 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 collectStates() { return (totalState, instanceState) -> { if ("RUNNING".equals(instanceState) || "RUNNING".equals(totalState)) { diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsV3Test.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsV3Test.java index 3e05995f57..f1c2681841 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsV3Test.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsV3Test.java @@ -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; @@ -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);