Skip to content

Commit 9c52faa

Browse files
flavianmissiopenshift-cherrypick-robot
authored andcommitted
pkg/storage/s3: use force path style in favour of virtual hosted style
the latest upgrade of our openshift/docker-distribution fork brought in a patch introducing `forcepathstyle` configuration, which was mistakenly merged the openshift only `virtualhostedstyle` configuration. to workaround the issue we simply drop the use of `virtualhostedstyle` in favour of `forcepathstyle`. we will eventually remove our custom `virtualhostedstyle` path from our docker-distribution fork, but using `.spec.storage.s3.virtualHostedStyle` should work as expected regardless.
1 parent 9043a97 commit 9c52faa

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

pkg/resource/podtemplatespec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ func TestMakePodTemplateSpecS3CloudFront(t *testing.T) {
521521
"REGISTRY_STORAGE_S3_BUCKET": {Value: "bucket"},
522522
"REGISTRY_STORAGE_S3_REGION": {Value: "region"},
523523
"REGISTRY_STORAGE_S3_ENCRYPT": {Value: "true"},
524-
"REGISTRY_STORAGE_S3_VIRTUALHOSTEDSTYLE": {Value: "true"},
524+
"REGISTRY_STORAGE_S3_FORCEPATHSTYLE": {Value: "false"},
525525
"REGISTRY_STORAGE_S3_USEDUALSTACK": {Value: "true"},
526526
"REGISTRY_STORAGE_S3_CREDENTIALSCONFIGPATH": {Value: "/var/run/secrets/cloud/credentials"},
527527
"REGISTRY_MIDDLEWARE_STORAGE": {Value: `- name: cloudfront

pkg/storage/ibmcos/ibmcos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (d *driver) ConfigEnv() (envs envvar.List, err error) {
8888
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_REGION", Value: d.Config.Location},
8989
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_REGIONENDPOINT", Value: fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", d.Config.Location)},
9090
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_ENCRYPT", Value: false},
91-
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_VIRTUALHOSTEDSTYLE", Value: false},
91+
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_FORCEPATHSTYLE", Value: true},
9292
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_USEDUALSTACK", Value: false},
9393
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_CREDENTIALSCONFIGPATH", Value: filepath.Join(imageRegistrySecretMountpoint, imageRegistrySecretDataKey)},
9494
)

pkg/storage/ibmcos/ibmcos_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestConfigEnv(t *testing.T) {
6060
"REGISTRY_STORAGE_S3_REGION": "us-east",
6161
"REGISTRY_STORAGE_S3_REGIONENDPOINT": "s3.us-east.cloud-object-storage.appdomain.cloud",
6262
"REGISTRY_STORAGE_S3_ENCRYPT": false,
63-
"REGISTRY_STORAGE_S3_VIRTUALHOSTEDSTYLE": false,
63+
"REGISTRY_STORAGE_S3_FORCEPATHSTYLE": true,
6464
"REGISTRY_STORAGE_S3_USEDUALSTACK": false,
6565
"REGISTRY_STORAGE_S3_CREDENTIALSCONFIGPATH": filepath.Join(imageRegistrySecretMountpoint, imageRegistrySecretDataKey),
6666
}

pkg/storage/s3/s3.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,31 @@ func (d *driver) ConfigEnv() (envs envvar.List, err error) {
409409
envs = append(envs, envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_KEYID", Value: d.Config.KeyID})
410410
}
411411

412+
// virtualHostedStyle tells the registry to use urls in the form of
413+
// bucket-name.s3-endpoint.etc.
414+
// the forcePathStyle setting was introduced to control the same
415+
// behaviour, but it's named after the opposite setting (path style
416+
// instead of virtual hosted style):
417+
// s3-endpoint.etc/bucket-name.
418+
// the PR that introduced virtual hosted style to upstream distribution
419+
// was never merged: https://github.com/distribution/distribution/pull/3131/files
420+
// and it's only present in our fork:
421+
// * https://github.com/openshift/docker-distribution/commit/e33e2357eb705f2ed7481e3510fceedb01a95bb6
422+
// * https://github.com/openshift/docker-distribution/commit/063574e3222f00556ec5113dddca9a0ac28ed4cb
423+
// the upstream introduction of the force path style config happened in:
424+
// * https://github.com/distribution/distribution/commit/15de9e21bad774b24e48a46d9238a5714e7ceb6c
425+
// and it's also present in our fork.
426+
// TODO: drop commits from openshift/docker-distribution during next rebase:
427+
// * https://github.com/openshift/docker-distribution/commit/e33e2357eb705f2ed7481e3510fceedb01a95bb6
428+
// * https://github.com/openshift/docker-distribution/commit/063574e3222f00556ec5113dddca9a0ac28ed4cb
429+
// Jira tracker: https://issues.redhat.com/browse/IR-470
430+
forcePathStyle := !d.Config.VirtualHostedStyle
412431
envs = append(envs,
413432
envvar.EnvVar{Name: "REGISTRY_STORAGE", Value: "s3"},
414433
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_BUCKET", Value: d.Config.Bucket},
415434
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_REGION", Value: d.Config.Region},
416435
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_ENCRYPT", Value: d.Config.Encrypt},
417-
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_VIRTUALHOSTEDSTYLE", Value: d.Config.VirtualHostedStyle},
436+
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_FORCEPATHSTYLE", Value: forcePathStyle},
418437
envvar.EnvVar{Name: "REGISTRY_STORAGE_S3_CREDENTIALSCONFIGPATH", Value: filepath.Join(imageRegistrySecretMountpoint, imageRegistrySecretDataKey)},
419438
)
420439

pkg/storage/s3/s3_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func TestConfigEnv(t *testing.T) {
267267
"REGISTRY_STORAGE": "s3",
268268
"REGISTRY_STORAGE_S3_REGION": "us-east-1",
269269
"REGISTRY_STORAGE_S3_USEDUALSTACK": true,
270-
"REGISTRY_STORAGE_S3_VIRTUALHOSTEDSTYLE": false,
270+
"REGISTRY_STORAGE_S3_FORCEPATHSTYLE": true,
271271
"REGISTRY_STORAGE_S3_CREDENTIALSCONFIGPATH": filepath.Join(imageRegistrySecretMountpoint, imageRegistrySecretDataKey),
272272
}
273273
for key, value := range expectedVars {
@@ -331,7 +331,7 @@ func TestServiceEndpointCanBeOverwritten(t *testing.T) {
331331
"REGISTRY_STORAGE": "s3",
332332
"REGISTRY_STORAGE_S3_REGION": "us-west-1",
333333
"REGISTRY_STORAGE_S3_USEDUALSTACK": true,
334-
"REGISTRY_STORAGE_S3_VIRTUALHOSTEDSTYLE": false,
334+
"REGISTRY_STORAGE_S3_FORCEPATHSTYLE": true,
335335
"REGISTRY_STORAGE_S3_CREDENTIALSCONFIGPATH": filepath.Join(imageRegistrySecretMountpoint, imageRegistrySecretDataKey),
336336
}
337337
for key, value := range expectedVars {

0 commit comments

Comments
 (0)