Skip to content

Commit

Permalink
feat: add support for docker images
Browse files Browse the repository at this point in the history
Issue project-zot#724

A new config section under "HTTP" called "Compat" is added which
currently takes a list of possible compatible legacy media-types.

Only "docker2s2" (Docker Manifest V2 Schema V2) is currently supported.

Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Oct 22, 2024
1 parent da6bd56 commit 8261da4
Show file tree
Hide file tree
Showing 34 changed files with 313 additions and 152 deletions.
14 changes: 14 additions & 0 deletions examples/config-docker-compat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"distSpecVersion": "1.1.0",
"storage": {
"rootDirectory": "/data/hdd/rchincha/tmp/zot"
},
"http": {
"address": "0.0.0.0",
"port": "8080",
"compat": ["docker2s2"]
},
"log": {
"level": "debug"
}
}
7 changes: 4 additions & 3 deletions examples/config-minimal.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"distSpecVersion": "1.1.0",
"storage": {
"rootDirectory": "/tmp/zot"
"rootDirectory": "/data/hdd/rchincha/tmp/zot"
},
"http": {
"address": "127.0.0.1",
"port": "8080"
"address": "0.0.0.0",
"port": "8080",
"compat": ["docker2s2"]
},
"log": {
"level": "debug"
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/authn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ func TestCookiestoreCleanup(t *testing.T) {
err = os.Chtimes(sessionPath, changeTime, changeTime)
So(err, ShouldBeNil)

imgStore := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil)
imgStore := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imgStore,
Expand Down Expand Up @@ -989,7 +989,7 @@ func TestCookiestoreCleanup(t *testing.T) {
err = os.WriteFile(sessionPath, []byte("session"), storageConstants.DefaultFilePerms)
So(err, ShouldBeNil)

imgStore := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil)
imgStore := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imgStore,
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

distspec "github.com/opencontainers/distribution-spec/specs-go"

"zotregistry.dev/zot/pkg/compat"
extconf "zotregistry.dev/zot/pkg/extensions/config"
storageConstants "zotregistry.dev/zot/pkg/storage/constants"
)
Expand Down Expand Up @@ -122,7 +123,8 @@ type HTTPConfig struct {
Auth *AuthConfig
AccessControl *AccessControlConfig `mapstructure:"accessControl,omitempty"`
Realm string
Ratelimit *RatelimitConfig `mapstructure:",omitempty"`
Ratelimit *RatelimitConfig `mapstructure:",omitempty"`
Compat []compat.MediaCompatibility `mapstructure:",omitempty"`
}

type SchedulerConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func (rh *RouteHandler) UpdateManifest(response http.ResponseWriter, request *ht
}

