Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fuzz Tests #1098

Closed
roberthbailey opened this issue Oct 3, 2019 · 9 comments · Fixed by #1308
Closed

Add Fuzz Tests #1098

roberthbailey opened this issue Oct 3, 2019 · 9 comments · Fixed by #1308
Labels
area/security Issues pertaining to security area/tests Unit tests, e2e tests, anything to make sure things don't break help wanted We would love help on these issues. Please come help us! kind/feature New features for Agones
Milestone

Comments

@roberthbailey
Copy link
Member

We should consider adding fuzz testing to Agones.

Kubernetes uses https://github.com/google/gofuzz (originally was in the Kubernetes repo but was split out).

https://github.com/google/oss-fuzz is Google’s free fuzzing-as-a-service platform and has recently added support for Go fuzzers.

There are probably other options as well that I'm not aware of.

@roberthbailey roberthbailey added kind/feature New features for Agones area/security Issues pertaining to security area/tests Unit tests, e2e tests, anything to make sure things don't break help wanted We would love help on these issues. Please come help us! labels Oct 3, 2019
@aLekSer
Copy link
Collaborator

aLekSer commented Nov 25, 2019

Question here: What parts of Agones should be covered with Fuzz testing?
Found a recent thread in Kubernetes slack about fuzz testing of CRDs:
https://kubernetes.slack.com/archives/CAR30FCJZ/p1573755986055900
I have tried to make a CRD fuzz test using this tool:
https://github.com/munnerz/crd-schema-fuzz
But we are not using fresh dependencies so I was not able to build a simple test.
Also I could not find https://github.com/kubernetes/apimachinery/tree/master/pkg/api/apitesting this functionality in the vendored apimachinery.

@roberthbailey
Copy link
Member Author

Question here: What parts of Agones should be covered with Fuzz testing?

I would imagine that our api surface would make the most sense. I think looking at how k8s does fuzz testing and doing something similar (which it looks like you were trying to do) would be a great starting point.

@aLekSer
Copy link
Collaborator

aLekSer commented Nov 26, 2019

Thanks for your answer.
Two more projects which is worth to consider:
https://github.com/fuzzitdev/fuzzit
https://github.com/dvyukov/go-fuzz

Fuzzit is free for open source, prometheus is using it, it adds a new fuzzit: pass label on repo main page, and could be exucuted on every pull request.

Currently investigating if we can add fuzz tests also for applyBufferPolicy() func of a FleetAutoScaler.

@aLekSer
Copy link
Collaborator

aLekSer commented Nov 27, 2019

@aLekSer
Copy link
Collaborator

aLekSer commented Nov 28, 2019

Followed an example from the book "Programming Kubernetes" https://github.com/programming-kubernetes/pizza-apiserver/tree/master/pkg/apis/restaurant/fuzzer
Was able to run a simple roundtrip fuzz test for agones.dev/v1.
It seems that we need to have additional addKnownTypes() call for the __internal GroupVersion:

var SchemeGroupVersion = schema.GroupVersion{Group: agones.GroupName, Version: k8sruntime.APIVersionInternal}
//with next line commented out
// metav1.AddToGroupVersion(scheme, SchemeGroupVersion)

@aLekSer
Copy link
Collaborator

aLekSer commented Jan 13, 2020

Picked this ticket back. Now I am using this code as an example:
k8s.io/api/roundtrip_test.go
The point which is failing is:

    roundtrip.go:385: GameServerAllocationPolicyList: fuzzing a copy altered the original, diff:
        object.Items[0].Spec.ConnectionInfo.AllocationEndpoints[0]:
          a: "昭鴁Ō\u00a0袺\"祋ī·#x"
          b: "昭鴁Ō\u00a0袺\"祋ī·#"
    roundtrip.go:166: round tripping /v1, Kind=Status
    roundtrip.go:254:   round tripping external type /v1, Kind=Status
    roundtrip.go:166: round tripping autoscaling.agones.dev/v1, Kind=FleetAutoscalerList
    roundtrip.go:254:   round tripping external type autoscaling.agones.dev/v1, Kind=FleetAutoscalerList
    roundtrip.go:166: round tripping allocation.agones.dev/v1, Kind=CreateOptions
    roundtrip.go:254:   round tripping external type allocation.agones.dev/v1, Kind=CreateOptions
    roundtrip.go:166: round tripping allocation.agones.dev/v1, Kind=UpdateOptions
    roundtrip.go:254:   round tripping external type allocation.agones.dev/v1, Kind=UpdateOptions
    roundtrip.go:166: round tripping multicluster.agones.dev/v1alpha1, Kind=GameServerAllocationPolicy
    roundtrip.go:254:   round tripping external type multicluster.agones.dev/v1alpha1, Kind=GameServerAllocationPolicy
    roundtrip.go:166: round tripping agones.dev/v1, Kind=GameServer
    roundtrip.go:254:   round tripping external type agones.dev/v1, Kind=GameServer
    roundtrip.go:166: round tripping agones.dev/v1, Kind=Fleet
    roundtrip.go:254:   round tripping external type agones.dev/v1, Kind=Fleet
    roundtrip.go:166: round tripping /v1, Kind=APIResourceList
    roundtrip.go:254:   round tripping external type /v1, Kind=APIResourceList
    roundtrip.go:166: round tripping allocation.agones.dev/v1, Kind=GameServerAllocationList
    roundtrip.go:254:   round tripping external type allocation.agones.dev/v1, Kind=GameServerAllocationList
FAIL

@roberthbailey
Copy link
Member Author

It looks like that field is in the v1alpha1 api surface:

AllocationEndpoints []string `json:"allocationEndpoints,omitempty"`
which means that we can fix it without it being a breaking change.

/cc @pooneh-m (for when she's back in the office)

@roberthbailey
Copy link
Member Author

Is there a way to only fuzz the v1 apis to start so that we can get your PR merged while we decide how to fix this?

@aLekSer
Copy link
Collaborator

aLekSer commented Jan 14, 2020

Hello, will do, I think we can skip alpha for now. Nice solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/security Issues pertaining to security area/tests Unit tests, e2e tests, anything to make sure things don't break help wanted We would love help on these issues. Please come help us! kind/feature New features for Agones
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants