Skip to content

webhooks to work with gogs and github projects #1317

Closed

Description

@jstrachan

we've been trying to setup gogs which uses github style webhooks so that a git push in gogs results in a new build in OpenShift. There's no errors in openshift but the webhook request is ignored.

However we can use the webhook REST API (generic) without passing any payload and it works fine - a build is actually triggered. (We use this in hawtio-kubernetes to trigger new builds and it works fine).

However both github and gogs post a blob of JSON when they fire a webhook which seems to not get parsed correctly by OpenShift meaning the webhook doesn't result in a new build and there's no error in the log to indicate whats wrong.

Its far better if in doubt, to trigger a new build. I can imagine various git / scm hosting solutions posting various JSON blobs & its better to assume its a well intentioned attempt to trigger a build than just ignore the request and not to log any useful information about why the request was ignored ;)

So can we either:

  • make the webhook work even if the code can't parse the JSON correctly (despite it being valid JSON - just not of the expected shape)
  • have a new webhook API (or query argument) which ignores the payload if any is posted and just trigger a new build?

Ideally having better logging would help too so that we've a clue trying to diagnose why webhooks don't work; there's no errors in the openshift log right now when gogs invokes it.

FWIW here's an example blob of JSON sent from gogs:

{
  "secret":"secret101",
  "ref": "refs/heads/master",
  "commits": [{
    "id": "0330eeb868d42499ecfad174f415aabd166f16af",
    "message": "testing webhook\n",
    "url": "http://localhost:3000/jstrachan/lager1/commit/0330eeb868d42499ecfad174f415aabd166f16af",
    "author": {
      "name": "James Strachan",
      "email": "[email protected]",
      "username": "jstrachan"
    }
  }],
  "repository": {
    "id": 2,
    "name": "lager1",
    "url": "http://localhost:3000/jstrachan/lager1",
    "description": "",
    "website": "",
    "watchers": 1,
    "owner": {
      "name": "jstrachan",
      "email": "[email protected]",
      "username": "jstrachan"
    },
    "private": false
  },
  "pusher": {
    "name": "jstrachan",
    "email": "[email protected]",
    "username": "jstrachan"
  },
  "before": "826aa9e6424006faff9440b4cd336aaf72de8136",
  "after": "0330eeb868d42499ecfad174f415aabd166f16af",
  "compare_url": "http://localhost:3000/jstrachan/lager1/compare/826aa9e6424006faff9440b4cd336aaf72de8136...0330eeb868d42499ecfad174f415aabd166f16af"
}```

Activity

  1. smarterclayton commented on Mar 17, 2015

    @smarterclayton
    Contributor

    Are you using the generic webhook? That's what supports arbitrary schemas.

  2. jstrachan commented on Mar 17, 2015

    @jstrachan
    ContributorAuthor

    Yes, generic webhook.

  3. jstrachan commented on Mar 17, 2015

    @jstrachan
    ContributorAuthor

    Our workaround for now is to write a custom proxy to strip the JSON payload out and send an empty body so that we can get gogs to trigger builds on a git push

  4. soltysh commented on Mar 17, 2015

    @soltysh
    Contributor

    @jstrachan if you have a look at our webhook controller, you'll notice we're sending the error back to the source of the request (see here). The other things being checked besides json are listed here, this includes: POST, non-empty User-Agent and Content-Length headers. It would be helpful if you could provide us with full request being passed to OpenShift (including headers) as the json itself is not enough.

    Re error logging see #1333

  5. smarterclayton commented on Mar 17, 2015

    @smarterclayton
    Contributor

    Generic web hooks should not fail if the JSON is invalid, period. We should log it, and move on.

    ----- Original Message -----

    @jstrachan if you have a look at our webhook controller, you'll notice we're
    sending the error back to the source of the request (see
    here).
    The other things being checked besides json are listed
    here,
    this includes: POST, non-empty User-Agent and Content-Length headers. It
    would be helpful if you could provide us with full request being passed to
    OpenShift (including headers) as the json itself is not enough.

    Re error logging see #1333


    Reply to this email directly or view it on GitHub:
    #1317 (comment)

  6. soltysh commented on Mar 17, 2015

    @soltysh
    Contributor

    Generic web hooks should not fail if the JSON is invalid, period. We should log it, and move on.

    @smarterclayton updated PR with that behavior.

  7. jimmidyson commented on Apr 13, 2015

    @jimmidyson
    Contributor

    @soltysh - we've just tried that out with 0.4.3 & sadly this doesn't work. I guess something needs updating in webhook controller to work properly if there is no source revision available from the webhook payload?

  8. jstrachan commented on Apr 14, 2015

    @jstrachan
    ContributorAuthor

    I was looking at the swagger for 0.4.3 and couldn't find the /osapi/v1beta1/buildConfigHooks/{name}/{secret}/{type} URI any more to trigger a build from a webhook but I spotted this URI:

    /osapi/v1beta1/buildconfigs/{name}/instantiate
    

    Is this the new URL used to trigger a build? Only I couldn't seem to invoke it from 0.4.3; gets a 404 when I try use it. Maybe buildConfigHooks is still there it just isn't in swagger?

  9. smarterclayton commented on Apr 14, 2015

    @smarterclayton
    Contributor

    It's not in swagger yet - there's an issue open to move it into the framework that will allow that.

    On Apr 14, 2015, at 8:59 AM, James Strachan [email protected] wrote:

    I was looking at the swagger for 0.4.3 and couldn't find the /osapi/v1beta1/buildConfigHooks/{name}/{secret}/{type} URI any more to trigger a build from a webhook but I spotted this URI:

    /osapi/v1beta1/buildconfigs/{name}/instantiate
    Is this the new URL used to trigger a build? Only I couldn't seem to invoke it from 0.4.3; gets a 404 when I try use it. Maybe buildConfigHooks is still there it just isn't in swagger?

    —
    Reply to this email directly or view it on GitHub.

  10. jstrachan commented on Apr 14, 2015

    @jstrachan
    ContributorAuthor
  11. jstrachan commented on Apr 14, 2015

    @jstrachan
    ContributorAuthor

    FWIW trying to POST to the webhook from java on 0.4.3 I get:

    URL: /osapi/v1beta1/buildConfigHooks/james3/secret101/github
    headers: 
      Content-Type: application/json
      Accept: application/json
    
    returns:
    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type */*
    
  12. smarterclayton commented on Apr 14, 2015

    @smarterclayton
    Contributor

    Hrm, that may be swagger setting that (since there's no response defined). Definitely a bug @soltysh

    On Apr 14, 2015, at 9:24 AM, James Strachan [email protected] wrote:

    FWIW trying to POST to the webhook from java on 0.4.3 I get:

    URL: /osapi/v1beta1/buildConfigHooks/james3/secret101/github
    headers:
    Content-Type: application/json
    Accept: application/json

    returns:
    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type /
    —
    Reply to this email directly or view it on GitHub.

  13. soltysh commented on Apr 14, 2015

    @soltysh
    Contributor

    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type /

    We should accept that, probably our accept logic is wrong, I guess our
    acceptance for 'application/json' is hard coded. Definitely a bug.

    On Tue, Apr 14, 2015 at 3:35 PM Clayton Coleman [email protected]
    wrote:

    Hrm, that may be swagger setting that (since there's no response defined).
    Definitely a bug @soltysh

    On Apr 14, 2015, at 9:24 AM, James Strachan [email protected]
    wrote:

    FWIW trying to POST to the webhook from java on 0.4.3 I get:

    URL: /osapi/v1beta1/buildConfigHooks/james3/secret101/github
    headers:
    Content-Type: application/json
    Accept: application/json

    returns:
    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type /
    —
    Reply to this email directly or view it on GitHub.

    —
    Reply to this email directly or view it on GitHub
    #1317 (comment).

  14. smarterclayton commented on Apr 14, 2015

    @smarterclayton
    Contributor

    Probably. We should be very flexible about what we accept, and log an error if it doesn't quite match the expected input (not fail).

    ----- Original Message -----

    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type /

    We should accept that, probably our accept logic is wrong, I guess our
    acceptance for 'application/json' is hard coded. Definitely a bug.

    On Tue, Apr 14, 2015 at 3:35 PM Clayton Coleman [email protected]
    wrote:

    Hrm, that may be swagger setting that (since there's no response defined).
    Definitely a bug @soltysh

    On Apr 14, 2015, at 9:24 AM, James Strachan [email protected]
    wrote:

    FWIW trying to POST to the webhook from java on 0.4.3 I get:

    URL: /osapi/v1beta1/buildConfigHooks/james3/secret101/github
    headers:
    Content-Type: application/json
    Accept: application/json

    returns:
    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type /
    —
    Reply to this email directly or view it on GitHub.

    —
    Reply to this email directly or view it on GitHub
    #1317 (comment).


    Reply to this email directly or view it on GitHub:
    #1317 (comment)

  15. soltysh commented on Apr 14, 2015

    @soltysh
    Contributor

    This will be related to #1480 as well, in that we should exactly the same
    mechanism used here.

    On Tue, Apr 14, 2015 at 5:43 PM, Clayton Coleman [email protected]
    wrote:

    Probably. We should be very flexible about what we accept, and log an
    error if it doesn't quite match the expected input (not fail).

    ----- Original Message -----

    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type /

    We should accept that, probably our accept logic is wrong, I guess our
    acceptance for 'application/json' is hard coded. Definitely a bug.

    On Tue, Apr 14, 2015 at 3:35 PM Clayton Coleman <
    [email protected]>
    wrote:

    Hrm, that may be swagger setting that (since there's no response
    defined).
    Definitely a bug @soltysh

    On Apr 14, 2015, at 9:24 AM, James Strachan <
    [email protected]>
    wrote:

    FWIW trying to POST to the webhook from java on 0.4.3 I get:

    URL: /osapi/v1beta1/buildConfigHooks/james3/secret101/github
    headers:
    Content-Type: application/json
    Accept: application/json

    returns:
    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type
    /
    —
    Reply to this email directly or view it on GitHub.

    —
    Reply to this email directly or view it on GitHub
    <#1317 (comment)
    .


    Reply to this email directly or view it on GitHub:
    #1317 (comment)

    —
    Reply to this email directly or view it on GitHub
    #1317 (comment).

  16. soltysh commented on May 8, 2015

    @soltysh
    Contributor

    @jstrachan looking carefully at our output there's one thing that bothers me:

    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type */*
    

    We specifically expect application/json content-type, but for some reason you (or your server) are setting it wrong. Could you please double check that. I just did small test with curl:

    $ curl -H "Content-Type: */*" -X POST -d @push.json https://localhost:8443/osapi/v1beta3/namespaces/test/buildconfigs/ruby-sample-build/webhooks/secret101/generic
    Internal error occurred: hook failed: Unsupported Content-Type */*
    

    But with application/json it works just fine:

    curl -H "Content-Type: application/json" -X POST -d @push.json https://localhost:8443/osapi/v1beta3/namespaces/test/buildconfigs/ruby-sample-build/webhooks/secret101/generic
    
  17. smarterclayton commented on May 8, 2015

    @smarterclayton
    Contributor

    We should probably not require a mime type - a generic web-hook is an endpoint you should be able to ping from anywhere

    On May 8, 2015, at 9:07 AM, Maciej Szulik [email protected] wrote:

    @jstrachan looking carefully at our output there's one thing that bothers me:

    javax.ws.rs.WebApplicationException: 400: Unsupported Content-Type /
    We specifically expect application/json content-type, but for some reason you (or your server) are setting it wrong. Could you please double check that. I just did small test with curl:

    $ curl -H "Content-Type: /" -X POST -d @push.json https://localhost:8443/osapi/v1beta3/namespaces/test/buildconfigs/ruby-sample-build/webhooks/secret101/generic
    Internal error occurred: hook failed: Unsupported Content-Type /
    But with application/json it works just fine:

    curl -H "Content-Type: application/json" -X POST -d @push.json https://localhost:8443/osapi/v1beta3/namespaces/test/buildconfigs/ruby-sample-build/webhooks/secret101/generic
    —
    Reply to this email directly or view it on GitHub.

  18. soltysh commented on May 8, 2015

    @soltysh
    Contributor

    And parse contents of the body only if it matches the content-type? I'll start coding that right away.

  19. smarterclayton commented on May 8, 2015

    @smarterclayton
    Contributor

    Yeah, application/json is required to handle the body as a structured object.

    ----- Original Message -----

    And parse contents of the body only if it matches the content-type? I'll
    start coding that right away.


    Reply to this email directly or view it on GitHub:
    #1317 (comment)

  20. soltysh commented on May 8, 2015

    @soltysh
    Contributor

    @jstrachan give it a try once again when #2136 gets merged and if it works, please close the issue. Thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions