Webhook from Gitea not working
Completed
Hi there,
I have a problem with webhooks and Gitea.
I set up a Webhook in Gitea which is executed after every push to the repository.
To set it up, I followed this documentation: https://www.jetbrains.com/help/teamcity/configuring-vcs-post-commit-hooks-for-teamcity.html
I generated a token in teamcity which I then specified as secret in Gitea. Is this correct?
The answer from team city is always 401 go back to login.
This is my request: (myhost is replaced with the actual host)
Request URL: https://myhost/app/rest/vcs-root-instances/commitHookNotification?locator=vcsRoot:(type:jetbrains.git),property:(name:Backend,value:myhost/Project/Backend,matchType:contains,ignoreCase:true) Request method: POST Content-Type: application/json X-GitHub-Delivery: 4fe9a9da-6698-405e-8fdd-eed41e19e856 X-GitHub-Event: push X-Gitea-Delivery: 4fe9a9da-6698-405e-8fdd-eed41e19e856 X-Gitea-Event: push X-Gitea-Signature: 023b600deb68e454b48067c9686197fb91f36529419116e281e9ca8fb3ca61c0 X-Gogs-Delivery: 4fe9a9da-6698-405e-8fdd-eed41e19e856 X-Gogs-Event: push X-Gogs-Signature: 023b600deb68e454b48067c9686197fb91f36529419116e281e9ca8fb3ca61c0
{ "secret": "eyJ0eXAiOiAiVENWMiJ9.bGF6OGEzY08zZnhZMEVpczBxWlVSQmtrZmt3.MzU5NTQwYjUtYjllMi00YmQwLWFjNTYtMjAyYzk2ODNiMGY4", "ref": "refs/heads/master", "before": "6831e20444ab96ff51be7284b342e04b6fd63002", "after": "6831e20444ab96ff51be7284b342e04b6fd63002", "compare_url": "", "commits": [ { .......
This is the response:
Cache-Control: no-store Connection: keep-alive Content-Type: text/plain;charset=UTF-8 Date: Fri, 10 Apr 2020 22:11:58 GMT Server: nginx/1.17.9 Strict-Transport-Security: max-age=31536000 Teamcity-Node-Id: MAIN_SERVER Www-Authenticate: Basic realm="TeamCity",Bearer realm="TeamCity"
Authentication required To login manually go to "/login.html" page
Please sign in to leave a comment.
Unfortunately, the POST request you have provided above does not appear to have the expected header "Authorization: Bearer <token-value>":
https://www.jetbrains.com/help/teamcity/rest-api.html#RESTAPI-RESTAuthentication
TeamCity does not recognize "secret" property in request body for the purposes of authentication.
As per the Gitea documentation (https://docs.gitea.io/en-us/webhooks/#event-information), it appears that the header set is not customizable. Here are the alternatives I could think of:
1) a preferred approach would be to use a custom script and force your server to execute it each time condition is met. An example of .sh generic script could be found here: https://www.jetbrains.com/help/teamcity/configuring-vcs-post-commit-hooks-for-teamcity.html#ConfiguringVCSPost-CommitHooksforTeamCity-Post-commitgenericscript
It`s preferred because you can make use of token header which is generally safer than other options.
2) as per above article regarding REST auth, we do support basic auth with http://teamcity:8111/httpAuth/* endpoints. If Gitea can be configured to provide basic credentials and this approach works for you security-wise, I`d suggest to consider this option;