Skip to content

[github] Add dependabot alerts data stream #3754

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 21 commits into from
Aug 24, 2022

Conversation

kcreddy
Copy link
Contributor

@kcreddy kcreddy commented Jul 19, 2022

What does this PR do?

For ingesting Github Advanced Security (GHAS) Dependabot alerts

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

Screenshots

Screenshot 2022-08-22 at 8 27 24 PM

Demo

Demo of Github Advanced Security (GHAS) Alerts:

GHAS.Demo.mp4

@elasticmachine
Copy link

elasticmachine commented Jul 19, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-08-24T11:39:28.359+0000

  • Duration: 17 min 56 sec

Test stats 🧪

Test Results
Failed 0
Passed 49
Skipped 0
Total 49

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link

elasticmachine commented Jul 22, 2022

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (4/4) 💚
Files 100.0% (4/4) 💚 2.825
Classes 100.0% (4/4) 💚 2.825
Methods 100.0% (45/45) 💚 10.619
Lines 94.958% (678/714) 👍 3.961
Conditionals 100.0% (0/0) 💚

@kcreddy kcreddy marked this pull request as ready for review July 22, 2022 07:05
@kcreddy kcreddy requested a review from a team as a code owner July 22, 2022 07:05
@elasticmachine
Copy link

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

{{/if}}

request.body:
query:
Copy link
Member

Choose a reason for hiding this comment

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

Could we store this as a formatted string to make reading it easier? Like

  query: |-
    query fetchRepoAlerts($org: String!, $repo: String!) {
      repository(owner: $org, name: $repo) {
        vulnerabilityAlerts(first: 2) {
          nodes {
            createdAt
            dependabotUpdate {
              error {
                body
                errorType
                title
              }
              pullRequest {
                createdAt
                closed
                closedAt
                merged
                mergedAt
                number
                url
                title
              }
            }
            dependencyScope
            dismissReason
            dismissedAt
            dismisser {
              login
              url
            }
            fixReason
            fixedAt
            number
            repository {
              description
              isInOrganization
              isPrivate
              name
              owner {
                login
                url
              }
              url
            }
            securityAdvisory {
              classification
              cvss {
                score
                vectorString
              }
              cwes(first: 100) {
                nodes {
                  cweId
                  description
                  name
                }
              }
              description
              ghsaId
              identifiers {
                type
                value
              }
              origin
              permalink
              references {
                url
              }
              publishedAt
              severity
              summary
              updatedAt
              withdrawnAt
            }
            securityVulnerability {
              firstPatchedVersion {
                identifier
              }
              package {
                ecosystem
                name
              }
              severity
              updatedAt
              vulnerableVersionRange
            }
            state
            vulnerableManifestPath
            vulnerableManifestFilename
            vulnerableRequirements
          }
          pageInfo {
            hasNextPage
            endCursor
          }
        }
      }
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrewkroh Thanks for the suggestion. Unfortunately, the above formatted string doesn't seem to be working. Following is the error message in the agent logs:
"message":"error processing response: template: :1:69: executing \"\" at <.last_response.body.data.repository.vulnerabilityAlerts.pageInfo.endCursor>: map has no entry for key \"data\""
I think the request might be getting an empty response and trying to get cursor info where there is none and logging it.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think the request body gets marshalled correctly that way, a bit unsure if that is just because of a typo or not

api_url: http://{{Hostname}}:{{Port}}
access_token: xxxxxxxxxx
owner: sample_owner
repo: sample_repo
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to construct a query that gets the alerts from all repos in an org? As repos are added within an org, then you will need to keep adding new inputs which isn't sustainable for big orgs.

Copy link
Member

Choose a reason for hiding this comment

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

This is an incomplete PoC, but it appears that it is possible (I know very little about graphql). So perhaps the integration could function is two modes like org mode or single repo mode. I think org mode will be used the most.

query orgRepoVulnerabilities($org: String!) {
  organization(login: $org) {
    repositories(first: 100) {
      nodes {
        name
        vulnerabilityAlerts(first: 10) {
          nodes {
            createdAt
            dependabotUpdate {
              error {
                body
                errorType
                title
              }
              pullRequest {
                createdAt
                closed
                closedAt
                merged
                mergedAt
                number
                url
                title
              }
            }
          }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great suggestion @andrewkroh. When I met with Github folks they also wanted organisation level alerts implemented. Here is the PR where this enhancement will be implemented(targeting for 8.5): #3935

The reason repository was targeted in the first run was to have some consistency in the implementation as their REST APIs for Github Code Scanning alerts at ORG level wasn't working. So, thought of adding repo endpoint first, then followup with org endpoint and provide choice to the user.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah the end goal is to offer 2 options.
Organization level as default, and a repo option in advanced options, if repo is set, it will focus on a single repo, as there is no way to filter on repo's at all when using organization/root level API's.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code changed to query organization level alerts by default, and if repository (optional) is provided, the integration would only query repository level alerts.

@andrewkroh andrewkroh changed the title Add GitHub Dependabot alerts datastream [github] Add dependabot alerts data stream Aug 16, 2022
"name": "jsonwebtoken"
},
"updated_at": "2018-11-30T19:54:28Z",
"vulnerable_version_range": "\u003c 4.2.2"
Copy link
Contributor

Choose a reason for hiding this comment

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

The \u encoding of < is unfortunate. This is also present in event.original which seems worse, verging on a bug.

ISTM that this should be fixed in httpjson (https://play.golang.com/p/YGhWbtX7jO0)

Copy link
Member

@P1llus P1llus left a comment

Choose a reason for hiding this comment

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

LGTM

@kcreddy
Copy link
Contributor Author

kcreddy commented Sep 13, 2022

Demo of Github Advanced Security (GHAS) Alerts:

GHAS.Demo.mp4

@andrewkroh
Copy link
Member

Great demo! Thank you for adding that!

Feedback

  • Consider moving the Personal Access Token config into main manifest so that only needs to be configured once. As an example, we do this in the aws integration for the access / secret tokens.

  • I'm not sure if there is precedent, but should the Personal Access Token be marked as a password type to mask it in the UI?

  • Since all of the individual visualizations in the dashboards are supposed to be embedded in the dashboard (as opposed to stored as an independent saved object), you no longer need to title the visualizations with the suffix of the dashboard name. That is, you can remove the [Githbub Code Scanning] from viz titles.

@kcreddy
Copy link
Contributor Author

kcreddy commented Sep 22, 2022

Thanks for the feedback @andrewkroh! I will be implementing above suggestions in the subsequent release.

@kcreddy kcreddy deleted the github_dependabot branch February 7, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Integration:github GitHub
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants