Skip to content

Commit 8f4b2eb

Browse files
authored
Merge pull request #298 from kubescape/pullsec
add pullsecrets from pod for scanAP
2 parents 1e005f2 + 4550ba3 commit 8f4b2eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+353
-392
lines changed

admission/exporter/http_exporter.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import (
99
"sync"
1010
"time"
1111

12+
apitypes "github.com/armosec/armoapi-go/armotypes"
1213
"github.com/kubescape/go-logger"
1314
"github.com/kubescape/go-logger/helpers"
1415
"github.com/kubescape/operator/admission/rules"
15-
16-
apitypes "github.com/armosec/armoapi-go/armotypes"
1716
)
1817

1918
type HTTPExporterConfig struct {

admission/rulebinding/cache/cache.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@ import (
44
"context"
55
"strings"
66

7-
typesv1 "github.com/kubescape/node-agent/pkg/rulebindingmanager/types/v1"
8-
"github.com/kubescape/node-agent/pkg/watcher"
9-
"k8s.io/apimachinery/pkg/runtime"
10-
11-
"github.com/kubescape/node-agent/pkg/k8sclient"
12-
13-
"github.com/kubescape/node-agent/pkg/rulebindingmanager"
14-
15-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
17-
"k8s.io/apimachinery/pkg/labels"
18-
197
"github.com/goradd/maps"
208
"github.com/kubescape/go-logger"
219
"github.com/kubescape/go-logger/helpers"
10+
"github.com/kubescape/node-agent/pkg/k8sclient"
11+
"github.com/kubescape/node-agent/pkg/rulebindingmanager"
12+
typesv1 "github.com/kubescape/node-agent/pkg/rulebindingmanager/types/v1"
13+
"github.com/kubescape/node-agent/pkg/watcher"
2214
"github.com/kubescape/operator/admission/rulebinding"
2315
"github.com/kubescape/operator/admission/rules"
2416
rulesv1 "github.com/kubescape/operator/admission/rules/v1"
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
19+
"k8s.io/apimachinery/pkg/labels"
20+
"k8s.io/apimachinery/pkg/runtime"
2521
)
2622

2723
const (

admission/rulebinding/cache/cache_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"context"
55
"testing"
66

7-
typesv1 "github.com/kubescape/node-agent/pkg/rulebindingmanager/types/v1"
8-
97
"github.com/goradd/maps"
108
"github.com/kubescape/k8s-interface/k8sinterface"
9+
typesv1 "github.com/kubescape/node-agent/pkg/rulebindingmanager/types/v1"
1110
"github.com/kubescape/operator/admission/rules"
1211
"github.com/kubescape/operator/utils"
1312
"github.com/stretchr/testify/assert"

admission/rulebinding/cache/helpers.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import (
44
typesv1 "github.com/kubescape/node-agent/pkg/rulebindingmanager/types/v1"
55
"github.com/kubescape/node-agent/pkg/utils"
66
"github.com/kubescape/node-agent/pkg/watcher"
7-
8-
k8sruntime "k8s.io/apimachinery/pkg/runtime"
9-
107
corev1 "k8s.io/api/core/v1"
118
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
129
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
10+
k8sruntime "k8s.io/apimachinery/pkg/runtime"
1311
)
1412

1513
func uniqueName(obj metav1.Object) string {

admission/rulebinding/cache/helpers_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
typesv1 "github.com/kubescape/node-agent/pkg/rulebindingmanager/types/v1"
7-
87
"github.com/stretchr/testify/assert"
98
corev1 "k8s.io/api/core/v1"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

admission/rules/v1/helpers.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"fmt"
66

7-
v1 "k8s.io/api/core/v1"
7+
corev1 "k8s.io/api/core/v1"
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
99
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1010
"k8s.io/apimachinery/pkg/runtime"
@@ -22,7 +22,7 @@ func GetControllerDetails(event admission.Attributes, clientset kubernetes.Inter
2222

2323
pod, err := GetPodDetails(clientset, podName, namespace)
2424
if err != nil {
25-
return "", "", "", "", fmt.Errorf("failed to get pod details: %v", err)
25+
return "", "", "", "", fmt.Errorf("failed to get pod details: %w", err)
2626
}
2727

2828
workloadKind, workloadName, workloadNamespace := ExtractPodOwner(pod, clientset)
@@ -32,16 +32,16 @@ func GetControllerDetails(event admission.Attributes, clientset kubernetes.Inter
3232
}
3333

3434
// GetPodDetails returns the pod details from the Kubernetes API server.
35-
func GetPodDetails(clientset kubernetes.Interface, podName, namespace string) (*v1.Pod, error) {
35+
func GetPodDetails(clientset kubernetes.Interface, podName, namespace string) (*corev1.Pod, error) {
3636
pod, err := clientset.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{})
3737
if err != nil {
38-
return nil, fmt.Errorf("failed to get pod: %v", err)
38+
return nil, fmt.Errorf("failed to get pod: %w", err)
3939
}
4040
return pod, nil
4141
}
4242

4343
// ExtractPodOwner returns the kind, name, and namespace of the controller that owns the pod.
44-
func ExtractPodOwner(pod *v1.Pod, clientset kubernetes.Interface) (string, string, string) {
44+
func ExtractPodOwner(pod *corev1.Pod, clientset kubernetes.Interface) (string, string, string) {
4545
for _, ownerRef := range pod.OwnerReferences {
4646
switch ownerRef.Kind {
4747
case "ReplicaSet":
@@ -91,9 +91,9 @@ func GetContainerNameFromExecToPodEvent(event admission.Attributes) (string, err
9191
return "", fmt.Errorf("object is not of type *unstructured.Unstructured")
9292
}
9393

94-
podExecOptions := &v1.PodExecOptions{}
94+
podExecOptions := &corev1.PodExecOptions{}
9595
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.Object, podExecOptions); err != nil {
96-
return "", fmt.Errorf("failed to decode PodExecOptions: %v", err)
96+
return "", fmt.Errorf("failed to decode PodExecOptions: %w", err)
9797
}
9898

9999
return podExecOptions.Container, nil

admission/rules/v1/r2000_exec_to_pod.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import (
44
"fmt"
55
"time"
66

7+
apitypes "github.com/armosec/armoapi-go/armotypes"
78
"github.com/kubescape/go-logger"
89
"github.com/kubescape/go-logger/helpers"
910
"github.com/kubescape/operator/admission/rules"
1011
"github.com/kubescape/operator/objectcache"
11-
1212
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1313
"k8s.io/apiserver/pkg/admission"
1414
"k8s.io/apiserver/pkg/authentication/user"
15-
16-
apitypes "github.com/armosec/armoapi-go/armotypes"
1715
)
1816

1917
const (

admission/rules/v1/r2001_portforward.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import (
44
"fmt"
55
"time"
66

7-
"github.com/kubescape/operator/admission/rules"
8-
"github.com/kubescape/operator/objectcache"
9-
7+
apitypes "github.com/armosec/armoapi-go/armotypes"
108
"github.com/kubescape/go-logger"
119
"github.com/kubescape/go-logger/helpers"
10+
"github.com/kubescape/operator/admission/rules"
11+
"github.com/kubescape/operator/objectcache"
1212
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1313
"k8s.io/apiserver/pkg/admission"
1414
"k8s.io/apiserver/pkg/authentication/user"
15-
16-
apitypes "github.com/armosec/armoapi-go/armotypes"
1715
)
1816

1917
const (

admission/rules/v1/rule.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package rules
22

33
import (
4-
"github.com/kubescape/operator/admission/rules"
5-
64
"github.com/goradd/maps"
5+
"github.com/kubescape/operator/admission/rules"
76
)
87

98
const (

admission/webhook/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import (
1212
"sync"
1313
"time"
1414

15-
"github.com/kubescape/node-agent/pkg/watcher"
16-
1715
"github.com/kubescape/go-logger"
1816
"github.com/kubescape/go-logger/helpers"
17+
"github.com/kubescape/node-agent/pkg/watcher"
1918
admissionv1 "k8s.io/api/admission/v1"
2019
authenticationv1 "k8s.io/api/authentication/v1"
2120
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -393,7 +392,7 @@ func parseRequest(r *http.Request) (*admissionv1.AdmissionReview, error) {
393392
var admissionReview admissionv1.AdmissionReview
394393

395394
if err := json.Unmarshal(body, &admissionReview); err != nil {
396-
return nil, fmt.Errorf("could not parse admission review request: %v", err)
395+
return nil, fmt.Errorf("could not parse admission review request: %w", err)
397396
}
398397

399398
if admissionReview.Request == nil {

0 commit comments

Comments
 (0)