【发布时间】:2020-10-23 07:41:38
【问题描述】:
我目前正在尝试将 AWS ECR 扫描集成到我们的 CI/CD 管道中,并将结果以人类可读的形式传递给我们的工程师。
命令 - aws ecr describe-image-scan-findings --repository-name ${REPNAME} --image-id imageTag=latest --profile ${PROFILE} --region ${REGION}
返回类似于以下 [redacted] 输出的内容 -
"imageScanFindings": {
"findings": [
{
"name": "CVE-2018-12886",
"description": "stack_protect_prologue in cfgexpand.c and stack_protect_epilogue in function.c in GNU Compiler Collection (GCC) 4.1 through 8 (under certain circumstances) generate instruction sequences when targeting ARM targets that spill the address of the stack protector guard, which allows an attacker to bypass the protection of -fstack-protector, -fstack-protector-all, -fstack-protector-strong, and -fstack-protector-explicit against stack overflow by controlling what the stack canary is compared against.",
"uri": "https://security-tracker.debian.org/tracker/CVE-2018-12886",
"severity": "MEDIUM",
"attributes": [
{
"key": "package_version",
"value": "8.3.0-6"
},
{
"key": "package_name",
"value": "gcc-8"
},
{
"key": "CVSS2_VECTOR",
"value": "AV:N/AC:M/Au:N/C:P/I:P/A:P"
},
{
"key": "CVSS2_SCORE",
"value": "6.8"
}
]
},
{
"name": "CVE-2020-1751",
"description": "An out-of-bounds write vulnerability was found in glibc before 2.31 when handling signal trampolines on PowerPC. Specifically, the backtrace function did not properly check the array bounds when storing the frame address, resulting in a denial of service or potential code execution. The highest threat from this vulnerability is to system availability.",
"uri": "https://security-tracker.debian.org/tracker/CVE-2020-1751",
"severity": "MEDIUM",
"attributes": [
{
"key": "package_version",
"value": "2.28-10"
},
{
"key": "package_name",
"value": "glibc"
},
{
"key": "CVSS2_VECTOR",
"value": "AV:L/AC:M/Au:N/C:P/I:P/A:C"
},
{
"key": "CVSS2_SCORE",
"value": "5.9"
}
]
},
{
"name": "CVE-2019-20367",
"description": "nlist.c in libbsd before 0.10.0 has an out-of-bounds read during a comparison for a symbol name from the string table (strtab).",
"uri": "https://security-tracker.debian.org/tracker/CVE-2019-20367",
"severity": "MEDIUM",
"attributes": [
{
"key": "package_version",
"value": "0.9.1-2"
},
{
"key": "package_name",
"value": "libbsd"
},
{
"key": "CVSS2_VECTOR",
"value": "AV:N/AC:L/Au:N/C:P/I:N/A:P"
},
{
"key": "CVSS2_SCORE",
"value": "6.4"
}
]
},
{
"name": "CVE-2019-12904",
"description": "In Libgcrypt 1.8.4, the C implementation of AES is vulnerable to a flush-and-reload side-channel attack because physical addresses are available to other processes. (The C implementation is used on platforms where an assembly-language implementation is unavailable.)",
"uri": "https://security-tracker.debian.org/tracker/CVE-2019-12904",
"severity": "MEDIUM",
"attributes": [
{
"key": "package_version",
"value": "1.8.4-5"
},
{
"key": "package_name",
"value": "libgcrypt20"
},
{
"key": "CVSS2_VECTOR",
"value": "AV:N/AC:M/Au:N/C:P/I:N/A:N"
},
{
"key": "CVSS2_SCORE",
"value": "4.3"
}
]
}
],
"imageScanCompletedAt": "2020-10-23T00:03:10+05:30",
"vulnerabilitySourceUpdatedAt": "2020-10-22T16:21:44+05:30",
"findingSeverityCounts": {
"MEDIUM": 14,
"INFORMATIONAL": 72,
"LOW": 18,
"UNDEFINED": 3
}
},
"registryId": "12345678911",
"repositoryName": "name-of-repo",
"imageId": {
"imageDigest": "sha256:1213412412412451241414214141412412",
"imageTag": "latest"
},
"imageScanStatus": {
"status": "COMPLETE",
"description": "The scan was completed successfully."
}
}
上面的内容不适合人类阅读,特别是如果有很多发现并且 JSON 输出有数百行。
我想将上述输出转换为更“人类”可读的形式,而不会省略任何返回的信息。我尝试为AWS CLI 使用--output table 选项,但它在列和行之间包含很多空格。
我尝试使用jq 将其转换为表格或使用map 的某种.tsv,但没有运气,因为我是JQ 的初学者。如果有人对如何解决这个问题有任何想法 - 任何帮助将不胜感激。
我的目标是从http://json2table.com/ 获得以下内容-
【问题讨论】:
-
使用
jq发布您的尝试并发布预期的表格输出格式 -
在样例的开头放一个大括号以便格式化
-
在许多不同的脚本语言中有大量的
json2table或json2html转换器。也许其中之一就足够了?
标签: json formatting jq aws-cli amazon-ecr