-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: tracee loads CRDs policies if avaliable
- Loading branch information
1 parent
c212fe0
commit 4595399
Showing
5 changed files
with
149 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package k8s | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aquasecurity/tracee/pkg/k8s/apis/tracee.aquasec.com/v1beta1" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/kubectl/pkg/scheme" | ||
) | ||
|
||
type Client struct { | ||
restClient *rest.RESTClient | ||
} | ||
|
||
func New() (*Client, error) { | ||
config, err := rest.InClusterConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
v1beta1.AddToScheme(scheme.Scheme) | ||
|
||
crdConfig := *config | ||
crdConfig.ContentConfig.GroupVersion = &v1beta1.GroupVersion | ||
crdConfig.APIPath = "/apis" | ||
crdConfig.NegotiatedSerializer = serializer.NewCodecFactory(scheme.Scheme) | ||
crdConfig.UserAgent = rest.DefaultKubernetesUserAgent() | ||
|
||
client, err := rest.UnversionedRESTClientFor(&crdConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Client{client}, nil | ||
} | ||
|
||
func (c Client) GetPolicy(ctx context.Context) ([]v1beta1.PolicyInterface, error) { | ||
result := v1beta1.PolicyList{} | ||
|
||
err := c.restClient. | ||
Get(). | ||
Resource("policies"). | ||
Do(ctx). | ||
Into(&result) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
policies := make([]v1beta1.PolicyInterface, len(result.Items)) | ||
for i, item := range result.Items { | ||
policies[i] = item | ||
} | ||
|
||
return policies, nil | ||
} |
Oops, something went wrong.