Repository navigation
Conversation
|
Did you find out why we need to track the jira comment id. It should be sufficient to use Dave with push_to_jira set to false. |
Well after investigation I think that tracking the jira comment id is the safest way to avoid comment loops (DDJ comment -> Jira comment -> Jira webhook -> DDJ comment -> ...). I carefully analysed data coming from Jira webhooks (when posting comments from Jira) and haven't found a better approach. Yes we could analyse the body of the comment + the timestamp but it's probably be less robust and if we want to also support comment deletion (Jira comment -> DDJ) later that's probably our best option. |
8cb8e96 to
0a0ff1d
Compare
Goal of this commit is to make the DDJ<->Jira comments mechanism more robust. Some notable changes that have been introduced with this commit: 1. Tracking of Jira comments IDs inside DDJ notes: To better handle loops a new field "jira_id" was added to DDJ notes so every time a new note is created, either from the UI or the API, the jira comment reference will be stored inside the DDJ note. 2. Better handling of comments loops: With the help of point 1 we can now properly track webhooks received from Jira. 3. Better control of comments creation date: We're now using the Jira comment creation time-stamp when storing a note coming from Jira inside a DDJ note, this way we avoid out-of-order messages inside DDJ notes. Also in case of issues between Jira and the DDJ webhook endpoint (network outage, ...) Jira will always retry later to resend comments that have not been posted, this way we ensure that the note creation time-stamp is always correct. 4. Better error handling: A couple of try/except were added to catch common errors, previously DDJ was stack-tracing on some function for example if some optional fields were not present in the POST of an API_V2 call.
0a0ff1d to
60fe851
Compare
|
I fixed the remaining issues and remove the WIP status. Let me know if it can be merged as-is. |
I believe it would be better long-term to have a dedicated structure to store meta information and not use notes there, to also set the tone for the future. Could this be something using your proposal at https://owasp.slack.com/archives/C014H3ZV9U6/p1598967744017100 ? |
|
Well IMHO "meta information" on a model should be here to store user-specific-use-cases only, like storing a custom key-value attribute that would not make a lot of sense for the upstream-project. So we should extend that logic to not only When it comes to this PR and tracking the ticketing-system-ID, it's a bit the opposite; it's should be part of the model as it'll help DDJ better handle external notes (Jira in that case). This filed will be helpful to:
Maybe something we could do is rename the field |
| finding.save() | ||
| create_notification(event='other', title='JIRA Update - %s' % (jissue.finding), url=reverse("view_finding", args=(jissue.id,)), icon='check') | ||
| except Exception as e: | ||
| print("catch all") |
There was a problem hiding this comment.
Using logger would be better than print. Or remove.
Definitely sounds right if we're going with this approach. |
At any point in time, there would be only a single ID from either of these (external) systems I assume that could post back a note to DefectDojo. What's the actual downside of storing an external reference ID in the Notes model, especially if it allows for a more deterministic handling? |
|
Using one external id won't work if someone has 2 tools connected is jira and GitHub. |
|
As I understand today it's not possible to have 2 tools connected at the same time from a note perspective as you can't select where to route the note (or maybe I'm missing something) so a single ID should work. But anyway I understand your concern about code complexity and the current (sad) state of the Jira integration. I'll close this PR for now, feel free to re-open it if you've find a better idea on how to implement that and I'll be happy to work on it. |
|
🧟 re-opening this PR after discussing with @valentijnscholten over Slack. I'll cherry-pick things that still make sense and rework it a bit (error handling, comments date/time, ...). I also thought of another approach to handle comment loops while reading the Jira webhook docuemntation without having to maintain the note_id locally; We could extend what has been done in #2786 by also leveraging the updateAuthor.emailAddress field as this field is also available in the webhook payload if the bot/user-profile is configured properly VS forcing users to have an exact match between the Jira username (user for the integration) and the Jira DisplayName which are usually different by default. Let me know what you think. |
|
Not sure if email address will be reliable as most of the time defect dojo will use some kind of service account and we don't know if people will configure the correct emails address on both sides. A quick look at the JIRA docs shows they are using an accountId identifier for users. We could store that in the jira config (when the credentials are provided, the accountId can be retrieved from JIRA) on defect dojo and then compare on the incoming webhook. |
|
So it seems we have real-world issues: https://owasp.slack.com/archives/C2P5BA8MN/p1601478823038900 |
|
based on the discussion on slack it looks like the change in #2801 is causing the push_to_jira become true when it shouldn't |
|
I found out that the existing logic to detect that an incoming comment from JIRA is actually triggered by Defect Dojo was flawed. Is now fixed in #3606. |
This was also fixed in one of my JIRA revamp PRs |
|
@xens This branch have conflicts now, could you rebase your pull request? |
|
Do we actually still need it based on the discussion that aimed to reduce this PR's scope, as #3606 was merged? |
|
Good question |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
Closing it for now. The most important problem, the looping, was resolved. Most current requests or problem reports around JIRA are mainly about syncing of statuses or having no sync at all without clear errors message. |
Goal of this commit is to make the DDJ<->Jira comments mechanism more robust.
Some notable changes that have been introduced with this commit:
Tracking of Jira comments IDs inside DDJ notes:
To better handle loops a new field "jira_id" was added to DDJ notes
so every time a new note is created, either from the UI or the API,
the jira comment reference will be stored inside the DDJ note.
Better handling of comments loops:
With the help of point 1 we can now properly track webhooks received
from Jira.
Better control of comments creation date:
We're now using the Jira comment creation time-stamp when storing a note
coming from Jira inside a DDJ note, this way we avoid out-of-order messages
inside DDJ notes. Also in case of issues between Jira and the DDJ webhook endpoint
(network outage, ...) Jira will always retry later to resend comments that have
not been posted, this way we ensure that the note creation time-stamp is correct.
Better error handling:
A couple of try/except were added to catch common errors, previously DDJ was
stack-tracing on some function for example if some optional fields were not
present in the POST of an API_V2 call.