如何添加极狐GitLab Runner 信任域名证书

news2024/9/23 15:31:09

本文作者 徐晓伟

极狐Gitlab Runner 信任实例域名证书,用于注册注册极狐 GitLab Runner。

问题

参见 极狐gitlab-runner-host.md

说明

  • 解决方案是使用颁发给域名 gitlab.test.helm.xuxiaowei.cn 的证书,可以使用自己的域名去各大云厂商免费申请,或者使用自己根据域名 gitlab.test.helm.xuxiaowei.cn 生成的证书

    1. 阿里云SSL(https)证书免费申请
    2. 腾讯云SSL(https)证书免费申请
    3. 华为云SSL(https)证书免费申请
    4. 百度云SSL(https)证书免费申请

域名证书解决方案

方案1:重新配置极狐 GitLab,自动生成对应证书并自动配置,然后在极狐 GitLab runner 中信任证书

  1. 问题1:tls: failed to verify certificate: x509: certificate signed by unknown authority

    1. 文档

      1. runners 部分
      2. 自签名证书或自定义证书颁发机构
      3. ConfigMap
      4. 配置 Pod 使用 ConfigMap
    2. 根据上述文档可知,有三种方式可以解决证书信任问题:

      1. 在 极狐GitLab Runner 注册时配置 --tls-ca-file 参数并指向证书文件
      2. 在配置文件中增加 tls-ca-file 并指向配置文件, 此方式本文不做介绍,可参考 gitlab-runner-kubernetes-host.md ,原理相同
      3. 将证书放在 /etc/gitlab-runner/certs/ 文件夹下,使用域名命名证书,证书后缀名是 .crt由于篇幅限制,这里只介绍这一种方式
    3. 由于 k8s 的 pod 可能随时会被删除(故障转移、主动删除等),所以直接在 pod 内部配置不是上策

    4. k8s 中的 ConfigMap 可以挂载到 pod 内部,所以可以考虑在 ConfigMap 中配置证书,然后 pod 内部使用 ConfigMap 中的证书

    5. 下载证书

      1. 方式1

        1. 浏览器访问域名 https://gitlab.test.helm.xuxiaowei.cn
        2. 按照图中操作,下载证书,上传之服务器,用于后期操作
      2. 方式2

        # 下载证书
        openssl s_client -showcerts -connect gitlab.test.helm.xuxiaowei.cn:443 -servername gitlab.test.helm.xuxiaowei.cn < /dev/null 2>/dev/null | openssl x509 -outform PEM > gitlab.test.helm.xuxiaowei.cn.crt
        
    6. 将证书导入到 k8s 中

      # -n=gitlab-test:指定命名空间
      # create configmap etc-gitlab-runner-certs:创建 ConfigMap 名称是 etc-gitlab-runner-certs
      # --from-file=gitlab.test.helm.xuxiaowei.cn.crt=gitlab.test.helm.xuxiaowei.cn.crt:配置来自文件,文件名 gitlab.test.helm.xuxiaowei.cn.crt,放入 ConfigMap 中的键也是 gitlab.test.helm.xuxiaowei.cn.crt
      kubectl -n=gitlab-test create configmap etc-gitlab-runner-certs --from-file=gitlab.test.helm.xuxiaowei.cn.crt=gitlab.test.helm.xuxiaowei.cn.crt
      
      # 查看
      # kubectl -n=gitlab-test get configmap etc-gitlab-runner-certs -o yaml
      
    7. 导出 helm 极狐GitLab 配置

      helm -n gitlab-test get values my-gitlab > my-gitlab.yaml
      
    8. 修改 helm 极狐GitLab 配置

      gitlab-runner:
        # 挂载卷名称
        volumeMounts:
          # 挂载到 pod 路径(文件/文件夹)
          # 此处是在容器内运行的 gitlab runner,由于权限限制等原因,
          # 所以 配置文件不是在 /etc/gitlab-runner/ 目录下,而是 /home/gitlab-runner/.gitlab-runner/
          - mountPath: /home/gitlab-runner/.gitlab-runner/certs
            name: etc-gitlab-runner-certs-volumes
        # 卷
        volumes:
          # 卷类型
          - configMap:
              items:
              # configMap 中的键
              - key: gitlab.test.helm.xuxiaowei.cn.crt
                # 挂载的路径
                path: gitlab.test.helm.xuxiaowei.cn.crt
              name: etc-gitlab-runner-certs
            # 配置 ConfigMap 名称
            name: etc-gitlab-runner-certs-volumes
      
    9. 更新 helm 极狐GitLab 配置

      helm upgrade -n gitlab-test --install my-gitlab gitlab/gitlab -f my-gitlab.yaml --timeout 600s --version 7.7.0
      
    10. 查看修改结果

      kubectl -n gitlab-test get deployments.apps my-gitlab-gitlab-runner -o yaml
      
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        annotations:
          deployment.kubernetes.io/revision: "5"
          meta.helm.sh/release-name: my-gitlab
          meta.helm.sh/release-namespace: gitlab-test
        creationTimestamp: "2023-12-22T05:03:46Z"
        generation: 7
        labels:
          app: my-gitlab-gitlab-runner
          app.kubernetes.io/managed-by: Helm
          chart: gitlab-runner-0.59.2
          heritage: Helm
          release: my-gitlab
        name: my-gitlab-gitlab-runner
        namespace: gitlab-test
        resourceVersion: "30086"
        uid: 8c46c44a-5b67-44ae-90d0-008daa3fa388
      spec:
        progressDeadlineSeconds: 600
        replicas: 1
        revisionHistoryLimit: 10
        selector:
          matchLabels:
            app: my-gitlab-gitlab-runner
        strategy:
          rollingUpdate:
            maxSurge: 25%
            maxUnavailable: 25%
          type: RollingUpdate
        template:
          metadata:
            annotations:
              checksum/configmap: f35865354f043583d0903b0a8350830a486eb0e289d18271cf3f533e7d89c5f7
              checksum/secrets: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
              gitlab.com/prometheus_port: "9252"
              gitlab.com/prometheus_scrape: "true"
            creationTimestamp: null
            labels:
              app: my-gitlab-gitlab-runner
              chart: gitlab-runner-0.59.2
              heritage: Helm
              release: my-gitlab
          spec:
            containers:
              - command:
                  - /usr/bin/dumb-init
                  - --
                  - /bin/bash
                  - /configmaps/entrypoint
                env:
                  - name: CI_SERVER_URL
                    value: https://gitlab.test.helm.xuxiaowei.cn
                  - name: RUNNER_EXECUTOR
                    value: kubernetes
                  - name: REGISTER_LOCKED
                    value: "false"
                  - name: RUNNER_TAG_LIST
                  - name: KUBERNETES_NAMESPACE
                    value: gitlab-test
                image: registry.gitlab.com/gitlab-org/gitlab-runner:alpine-v16.6.1
                imagePullPolicy: IfNotPresent
                livenessProbe:
                  exec:
                    command:
                      - /bin/bash
                      - /configmaps/check-live
                  failureThreshold: 3
                  initialDelaySeconds: 60
                  periodSeconds: 10
                  successThreshold: 1
                  timeoutSeconds: 3
                name: my-gitlab-gitlab-runner
                ports:
                  - containerPort: 9252
                    name: metrics
                    protocol: TCP
                readinessProbe:
                  exec:
                    command:
                      - /usr/bin/pgrep
                      - gitlab.*runner
                  failureThreshold: 3
                  initialDelaySeconds: 10
                  periodSeconds: 10
                  successThreshold: 1
                  timeoutSeconds: 3
                resources: {}
                securityContext:
                  allowPrivilegeEscalation: false
                  capabilities:
                    drop:
                      - ALL
                  privileged: false
                  readOnlyRootFilesystem: false
                  runAsNonRoot: true
                terminationMessagePath: /dev/termination-log
                terminationMessagePolicy: File
                volumeMounts:
                  - mountPath: /secrets
                    name: projected-secrets
                  - mountPath: /home/gitlab-runner/.gitlab-runner
                    name: etc-gitlab-runner
                  - mountPath: /configmaps
                    name: configmaps
                  - mountPath: /home/gitlab-runner/.gitlab-runner/certs
                    name: etc-gitlab-runner-certs-volumes
            dnsPolicy: ClusterFirst
            hostAliases:
              - hostnames:
                  - gitlab.test.helm.xuxiaowei.cn
                ip: 172.25.25.32
            restartPolicy: Always
            schedulerName: default-scheduler
            securityContext:
              fsGroup: 65533
              runAsUser: 100
            serviceAccount: my-gitlab-gitlab-runner
            serviceAccountName: my-gitlab-gitlab-runner
            terminationGracePeriodSeconds: 3600
            volumes:
              - emptyDir:
                  medium: Memory
                name: runner-secrets
              - emptyDir:
                  medium: Memory
                name: etc-gitlab-runner
              - name: projected-secrets
                projected:
                  defaultMode: 420
                  sources:
                    - secret:
                        name: my-gitlab-minio-secret
                    - secret:
                        items:
                          - key: runner-registration-token
                            path: runner-registration-token
                          - key: runner-token
                            path: runner-token
                        name: my-gitlab-gitlab-runner-secret
              - configMap:
                  defaultMode: 420
                  name: my-gitlab-gitlab-runner
                name: configmaps
              - configMap:
                  defaultMode: 420
                  items:
                    - key: gitlab.test.helm.xuxiaowei.cn.crt
                      path: gitlab.test.helm.xuxiaowei.cn.crt
                  name: etc-gitlab-runner-certs
                name: etc-gitlab-runner-certs-volumes
      status:
        availableReplicas: 1
        conditions:
          - lastTransitionTime: "2023-12-22T07:43:25Z"
            lastUpdateTime: "2023-12-22T07:43:25Z"
            message: Deployment has minimum availability.
            reason: MinimumReplicasAvailable
            status: "True"
            type: Available
          - lastTransitionTime: "2023-12-22T05:03:46Z"
            lastUpdateTime: "2023-12-22T07:43:25Z"
            message: ReplicaSet "my-gitlab-gitlab-runner-597d6d8f7c" has successfully progressed.
            reason: NewReplicaSetAvailable
            status: "True"
            type: Progressing
        observedGeneration: 7
        readyReplicas: 1
        replicas: 1
        updatedReplicas: 1
      
    11. 查看 gitlab runner 日志

      [root@anolis-7-9 ~]# kubectl -n gitlab-test get pod | grep gitlab-runner
      my-gitlab-gitlab-runner-597d6d8f7c-8v466             1/1     Running     0              5m52s
      [root@anolis-7-9 ~]#
      

      根据日志判断,已经注册成功了

      [root@anolis-7-9 ~]# kubectl -n gitlab-test logs -f my-gitlab-gitlab-runner-597d6d8f7c-8v466
      Registration attempt 1 of 30
      Runtime platform                                    arch=amd64 os=linux pid=16 revision=f5da3c5a version=16.6.1
      WARNING: Running in user-mode.                     
      WARNING: The user-mode requires you to manually start builds processing:
      WARNING: $ gitlab-runner run                       
      WARNING: Use sudo for system-mode:                 
      WARNING: $ sudo gitlab-runner...
      
      Created missing unique system ID                    system_id=r_3WsywNzJqRud
      Merging configuration from template file "/configmaps/config.template.toml"
      WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://docs.gitlab.com/ee/ci/runners/new_creation_workflow
      Registering runner... succeeded                     runner=BtGwLEwc
      Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
      
      Configuration (with the authentication token) was saved in "/home/gitlab-runner/.gitlab-runner/config.toml"
      Runtime platform                                    arch=amd64 os=linux pid=7 revision=f5da3c5a version=16.6.1
      Starting multi-runner from /home/gitlab-runner/.gitlab-runner/config.toml...  builds=0 max_builds=0
      WARNING: Running in user-mode.                     
      WARNING: Use sudo for system-mode:                 
      WARNING: $ sudo gitlab-runner...
      
      There might be a problem with your config based on jsonschema annotations in common/config.go (experimental feature):
      jsonschema: '/runners/0/kubernetes/pull_policy' does not validate with https://gitlab.com/gitlab-org/gitlab-runner/common/config#/$ref/properties/runners/items/$ref/properties/kubernetes/$ref/properties/pull_policy/$ref/type: expected array, but got null
      
      Configuration loaded                                builds=0 max_builds=10
      listen_address not defined, metrics & debug endpoints disabled  builds=0 max_builds=10
      [session_server].listen_address not defined, session endpoints disabled  builds=0 max_builds=10
      Initializing executor providers                     builds=0 max_builds=10
      ^C
      [root@anolis-7-9 ~]#
      
    12. 管理员访问 https://gitlab.test.helm.xuxiaowei.cn/admin/runners 可以看到 pod my-gitlab-gitlab-runner-597d6d8f7c-8v466 已经注册成了

      1. 如果存在极狐 GitLab Runner Pod 被删除(故障转译、手动删除等等),这里可能会存在不可用的 Runner

  2. 问题2: tls: failed to verify certificate: x509: certificate is valid for ingress.local, not gitlab.test.helm.xuxiaowei.cn

    1. 访问的域名与使用的证书补匹配,可通过更换证书、域名来解决此问题(一般情况是更换证书)

    2. 如果要更换证书:

      1. 证书属于正规机构颁发的(如:上述各大云厂商的证书),请看下方方案2
      2. 如果是自己生成的证书(不受信任),请看下方方案2,并结合上方问题1来解决此问题

方案2:配置正规机构颁发的证书(如:上述各大云厂商的证书),一般无需在 gitlab 配置信任证书,即可正常使用

  1. 正常情况

    1. 要求证书与域名对应
    2. 将证书上传至服务器,解压,使用证书文件创建 k8s TLS Secret
    3. 修改 极狐GitLab 配置,使用 上述步骤创建的 k8s TLS Secret
  2. 异常情况:正规机构颁发的证书,在极狐 GitLab Runner 中依然无法正常使用,但是在浏览器中可以正常使用

    1. 原因是颁发机构的根证书不在极狐 GitLab Runner 的信任列表中,需要手动添加信任(例如:常见的 Windows 较低版本运行一些软件时,也是无法执行,显示证书无法识别,需要在 Windows 导入软件签名所使用的证书链)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1490340.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

重学SpringBoot3-yaml文件配置

重学SpringBoot3-yaml文件配置 引言YAML 基本语法YAML 数据类型YAML 对象YAML 数组复合结构标量引用 YAML 文件结构Spring Boot 中的 YAML 配置注意事项总结参考 引言 YAML&#xff08;YAML Ain’t Markup Language&#xff09;是一种常用于配置文件的数据序列化格式&#xff…

Unity3D

一、C# 输入输出 二、三维数学

