首页 > 其他分享 >容器签名验证

容器签名验证

时间:2023-07-14 17:25:38浏览次数:42  
标签:容器 aliyuncs cosign 验证 bfmq 签名 key com registry

如果容器构建过程受到破坏,它会使用户很容易意外使用恶意镜像而不是实际的容器镜像。对容器进行签名和验证始终确保我们运行的是实际的容器镜像。
https://github.com/sigstore/cosign

安装二进制命令

git clone https://github.com/sigstore/cosign
go mod tidy
go build cmd/cosign/main.go

拿目标仓库的两个镜像进行sign测试,对170签名,171保留原状

[root@jenkins-bj-ali-ql1 ssl]# cosign generate-key-pair
Enter password for private key: 
Enter password for private key again: 
Private key written to cosign.key
Public key written to cosign.pub
[root@jenkins-bj-ali-ql1 ssl]# ls
cosign.key  cosign.pub
# Sign前仓库里必须已存在目标镜像!!!!!!!注意这个-y很重要
[root@jenkins-bj-ali-ql1 ssl]# cosign sign -y --key cosign.key registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:170
Enter password for private key: 
WARNING: Image reference registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:170 uses a tag, not a digest, to identify the image to sign.
    This can lead you to sign a different image than the intended one. Please use a
    digest (example.com/ubuntu@sha256:abc123...) rather than tag
    (example.com/ubuntu:latest) for the input to cosign. The ability to refer to
    images by tag will be removed in a future release.


	The sigstore service, hosted by sigstore a Series of LF Projects, LLC, is provided pursuant to the Hosted Project Tools Terms of Use, available at https://lfprojects.org/policies/hosted-project-tools-terms-of-use/.
	Note that if your submission includes personal data associated with this signed artifact, it will be part of an immutable record.
	This may include the email address associated with the account with which you authenticate your contractual Agreement.
	This information will be used for signing this artifact and will be stored in public transparency logs and cannot be removed later, and is subject to the Immutable Record notice at https://lfprojects.org/policies/hosted-project-tools-immutable-records/.

By typing 'y', you attest that (1) you are not submitting the personal data of any other person; and (2) you understand and agree to the statement and the Agreement terms at the URLs listed above.
tlog entry created with index: 27465650
Pushing signature to: registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud

# 对仓库内不存在的镜像sign会报错
[root@jenkins-bj-ali-ql1 ssl]# cosign sign --key cosign.key registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:999
Enter password for private key: 
WARNING: Image reference registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:999 uses a tag, not a digest, to identify the image to sign.
    This can lead you to sign a different image than the intended one. Please use a
    digest (example.com/ubuntu@sha256:abc123...) rather than tag
    (example.com/ubuntu:latest) for the input to cosign. The ability to refer to
    images by tag will be removed in a future release.


Error: signing [registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:999]: accessing entity: entity not found in registry
main.go:74: error during command execution: signing [registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:999]: accessing entity: entity not found in registry

image

对两个镜像进行验证

[root@jenkins-bj-ali-ql1 ssl]# cosign verify --key cosign.pub registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:170
WARNING: Skipping tlog verification is an insecure practice that lacks of transparency and auditability verification for the signature.

Verification for registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:170 --
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - The signatures were verified against the specified public key

[{"critical":{"identity":{"docker-reference":"registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud"},"image":{"docker-manifest-digest":"sha256:111b8d2395971a50057519c19d23e521d03d436769e14da990dfa4dce32ff17d"},"type":"cosign container image signature"},"optional":null}]
[root@jenkins-bj-ali-ql1 ssl]# cosign verify --insecure-ignore-tlog=true --key cosign.pub registry.cn-beijing.aliyuncs.com/bfmq/devops-cicd-dev-bfmq-cloud:171
WARNING: Skipping tlog verification is an insecure practice that lacks of transparency and auditability verification for the signature.
Error: no matching signatures
main.go:69: error during command execution: no matching signatures

编写jenkins pipeline

sign是对仓库镜像进行签名,因此需要在push完成后了

        stage('Push') {
            steps {
                script {
                    def exitValue = sh(script: "trivy image ${JOB_NAME}:${BUILD_NUMBER} -o layer.table --exit-code 0 -s MEDIUM,HIGH,CRITICAL --skip-db-update=true -q", returnStatus: true)
                    if (exitValue != 0) {
                        sh "cat layer.table"
                        error "Docker layer security scan failed"
                    }
                    sh "docker push ${env.registry_url}/${JOB_NAME}:${BUILD_NUMBER}"
                }
            }
        }
        stage('Sign') {
            steps {
                script {
                    sh "export COSIGN_PASSWORD=123456"
                    sh "cosign sign -y --key ${JENKINS_HOME}/conf.d/ssl/cosign.key ${env.registry_url}/${JOB_NAME}:${BUILD_NUMBER}"
                }
            }
        }