mediaType := request.Header.Get("Content-Type")
if !storageCommon.IsSupportedMediaType(mediaType) {
if !storageCommon.IsSupportedMediaType(rh.c.Config.HTTP.Compat, mediaType) {
err := apiErr.NewError(apiErr.MANIFEST_INVALID).AddDetail(map[string]string{"mediaType": mediaType})
zcommon.WriteJSON(response, http.StatusUnsupportedMediaType, apiErr.NewErrorList(err))

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/client/cve_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestNegativeServerResponse(t *testing.T) {
dir := t.TempDir()

imageStore := local.NewImageStore(dir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), nil, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down
41 changes: 41 additions & 0 deletions pkg/compat/compat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package compat

import (
"encoding/json"

"zotregistry.dev/zot/errors"
)

// MediaCompatibility determines non-OCI media-compatilibility.
type MediaCompatibility string

const (
DockerManifestV2SchemaV2 = "docker2s2"
)

func (mc MediaCompatibility) MarshalJSON() ([]byte, error) {
switch mc {
case DockerManifestV2SchemaV2:
return json.Marshal(DockerManifestV2SchemaV2)
default:
return nil, errors.ErrUnexpectedMediaType
}
}

func (mc *MediaCompatibility) UnmarshalJSON(data []byte) error {
var str string

err := json.Unmarshal(data, &str)
if err != nil {
return err
}

switch str {
case DockerManifestV2SchemaV2:
*mc = MediaCompatibility(DockerManifestV2SchemaV2)
default:
return errors.ErrUnexpectedMediaType
}

return nil
}
10 changes: 5 additions & 5 deletions pkg/extensions/extension_image_trust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
logger.Logger = logger.Output(writers)

imageStore := local.NewImageStore(globalDir, false, false,
logger, monitoring.NewMetricsServer(false, logger), nil, nil)
logger, monitoring.NewMetricsServer(false, logger), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down Expand Up @@ -321,7 +321,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
logger.Logger = logger.Output(writers)

imageStore := local.NewImageStore(globalDir, false, false,
logger, monitoring.NewMetricsServer(false, logger), nil, nil)
logger, monitoring.NewMetricsServer(false, logger), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down Expand Up @@ -429,7 +429,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
logger.Logger = logger.Output(writers)

imageStore := local.NewImageStore(globalDir, false, false,
logger, monitoring.NewMetricsServer(false, logger), nil, nil)
logger, monitoring.NewMetricsServer(false, logger), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down Expand Up @@ -592,7 +592,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
logger.Logger = logger.Output(writers)

imageStore := local.NewImageStore(globalDir, false, false,
logger, monitoring.NewMetricsServer(false, logger), nil, nil)
logger, monitoring.NewMetricsServer(false, logger), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down Expand Up @@ -856,7 +856,7 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
logger.Logger = logger.Output(writers)

imageStore := local.NewImageStore(globalDir, false, false,
logger, monitoring.NewMetricsServer(false, logger), nil, nil)
logger, monitoring.NewMetricsServer(false, logger), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down
14 changes: 7 additions & 7 deletions pkg/extensions/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {

linter := lint.NewLinter(lintConfig, log.NewLogger("debug", ""))
imgStore := local.NewImageStore(dir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil, nil)

indexContent, err := imgStore.GetIndexContent("zot-test")
So(err, ShouldBeNil)
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {

linter := lint.NewLinter(lintConfig, log.NewLogger("debug", ""))
imgStore := local.NewImageStore(dir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil, nil)

indexContent, err := imgStore.GetIndexContent("zot-test")
So(err, ShouldBeNil)
Expand Down Expand Up @@ -591,7 +591,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {

linter := lint.NewLinter(lintConfig, log.NewLogger("debug", ""))
imgStore := local.NewImageStore(dir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil, nil)

pass, err := linter.CheckMandatoryAnnotations("zot-test", digest, imgStore)
So(err, ShouldBeNil)
Expand Down Expand Up @@ -653,7 +653,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {

linter := lint.NewLinter(lintConfig, log.NewLogger("debug", ""))
imgStore := local.NewImageStore(dir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil, nil)

pass, err := linter.CheckMandatoryAnnotations("zot-test", digest, imgStore)
So(err, ShouldNotBeNil)
Expand Down Expand Up @@ -717,7 +717,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {

linter := lint.NewLinter(lintConfig, log.NewLogger("debug", ""))
imgStore := local.NewImageStore(dir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil, nil)

pass, err := linter.CheckMandatoryAnnotations("zot-test", digest, imgStore)
So(err, ShouldBeNil)
Expand Down Expand Up @@ -780,7 +780,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {

linter := lint.NewLinter(lintConfig, log.NewLogger("debug", ""))
imgStore := local.NewImageStore(dir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil, nil)

err = os.Chmod(path.Join(dir, "zot-test", "blobs"), 0o000)
if err != nil {
Expand Down Expand Up @@ -878,7 +878,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {

linter := lint.NewLinter(lintConfig, log.NewLogger("debug", ""))
imgStore := local.NewImageStore(dir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), linter, nil, nil)

err = os.Chmod(path.Join(dir, "zot-test", "blobs", "sha256", manifest.Config.Digest.Encoded()), 0o000)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/extensions/scrub/scrub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestRunScrubRepo(t *testing.T) {
UseRelPaths: true,
}, log)
imgStore := local.NewImageStore(dir, true,
true, log, metrics, nil, cacheDriver)
true, log, metrics, nil, cacheDriver, nil)

srcStorageCtlr := ociutils.GetDefaultStoreController(dir, log)
image := CreateDefaultVulnerableImage()
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestRunScrubRepo(t *testing.T) {
UseRelPaths: true,
}, log)
imgStore := local.NewImageStore(dir, true,
true, log, metrics, nil, cacheDriver)
true, log, metrics, nil, cacheDriver, nil)

srcStorageCtlr := ociutils.GetDefaultStoreController(dir, log)
image := CreateDefaultVulnerableImage()
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestRunScrubRepo(t *testing.T) {
Name: "cache",
UseRelPaths: true,
}, log)
imgStore := local.NewImageStore(dir, true, true, log, metrics, nil, cacheDriver)
imgStore := local.NewImageStore(dir, true, true, log, metrics, nil, cacheDriver, nil)

srcStorageCtlr := ociutils.GetDefaultStoreController(dir, log)
image := CreateDefaultVulnerableImage()
Expand Down
2 changes: 1 addition & 1 deletion pkg/extensions/search/cve/cve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func TestImageFormat(t *testing.T) {
dbDir := t.TempDir()

metrics := monitoring.NewMetricsServer(false, log)
defaultStore := local.NewImageStore(imgDir, false, false, log, metrics, nil, nil)
defaultStore := local.NewImageStore(imgDir, false, false, log, metrics, nil, nil, nil)
storeController := storage.StoreController{DefaultStore: defaultStore}

params := boltdb.DBParameters{
Expand Down
2 changes: 1 addition & 1 deletion pkg/extensions/search/cve/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func TestScanGeneratorWithRealData(t *testing.T) {

metrics := monitoring.NewMetricsServer(true, logger)
imageStore := local.NewImageStore(rootDir, false, false,
logger, metrics, nil, nil)
logger, metrics, nil, nil, nil)
storeController := storage.StoreController{DefaultStore: imageStore}

image := CreateRandomVulnerableImage()
Expand Down
12 changes: 6 additions & 6 deletions pkg/extensions/search/cve/trivy/scanner_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func TestMultipleStoragePath(t *testing.T) {

// Create ImageStore

firstStore := local.NewImageStore(firstRootDir, false, false, log, metrics, nil, nil)
firstStore := local.NewImageStore(firstRootDir, false, false, log, metrics, nil, nil, nil)

secondStore := local.NewImageStore(secondRootDir, false, false, log, metrics, nil, nil)
secondStore := local.NewImageStore(secondRootDir, false, false, log, metrics, nil, nil, nil)

thirdStore := local.NewImageStore(thirdRootDir, false, false, log, metrics, nil, nil)
thirdStore := local.NewImageStore(thirdRootDir, false, false, log, metrics, nil, nil, nil)

storeController := storage.StoreController{}

Expand Down Expand Up @@ -172,7 +172,7 @@ func TestTrivyLibraryErrors(t *testing.T) {
metrics := monitoring.NewMetricsServer(false, log)

// Create ImageStore
store := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil)
store := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil)

storeController := storage.StoreController{}
storeController.DefaultStore = store
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestImageScannable(t *testing.T) {
// Continue with initializing the objects the scanner depends on
metrics := monitoring.NewMetricsServer(false, log)

store := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil)
store := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil)

storeController := storage.StoreController{}
storeController.DefaultStore = store
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestDefaultTrivyDBUrl(t *testing.T) {
metrics := monitoring.NewMetricsServer(false, log)

// Create ImageStore
store := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil)
store := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil)

storeController := storage.StoreController{}
storeController.DefaultStore = store
Expand Down
4 changes: 2 additions & 2 deletions pkg/extensions/search/cve/trivy/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestVulnerableLayer(t *testing.T) {

log := log.NewLogger("debug", "")
imageStore := local.NewImageStore(tempDir, false, false,
log, monitoring.NewMetricsServer(false, log), nil, nil)
log, monitoring.NewMetricsServer(false, log), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestVulnerableLayer(t *testing.T) {

log := log.NewLogger("debug", "")
imageStore := local.NewImageStore(tempDir, false, false,
log, monitoring.NewMetricsServer(false, log), nil, nil)
log, monitoring.NewMetricsServer(false, log), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down
10 changes: 5 additions & 5 deletions pkg/extensions/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ func TestExpandedRepoInfo(t *testing.T) {
ctlr := api.NewController(conf)

imageStore := local.NewImageStore(tempDir, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), nil, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down Expand Up @@ -1280,7 +1280,7 @@ func TestExpandedRepoInfo(t *testing.T) {

log := log.NewLogger("debug", "")
metrics := monitoring.NewMetricsServer(false, log)
testStorage := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil)
testStorage := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil)

resp, err := resty.R().Get(baseURL + "/v2/")
So(resp, ShouldNotBeNil)
Expand Down Expand Up @@ -1636,7 +1636,7 @@ func TestExpandedRepoInfo(t *testing.T) {
ctlr := api.NewController(conf)

imageStore := local.NewImageStore(conf.Storage.RootDirectory, false, false,
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), nil, nil)
log.NewLogger("debug", ""), monitoring.NewMetricsServer(false, log.NewLogger("debug", "")), nil, nil, nil)

storeController := storage.StoreController{
DefaultStore: imageStore,
Expand Down Expand Up @@ -5774,7 +5774,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) {
// get signatur digest
log := log.NewLogger("debug", "")
metrics := monitoring.NewMetricsServer(false, log)
storage := local.NewImageStore(dir, false, false, log, metrics, nil, nil)
storage := local.NewImageStore(dir, false, false, log, metrics, nil, nil, nil)

indexBlob, err := storage.GetIndexContent(repo)
So(err, ShouldBeNil)
Expand Down Expand Up @@ -5848,7 +5848,7 @@ func TestMetaDBWhenDeletingImages(t *testing.T) {
// get signatur digest
log := log.NewLogger("debug", "")
metrics := monitoring.NewMetricsServer(false, log)
storage := local.NewImageStore(dir, false, false, log, metrics, nil, nil)
storage := local.NewImageStore(dir, false, false, log, metrics, nil, nil, nil)

indexBlob, err := storage.GetIndexContent(repo)
So(err, ShouldBeNil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/extensions/sync/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,5 @@ func getTempRootDirFromImageReference(imageReference types.ImageReference, repo,
func getImageStore(rootDir string, log log.Logger) storageTypes.ImageStore {
metrics := monitoring.NewMetricsServer(false, log)

return local.NewImageStore(rootDir, false, false, log, metrics, nil, nil)
return local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil)
}
Loading

0 comments on commit 8261da4

Please sign in to comment.