简体   繁体   English

Anchore Engine-Jenkins CI插件

[英]Anchore Engine - Jenkins CI plugin

We are trying to scan our docker images using Anchore Engine Jenkins plugin. 我们正在尝试使用Anchore Engine Jenkins插件扫描docker图像。

Currently we create our application docker images, push it in our own private local registry and then deploy it in our test environments. 当前,我们创建应用程序docker映像,将其推送到我们自己的私有本地注册表中,然后将其部署在我们的测试环境中。

Now, we want to setup docker image scanning in our CI/CD process to check for any vulnerabilities. 现在,我们要在CI / CD流程中设置docker图像扫描,以检查是否存在任何漏洞。

We have installed Anchore Engine using the recommended Docker-Compose yaml method given in the Documentation link: https://anchore.freshdesk.com/support/solutions/articles/36000020729-install-on-docker-swarm 我们已使用文档链接中提供的推荐的Docker-Compose yaml方法安装了Anchore Engine: https ://anchore.freshdesk.com/support/solutions/articles/36000020729-install-on-docker-swarm

Post installation, we installed the 安装后,我们安装了
Anchore Container Image Scanner Plugin in Jenkins. Jenkins中的Anchore容器图像扫描仪插件。

We configured the plugin as mentioned in the document link: https://wiki.jenkins.io/display/JENKINS/Anchore+Container+Image+Scanner+Plugin 我们按照文档链接中所述配置了插件: https : //wiki.jenkins.io/display/JENKINS/Anchore+Container+Image+Scanner+Plugin

However, the scanning fails. 但是,扫描失败。 Error Message as follows: 错误消息如下:

2018-10-11T07:01:44.647 INFO   AnchoreWorker   Analysis request accepted, received image digest sha256:7d6fb7e5e7a74a4309cc436f6d11c29a96cbf27a4a8cb45a50cb0a326dc32fe8
2018-10-11T07:01:44.647 INFO   AnchoreWorker   Waiting for analysis of 10.180.25.2:5000/hello-world:latest, polling status periodically
2018-10-11T07:01:44.647 DEBUG  AnchoreWorker   anchore-engine get policy evaluation URL: http://10.180.25.2:8228/v1/images/sha256:7d6fb7e5e7a74a4309cc436f6d11c29a96cbf27a4a8cb45a50cb0a326dc32fe8/check?tag=10.180.25.2:5000/hello-world:latest&detail=true
2018-10-11T07:01:44.648 DEBUG  AnchoreWorker   Attempting anchore-engine get policy evaluation (1/300)
2018-10-11T07:01:44.675 DEBUG  AnchoreWorker   anchore-engine get policy evaluation failed. URL: http://10.180.25.2:8228/v1/images/sha256:7d6fb7e5e7a74a4309cc436f6d11c29a96cbf27a4a8cb45a50cb0a326dc32fe8/check?tag=10.180.25.2:5000/hello-world:latest&detail=true, status: HTTP/1.1 404 NOT FOUND, error: {
  "detail": {}, 
  "httpcode": 404, 
  "message": "image is not analyzed - analysis_status: not_analyzed"
}

NOTE: In Image TAG 10.180.25.2:5000/hello-world:latest , 10.180.25.2:5000 is our local private registry and hello-world:latest is latest hello-world image available in docker hub which we pulled and pushed in our registry to try out image scanning using Anchore-Engine. 注意:在Image TAG 10.180.25.2:5000/hello-world:latest10.180.25.2:5000 : 10.180.25.2:5000是我们的本地私有注册表,而hello-world:latest是我们在docker hub中可用的最新hello-world映像,注册表以尝试使用Anchore-Engine进行图像扫描。

Unfortunately we are not able to find much resource online to try and resolve the above mentioned issue. 不幸的是,我们无法在线找到太多资源来尝试解决上述问题。

Anyone who might have worked on Anchore-Engine, please may I request to have a look and help us resolve this issue. 任何可能曾经在Anchore-Engine上工作过的人,请允许我查看一下并帮助我们解决此问题。

Also, any suggestions or alternatives to anchore-engine or detailed steps in case we might have missed anything would be really appreciated. 此外,如果我们可能错过了任何内容,那么对锚定引擎的任何建议或替代方案或详细步骤将不胜感激。

End of the output is as follows: 输出结果如下:

2018-10-15T00:48:43.880 WARN AnchoreWorker anchore-engine get policy evaluation failed. HTTP method: GET, URL: http://10.180.25.2:8228/v1/images/sha256:7d6fb7e5e7a74a4309cc436f6d11c29a96cbf27a4a8cb45a50cb0a326dc32fe8/check?tag=10.180.25.2:5000/hello-world:latest&detail=true, status: 404, error: {
"detail": {},
"httpcode": 404,
"message": "image is not analyzed - analysis_status: not_analyzed"
}

2018-10-15T00:48:43.880 WARN AnchoreWorker Exhausted all attempts polling anchore-engine. Analysis is incomplete for sha256:7d6fb7e5e7a74a4309cc436f6d11c29a96cbf27a4a8cb45a50cb0a326dc32fe8
2018-10-15T00:48:43.880 ERROR AnchorePlugin Failing Anchore Container Image Scanner Plugin step due to errors in plugin execution
hudson.AbortException: Timed out waiting for anchore-engine analysis to complete (increasing engineRetries might help). Check above logs for errors from anchore-engine
at com.anchore.jenkins.plugins.anchore.BuildWorker.runGatesEngine(BuildWorker.java:480)
at com.anchore.jenkins.plugins.anchore.BuildWorker.runGates(BuildWorker.java:343)
at com.anchore.jenkins.plugins.anchore.AnchoreBuilder.perform(AnchoreBuilder.java:338)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1724)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:421)

I also checked status and found below: 我还检查了状态,发现如下:

