Skip to content

Commit f809066

Browse files
alegrey91knqyf263
andauthored
feat(vex): support per-repo tls configuration (#10030)
Signed-off-by: Alessio Greggi <alessio.greggi@suse.com> Co-authored-by: knqyf263 <knqyf263@gmail.com>
1 parent f97ac7e commit f809066

File tree

6 files changed

+60
-15
lines changed

6 files changed

+60
-15
lines changed

docs/guide/supply-chain/vex/repo.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ For private repositories:
8080
token: "my-token"
8181
```
8282

83+
#### TLS Verification
84+
85+
In some cases, you might want to skip the TLS verification, per-repository:
86+
87+
```yaml
88+
- name: custom
89+
url: https://example.com/custom-repo
90+
enabled: true
91+
insecure: true
92+
```
93+
8394
#### Repository Priority
8495

8596
The priority of VEX repositories is determined by their order in the configuration file.

pkg/downloader/download.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ func Download(ctx context.Context, src, dst, pwd string, opts Options) (string,
105105
}
106106

107107
type CustomTransport struct {
108+
insecure bool
108109
auth Auth
109110
cachedETag string
110111
newETag string
111112
}
112113

113114
func NewCustomTransport(opts Options) *CustomTransport {
114115
return &CustomTransport{
116+
insecure: opts.Insecure,
115117
auth: opts.Auth,
116118
cachedETag: opts.ETag,
117119
}
@@ -127,7 +129,7 @@ func (t *CustomTransport) RoundTrip(req *http.Request) (*http.Response, error) {
127129
req.SetBasicAuth(t.auth.Username, t.auth.Password)
128130
}
129131

130-
transport := xhttp.RoundTripper(req.Context())
132+
transport := xhttp.RoundTripper(req.Context(), xhttp.WithInsecure(t.insecure))
131133
if req.URL.Host == "github.com" {
132134
transport = NewGitHubTransport(req.URL, t.auth.Token)
133135
}

pkg/vex/repo/manager.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ func (m *Manager) List(ctx context.Context) error {
173173
if !repo.Enabled {
174174
status = "Disabled"
175175
}
176-
output.WriteString(fmt.Sprintf("- Name: %s\n URL: %s\n Status: %s\n\n", repo.Name, repo.URL, status))
176+
tlsVerify := ""
177+
if repo.Insecure {
178+
tlsVerify = "\n TLS Verify: No"
179+
}
180+
output.WriteString(fmt.Sprintf("- Name: %s\n URL: %s\n Status: %s%s\n\n", repo.Name, repo.URL, status, tlsVerify))
177181
}
178182
}
179183

pkg/vex/repo/manager_test.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ func TestManager_DownloadRepositories(t *testing.T) {
154154
config: repo.Config{
155155
Repositories: []repo.Repository{
156156
{
157-
Name: "test-repo",
158-
URL: ts.URL,
159-
Enabled: true,
157+
Name: "test-repo",
158+
URL: ts.URL,
159+
Enabled: true,
160+
Insecure: true,
160161
},
161162
},
162163
},
@@ -187,9 +188,10 @@ func TestManager_DownloadRepositories(t *testing.T) {
187188
Enabled: true,
188189
},
189190
{
190-
Name: "test-repo",
191-
URL: ts.URL,
192-
Enabled: true,
191+
Name: "test-repo",
192+
URL: ts.URL,
193+
Enabled: true,
194+
Insecure: true,
193195
},
194196
},
195197
},
@@ -212,6 +214,22 @@ func TestManager_DownloadRepositories(t *testing.T) {
212214
wantErr: "failed to download the repository",
213215
wantDownload: false,
214216
},
217+
{
218+
name: "download error insecure flag false",
219+
config: repo.Config{
220+
Repositories: []repo.Repository{
221+
{
222+
Name: "test-repo",
223+
URL: ts.URL,
224+
Enabled: true,
225+
Insecure: false,
226+
},
227+
},
228+
},
229+
location: ts.URL + "/archive.zip",
230+
wantErr: "failed to download the repository",
231+
wantDownload: false,
232+
},
215233
}
216234

217235
for _, tt := range tests {
@@ -262,9 +280,10 @@ func TestManager_List(t *testing.T) {
262280
Enabled: true,
263281
},
264282
{
265-
Name: "custom",
266-
URL: "https://example.com/custom-vex-repo",
267-
Enabled: false,
283+
Name: "custom",
284+
URL: "https://example.com/custom-vex-repo",
285+
Enabled: false,
286+
Insecure: true,
268287
},
269288
},
270289
},
@@ -277,6 +296,7 @@ func TestManager_List(t *testing.T) {
277296
- Name: custom
278297
URL: https://example.com/custom-vex-repo
279298
Status: Disabled
299+
TLS Verify: No
280300
281301
`,
282302
},

pkg/vex/repo/repo.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type Repository struct {
9393
Username string
9494
Password string
9595
Token string // For Bearer
96+
Insecure bool
9697

9798
dir string // Root directory for this VEX repository, $CACHE_DIR/vex/repositories/$REPO_NAME/
9899
}
@@ -164,7 +165,9 @@ func (r *Repository) downloadManifest(ctx context.Context, opts Options) error {
164165

165166
log.DebugContext(ctx, "Downloading the repository metadata...", log.String("url", u.String()), log.String("dst", r.dir))
166167
_, err = downloader.Download(ctx, u.String(), filepath.Join(r.dir, manifestFile), ".", downloader.Options{
167-
Insecure: opts.Insecure,
168+
// if one between global and per-repo insecure option is set,
169+
// we set it to true accordingly
170+
Insecure: opts.Insecure || r.Insecure,
168171
Auth: downloader.Auth{
169172
Username: r.Username,
170173
Password: r.Password,
@@ -239,8 +242,11 @@ func (r *Repository) download(ctx context.Context, ver Version, dst string, opts
239242
logger := log.With(log.String("repo", r.Name))
240243
logger.DebugContext(ctx, "Downloading repository to cache dir...", log.String("url", loc.URL),
241244
log.String("dir", dst), log.String("etag", etags[loc.URL]))
245+
242246
etag, err := downloader.Download(ctx, loc.URL, dst, ".", downloader.Options{
243-
Insecure: opts.Insecure,
247+
// if one between global and per-repo insecure option is set,
248+
// we set it to true accordingly
249+
Insecure: opts.Insecure || r.Insecure,
244250
Auth: downloader.Auth{
245251
Username: r.Username,
246252
Password: r.Password,

pkg/vex/repo/repo_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ func TestRepository_Update(t *testing.T) {
301301
tt.setup(t, tempDir, &r)
302302

303303
ctx := clock.With(t.Context(), tt.clockTime)
304-
err = r.Update(ctx, repo.Options{})
304+
err = r.Update(ctx, repo.Options{
305+
Insecure: true,
306+
})
305307
if tt.wantErr != "" {
306308
assert.ErrorContains(t, err, tt.wantErr)
307309
return
@@ -344,7 +346,7 @@ func setUpManifest(t *testing.T, dir, url string) {
344346
}
345347

346348
func setUpRepository(t *testing.T) *httptest.Server {
347-
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
349+
return httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
348350
switch r.URL.Path {
349351
case "/archive.zip":
350352
if r.Header.Get("If-None-Match") == "current-etag" {

0 commit comments

Comments
 (0)