Skip to content

Commit

Permalink
chore: move signatures into their own top level directory (aquasecuri…
Browse files Browse the repository at this point in the history
…ty#1231)

Resolves: aquasecurity#1220
Resolves: aquasecurity#1229 
Resolves: aquasecurity#1199 

Signed-off-by: Simar <[email protected]>
Signed-off-by: Daniel Pacak <[email protected]>
Co-authored-by: Daniel Pacak <[email protected]>
  • Loading branch information
2 people authored and Rafael David Tinoco committed Dec 14, 2021
1 parent 7d083d7 commit 936af3f
Show file tree
Hide file tree
Showing 50 changed files with 43 additions and 32 deletions.
11 changes: 8 additions & 3 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Vagrant.configure("2") do |config|
end

config.vm.provision "shell", inline: <<-SHELL
GO_VERSION="1.16"
OPA_VERSION="v0.35.0"
apt-get update
apt-get install --yes build-essential pkgconf libelf-dev llvm-12 clang-12
Expand All @@ -22,9 +25,11 @@ Vagrant.configure("2") do |config|
apt-get install --yes docker.io
usermod -aG docker vagrant
wget --quiet https://golang.org/dl/go1.16.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.16.linux-amd64.tar.gz
wget --quiet https://golang.org/dl/go$GO_VERSION.linux-amd64.tar.gz
tar -C /usr/local -xzf go$GO_VERSION.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> /home/vagrant/.profile
curl -L -o /usr/bin/opa https://github.com/open-policy-agent/opa/releases/download/$OPA_VERSION/opa_linux_amd64
chmod 755 /usr/bin/opa
SHELL
end

6 changes: 6 additions & 0 deletions embedded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tracee

import _ "embed"

//go:embed signatures/rego/helpers.rego
var RegoHelpersCode string
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

tracee "github.com/aquasecurity/tracee/pkg/external"
"github.com/aquasecurity/tracee/tracee-rules/signatures/helpers"
"github.com/aquasecurity/tracee/signatures/helpers"
"github.com/aquasecurity/tracee/tracee-rules/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

tracee "github.com/aquasecurity/tracee/pkg/external"
"github.com/aquasecurity/tracee/tracee-rules/signatures/signaturestest"
"github.com/aquasecurity/tracee/signatures/signaturestest"
"github.com/aquasecurity/tracee/tracee-rules/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

tracee "github.com/aquasecurity/tracee/pkg/external"
"github.com/aquasecurity/tracee/tracee-rules/signatures/helpers"
"github.com/aquasecurity/tracee/signatures/helpers"
"github.com/aquasecurity/tracee/tracee-rules/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

tracee "github.com/aquasecurity/tracee/pkg/external"
"github.com/aquasecurity/tracee/tracee-rules/signatures/signaturestest"
"github.com/aquasecurity/tracee/signatures/signaturestest"
"github.com/aquasecurity/tracee/tracee-rules/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tracee-rules/Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17-buster as builder
RUN DEBIAN_FRONTEND=noninteractive apt-get update -y && apt-get install -y --no-install-recommends curl && \
curl -L -o /usr/bin/opa https://github.com/open-policy-agent/opa/releases/download/v0.33.1/opa_linux_amd64 && chmod 755 /usr/bin/opa
curl -L -o /usr/bin/opa https://github.com/open-policy-agent/opa/releases/download/v0.35.0/opa_linux_amd64 && chmod 755 /usr/bin/opa
WORKDIR /tracee
8 changes: 4 additions & 4 deletions tracee-rules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ OUT_DIR ?= dist
OUT_BIN := $(OUT_DIR)/tracee-rules
OUT_RULES := $(OUT_DIR)/rules
GO_SRC := $(shell find . -type f -name '*.go')
GOSIGNATURES_DIR ?= signatures/golang
GOSIGNATURES_DIR ?= ../signatures/golang
GOSIGNATURES_SRC := $(shell find $(GOSIGNATURES_DIR) -type f -name '*.go' ! -name '*_test.go' ! -path '$(GOSIGNATURES_DIR)/examples/*')
OUT_GOSIGNATURES := $(OUT_RULES)/builtin.so
REGO_SIGNATURES_DIR ?= signatures/rego
REGO_SIGNATURES_SRC := $(shell find $(REGO_SIGNATURES_DIR) -type f -name '*.rego' ! -name '*_test.rego' ! -path '$(REGO_SIGNATURES_DIR)/examples/*')
REGO_SIGNATURES_DIR ?= ../signatures/rego
REGO_SIGNATURES_SRC := $(shell find $(REGO_SIGNATURES_DIR) -type f -name '*.rego' ! -name '*_test.rego' ! -path '$(REGO_SIGNATURES_DIR)/examples/*' ! -name 'aio.rego')
DOCKER_BUILDER ?= tracee-rules-builder

$(OUT_DIR):
Expand Down Expand Up @@ -53,7 +53,7 @@ $(tools): % : check_%
ifndef DOCKER
test: $(GO_SRC) $(tools)
go test $(GOTEST_FLAGS) -v ./...
opa test . --verbose --ignore="examples" --ignore="dist" --ignore="benchmark"
opa test ../signatures/rego --verbose --ignore="examples" --ignore="dist" --ignore="benchmark"
else
test: $(DOCKER_BUILDER)
$(call docker_builder_make,$@)
Expand Down
2 changes: 1 addition & 1 deletion tracee-rules/benchmark/signature/golang/anti_debugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

tracee "github.com/aquasecurity/tracee/pkg/external"
"github.com/aquasecurity/tracee/tracee-rules/signatures/helpers"
"github.com/aquasecurity/tracee/signatures/helpers"
"github.com/aquasecurity/tracee/tracee-rules/types"
)

