@@ -28,6 +28,7 @@ import (
2828 "github.com/goharbor/harbor/src/controller/proxy"
2929 "github.com/goharbor/harbor/src/controller/registry"
3030 "github.com/goharbor/harbor/src/lib"
31+ "github.com/goharbor/harbor/src/lib/config"
3132 "github.com/goharbor/harbor/src/lib/errors"
3233 httpLib "github.com/goharbor/harbor/src/lib/http"
3334 "github.com/goharbor/harbor/src/lib/log"
@@ -259,16 +260,21 @@ func setHeaders(w http.ResponseWriter, size int64, mediaType string, dig string)
259260}
260261
261262// isProxySession check if current security context is proxy session
262- func isProxySession (ctx context.Context ) bool {
263+ func isProxySession (ctx context.Context , projectName string ) bool {
263264 sc , ok := security .FromContext (ctx )
264265 if ! ok {
265266 log .Error ("Failed to get security context" )
266267 return false
267268 }
268- if sc .GetUsername () == proxycachesecret .ProxyCacheService {
269+ username := sc .GetUsername ()
270+ if username == proxycachesecret .ProxyCacheService {
269271 return true
270272 }
271- return false
273+ // it should include the auto generate SBOM session, so that it could generate SBOM accessory in proxy cache project
274+ robotPrefix := config .RobotPrefix (ctx )
275+ scannerPrefix := config .ScannerRobotPrefix (ctx )
276+ prefix := fmt .Sprintf ("%s%s+%s" , robotPrefix , projectName , scannerPrefix )
277+ return strings .HasPrefix (username , prefix )
272278}
273279
274280// DisableBlobAndManifestUploadMiddleware disable push artifact to a proxy project with a non-proxy session
@@ -281,7 +287,7 @@ func DisableBlobAndManifestUploadMiddleware() func(http.Handler) http.Handler {
281287 httpLib .SendError (w , err )
282288 return
283289 }
284- if p .IsProxy () && ! isProxySession (ctx ) {
290+ if p .IsProxy () && ! isProxySession (ctx , art . ProjectName ) {
285291 httpLib .SendError (w ,
286292 errors .DeniedError (
287293 errors .Errorf ("can not push artifact to a proxy project: %v" , p .Name )))
0 commit comments