Skip to content

Commit 1f8bfa3

Browse files
committed
Add --validate-sha flag for Docker push command
1 parent 17a5ce9 commit 1f8bfa3

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

artifactory/utils/container/buildinfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (builder *buildInfoBuilder) getSearchableRepo() string {
9494
func setBuildProperties(buildName, buildNumber, project string, imageLayers []utils.ResultItem, serviceManager artifactory.ArtifactoryServicesManager) (err error) {
9595
// Skip if no build info is provided
9696
if buildName == "" || buildNumber == "" {
97-
log.Debug("Skipping setting properties - no build name or build number provided")
97+
log.Debug("Skipping setting properties - build name and build number are required")
9898
return nil
9999
}
100100

artifactory/utils/container/remoteagent.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ func (rabib *RemoteAgentBuildInfoBuilder) Build(module string) (*buildinfo.Build
5353
// Search for image manifest and layers in Artifactory.
5454
func (rabib *RemoteAgentBuildInfoBuilder) handleManifest(resultMap map[string]*utils.ResultItem) (map[string]*utils.ResultItem, *manifest, error) {
5555
if manifest, ok := resultMap["manifest.json"]; ok {
56-
err := rabib.isVerifiedManifest(manifest)
57-
if err != nil {
58-
return nil, nil, err
59-
56+
if !rabib.isVerifiedManifest(manifest) {
57+
log.Debug("Manifest verification failed, continuing with SHA-based validation...")
6058
}
6159
manifest, err := getManifest(resultMap, rabib.buildInfoBuilder.serviceManager, rabib.buildInfoBuilder.repositoryDetails.key)
6260
if err != nil {
6361
return nil, nil, err
6462
}
65-
// // Manifest may hold 'empty layers'. As a result, promotion will fail to promote the same layer more than once.
63+
// Manifest may hold 'empty layers'. As a result, promotion will fail to promote the same layer more than once.
6664
rabib.buildInfoBuilder.imageSha2 = manifest.Config.Digest
6765
log.Debug("Found manifest.json. Proceeding to create build-info.")
6866
return resultMap, manifest, nil
@@ -134,16 +132,15 @@ func (rabib *RemoteAgentBuildInfoBuilder) searchImage() (resultMap map[string]*u
134132
return nil, errorutils.CheckErrorf(imageNotFoundErrorMessage, rabib.buildInfoBuilder.image.name)
135133
}
136134

137-
// Verify manifest's sha256. If there is no match, return nil.
138-
func (rabib *RemoteAgentBuildInfoBuilder) isVerifiedManifest(imageManifest *utils.ResultItem) error {
135+
// Verify manifest's sha256. Returns true if manifest is verified, false otherwise.
136+
func (rabib *RemoteAgentBuildInfoBuilder) isVerifiedManifest(imageManifest *utils.ResultItem) bool {
139137
if imageManifest.GetProperty("docker.manifest.digest") != rabib.manifestSha2 {
140138
manifestDigest := imageManifest.GetProperty("docker.manifest.digest")
141139
log.Warn("Manifest digest mismatch detected. Local image digest: " + rabib.manifestSha2 + ", Repository digest: " + manifestDigest)
142140
log.Info("Proceeding with SHA-based validation to ensure correct image identification...")
143-
// Return nil instead of error to allow the operation to continue
144-
return nil
141+
return false
145142
}
146-
return nil
143+
return true
147144
}
148145

149146
func getFatManifestRoot(fatManifestPath string) string {

0 commit comments

Comments
 (0)