Expand Down
2 changes: 1 addition & 1 deletion tracee-rules/benchmark/signature/golang/code_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"regexp"

tracee "github.com/aquasecurity/tracee/pkg/external"
"github.com/aquasecurity/tracee/tracee-rules/signatures/helpers"
"github.com/aquasecurity/tracee/signatures/helpers"
"github.com/aquasecurity/tracee/tracee-rules/types"
)

Expand Down
5 changes: 2 additions & 3 deletions tracee-rules/benchmark/signature/rego/signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package rego
import (
_ "embed"

"github.com/open-policy-agent/opa/compile"

"github.com/aquasecurity/tracee/tracee-rules/signatures/rego/regosig"
"github.com/aquasecurity/tracee/tracee-rules/regosig"
"github.com/aquasecurity/tracee/tracee-rules/types"
"github.com/open-policy-agent/opa/compile"
)

var (
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"

tracee "github.com/aquasecurity/tracee/pkg/external"
"github.com/aquasecurity/tracee/tracee-rules/signatures/rego/regosig"
"github.com/aquasecurity/tracee/tracee-rules/signatures/signaturestest"
"github.com/aquasecurity/tracee/signatures/signaturestest"
"github.com/aquasecurity/tracee/tracee-rules/regosig"
"github.com/aquasecurity/tracee/tracee-rules/types"
"github.com/open-policy-agent/opa/compile"
"github.com/stretchr/testify/assert"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"testing"

tracee "github.com/aquasecurity/tracee/pkg/external"
"github.com/aquasecurity/tracee/signatures/signaturestest"
"github.com/aquasecurity/tracee/tracee-rules/engine"
"github.com/aquasecurity/tracee/tracee-rules/signatures/rego/regosig"
"github.com/aquasecurity/tracee/tracee-rules/signatures/signaturestest"
"github.com/aquasecurity/tracee/tracee-rules/regosig"
"github.com/aquasecurity/tracee/tracee-rules/types"
"github.com/open-policy-agent/opa/compile"
"github.com/stretchr/testify/assert"
Expand Down
12 changes: 5 additions & 7 deletions tracee-rules/signature.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"bytes"
_ "embed"

"bytes"
"io/fs"
"io/ioutil"
"log"
Expand All @@ -12,13 +12,11 @@ import (
"plugin"
"strings"

"github.com/aquasecurity/tracee/tracee-rules/signatures/rego/regosig"
embedded "github.com/aquasecurity/tracee"
"github.com/aquasecurity/tracee/tracee-rules/regosig"
"github.com/aquasecurity/tracee/tracee-rules/types"
)

//go:embed signatures/rego/helpers.rego
var regoHelpersCode string

func getSignatures(target string, partialEval bool, rulesDir string, rules []string, aioEnabled bool) ([]types.Signature, error) {
if rulesDir == "" {
exePath, err := os.Executable()
Expand Down Expand Up @@ -81,9 +79,9 @@ func findGoSigs(dir string) ([]types.Signature, error) {

func findRegoSigs(target string, partialEval bool, dir string, aioEnabled bool) ([]types.Signature, error) {
modules := make(map[string]string)
modules["helper.rego"] = regoHelpersCode
modules["helper.rego"] = embedded.RegoHelpersCode

regoHelpers := []string{regoHelpersCode}
regoHelpers := []string{embedded.RegoHelpersCode}
filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
Expand Down
11 changes: 7 additions & 4 deletions tracee-rules/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import (
"path/filepath"
"testing"

"github.com/open-policy-agent/opa/compile"

"github.com/aquasecurity/tracee/tracee-rules/types"
"github.com/open-policy-agent/opa/compile"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
exampleRulesDir = "../signatures/rego"
)

func Test_getSignatures(t *testing.T) {
sigs, err := getSignatures(compile.TargetRego, false, "signatures/rego", []string{"TRC-2"}, false)
sigs, err := getSignatures(compile.TargetRego, false, exampleRulesDir, []string{"TRC-2"}, false)
require.NoError(t, err)
require.Equal(t, 1, len(sigs))

Expand Down Expand Up @@ -104,7 +107,7 @@ func copyExampleSig(exampleName, destDir string) error {
var exampleDir string
extension := filepath.Ext(exampleName)
if extension == ".rego" {
exampleDir = "signatures/rego/%s"
exampleDir = fmt.Sprint(exampleRulesDir + "/%s")
} else {
return errors.New("unsupported signature type")
}
Expand Down

0 comments on commit 936af3f

Please sign in to comment.