-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-gc89-7gcr-jxqc
[0.11] provenance: ensure URLs are redacted before written
- Loading branch information
Showing
4 changed files
with
50 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ func testBuildInfoSources(t *testing.T, sb integration.Sandbox) { | |
dockerfile := ` | ||
FROM alpine:latest@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 AS alpine | ||
FROM busybox:latest | ||
ADD https://raw.githubusercontent.com/moby/moby/v20.10.21/README.md / | ||
ADD https://user2:pw2@raw.githubusercontent.com/moby/moby/v20.10.21/README.md / | ||
COPY --from=alpine /bin/busybox /alpine-busybox | ||
` | ||
|
||
|
@@ -93,10 +93,15 @@ COPY --from=alpine /bin/busybox /alpine-busybox | |
}} | ||
} | ||
|
||
expectedURL := strings.Replace(server.URL, "http://", "http://xxxxx:xxxxx@", 1) | ||
require.NotEqual(t, expectedURL, server.URL) | ||
server.URL = strings.Replace(server.URL, "http://", "http://user:pass@", 1) | ||
|
||
res, err := f.Solve(sb.Context(), c, client.SolveOpt{ | ||
Exports: exports, | ||
FrontendAttrs: map[string]string{ | ||
builder.DefaultLocalNameContext: server.URL + "/.git#buildinfo", | ||
builder.DefaultLocalNameContext: server.URL + "/.git#buildinfo", | ||
builder.DefaultLocalNameContext + ":foo": "https://foo:[email protected]/foo.html", | ||
}, | ||
}, nil) | ||
require.NoError(t, err) | ||
|
@@ -110,7 +115,9 @@ COPY --from=alpine /bin/busybox /alpine-busybox | |
require.NoError(t, err) | ||
|
||
require.Contains(t, bi.Attrs, "context") | ||
require.Equal(t, server.URL+"/.git#buildinfo", *bi.Attrs["context"]) | ||
require.Equal(t, expectedURL+"/.git#buildinfo", *bi.Attrs["context"]) | ||
|
||
require.Equal(t, "https://xxxxx:[email protected]/foo.html", *bi.Attrs["context:foo"]) | ||
|
||
_, isGateway := f.(*gatewayFrontend) | ||
|
||
|
@@ -131,11 +138,11 @@ COPY --from=alpine /bin/busybox /alpine-busybox | |
assert.NotEmpty(t, sources[1].Pin) | ||
|
||
assert.Equal(t, binfotypes.SourceTypeGit, sources[2].Type) | ||
assert.Equal(t, server.URL+"/.git#buildinfo", sources[2].Ref) | ||
assert.Equal(t, expectedURL+"/.git#buildinfo", sources[2].Ref) | ||
assert.NotEmpty(t, sources[2].Pin) | ||
|
||
assert.Equal(t, binfotypes.SourceTypeHTTP, sources[3].Type) | ||
assert.Equal(t, "https://raw.githubusercontent.com/moby/moby/v20.10.21/README.md", sources[3].Ref) | ||
assert.Equal(t, "https://xxxxx:xxxxx@raw.githubusercontent.com/moby/moby/v20.10.21/README.md", sources[3].Ref) | ||
assert.Equal(t, "sha256:419455202b0ef97e480d7f8199b26a721a417818bc0e2d106975f74323f25e6c", sources[3].Pin) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,12 +74,13 @@ RUN echo "ok" > /foo | |
builder.DefaultLocalNameContext: dir, | ||
}, | ||
FrontendAttrs: map[string]string{ | ||
"attest:provenance": provReq, | ||
"build-arg:FOO": "bar", | ||
"label:lbl": "abc", | ||
"vcs:source": "https://example.invalid/repo.git", | ||
"vcs:revision": "123456", | ||
"filename": "Dockerfile", | ||
"attest:provenance": provReq, | ||
"build-arg:FOO": "bar", | ||
"label:lbl": "abc", | ||
"vcs:source": "https://user:[email protected]/repo.git", | ||
"vcs:revision": "123456", | ||
"filename": "Dockerfile", | ||
builder.DefaultLocalNameContext + ":foo": "https://foo:[email protected]/foo.html", | ||
}, | ||
Exports: []client.ExportEntry{ | ||
{ | ||
|
@@ -137,30 +138,32 @@ RUN echo "ok" > /foo | |
require.Equal(t, "gateway.v0", pred.Invocation.Parameters.Frontend) | ||
|
||
if mode == "max" || mode == "" { | ||
require.Equal(t, 3, len(args), "%v", args) | ||
require.Equal(t, 4, len(args), "%v", args) | ||
require.True(t, pred.Metadata.Completeness.Parameters) | ||
|
||
require.Equal(t, "bar", args["build-arg:FOO"]) | ||
require.Equal(t, "abc", args["label:lbl"]) | ||
require.Contains(t, args["source"], "buildkit_test/") | ||
} else { | ||
require.False(t, pred.Metadata.Completeness.Parameters) | ||
require.Equal(t, 1, len(args), "%v", args) | ||
require.Equal(t, 2, len(args), "%v", args) | ||
require.Contains(t, args["source"], "buildkit_test/") | ||
} | ||
require.Equal(t, "https://xxxxx:[email protected]/foo.html", args["context:foo"]) | ||
} else { | ||
require.Equal(t, "dockerfile.v0", pred.Invocation.Parameters.Frontend) | ||
|
||
if mode == "max" || mode == "" { | ||
require.Equal(t, 2, len(args)) | ||
require.Equal(t, 3, len(args)) | ||
require.True(t, pred.Metadata.Completeness.Parameters) | ||
|
||
require.Equal(t, "bar", args["build-arg:FOO"]) | ||
require.Equal(t, "abc", args["label:lbl"]) | ||
} else { | ||
require.False(t, pred.Metadata.Completeness.Parameters) | ||
require.Equal(t, 0, len(args), "%v", args) | ||
require.Equal(t, 1, len(args), "%v", args) | ||
} | ||
require.Equal(t, "https://xxxxx:[email protected]/foo.html", args["context:foo"]) | ||
} | ||
|
||
expectedBase := "pkg:docker/busybox@latest?platform=" + url.PathEscape(platforms.Format(platforms.Normalize(platforms.DefaultSpec()))) | ||
|
@@ -177,7 +180,7 @@ RUN echo "ok" > /foo | |
|
||
if !isClient { | ||
require.Equal(t, "Dockerfile", pred.Invocation.ConfigSource.EntryPoint) | ||
require.Equal(t, "https://example.invalid/repo.git", pred.Metadata.BuildKitMetadata.VCS["source"]) | ||
require.Equal(t, "https://xxxxx:xxxxx@example.invalid/repo.git", pred.Metadata.BuildKitMetadata.VCS["source"]) | ||
require.Equal(t, "123456", pred.Metadata.BuildKitMetadata.VCS["revision"]) | ||
} | ||
|
||
|
@@ -265,6 +268,11 @@ COPY myapp.Dockerfile / | |
|
||
target := registry + "/buildkit/testwithprovenance:git" | ||
|
||
// inject dummy credentials to test that they are masked | ||
expectedURL := strings.Replace(server.URL, "http://", "http://xxxxx:xxxxx@", 1) | ||
require.NotEqual(t, expectedURL, server.URL) | ||
server.URL = strings.Replace(server.URL, "http://", "http://user:pass@", 1) | ||
|
||
_, err = f.Solve(sb.Context(), c, client.SolveOpt{ | ||
FrontendAttrs: map[string]string{ | ||
"context": server.URL + "/.git#v1", | ||
|
@@ -318,7 +326,7 @@ COPY myapp.Dockerfile / | |
require.Equal(t, "", pred.Invocation.ConfigSource.EntryPoint) | ||
} else { | ||
require.NotEmpty(t, pred.Invocation.Parameters.Frontend) | ||
require.Equal(t, server.URL+"/.git#v1", pred.Invocation.ConfigSource.URI) | ||
require.Equal(t, expectedURL+"/.git#v1", pred.Invocation.ConfigSource.URI) | ||
require.Equal(t, "myapp.Dockerfile", pred.Invocation.ConfigSource.EntryPoint) | ||
} | ||
|
||
|
@@ -332,15 +340,15 @@ COPY myapp.Dockerfile / | |
require.Equal(t, expBase, pred.Materials[1].URI) | ||
require.NotEmpty(t, pred.Materials[1].Digest["sha256"]) | ||
|
||
require.Equal(t, server.URL+"/.git#v1", pred.Materials[2].URI) | ||
require.Equal(t, expectedURL+"/.git#v1", pred.Materials[2].URI) | ||
require.Equal(t, strings.TrimSpace(string(expectedGitSHA)), pred.Materials[2].Digest["sha1"]) | ||
} else { | ||
require.Equal(t, 2, len(pred.Materials), "%+v", pred.Materials) | ||
|
||
require.Equal(t, expBase, pred.Materials[0].URI) | ||
require.NotEmpty(t, pred.Materials[0].Digest["sha256"]) | ||
|
||
require.Equal(t, server.URL+"/.git#v1", pred.Materials[1].URI) | ||
require.Equal(t, expectedURL+"/.git#v1", pred.Materials[1].URI) | ||
require.Equal(t, strings.TrimSpace(string(expectedGitSHA)), pred.Materials[1].Digest["sha1"]) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters