@@ -3,11 +3,12 @@ package mainhandler
3
3
import (
4
4
"context"
5
5
"fmt"
6
- exporters "github.com/kubescape/operator/admission/exporter"
7
6
"os"
8
7
"regexp"
9
8
"time"
10
9
10
+ exporters "github.com/kubescape/operator/admission/exporter"
11
+
11
12
"github.com/kubescape/backend/pkg/versioncheck"
12
13
"github.com/kubescape/k8s-interface/workloadinterface"
13
14
core1 "k8s.io/api/core/v1"
@@ -426,7 +427,6 @@ func (mainHandler *MainHandler) HandleImageScanningScopedRequest(ctx context.Con
426
427
logger .L ().Debug ("naked pod younger than guard time detected, skipping scan" , helpers .String ("pod" , pod .GetName ()), helpers .String ("namespace" , pod .GetNamespace ()), helpers .String ("creationTimestamp" , pod .CreationTimestamp .String ()))
427
428
return nil
428
429
}
429
-
430
430
for _ , instanceID := range instanceIDs {
431
431
s , _ := instanceID .GetSlug (false )
432
432
if ok := slugs [s ]; ok {
@@ -441,28 +441,44 @@ func (mainHandler *MainHandler) HandleImageScanningScopedRequest(ctx context.Con
441
441
continue
442
442
}
443
443
444
- // set scanning command
445
- cmd := & apis.Command {
446
- Wlid : containerData .Wlid ,
447
- CommandName : apis .TypeScanImages ,
448
- Args : map [string ]interface {}{
449
- utils .ArgsContainerData : containerData ,
450
- utils .ArgsPod : pod ,
451
- },
452
- }
453
-
454
- // send specific command to the channel
455
- newSessionObj := utils .NewSessionObj (ctx , mainHandler .config , cmd , "Websocket" , sessionObj .Reporter .GetJobID (), "" , 1 )
456
-
457
- logger .L ().Info ("triggering scan image" , helpers .String ("id" , newSessionObj .Command .GetID ()), helpers .String ("slug" , s ), helpers .String ("containerName" , containerData .ContainerName ), helpers .String ("imageTag" , containerData .ImageTag ), helpers .String ("imageID" , containerData .ImageID ))
458
- if err := mainHandler .HandleSingleRequest (ctx , newSessionObj ); err != nil {
459
- logger .L ().Info ("failed to complete action" , helpers .Error (err ), helpers .String ("id" , newSessionObj .Command .GetID ()), helpers .String ("slug" , s ), helpers .String ("containerName" , containerData .ContainerName ), helpers .String ("imageTag" , containerData .ImageTag ), helpers .String ("imageID" , containerData .ImageID ))
460
- newSessionObj .Reporter .SendError (err , mainHandler .sendReport , true )
461
- continue
444
+ noContainerSlug , _ := instanceID .GetSlug (true )
445
+ if appProfile := utils .GetApplicationProfileForRelevancyScan (ctx , mainHandler .ksStorageClient , noContainerSlug , ns ); appProfile != nil {
446
+ cmd := utils .GetApplicationProfileScanCommand (appProfile )
447
+
448
+ // send specific command to the channel
449
+ newSessionObj := utils .NewSessionObj (ctx , mainHandler .config , cmd , "Websocket" , sessionObj .Reporter .GetJobID (), "" , 1 )
450
+ logger .L ().Info ("triggering application profile scan" , helpers .String ("wlid" , cmd .Wlid ), helpers .String ("name" , appProfile .Name ), helpers .String ("namespace" , appProfile .Namespace ))
451
+ if err := mainHandler .HandleSingleRequest (ctx , newSessionObj ); err != nil {
452
+ logger .L ().Info ("failed to complete action" , helpers .Error (err ), helpers .String ("id" , newSessionObj .Command .GetID ()), helpers .String ("name" , appProfile .Name ), helpers .String ("namespace" , appProfile .Namespace ))
453
+ newSessionObj .Reporter .SendError (err , mainHandler .sendReport , true )
454
+ continue
455
+ }
456
+ newSessionObj .Reporter .SendStatus (systemreports .JobDone , mainHandler .sendReport )
457
+ logger .L ().Info ("action completed successfully" , helpers .String ("name" , appProfile .Name ), helpers .String ("namespace" , appProfile .Namespace ))
458
+ slugs [noContainerSlug ] = true
459
+ } else {
460
+ // set scanning command
461
+ cmd := & apis.Command {
462
+ Wlid : containerData .Wlid ,
463
+ CommandName : apis .TypeScanImages ,
464
+ Args : map [string ]interface {}{
465
+ utils .ArgsContainerData : containerData ,
466
+ utils .ArgsPod : pod ,
467
+ },
468
+ }
469
+ // send specific command to the channel
470
+ newSessionObj := utils .NewSessionObj (ctx , mainHandler .config , cmd , "Websocket" , sessionObj .Reporter .GetJobID (), "" , 1 )
471
+ logger .L ().Info ("triggering scan image" , helpers .String ("id" , newSessionObj .Command .GetID ()), helpers .String ("slug" , s ), helpers .String ("containerName" , containerData .ContainerName ), helpers .String ("imageTag" , containerData .ImageTag ), helpers .String ("imageID" , containerData .ImageID ))
472
+
473
+ if err := mainHandler .HandleSingleRequest (ctx , newSessionObj ); err != nil {
474
+ logger .L ().Info ("failed to complete action" , helpers .Error (err ), helpers .String ("id" , newSessionObj .Command .GetID ()), helpers .String ("slug" , s ), helpers .String ("containerName" , containerData .ContainerName ), helpers .String ("imageTag" , containerData .ImageTag ), helpers .String ("imageID" , containerData .ImageID ))
475
+ newSessionObj .Reporter .SendError (err , mainHandler .sendReport , true )
476
+ continue
477
+ }
478
+ newSessionObj .Reporter .SendStatus (systemreports .JobDone , mainHandler .sendReport )
479
+ logger .L ().Info ("action completed successfully" , helpers .String ("id" , newSessionObj .Command .GetID ()), helpers .String ("slug" , s ), helpers .String ("containerName" , containerData .ContainerName ), helpers .String ("imageTag" , containerData .ImageTag ), helpers .String ("imageID" , containerData .ImageID ))
480
+ slugs [s ] = true
462
481
}
463
- newSessionObj .Reporter .SendStatus (systemreports .JobDone , mainHandler .sendReport )
464
- logger .L ().Info ("action completed successfully" , helpers .String ("id" , newSessionObj .Command .GetID ()), helpers .String ("slug" , s ), helpers .String ("containerName" , containerData .ContainerName ), helpers .String ("imageTag" , containerData .ImageTag ), helpers .String ("imageID" , containerData .ImageID ))
465
- slugs [s ] = true
466
482
}
467
483
return nil
468
484
}); err != nil {
0 commit comments