其他容器签名验证工具
Cosign
Skopeo
goss
kgoss

参考
https://github.com/sigstore/cosign
https://github.com/sigstore/cosign/issues/2736
https://kyverno.io/docs/writing-policies/verify-images/sigstore/

标签:容器,aliyuncs,cosign,验证,bfmq,签名,key,com,registry
From: https://www.cnblogs.com/bfmq/p/17554522.html

相关文章

  • 容器镜像学习笔记
    目录docker在本地从DockerHub下载镜像的方法在OpenEuler系统上安装Docker的方法docker镜像的命名规则dockerdangling虚悬镜像dockermanifestmultiarchdockerdesktop配置使用curl访问registry的命令使用postman访问registry的urlsdocker重启命令docker的常见命令......
  • playwright+opencv 过滑块拼图验证码
    前言最近看到浏览器自动化框架playwright,就使用了一下在模拟登录掘金是通过密码登陆时遇到需要通过拼图验证码于是通过查找发现可以通过opencv库解决问题下面是解决过程过程1.首先需要获取到图片,通过查看html可以很容易找到需要的图片2.通过opencv进行图像处理来获取到拼......
  • 内网使用mkcert签名证书
    简介mkcert是一个用于生成本地自签名SSL证书的开源工具,项目基于Golang开发,可跨平台使用,不需要配置,支持多域名以及自动信任CA。请注意,自签名的证书只在开发和测试环境中使用,并不适用于生产环境。在生产环境中,你应该使用由受信任的证书颁发机构(CA)签名的证书。准备工作局......
  • dede后台验证码错误或不显示的解决办法
    用v56之前版权include/vdimgck.php覆盖现在的文件,测试可行,不过验证码样式就回到以前版本的,喜欢新版的朋友可能会不舒服。我们打开data/safe/inc_safe_config.php打开头一行$safe_gdopen='1,2,3,4,5,6';修改为$safe_gdopen='1,2,3,4,5';去掉6,即关闭后台验证码选项,测......
  • dede怎么取消后台验证码,DEDE取消后台验证码
    DEDEv5.5/v5.6怎么取消后台验证码,DEDE取消后台验证码有些时候,使用DEDECMS的时候,在后台登陆处遇到后台验证码错误,或者嫌弃后台验证码麻烦,我们就可以将后台的验证码取消掉.这篇文章是介绍教你如果取消DEDECMSv5.5后台验证码的步骤:找到DEDE后台目录,也就是默认的/dede/login.......
  • postman 自动签名
    选择Pre-requestScripts,输入脚本md5varappKey=pm.environment.get("appKey");varappSecret=pm.environment.get("appSecret");varqueryParam=pm.request.url.query.members;vartimestamp=newDate().getTime();letparam=JSON.parse(&q......
  • 爬虫突破验证码技巧 - 2Captcha
    在互联网世界中,验证码作为一种防止机器人访问的工具,是爬虫最常遇到的阻碍。验证码的类型众多,从简单的数字、字母验证码,到复杂的图像识别验证码,再到更为高级的交互式验证码,每一种都有其独特的识别方法和应对策略。在这篇文章中,我们将一一介绍各种验证码的工作原理和使用2Captcha进......
  • CentOS 空环境安装容器
    #安装gitsudoyuminstall-ygit#安装mavensudoyuminstall-ymaven#安装依赖sudoyuminstall-yyum-utilsdevice-mapper-persistent-datalvm2#设置源sudoyum-config-manager--add-repohttp://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo#下面......
  • HttpURLConnection绕过SSL验证,信任所有证书的工具类
    HttpURLConnection绕过SSL验证,信任所有证书的工具类发起https请求时经常会出现javax.net.ssl.SSLHandshakeException:java.security.cert.CertificateException这样的错误,那是因为环境中没有证书校验,我们可以在连接中设置绕过SSL校验来解决这个问题。publicclassSslUtil{......
  • 页面图片验证码显示(base64图片显示)
     前端在做登陆的时候经常会遇见输入验证码登陆的问题,一般情况下,后端返回的类似一个流图片,在页面中给图片赋值是不能显示的,想下面这种形式 这样的形式通常需要前端处理一下这个流,转成base64的形式,进行显示,代码如下:asyncgetInterfaceCode(){letres=awaitg......