Skip to content

Commit

Permalink
use application profile instead of sbomp
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <[email protected]>
  • Loading branch information
matthyx committed Sep 17, 2024
1 parent 686cea5 commit 7aee46a
Show file tree
Hide file tree
Showing 19 changed files with 1,047 additions and 233 deletions.
21 changes: 21 additions & 0 deletions adapters/mockrelevancy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package adapters

import (
"context"

mapset "github.com/deckarep/golang-set/v2"
"github.com/kubescape/kubevuln/core/ports"
)

type MockRelevancyAdapter struct {
}

var _ ports.Relevancy = (*MockRelevancyAdapter)(nil)

func NewMockRelevancyAdapter() *MockRelevancyAdapter {
return &MockRelevancyAdapter{}
}

func (m MockRelevancyAdapter) GetRelevantFiles(_ context.Context, _, _, _ string) (mapset.Set[string], map[string]string, error) {
return mapset.NewSet[string](), nil, nil
}
44 changes: 44 additions & 0 deletions adapters/v1/application_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package v1

import (
"context"
"fmt"
"slices"

mapset "github.com/deckarep/golang-set/v2"
helpersv1 "github.com/kubescape/k8s-interface/instanceidhandler/v1/helpers"
"github.com/kubescape/kubevuln/core/ports"
)

type ApplicationProfileAdapter struct {
repository ports.ApplicationProfileRepository
}

var _ ports.Relevancy = (*ApplicationProfileAdapter)(nil)

func NewApplicationProfileAdapter(repository ports.ApplicationProfileRepository) *ApplicationProfileAdapter {
return &ApplicationProfileAdapter{
repository: repository,
}
}

func (a *ApplicationProfileAdapter) GetRelevantFiles(ctx context.Context, namespace, name, container string) (mapset.Set[string], map[string]string, error) {
applicationProfile, err := a.repository.GetApplicationProfile(ctx, namespace, name)
if err != nil {
return nil, nil, fmt.Errorf("GetApplicationProfile: %w", err)
}
files := mapset.NewSet[string]()
for _, c := range slices.Concat(applicationProfile.Spec.InitContainers, applicationProfile.Spec.Containers, applicationProfile.Spec.EphemeralContainers) {
if c.Name == container {
for _, f := range c.Execs {
files.Add(f.Path)
}
for _, f := range c.Opens {
files.Add(f.Path)
}
}
}
labels := applicationProfile.Labels
labels[helpersv1.ContainerNameMetadataKey] = container
return files, labels, nil
}
Loading

0 comments on commit 7aee46a

Please sign in to comment.