From c9980ece1b514be84e8b8f461d357ebd79752fca Mon Sep 17 00:00:00 2001 From: nico-kn Date: Fri, 20 Nov 2026 18:11:16 +0100 Subject: [PATCH 1/3] fix(docker): omit docker password from manifest YAML serialization CAPI records the full manifest YAML verbatim in the audit.app.apply_manifest event and does not redact docker.password. Including the password in the manifest therefore leaks it into the audit log. Docker credentials must be passed via POST /v3/packages (createPackage), not embedded in the manifest. --- .../applications/ApplicationManifestUtilsCommon.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java index 79b50ab809..7541717911 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java @@ -467,7 +467,9 @@ static Map toDockerYaml(Docker docker) { Map yaml = new TreeMap<>(); putIfPresent(yaml, "image", docker.getImage()); putIfPresent(yaml, "username", docker.getUsername()); - putIfPresent(yaml, "password", docker.getPassword()); + // password is intentionally omitted: CAPI records the manifest YAML verbatim in the + // audit.app.apply_manifest event and does not redact docker.password there. Credentials + // must be passed via POST /v3/packages (createPackage), not embedded in the manifest. return yaml; } From f35a84a4ee2a999f14a5a24affc3f730a4fd75c2 Mon Sep 17 00:00:00 2001 From: Nicolas Knauber Date: Sun, 22 Nov 2026 10:56:48 +0100 Subject: [PATCH 2/3] fix(docker): address review comments on PR #1410 - Rename stripDockerPasswords to stripDockerCredentials (strips both username and password since @Value.Check prohibits username without password) - Restore ApplicationManifestUtilsCommon.toDockerYaml to upstream state (password omission moved to V3-only path in DefaultApplications) - Update comment to reference credentials instead of password - Add two tests: round-trip and credential stripping --- .../ApplicationManifestUtilsCommon.java | 4 +- .../applications/DefaultApplications.java | 26 +++++++++- .../ApplicationManifestUtilsV3Test.java | 52 +++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java index 7541717911..79b50ab809 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsCommon.java @@ -467,9 +467,7 @@ static Map toDockerYaml(Docker docker) { Map yaml = new TreeMap<>(); putIfPresent(yaml, "image", docker.getImage()); putIfPresent(yaml, "username", docker.getUsername()); - // password is intentionally omitted: CAPI records the manifest YAML verbatim in the - // audit.app.apply_manifest event and does not redact docker.password there. Credentials - // must be passed via POST /v3/packages (createPackage), not embedded in the manifest. + putIfPresent(yaml, "password", docker.getPassword()); return yaml; } 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..43a9f8bba5 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,27 @@ private static String cleanName(ApplicationManifest manifest) { return manifest.getName().replaceAll("\\.", ""); } + private static ManifestV3 stripDockerCredentials(ManifestV3 manifest) { + List scrubbed = manifest.getApplications().stream() + .map(app -> { + if (app.getDocker() == null || app.getDocker().getPassword() == null) { + return app; + } + Docker dockerWithoutCredentials = Docker.builder() + .image(app.getDocker().getImage()) + .build(); + return ManifestV3Application.builder() + .from(app) + .docker(dockerWithoutCredentials) + .build(); + }) + .collect(Collectors.toList()); + return ManifestV3.builder() + .applications(scrubbed) + .version(manifest.getVersion()) + .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..d83a5493c2 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,8 +1,11 @@ package org.cloudfoundry.operations.applications; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; @@ -148,6 +151,55 @@ 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 testDockerPasswordStrippedFromSerializedYaml() 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(); + + ManifestV3 scrubbed = ManifestV3.builder() + .application(ManifestV3Application.builder() + .from(manifest.getApplications().get(0)) + .docker(Docker.builder() + .image("my-registry/my-image:latest") + .build()) + .build()) + .build(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ApplicationManifestUtilsV3.write(baos, scrubbed); + String yaml = baos.toString(StandardCharsets.UTF_8); + + assertFalse(yaml.contains("password"), "docker password must not appear in manifest YAML sent to apply_manifest"); + } + private void assertSerializeDeserialize(ManifestV3 manifest) throws IOException { Path file = Files.createTempFile("test-manifest-", ".yml"); ApplicationManifestUtilsV3.write(file, manifest); From 68d01e7e35034a04e54dfe54d6641878c727da04 Mon Sep 17 00:00:00 2001 From: Nicolas Knauber Date: Tue, 24 Nov 2026 10:11:09 +0100 Subject: [PATCH 3/3] rescope unit test & rebuild docker and manifest from originals --- .../applications/DefaultApplications.java | 41 +++++++++------- .../ApplicationManifestUtilsV3Test.java | 49 +++++++++---------- 2 files changed, 44 insertions(+), 46 deletions(-) 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 43a9f8bba5..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 @@ -1230,25 +1230,28 @@ private static String cleanName(ApplicationManifest manifest) { return manifest.getName().replaceAll("\\.", ""); } - private static ManifestV3 stripDockerCredentials(ManifestV3 manifest) { - List scrubbed = manifest.getApplications().stream() - .map(app -> { - if (app.getDocker() == null || app.getDocker().getPassword() == null) { - return app; - } - Docker dockerWithoutCredentials = Docker.builder() - .image(app.getDocker().getImage()) - .build(); - return ManifestV3Application.builder() - .from(app) - .docker(dockerWithoutCredentials) - .build(); - }) - .collect(Collectors.toList()); - return ManifestV3.builder() - .applications(scrubbed) - .version(manifest.getVersion()) - .build(); + 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() { 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 d83a5493c2..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,11 +1,9 @@ package org.cloudfoundry.operations.applications; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; @@ -158,11 +156,12 @@ void testDockerPasswordRoundTrips() throws IOException { .application( ManifestV3Application.builder() .name("test-app") - .docker(Docker.builder() - .image("my-registry/my-image:latest") - .username("user") - .password("secret") - .build()) + .docker( + Docker.builder() + .image("my-registry/my-image:latest") + .username("user") + .password("secret") + .build()) .build()) .build(); @@ -170,34 +169,30 @@ void testDockerPasswordRoundTrips() throws IOException { } @Test - void testDockerPasswordStrippedFromSerializedYaml() throws IOException { + 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()) + .docker( + Docker.builder() + .image("my-registry/my-image:latest") + .username("user") + .password("secret") + .build()) .build()) .build(); - ManifestV3 scrubbed = ManifestV3.builder() - .application(ManifestV3Application.builder() - .from(manifest.getApplications().get(0)) - .docker(Docker.builder() - .image("my-registry/my-image:latest") - .build()) - .build()) - .build(); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ApplicationManifestUtilsV3.write(baos, scrubbed); - String yaml = baos.toString(StandardCharsets.UTF_8); + Docker docker = + DefaultApplications.stripDockerCredentials(manifest) + .getApplications() + .get(0) + .getDocker(); - assertFalse(yaml.contains("password"), "docker password must not appear in manifest YAML sent to apply_manifest"); + assertEquals("my-registry/my-image:latest", docker.getImage()); + assertNull(docker.getUsername()); + assertNull(docker.getPassword()); } private void assertSerializeDeserialize(ManifestV3 manifest) throws IOException {