CSS变量和@property

CSS变量 var() CSS 变量是由CSS作者定义的实体&#xff0c;其中包含要在整个文档中重复使用的特定值。使用自定义属性来设置变量名&#xff0c;并使用特定的 var() 来访问。&#xff08;比如 color: var(--main-color);&#xff09;。 基本用法 CSS变量定义的作用域只在定义该…

搞定国科金 必备王炸新技术!凌恩生物重磅推出微生物单细胞测序产品

单细胞异质性研究如火如荼&#xff0c;但原核生物研究却是个“坎”。 现有常规的原核生物研究&#xff0c;都集中于单菌群落或微生态大群体&#xff0c;只能从宏观角度研究群体状态&#xff0c;而经典的单细胞RNA测序技术无法应用于细菌。 单细胞技术应用于原核生物的几点障碍…

window10 安装配置docker

前言&#xff08;重要&#xff09;&#xff1a;确认window10版本已经更新到最新版 随着时间推移&#xff0c;docker对window版本的支持也在变&#xff0c;截至2024年3月份&#xff0c;支持win10最低版本号&#xff1a;22H2,操作系统最低版本&#xff1a;19045.2965&#xff0c…

学编程怎么样才能更快入手,编程怎么简单易学

学编程怎么样才能更快入手&#xff0c;编程怎么简单易学 一、前言 对于初学编程建议先从简单入手&#xff0c;然后再学习其他复杂的编程语言。 今天给大家分享的中文编程开发语言工具 进度条构件的用法。 编程入门视频教程链接 https://edu.csdn.net/course/detail/39036 …

