Skip to content

Commit

Permalink
Integrate with Fuzzit
Browse files Browse the repository at this point in the history
Enables automated fuzzing on Fuzzit. Fuzz regression tests run
every push and PR. Full fuzzing runs every push. Uses genetic
fuzzer go-fuzz.

Fuzz targets are:
* parse-config - Configuration file parsing.
* parse-reference - Docker image reference parsing.
* control-api-tcp - Binary requests to control API server.
* control-api-http - HTTP requests to control API server.
  • Loading branch information
bookmoons committed Oct 18, 2019
1 parent 8f37a85 commit 3ee0ca2
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 18 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
dist: xenial

services:
- docker

language: go
go: "1.12.x"
go_import_path: /skaffold
Expand Down Expand Up @@ -42,3 +45,16 @@ jobs:
- chmod +x ${HOME}/bin/kind
script:
- make integration-in-kind
- name: Fuzz regression
go: 1.12.x
dist: bionic
script:
- cd fuzz
- ./fuzzit.sh local-regression
- name: Fuzz
if: branch = master AND type IN (push)
go: 1.12.x
dist: bionic
script:
- cd fuzz
- ./fuzzit.sh fuzzing
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![Build Status](https://travis-ci.org/GoogleContainerTools/skaffold.svg?branch=master)](https://travis-ci.org/GoogleContainerTools/skaffold)
[![Code Coverage](https://codecov.io/gh/GoogleContainerTools/skaffold/branch/master/graph/badge.svg)](https://codecov.io/gh/GoogleContainerTools/skaffold)
[![Go Report Card](https://goreportcard.com/badge/GoogleContainerTools/skaffold)](https://goreportcard.com/report/GoogleContainerTools/skaffold)
[![Fuzzit Status](https://app.fuzzit.dev/badge?org_id=skaffold)](https://app.fuzzit.dev/orgs/skaffold/dashboard)
[![LICENSE](https://img.shields.io/github/license/GoogleContainerTools/skaffold.svg)](https://github.com/GoogleContainerTools/skaffold/blob/master/LICENSE)
[![Releases](https://img.shields.io/github/release-pre/GoogleContainerTools/skaffold.svg)](https://github.com/GoogleContainerTools/skaffold/releases)

Expand Down
49 changes: 49 additions & 0 deletions fuzz/config_fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// +build gofuzz

/*
Copyright 2019 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fuzz

import (
"io/ioutil"
"os"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
_ "github.com/dvyukov/go-fuzz/go-fuzz-dep"
)

// FuzzParseConfig tests configuration file parsing.
func FuzzParseConfig(fuzz []byte) int {
file, err := ioutil.TempFile("", "fuzzconfig")
if err != nil {
panic(err)
}
defer os.Remove(file.Name())
_, err = file.Write(fuzz)
if err != nil {
panic(err)
}
err = file.Close()
if err != nil {
panic(err)
}
_, err = config.ReadConfigFileNoCache(file.Name())
if err != nil {
return 0
}
return 1
}
56 changes: 56 additions & 0 deletions fuzz/fuzzit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Copyright 2019 The Skaffold Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -xe

# Validate arguments
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <fuzz-type>"
exit 1
fi

# Configure
NAME=skaffold
ROOT=.
TYPE=$1

# Setup
export GO111MODULE=on
go install \
golang.org/x/net/proxy \
github.com/dvyukov/go-fuzz/go-fuzz \
github.com/dvyukov/go-fuzz/go-fuzz-build \
github.com/fuzzitdev/fuzzit/v2
go mod vendor -v
rm -rf gopath
mkdir -p gopath/src
mv vendor/* gopath/src
rm -rf vendor
export GOPATH=$PWD/gopath
export GO111MODULE=off
fuzzit --version

# Fuzz
function fuzz {
FUNC=Fuzz$1
TARGET=$2
go-fuzz-build -libfuzzer -func $FUNC -o fuzzer.a .
clang -fsanitize=fuzzer fuzzer.a -o fuzzer
fuzzit create job --type $TYPE $NAME/$TARGET fuzzer
}
fuzz ParseConfig parse-config
fuzz ParseReference parse-reference
fuzz ServerTCP control-api-tcp
fuzz ServerHTTP control-api-http
14 changes: 14 additions & 0 deletions fuzz/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module fuzz.test/fuzz

go 1.13

replace github.com/GoogleContainerTools/skaffold => ../

replace gopkg.in/russross/blackfriday.v2 v2.0.1 => github.com/russross/blackfriday/v2 v2.0.1

require (
github.com/GoogleContainerTools/skaffold v0.0.0-00010101000000-000000000000
github.com/dvyukov/go-fuzz v0.0.0-20190808141544-193030f1cb16
github.com/fuzzitdev/fuzzit/v2 v2.4.46
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b
)
32 changes: 32 additions & 0 deletions fuzz/reference_fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// +build gofuzz

/*
Copyright 2019 The Skaffold Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fuzz

import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
_ "github.com/dvyukov/go-fuzz/go-fuzz-dep"
)

// FuzzParseReference tests Docker image reference parsing.
func FuzzParseReference(data []byte) int {
if _, err := docker.ParseReference(string(data)); err != nil {
return 0
}
return 1
}
Loading

0 comments on commit 3ee0ca2

Please sign in to comment.