Skip to content
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

How to get full list of affected digest for ACR vulnerability via REST API? #64

Closed
zhongyi-zhang opened this issue Mar 26, 2020 · 19 comments

Comments

@zhongyi-zhang
Copy link

zhongyi-zhang commented Mar 26, 2020

image

In Portal, I can see the full list of an ACR vulnerability like above.
I tried this API: https://docs.microsoft.com/en-us/rest/api/securitycenter/subassessments/list
For each vulnerability in one repo, it returns only one digest.

It is important to get the full list for our team. Could you guide me how to do this? Thanks a bunch!

@zhongyi-zhang zhongyi-zhang changed the title How to get full list of affected digest for ACR vulnerability via REST API How to get full list of affected digest for ACR vulnerability via REST API? Mar 26, 2020
@wtomw
Copy link
Contributor

wtomw commented Mar 29, 2020

Hello @zhongyi-zhang ,

SubAssessments API is yet to support resource filtering.
For a specific repository or image scan findings, I would recommend using Azure resource graph (ARG) resource query API.

You can use this guide as a reference for Image scan findings extraction using ARG query API.

@zhongyi-zhang
Copy link
Author

Hi @wtomw, thanks for the points! Appreciate it! The guide is very helpful. I can get the data what I expect to get. The only problem is that, it can return at most 1000 rows. That's fine. I'd like to remediate the vulnerability one by one until all of them resolved...
One more question, what's the least permission to assign to a service principal so that it can call the ARG REST API? Hope it doesn't require permission as large as a subscription contributor...

@wtomw
Copy link
Contributor

wtomw commented Mar 30, 2020

Hi @zhongyi-zhang,
ARG REST API supports paging, so you can use that to extract the all records.

As for ARG REST API permissions requirements you can read more here, which should be correlated to Azure Security Center permissions requirements where you can read more on in here.

@zhongyi-zhang
Copy link
Author

@wtomw thanks for the prompt reply!
Yeah, I find the $skipToken for paging in doc. But somehow in the response to my request, it doesn't return $skipToken, and returns "resultTruncated": "true". The result is indeed not complete since it shows "totalRecords": 8585, "count": 1000, in the response. Is there any required parameter to enable paging?

@wtomw
Copy link
Contributor

wtomw commented Mar 30, 2020

@zhongyi-zhang
ARG REST API query paging can be found in quey request options under here

@zhongyi-zhang
Copy link
Author

@wtomw yes, I even tried adding the same option

"options": {
      "$top": 3,
      "$skip": 0
}

Then I got:

{
"totalRecords": 8585,
"count": 3,
"data": "<a-lot-of-rows>",
"facets": [],
"resultTruncated": "true"
}

No "$skipToken" returned.

This is my script:

DATA='{
  "subscriptions": [ <mySub> ],
  "query":"<myQuery>",
  "options": {
    "$top": 3,
    "$skip": 0
  }
}'
curl \
  -H "Content-Type:application/json" \
  -H "Authorization: Bearer ${accessToken}" \
  -d "${DATA}" \
  "https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2019-04-01"

@YuriDio
Copy link
Member

YuriDio commented May 4, 2020

Looks like @wtomw - addressed the question from ASC perspective, now is more an ARG question and @wtomw provided the ARG documentation link.

@YuriDio YuriDio closed this as completed May 4, 2020
@gadinaor
Copy link

gadinaor commented Oct 9, 2020

@wtomw is there any update/ETA for a a reasonable REST API to obtain findings for a given image Id ?

I am looking for something that's similar to https://docs.aws.amazon.com/cli/latest/reference/ecr/describe-image-scan-findings.html

@wtomw
Copy link
Contributor

wtomw commented Oct 11, 2020

@gadinaor, the way to extract specific image findings is using Azure resource graph (ARG) resource query API.

You can use this guide as a reference for Image scan findings extraction using ARG query API.

Unfortunately, currently there is no support for filtering a specific image using the Sub Assessment REST API.

@gadinaor
Copy link

@wtomw so, I am down this rabbit 🐇 hole ... and the ARG query I have based on the guide you shared doesn't return the package name as a structured field (see info below) - am I missing anything? if not, what's the plan to add this field to the returned object?

My query:

securityresources
| where type == "microsoft.security/assessments"
//| where properties.displayName contains "Vulnerabilities in Azure Container Registry images should be remediated"
| summarize by assessmentKey=name //the ID of the assessment
| join kind=inner (
    securityresources
     | where type == "microsoft.security/assessments/subassessments"
     | extend assessmentKey = extract(".*assessments/(.+?)/.*",1,  id)
 ) on assessmentKey