docker run anchore/engine-cli:latest anchore-cli --u admin --p admin123 --url http://172.18.0.1:8228/v1 system status
Service analyzer (dockerhostid-anchore-engine, http://anchore-engine:8084): up
Service catalog (dockerhostid-anchore-engine, http://anchore-engine:8082): up
Service policy_engine (dockerhostid-anchore-engine, http://anchore-engine:8087): down (unavailable)
Service simplequeue (dockerhostid-anchore-engine, http://anchore-engine:8083): up
Service apiext (dockerhostid-anchore-engine, http://anchore-engine:8228): up
Service kubernetes_webhook (dockerhostid-anchore-engine, http://anchore-engine:8338): up

Engine DB Version: 0.0.7 Engine Code Version: 0.2.4 引擎数据库版本:0.0.7引擎代码版本:0.2.4

It seems service policy engine is down 服务策略引擎似乎已关闭

Service policy_engine (dockerhostid-anchore-engine, http://anchore-engine:8087 ): down (unavailable) 服务policy_engine(dockerhostid-anchore-engine, http:// anchore-engine:8087 ):关闭(不可用)

I also checked the docker logs . 我还检查了docker日志。 I found below error: 我发现以下错误:

[service:policy_engine] 2018-10-15 09:37:46+0000 [-] [bootstrap] [DEBUG] service (policy_engine) starting in: 4
[service:policy_engine] 2018-10-15 09:37:46+0000 [-] [bootstrap] [INFO] Registration complete.
[service:policy_engine] 2018-10-15 09:37:46+0000 [-] [bootstrap] [INFO] Checking feeds client credentials
[service:policy_engine] 2018-10-15 09:37:46+0000 [-] [bootstrap] [DEBUG] Initializing a feeds client
[service:policy_engine] 2018-10-15 09:37:47+0000 [-] [bootstrap] [DEBUG] init values: [None, None, None, (), None, None]
[service:policy_engine] 2018-10-15 09:37:47+0000 [-] [bootstrap] [DEBUG] using values: ['https://ancho.re/v1/service/feeds', 'https://ancho.re/oauth/token', 'https://ancho.re/v1/account/users', 'anon@ancho.re', 3, 60]
[service:policy_engine] 2018-10-15 09:37:47+0000 [-] [urllib3.connectionpool] [DEBUG] Starting new HTTPS connection (1): ancho.re
[service:policy_engine] 2018-10-15 09:37:50+0000 [-] [bootstrap] [ERROR] Preflight checks failed with error: HTTPSConnectionPool(host='ancho.re', port=443): Max retries exceeded with url: /v1/account/users/anon@ancho.re (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7ffa905f0b90>: Failed to establish a new connection: [Errno 113] No route to host',)). Aborting service startup
Traceback (most recent call last):
 File "/usr/lib/python2.7/site-packages/anchore_manager/cli/service.py", line 158, in startup_service
   raise Exception("process exited: " + str(rc))
Exception: process exited: 1
[anchore-policy-engine] [anchore_manager.cli.service/startup_service()] [INFO] service process exited at (Mon Oct 15 09:37:50 2018): process exited: 1
[anchore-policy-engine] [anchore_manager.cli.service/startup_service()] [INFO] exiting service thread

Thanks and Regards, 谢谢并恭祝安康,

Rohan Shetty 罗汉·谢蒂(Rohan Shetty)

When images are added to anchore-engine, they are queued for analysis which moves them through a simple state machine that starts with 'not_analyzed', goes to 'analyzing' and finally ends in either 'analyzed' or 'analysis_failed'. 将图像添加到锚定引擎后,它们会排队等待分析,这些图像会通过简单的状态机(以“ not_analyzed”开头,进入“ analyzing”并最终以“ analyzed”或“ analysis_failed”结束)进行分析。 Only when an image has reached 'analyzed' will a policy evaluation be possible. 只有当图像达到“分析”时,才可以进行策略评估。

The anchore Jenkins plugin will add an image, then poll the engine for image status/evaluation for the configured number of tries (default 300). 锚定Jenkins插件将添加一个图像,然后轮询引擎以获取图像状态/评估以获取配置的尝试次数(默认为300)。 Once the image goes to 'analyzed' (where policy evaluation is possible), the plugin will then receive a policy evaluation result from the engine. 一旦图像进入“分析”状态(可以进行策略评估),插件就会从引擎接收策略评估结果。

The plugin will fail the build (by default) if the max retries has been performed and the image has not reached 'analyzed', if the image does reach 'analyzed' but the policy evaluation is producing a 'fail' result (meaning the image didn't pass your configured policy checks). 如果执行了最大重试并且图像未达到“已分析”,则插件将使构建失败(默认情况下),如果图像达到“已分析”,但策略评估产生“失败”结果(意味着该图像)没有通过您配置的策略检查)。 Note that all build failure behavior can be controlled in the plugin (Ie there are options to allow the plugin to succeed even if the analysis or image eval fails). 请注意,所有构建失败行为都可以在插件中进行控制(即,即使分析或图像评估失败,也存在允许插件成功运行的选项)。

You'll need to look at the end of the output from your build run (instead of just the beginning from your post), and combined with the information above, it should be clear which scenario is causing the plugin to fail the build. 您需要查看构建运行输出的末尾(而不仅仅是发布后的开始),并结合以上信息,应该清楚是哪种情况导致插件无法构建。

We have resolved the issue. 我们已经解决了这个问题。

Root Cause: 根本原因:

We were not able to establish a successful https connection to URL : https://ancho.re from within the anchore-engine docker container. 我们无法从anchore-engine docker容器中建立与URL的成功https连接: https ://ancho.re。 As a result the service:policy_engine was not able to start. 结果,service:policy_engine无法启动。

https://ancho.re is required to download policy feeds and sync-up periodically. 需要https://ancho.re下载策略供稿并定期同步。 Without these policy anchore-engine won't be able to analyse the docker images. 没有这些政策,锚定引擎将无法分析docker映像。

Solution: 解:

1) We passed a HTTPS_PROXY URL as an environment variable in the docker-compose.yaml of anchore-engine. 1)我们在定位引擎的docker-compose.yaml中传递了HTTPS_PROXY URL作为环境变量。

We used this proxy URL to bypass restrictions in our environment and establish a connection with https://ancho.re url. 我们使用此代理URL绕过我们环境中的限制,并与https://ancho.re url建立连接。

2) Restarted the docker containers. 2)重新启动docker容器。

Finally we got all services up and running including Anchore policy-engine. 最后,我们启动并运行了包括Anchore策略引擎在内的所有服务。

FYI: It takes a while to download all the required Feeds depending on your internet speed. 仅供参考:根据您的互联网速度,下载所有必需的供稿要花一些时间。

Lastly, Thanks to the Anchore community for quick responses and support over slack. 最后,感谢Anchore社区的快速响应和对松弛的支持。

Hope this helps. 希望这可以帮助。

Warm Regards, 温暖的问候,

Rohan Shetty 罗汉·谢蒂(Rohan Shetty)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM