Skip to content

Latest commit

 

History

History
85 lines (46 loc) · 3.22 KB

File metadata and controls

85 lines (46 loc) · 3.22 KB

summary: 如何用 Jenkins + 墨菲安全 让线上代码更安全 id: Jenkins categories: Jenkins environments: Web status: Published feedback link: https://github.com/murphysecurty/murphysec-bootcamp/issues

如何将墨菲安全检测能力集成在 Jenkins 让线上代码更安全

概述

Duration: 0:01:00

本文主要介绍如何将墨菲安全的代码检测能力集成到 Jenkins 中,提高线上代码安全质量。

Jenkins 是企业广泛使用的持续集成项目,将代码安全检测能力集成到 Jenkins 中,实现代码打包前即对代码进行安全扫描,降低线上代码因安全问题导致的公司数据泄漏风险,同时也会减少项目发布时的压力。且持续集成中的任何一个环节都是自动完成的,无需太多人工干预,有利于减少重复过程以节省时间和工作量。

jenkins

实现效果

  1. 每次 Jenkins 构建的时候自动检测代码中存在的三方开源组件,并识别漏洞
  2. 配置规则,识别到严重漏洞就中断构建
  3. 结果推送到飞书群中,相关工程师都能看到

配置 Jenkinsfile

Duration: 0:02:00

  • 在项目根目录放置 Jenkinsfile 文件

jenkinsfile

执行逻辑:代码下拉后,通过墨菲安全 CLI 对代码进行检测,然后使用 Linux 工具 jq 解析检查结果,如检测结果存在强烈建议修复级别的缺陷组件,则终止构建流程。

Jenkins上设置脚本路径

Duration: 0:03:00

  • 在 Jenkins 后台找到项目后,配置管理 Advanced Project Options -> Pipeline -> Script Path = Jenkinsfile ,这样 Jenkins CI 执行的时候,pipline 流程就会执行 Jenkinsfile 里的逻辑。

script-path-config

Jenkins 设置 Webhook

Duration: 0:03:00

  • 配置 Webhooks 以便项目在更新后,能够自动触发 Jenkins

注意:Jenkins 需安装插件 Git、GitLab Plugin

plugin-manager

  • 构建触发器勾选 Build when a changs is ... 选项,该 URL 在 GitLab 项目 Webhooks 中会用到

jenkins-webhook

  • 创建 Secret token,用于 GitLab Webhooks 做验证 secret-generate

GitLab 设置 Webhook

Duration: 0:01:00

  • 将 Jenkins 设置 Webhook 时获取到的 URLSecret token 设置在 GitLab 中

gitlab-webhook

飞书通知

Duration: 0:01:00

  • 做好异常处理,某个stage抛出异常后,要及时做出通知,避免影响打包。下图为构建流程:

pipeline

  • 调用飞书机器人 Webhook 将构建结果发送到群内。当项目检测未通过时,可以在后台将检测结果导入发送给开发人员做修复参考。

feishu-message