Skip to content

Commit

Permalink
Add support for fuzzing tests using oss-fuzz-build.
Browse files Browse the repository at this point in the history
Co-authored-by: Paulo Gomes <[email protected]>
Co-authored-by: AdamKorcz <[email protected]>
Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
3 people committed Feb 10, 2022
1 parent a348d9f commit e024c9b
Show file tree
Hide file tree
Showing 7 changed files with 668 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/cifuzz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CIFuzz
on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Restore Go cache
uses: actions/cache@v1
with:
path: /home/runner/work/_temp/_github_home/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Fetch CRDs
run: make test_deps
- name: Smoke test Fuzzers
run: make fuzz-smoketest
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ ENVTEST = $(GOBIN)/setup-envtest
setup-envtest: ## Download envtest-setup locally if necessary.
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# Build fuzzers
fuzz-build: $(LIBGIT2)
rm -rf $(shell pwd)/build/fuzz/
mkdir -p $(shell pwd)/build/fuzz/out/

# TODO: remove mapping of current libgit2 dir and pull binaries from release or build dependency chain on demand.
docker build . --tag local-fuzzing:latest -f tests/fuzz/Dockerfile.builder
docker run --rm \
-e FUZZING_LANGUAGE=go -e SANITIZER=address \
-e CIFUZZ_DEBUG='True' -e OSS_FUZZ_PROJECT_NAME=fluxcd \
-v "$(shell pwd)/build/fuzz/out":/out \
-v "$(shell pwd)/build/libgit2":"/root/go/src/github.com/fluxcd/source-controller/build/libgit2" \
local-fuzzing:latest

fuzz-smoketest: fuzz-build
docker run --rm \
-v "$(shell pwd)/build/fuzz/out":/out \
-v "$(shell pwd)/tests/fuzz/oss_fuzz_run.sh":/runner.sh \
local-fuzzing:latest \
bash -c "/runner.sh"

# go-install-tool will 'go install' any package $2 and install it to $1.
define go-install-tool
@[ -f $(1) ] || { \
Expand Down
8 changes: 8 additions & 0 deletions tests/fuzz/Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM gcr.io/oss-fuzz-base/base-builder-go

RUN apt-get update && apt-get install -y cmake pkg-config

COPY ./ $GOPATH/src/github.com/fluxcd/image-automation-controller/
COPY ./tests/fuzz/oss_fuzz_build.sh $SRC/build.sh

WORKDIR $SRC
3 changes: 3 additions & 0 deletions tests/fuzz/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/fluxcd/image-automation-controller/tests/fuzz

go 1.17
Loading

0 comments on commit e024c9b

Please sign in to comment.