26、Qt调用.py文件中的函数

一、开发环境 Qt5.12.0 Python3.7.8 64bit 二、使用 新建一个Qt项目&#xff0c;右击项目名称&#xff0c;选择“添加库” 选择“外部库”&#xff0c;点击“下一步” 点击“浏览”&#xff0c;选择Python安装目录下的libs文件夹中的“python37.lib”文件&#xff0c;点击“下…

【Python如何输入工资,五险一金,专项扣除后得出个税和到手工资(2024年最新)】

最近综合所得年度汇算&#xff0c;正好心血来潮算一下到手工资对不对&#xff0c;有些朋友年综合收入也才几万块&#xff0c;结果年综报税时还要补一两万的个税&#xff0c;这主要是因为跳槽后&#xff0c;上家公司的年薪全平均移到了新的公司每个月中&#xff0c;系统的缺陷导…

第16课:如何出版人生第一本书

机会是留给有准备的人的&#xff0c;在网上多输出文章&#xff0c;就会有更好的曝光机会&#xff0c;有可能被潜在的机会捕捉到。 除了不断的写文章&#xff0c;还可以通过书籍封面的投稿信息进行文章投稿&#xff0c;投稿的文章一定要符合要求。 出书从来不是一件简单的事&am…

Spring MVC源码中设计模式——适配器模式