| project assessmentKey, subassessmentKey=name, id, parse_json(properties), resourceGroup, subscriptionId, tenantId
| where properties.additionalData.imageDigest == "sha256:4343f035d365cc3968f4276e712dbb42908de6f5538611668b03b7b69c142593"
| extend description = properties.description,
         displayName = properties.displayName,
         resourceId = properties.resourceDetails.id,
         resourceSource = properties.resourceDetails.source,
         category = properties.category,
         severity = properties.status.severity,
         code = properties.status.code,
         timeGenerated = properties.timeGenerated,
         remediation = properties.remediation,
         impact = properties.impact,
         vulnId = properties.id,
         additionalData = properties.additionalData,
	repositoryName = properties.additionalData.repositoryName,
        imageDigest = properties.additionalData.imageDigest

here's the properties object returned from this query:

{
    "description": "Debian has released security update for systemd to fix the vulnerabilities.<P>",
    "displayName": "Debian Security Update for systemd",
    "resourceDetails": {
        "source": "Azure",
        "id": "/repositories/myrepo/manyvuln/images/sha256:4343f035d365cc3968f4276e712dbb42908de6f5538611668b03b7b69c142593"
    },
    "additionalData": {
        "assessedResourceType": "ContainerRegistryVulnerability",
        "vendorReferences": [
            {
                "title": "CVE-2018-1049",
                "link": "https://security-tracker.debian.org/tracker/CVE-2018-1049"
            },
            {
                "title": "CVE-2018-15686",
                "link": "https://security-tracker.debian.org/tracker/CVE-2018-15686"
            }
        ],
        "publishedTime": "2019-05-06T10:54:00.0000000Z",
        "patchable": true,
        "type": "Vulnerability",
        "cvss": {
            "2.0": {
                "base": 10
            },
            "3.0": {
                "base": 9.8
            }
        },
        "cve": [
            {
                "title": "CVE-2018-1049",
                "link": "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-1049"
            },
            {
                "title": "CVE-2018-15686",
                "link": "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-15686"
            }
        ],
        "repositoryName": "myrepo/manyvuln",
        "registryHost": "myregistry.azurecr.io",
        "imageDigest": "sha256:4343f035d365cc3968f4276e712dbb42908de6f5538611668b03b7b69c142593"
    },
    "status": {
        "severity": "High",
        "code": "Unhealthy"
    },
    "timeGenerated": "2020-10-17T07:35:03.4900000Z",
    "remediation": "Refer to <A HREF=\"https://security-tracker.debian.org/tracker/CVE-2018-15686\" TARGET=\"_blank\">Debian 9 - CVE-2018-15686</A> and <A HREF=\"https://security-tracker.debian.org/tracker/CVE-2018-1049\" TARGET=\"_blank\">Debian 9 - CVE-2018-1049</A> to address this issue and obtain further details.\n<P>Patch:<BR>\nFollowing are links for downloading patches to fix the vulnerabilities:\n<P> <A HREF=\"https://security-tracker.debian.org/tracker/CVE-2018-15686\" TARGET=\"_blank\">CVE-2018-15686: Debian</A><P> <A HREF=\"https://security-tracker.debian.org/tracker/https://security-tracker.debian.org/tracker/CVE-2018-15686\" TARGET=\"_blank\">CVE-2018-1049: Debian</A>",
    "category": "Debian",
    "id": "176875",
    "impact": "This vulnerability could be exploited to gain partial access to sensitive information. Malicious users could also use this vulnerability to change partial contents or configuration on the system. Additionally this vulnerability can also be used to cause a limited denial of service in the form of interruptions in resource availability."
}

@wtomw
Copy link
Contributor

wtomw commented Oct 18, 2020

@gadinaor, what do you mean by package name? which property is missing?

@gadinaor
Copy link

gadinaor commented Oct 18, 2020

@wtomw in the example above ... the findings are on systemd package - it’s noted in the description field , however there is no field in the properties that this information is available . Normally - the information includes the vulnerable package name and vulnerable package version

@wtomw
Copy link
Contributor

wtomw commented Oct 20, 2020

@gadinaor, Currently there is no property in the SubAssessment object that reflects the specific package the vulnerability is related to.

@sean-keane25
Copy link

sean-keane25 commented Oct 20, 2020

Knowing the specific package and version the vulnerability was found for in a container image is a crucial piece of information so that you can address the vulnerability. Are there any plans to add this information to the SubAssessment Object?

@wtomw
Copy link
Contributor

wtomw commented Oct 21, 2020

@sean-keane25, the package details are available in finding's description. Currently we don't have a dedicated property for package version.

@gadinaor
Copy link

@wtomw - is there an open issue for this ? or shall I create one?

@sean-keane25
Copy link

@wtomw I do not see the package details in findings description. Even in the example @gadinaor posts above I do not see this information. Perhaps I am missing something ?

@wtomw
Copy link
Contributor

wtomw commented Oct 22, 2020

@sean-keane25, are you referring perhaps to specifying the layer of which the finds were found on? if so, this is in our plans, no ETA at the moment.

@wtomw
Copy link
Contributor

wtomw commented Oct 22, 2020

@gadinaor, you can add dedicated affected package property as a feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants