Skip to content

[gitlab/webhook] return code 200 on Unauthorized #14421

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

Merged
merged 1 commit into from
Nov 7, 2022
Merged

Conversation

AlexTugarev
Copy link
Member

@AlexTugarev AlexTugarev commented Nov 4, 2022

To avoid provoking permanent deactivation of the webhooks we need to stop responding with status 401. In future we need to make the Unauthorized situation fixable from Gitpod.

Related Issue(s)

Fixes #13985

How to test

  1. Do a manual test with a GitLab project, including pushing to a repo and verifying that a prebuild was triggered.
  2. Delete your test account.
  3. Push a change to the test repo, and verify that Gitpod is not responding with code 401. See: https://gitlab.com/YOUR_ACCOUNT/TEST_REPO/-/hooks/WEBHOOK_ID/edit

Release Notes

Gitlab webhooks: play nice, don't respond with code 401.

Documentation

Werft options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide

@AlexTugarev AlexTugarev requested a review from a team November 4, 2022 08:02
@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-at-gitlab-401-fix.1 because the annotations in the pull request description changed
(with .werft/ from main)

@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Nov 4, 2022
@AlexTugarev AlexTugarev changed the title [gitlab/webghook] return code 200 on Unauthorized [gitlab/webhook] return code 200 on Unauthorized Nov 4, 2022
await this.webhookEvents.updateEvent(event.id, { status: "dismissed_unauthorized" });
// TODO(at) explore ways to mark a project having issues with permissions.
Copy link
Member Author

Choose a reason for hiding this comment

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

this as a followup to #13985

@@ -75,11 +75,11 @@ export class GitLabApp {
TraceContext.setError({ span }, error);
}
if (!user) {
// If the webhook installer is no longer found in Gitpod's DB
// we should send a UNAUTHORIZED signal.
// Gitpod is not supposed to return 4xx codes on issues with project permissions.
Copy link
Member

Choose a reason for hiding this comment

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

Given this behaviour (200 on Error) is gonna look pretty bizzare to future readers, could you explain WHY it's doing it, rather than WHAT it's doing?

What I mean is to elaborate on why we cannot return a 4xx, and what are the implications if we do.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good question. The complete answer and docs are already contained at the top of this handler.

From the webhook event sender's perspective this is is not a 4xx case. We are not interested in a permanent disablement of the webhook if project permissions are temporarily "broken", instead prebuilds won't be executed until the maintainer had a chance to fix the issue.

Also noteworthy, the response text is completely optional and helps us to understand the delivery logs on GitLab, but it's ignored otherwise. So this is the place where we may encode the App level error.

The sender expects a 2xx response whenever it was a successful and legit delivery. It's up to the receiver to deal with issues of the application. For more on this see the linked issue and https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#failing-webhooks

Copy link
Member

Choose a reason for hiding this comment

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

The complete answer and docs are already contained at the top of this handler.

@AlexTugarev Looks like it only mentions 500. Can you add a line about 4xx as well? 🙏

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks both of you for the hint. Just added some more details on the special behavior of webhooks, so that reading code makes more sense to future readers.

@geropl
Copy link
Member

geropl commented Nov 4, 2022

Start ŧesting now...

@geropl
Copy link
Member

geropl commented Nov 4, 2022

Worked:
image

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Code LGTM, tested and works 🎉

/hold for this small ask

@AlexTugarev
Copy link
Member Author

/hold cancel

@geropl
Copy link
Member

geropl commented Nov 4, 2022

/hold Blocks the queue.

@AlexTugarev
Copy link
Member Author

AlexTugarev commented Nov 7, 2022

/werft run

👍 started the job as gitpod-build-at-gitlab-401-fix.4
(with .werft/ from main)

Otherwise we provoke permanent deactivation of the webhook. In future we need to make the Unauthorized situation fixable from Gitpod.
@AlexTugarev
Copy link
Member Author

/hold cancel

@roboquat roboquat merged commit 51bac3a into main Nov 7, 2022
@roboquat roboquat deleted the at/gitlab-401-fix branch November 7, 2022 09:59
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note size/S team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Webhooks for GitLab projects are disabled on Unauthorized Errors
4 participants