适配器模式介绍 适配器模式&#xff08;Adapter Pattern&#xff09;是作为两个不兼容的接口之间的桥梁。这种类型的设计模式属于结构型模式&#xff0c;它结合了两个独立接口的功能。 应用场景&#xff1a; 1、系统需要使用现有的类&#xff0c;而此类的接口不符合系统的需要…

EdgeX Foundry 边缘物联网中间件平台

文章目录 1.EdgeX Foundry2.平台架构3.平台服务3.1.设备服务3.2.核心服务3.3.支持服务3.4.应用服务3.5.安全服务3.6.管理服务 EdgeX Foundry # EdgeX Foundryhttps://iothub.org.cn/docs/edgex/ https://iothub.org.cn/docs/edgex/edgex-foundry/1.EdgeX Foundry EdgeX Found…

JavaScript快速入门+文档查询【详解】

目录 1. js简介 2.js引入方式 3. JS基础语法(ECMAScript) 4. js函数和事件【js的核心】 5.js对象 6.BOM对象 7.DOM对象 8.案例全选全消 1. js简介 1.什么是js JavaScript&#xff0c;简称js&#xff0c;是web开发中不可缺少的脚本语言&#xff0c;不需要编译就能…

Spring Test 常见错误

前面我们介绍了许多 Spring 常用知识点上的常见应用错误。当然或许这些所谓的常用&#xff0c;你仍然没有使用&#xff0c;例如对于 Spring Data 的使用&#xff0c;&#xff0c;有的项目确实用不到。那么这一讲&#xff0c;我们聊聊 Spring Test&#xff0c;相信你肯定绕不开对…

IDEA自动导入provided的依赖

最近在学习flink 流程序&#xff0c;在写demo程序的时候依赖flink依赖&#xff0c;依赖的包在flink集群里面是自己已经提供了的&#xff0c;在导入的时候配置为provided&#xff0c;像下面这样&#xff0c;以使打包的时候不用打到最终的程序包里面。 <dependency><gro…

STM32USART串口数据包

文章目录 前言一、介绍部分数据包两种包装方式&#xff08;分割数据&#xff09;HEX数据包文本数据包 数据包的收发流程数据包的发送数据包的接收固定包长的hex数据包接收可变包长的文本数据包接收 二、实例部分固定包长的hex数据包接收连接线路代码实现 可变包长的文本数据包接…

AWS的RDS数据库开启慢查询日志

#开启慢日志两个参数 slow_query_log 1 设置为1&#xff0c;来启用慢查询日志 long_query_time 5 &#xff08;单位秒&#xff09; sql执行多长时间被定义为慢日志1. 点击RDS然后点击参数组&#xff0c;选择slow_query_log&#xff0c;设置为1【表示开启慢日志】点击保存…

[cg] Games 202 - NPR 非真实感渲染

NPR特性&#xff08;基于真实感渲染&#xff09; 真实感--》翻译成非真实感的过程 NPR风格 需要转换为渲染中的操作 1.描边 B-->普通边界&#xff08;不是下面几种的&#xff09; C-->折痕 M-->材质边界 S-->需要在物体外面一圈上&#xff0c;并且是多个面共享…

使用GitHub API 查询开源项目信息

一、GitHub API介绍 GitHub API 是一组 RESTful API 接口&#xff0c;用于与 GitHub 平台进行交互。通过使用 GitHub API&#xff0c;开发人员可以访问和操作 GitHub 平台上的各种资源&#xff0c;如仓库、提交记录、问题等。 GitHub API 提供了多种功能和端点&#xff0c;以…

gin gorm学习笔记

代码仓库 https://gitee.com/zhupeng911/go-advanced.git https://gitee.com/zhupeng911/go-project.git 1. gin介绍 Gin 是使用纯 Golang 语言实现的 HTTP Web框架&#xff0c;Gin接口设计简洁&#xff0c;提供类似Martini的API&#xff0c;性能极高&#xff0c;现在被广泛使用…

SpringBoot接口防抖(防重复提交)的一些实现方案

前言 啥是防抖 思路解析 分布式部署下如何做接口防抖&#xff1f; 具体实现 请求锁 唯一key生成 重复提交判断 前言 作为一名老码农&#xff0c;在开发后端Java业务系统&#xff0c;包括各种管理后台和小程序等。在这些项目中&#xff0c;我设计过单/多租户体系系统&a…