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

WIP Fix bug 1373330 Invalid formatted generic webhook can trigger new… #11077

Merged
merged 1 commit into from
Oct 25, 2016

Conversation

jim-minter
Copy link
Contributor

… build without warning

@jim-minter
Copy link
Contributor Author

@bparees ptal

@@ -43,67 +43,74 @@ func (p *WebHookPlugin) Extract(buildCfg *api.BuildConfig, secret, path string,
}

if buildCfg.Spec.Source.Git == nil {
glog.V(4).Infof("No git source defined for BuildConfig %s/%s, but triggering anyway", buildCfg.Namespace, buildCfg.Name)
return revision, envvars, true, err
warning := webhook.NewWarning("BuildConfig has no git source defined, ignoring and continuing with build")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we need this warning anymore. once upon a time git source was pretty much it, but now you could have pipeline builds, or builds that take input from images and builds that embed docker files. if we're going to keep it, it needs to check for all the possible sources of "source" input, basically to ensure it's not a pure binary-only buildconfig.

}

contentType := req.Header.Get("Content-Type")
if len(contentType) != 0 {
contentType, _, err = mime.ParseMediaType(contentType)
if err != nil {
return nil, envvars, false, fmt.Errorf("non-parseable Content-Type %s (%s)", contentType, err)
return revision, envvars, false, fmt.Errorf("Error parsing Content-Type: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know the reason behind it, but we never uppercase the start of our error messages. possibly because they end up embedded in other output and look strange.

envvars = data.Env
}
if data.Git == nil {
warning := webhook.NewWarning("No git information found in payload, ignoring and continuing with build")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this necessitates a warning. if we warn here, users who just want to supply env variables are going to get spurious warnings.

I think if

  1. we can parse the payload and
  2. the result is either git data or env variable data (or both)

we should not warn.

func matchWarning(t *testing.T, err error, message string) {
if status, ok := err.(*errors.StatusError); !ok {
t.Errorf("Expected %v to be a StatusError object", err)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the else. just return inside the if-block above.

@bparees
Copy link
Contributor

bparees commented Sep 23, 2016

@openshift/api-review any other thoughts on how we can handle returning a warning on the webhook invocation? basically we need to tell them "you gave us bad payload data, but we're running a build anyway(because that's what we've always done, so compatibility...), using the buildconfig defaults".

so here we're returning a StatusError w/ a status code of 200 and a warning message which feels icky to me, but i don't have a better idea.

@jim-minter
Copy link
Contributor Author

@bparees all changes requested above made, ptal

}
warning := webhook.NewWarning(fmt.Sprintf("skipping build. None of the supplied refs matched %q", buildCfg.Spec.Source.Git.Ref))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a warning and not an error, since it's not actually going to result in a build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is maintaining previous API. This is identical behaviour as before, but I converted a glog.V(2).Infof (only accessible by admin, and tricky to find) to a returned "warning" (clearer to end user) as it felt within the scope and aims of this patch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing api returns a 200 in this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is my understanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I've tried it again - yes, it currently returns a 200 in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm. that was probably the wrong choice when we implemented the api, but ok I guess we're stuck with it. Still feels awkward to call it a warning since in all the other cases a warning means "something went wrong but we're proceeding with the build" and here the warning means "something went wrong and we're not doing the build even though we gave you back a 200"

I wonder if we could get away w/ changing this to a non-200 return code even though it's technically breaking the existing api. @smarterclayton ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm going to interpret @smarterclayton's response on the main thread as a "no, you can't change it to a non-200". oh well.

return revision, envvars, false, warning
}
if !webhook.GitRefMatches(data.Git.Ref, webhook.DefaultConfigRef, &buildCfg.Spec.Source) {
warning := webhook.NewWarning(fmt.Sprintf("skipping build. Branch reference from %q does not match configuration", data.Git.Ref))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here

@smarterclayton
Copy link
Contributor

Is this bad data we allowed to be sent in 1.0? Or bad data we started allowing someone to send us in 1.3?

@bparees
Copy link
Contributor

bparees commented Sep 26, 2016

Is this bad data we allowed to be sent in 1.0? Or bad data we started allowing someone to send us in 1.3?

we've always allowed this data to be sent, though it looks like in the original implementation we immediately failed if the data wasn't readable and at some point we changed to proceeding w/ the build but ignoring the bad data:

6594ffd#diff-d0545fc405d0111150cfcc584145ed18

That change was in march 2015.

@smarterclayton
Copy link
Contributor

Did we actually honor any data in here in 1.0? Or was that only later
where we added info to generic web hook?

On Mon, Sep 26, 2016 at 11:26 AM, Ben Parees [email protected]
wrote:

Is this bad data we allowed to be sent in 1.0? Or bad data we started
allowing someone to send us in 1.3?

we've always allowed this data to be sent, though it looks like in the
original implementation we immediately failed if the data wasn't readable
and at some point we changed to proceeding w/ the build but ignoring the
bad data:

6594ffd#diff-d0545fc405d0111150cfcc584145ed18
6594ffd#diff-d0545fc405d0111150cfcc584145ed18

That change was in march 2015.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#11077 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABG_p7RSsMh5HPAzvlAkZAv6Phh63MHSks5qt-Q4gaJpZM4KFJXe
.

@bparees
Copy link
Contributor

bparees commented Sep 26, 2016

Did we actually honor any data in here in 1.0? Or was that only later
where we added info to generic web hook?

yes we honored it. we used the git ref.

@jim-minter
Copy link
Contributor Author

@smarterclayton @bparees the conversation left me hanging - please advise if I need to make changes to the PR in order to get it merged.

@jim-minter jim-minter self-assigned this Sep 28, 2016
@bparees
Copy link
Contributor

bparees commented Sep 28, 2016

@smarterclayton @bparees the conversation left me hanging - please advise if I need to make changes to the PR in order to get it merged.

at this point i'm fine with it as is. still need @openshift/api-review to sign off though.

@bparees
Copy link
Contributor

bparees commented Oct 19, 2016

@openshift/api-review bump

@smarterclayton
Copy link
Contributor

Preserve existing error behavior and document why it is that way.

@bparees
Copy link
Contributor

bparees commented Oct 20, 2016

this PR is preserving the existing behavior, just adding a warning to the response body (while still returning a 200 status)

@jim-minter you can doc the behavior here:
https://docs.openshift.org/latest/dev_guide/builds.html#webhook-triggers

@smarterclayton
Copy link
Contributor

That is correct.

On Wed, Oct 19, 2016 at 10:59 PM, Ben Parees [email protected]
wrote:

@bparees commented on this pull request.

In pkg/build/webhook/generic/generic.go
#11077:

    }
  • warning := webhook.NewWarning(fmt.Sprintf("skipping build. None of the supplied refs matched %q", buildCfg.Spec.Source.Git.Ref))
    

i'm going to interpret @smarterclayton https://github.com/smarterclayton's
response on the main thread as a "no, you can't change it to a non-200". oh
well.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#11077, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABG_p9lyQQ6SPBxyllLWw_fXjWTaaOFJks5q1tktgaJpZM4KFJXe
.

@bparees
Copy link
Contributor

bparees commented Oct 20, 2016

@openshift/api-review so is this api approved? basically the change is a warning message that comes back w/ your 200 status code in certain cases.

@smarterclayton
Copy link
Contributor

It's possible you're going to break people because they aren't expecting a body. What are the odds of that?

@jim-minter
Copy link
Contributor Author

@smarterclayton Inevitably it is feasible, but I think it's a pretty poor show if any modern HTTP client posts a GET or a POST and doesn't know what to do with a response. It's hardly out of HTTP spec for us to do this. The warnings closely match the k8s StatusError responses so are in idiom for a client which is already reading these for error cases. In addition I think they add helpful information (you sent content with an invalid content-type; your build didn't trigger because of XYZ) which is better sent back than left lurking in a server-side log.

@bparees bparees assigned bparees and unassigned jim-minter Oct 21, 2016
@smarterclayton
Copy link
Contributor

Once we've released an API we have to act like every change could break a client. For this one the odds seem low, so I'll let it pass here. But we've broken people before with much less why it's important to be cautious.

@bparees
Copy link
Contributor

bparees commented Oct 22, 2016

@smarterclayton can you mark it approved, then?

@bparees
Copy link
Contributor

bparees commented Oct 24, 2016

[merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Oct 24, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10622/) (Image: devenv-rhel7_5240)

@bparees
Copy link
Contributor

bparees commented Oct 25, 2016

--- FAIL: TestWebhookGitHubPing (5.16s)
    webhookgithub_test.go:300: Wrong response code, expecting 200, got 500: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Internal error occurred: hook failed: \u003cnil\u003e","reason":"InternalError","details":{"causes":[{"message":"hook failed: \u003cnil\u003e"}]},"code":500}

@jim-minter
Copy link
Contributor Author

flake #11517

@bparees
Copy link
Contributor

bparees commented Oct 25, 2016

[test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to aea22a7

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10622/) (Base Commit: 1f62556)

@bparees
Copy link
Contributor

bparees commented Oct 25, 2016

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to aea22a7

@openshift-bot openshift-bot merged commit 833eb03 into openshift:master Oct 25, 2016
@jim-minter
Copy link
Contributor Author

@bparees just to check with this - is the expectation a docs PR against https://docs.openshift.org/latest/dev_guide/builds.html#webhook-triggers and doc text in https://bugzilla.redhat.com/show_bug.cgi?id=1373330 ?

@bparees
Copy link
Contributor

bparees commented Oct 31, 2016

@jim-minter yup

jim-minter pushed a commit to jim-minter/origin that referenced this pull request Nov 7, 2016
…ors instead of 500 errors where possible
jim-minter pushed a commit to jim-minter/origin that referenced this pull request Nov 8, 2016
…ors instead of 500 errors where possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants