@@ -20,27 +20,14 @@ import (
2020
2121 "github.com/uber/kraken/utils/closers"
2222
23- "github.com/uber-go/tally"
24- "github.com/uber/kraken/lib/store"
25-
2623 storagedriver "github.com/docker/distribution/registry/storage/driver"
24+
2725 "github.com/uber/kraken/core"
2826 "github.com/uber/kraken/lib/dockerregistry/transfer"
29- "github.com/uber/kraken/utils/cache "
27+ "github.com/uber/kraken/lib/store "
3028 "github.com/uber/kraken/utils/log"
3129)
3230
33- const (
34- signatureVerificationSuccessCounter = "signature_verification_success"
35- signatureVerificationFailureCounter = "signature_verification_failure"
36- signatureVerificationErrorCounter = "signature_verification_error"
37- signatureVerificationDuration = "signature_verification_duration"
38-
39- // Verification cache configuration
40- defaultVerificationCacheSize = 300 // Maximum number of entries
41- defaultVerificationCacheTTL = 5 * time .Minute // TTL for verification cache entries
42- )
43-
4431type SignatureVerificationDecision int
4532
4633const (
@@ -52,22 +39,15 @@ const (
5239type manifests struct {
5340 transferer transfer.ImageTransferer
5441 verification func (repo string , digest core.Digest , blob store.FileReader ) (SignatureVerificationDecision , error )
55- metrics tally.Scope
56-
57- // Cache to track verified (repo, digest) combinations to avoid duplicate metric emission.
58- verifiedCache * cache.LRUCache
5942}
6043
6144func newManifests (
6245 transferer transfer.ImageTransferer ,
6346 verification func (repo string , digest core.Digest , blob store.FileReader ) (SignatureVerificationDecision , error ),
64- metrics tally.Scope ,
6547) * manifests {
6648 return & manifests {
67- transferer : transferer ,
68- verification : verification ,
69- metrics : metrics ,
70- verifiedCache : cache .NewLRUCache (defaultVerificationCacheSize , defaultVerificationCacheTTL ),
49+ transferer : transferer ,
50+ verification : verification ,
7151 }
7252}
7353
@@ -80,7 +60,7 @@ func newManifests(
8060// if subtype is revisions, parses the digest directly from the path.
8161// 3. Downloads the manifest blob via the transferer using (repo, digest).
8262// 4. Opportunistically invokes verify to run signature/image checks and
83- // record metrics/ logs. Verification result is not enforced here.
63+ // record logs. Verification result is not enforced here.
8464// 5. Returns the digest in ASCII string form as a byte slice.
8565//
8666// Notes
@@ -121,36 +101,22 @@ func (t *manifests) getDigest(path string, subtype PathSubType) ([]byte, error)
121101 }
122102 defer closers .Close (blob )
123103
124- // Only verify if we haven't already verified this (repo, digest) combination
125- cacheKey := fmt .Sprintf ("%s:%s" , repo , digest .String ())
126- shouldEmitMetrics := ! t .verifiedCache .Has (cacheKey )
127-
128104 // Signature verification is currently not enforced: errors from t.verify are ignored.
129105 // This is intentional because verification enforcement is planned for a future release.
130106 // Risks: manifests may be accepted without verification, which could allow untrusted content.
131107 // TODO: Remove error ignoring and enforce verification once the feature is activated.
132- _ , _ = t .verify (path , repo , digest , blob , shouldEmitMetrics ) //nolint:errcheck
133-
134- if shouldEmitMetrics {
135- t .verifiedCache .Add (cacheKey )
136- }
108+ _ , _ = t .verify (path , repo , digest , blob ) //nolint:errcheck
137109 return []byte (digest .String ()), nil
138110}
139111
140112// verify runs signature/image verification for a downloaded manifest blob and
141- // records metrics/ logs around the decision and duration .
113+ // logs around the decision.
142114//
143115// Returns
144116// - (true, nil) when verification is allowed or intentionally skipped.
145117// - (false, nil) when verification explicitly denies.
146118// - (false, err) on verification errors or unknown decisions.
147119//
148- // Metrics
149- // - signature_verification_duration (timer): end-to-end verification latency.
150- // - signature_verification_success (counter): allow decisions.
151- // - signature_verification_failure (counter): deny decisions.
152- // - signature_verification_error (counter): errors/unknown decisions.
153- //
154120// Logging
155121// - Error on verification error (includes repo/digest).
156122// - Warn on deny (includes original path).
@@ -160,43 +126,23 @@ func (t *manifests) verify(
160126 repo string ,
161127 digest core.Digest ,
162128 blob store.FileReader ,
163- emitMetrics bool ,
164129) (bool , error ) {
165- // Always measure duration, but only emit if not cached
166- var stopwatch tally.Stopwatch
167- if emitMetrics {
168- stopwatch = t .metrics .Timer (signatureVerificationDuration ).Start ()
169- defer stopwatch .Stop ()
170- }
171-
172130 decision , err := t .verification (repo , digest , blob )
173131 if err != nil {
174- if emitMetrics {
175- t .metrics .Counter (signatureVerificationErrorCounter ).Inc (1 )
176- }
177132 log .With ("repo" , repo , "digest" , digest ).Errorf ("Error while performing image validation %s" , err )
178133 return false , err
179134 }
180135
181136 switch decision {
182137 case DecisionAllow :
183- if emitMetrics {
184- t .metrics .Counter (signatureVerificationSuccessCounter ).Inc (1 )
185- }
186138 return true , nil
187139 case DecisionDeny :
188- if emitMetrics {
189- t .metrics .Counter (signatureVerificationFailureCounter ).Inc (1 )
190- }
191140 log .With ("repo" , repo , "digest" , digest ).Warnf ("Verification failed %s" , path )
192141 return false , nil
193142 case DecisionSkip :
194143 log .With ("repo" , repo , "digest" , digest ).Debugf ("Verification skipped for %s" , path )
195144 return true , nil
196145 default :
197- if emitMetrics {
198- t .metrics .Counter (signatureVerificationErrorCounter ).Inc (1 )
199- }
200146 return false , fmt .Errorf ("unknown verification decision: %d" , decision )
201147 }
202148}
0 commit comments