利用 Tekton + ArgoCD 打造云原生 GitSecOps | IDCF
来源:DevSecOps SIG
作者:小马哥
内容来源:作者在GOTC(全球开源技术大会)的演讲实录
一、云原生应用交付之痛
云原生未来已来,随着云原生的持续升温,云原生应用的交付也成了人们重点讨论的焦点。容器化技术和声明式系统对于应用程序的交付确实起到了很大的帮助,可以帮我们很方便的实现一键式部署和持续交付。
典型的流程如下:
上述流程包含了从开发人员提交代码到代码构建检测再到镜像构建最后进行数据以及后续测试的流程(可能每个公司针对不同项目会略有不同,但是整体不会有太大出入)。当做好自动化以后,上述流程可以很好的实践持续集成、持续部署、持续交付,从而提升研发效率的。
但是却也有一个很大的问题:流程都是从左往右进行(我称之为一杆子到底),针对于云原生应用(一切都可以用 yaml 文件进行描述,并存储在配置仓库中),很难保证配置描述和云原生底座(kubernetes 集群)上的实际状态真正相符,随着时间的推移,很容易发生另外一种“配置漂移”(配置仓库和实际状态不相符合)。
这种情况下就免不了人工智能(Human Intelligence)的再次介入:
登陆 kubernetes 集群,查看应用程序相应的状态,包括对某些环境变量、资源配置、版本信息等进行确认。 通过查看 IAM 用户信息及其他审计工具来应对安全合规团队的审计(比如列举出某个集群的用户以及用户曾经做了哪些操作)。 用 kubectl 命令来做一些变更。
二、痛则思变

以声明式系统为基座(典型如 Kubernetes)。 以 Git(GitHub/GitLab等)为单一可信源。

三、GitOps实现之拦路虎





EventListener 主要用来监听 GitHub/GitLab 等系统的事件(push,pr 等),然后解析相关的参数(代码变更文件、提交人等),随后参数被传递到后面的 PipelineRun 环节。PipelineRun 会生成一个 Pipeline 对象。 Pipeline 是一个很形象的抽象,CI/CD 就像工厂的流水线一样(pipeline),原材料是源码,每一个工人处理一个步骤(task),可能是一个动作(one step),也可能是多个动作(multiple step),然后交付给下一个工人(task),最后产出产品(software)。


resources:
- name: source-apim
resourceSpec:
type: git
params:
- name: revision
value: master
- name: url
value: https://your.source.code.github.com.url.git
- name: devops
resourceSpec:
type: git
params:
- name: revision
value: master
- name: url
value: https://your.devops.code.github.com.url.git
- name: docker-image
resourceSpec:
type: image
params:
- name: url
value: your/docker/image/url
用 kaniko 构建镜像。
- name: image-build-and-push
image: gcr.io/kaniko-project/executor:v0.17.1
env:
- name: "DOCKER_CONFIG"
value: "/tekton/home/.docker/"
command:
- /kaniko/executor
args:
- --dockerfile=$(resources.inputs.source-code.path)/Dockerfile
- --destination=$(resources.outputs.docker-image.url):$(params.image-tag)
- --context=$(resources.inputs.source-code.path)
四、GitSecOps体系
基于上述的技术栈,就完成了 GitSecOps 体系:Tekton + ArgoCD + Kustomize + SOPS(GPG) = GitSecOps。
当然,仅仅是做了敏感信息加密和镜像安全扫描,就能称之为 GitSecOps,岂不是有点 too yong too simple 了。其实还要融合更多的安全内容进去。
Demo:https://www.bilibili.com/video/BV1cq4y1W7PZ
演示代码仓库
https://github.com/majinghe/argocd-sops.git
https://github.com/majinghe/tekton-demo.git
https://github.com/majinghe/GitOps-demo.git
https://github.com/majinghe/Demo.git

#规模化敏捷联合作战沙盘之「乌托邦计划」,玩乐高,学敏捷,将“多团队敏捷协同”基因内化在研发流程中,为规模化提升研发效能保驾护航!!🏰
2022年社区开年赋能计划,#DevOps黑客马拉松 和 #规模化敏捷联合作战沙盘之「乌托邦计划」两大公开课,将在北京、上海、深圳、大连、成都等多个城市开启
企业组队参赛&个人参赛均可,赶紧上车~👇