Authentication

如果在tekton中使用git或者docker需要用户名密码登录,需要怎么设置呢?

我们知道kubernetes中是使用Secret,使用volumes或者env将这个配置文件直接mount到pod中。

类似tekton也沿用了这一思路

Tekton Authentication

Tekton 可以直接使用了Kubernetes Secret定义的类型,处理Git和Docker登录

Git Docker
kubernetes.io/basic-auth
kubernetes.io/ssh-auth
kubernetes.io/basic-auth
kubernetes.io/dockercfg
kubernetes.io/dockerconfigjson

以下演示一个以docker basic-auth authentication为例的设置

  1. 先创建一个包含密码的Secret。并加上tektonannotations,这个非常重要。

    apiVersion: v1
    kind: Secret
    metadata:name: basic-user-passannotations:tekton.dev/docker-0: https://gcr.io # Described below
    type: kubernetes.io/basic-auth
    stringData:username: <cleartext username>password: <cleartext password>
    

    annotations必须要是要以tekton.dev/docker-开头

  2. 创建ServiceAccount绑定这个Secret

    apiVersion: v1
    kind: ServiceAccount
    metadata:name: build-bot
    secrets:- name: basic-user-pass
    
  3. 在运行配置中绑定这个ServiceAccount
    TaskRun

    apiVersion: tekton.dev/v1beta1
    kind: TaskRun
    metadata:name: build-push-task-run-2
    spec:serviceAccountName: build-bottaskRef:name: build-push
    

    再如PipelineRun

    apiVersion: tekton.dev/v1beta1
    kind: PipelineRun
    metadata:name: demo-pipelinenamespace: default
    spec:serviceAccountName: build-botpipelineRef:name: demo-pipeline
    
  4. 最后执行即可

    kubectl apply --filename secret.yaml serviceaccount.yaml run.yaml
    

至于具体发生了什么,其实就是tekton自动将Secret mount到了HOME目录,原理跟kubernetes是相似的。

其中的关键的关键就是Secret 中的这个annotations,必须是tekton.dev/git- or tekton.dev/docker-开头

tekton就是根据这个annotations,判断对应是docker还是git,找到对应的用户名密码。

避免全局使用credentials

细心的读者会发现serviceAccount绑定在PipelineRunTaskRun上,那么对整个PipelineTask都生效的

所有步骤不管有没有需要登录认证,pod里都会有credentials

如果想避免这里情况,那么就不能用上文所述的这种做法了。

一个变通的办法是单独将不同的Secret 放到不同的workspace中,

对应的task可以根据需要挂载一个或者多个workspace使用credentials。

skopeo

接下来我们实际使用skopeo演示这两种认证方法

skopeo是一个给docker image打标签的工具,不需要把镜像完整拖下来,直接在registry上操作。

集中认证方式

  1. 先创建docker登录Secret,注意annotations中定义了对应docker.io这个仓库

    apiVersion: v1
    kind: Secret
    metadata:name: docker-credsannotations:tekton.dev/docker-0: https://docker.io
    type: kubernetes.io/basic-auth
    stringData:username: massivezhpassword: xxxx-xxxx-xxxx-xxxx-xxxx
  2. 创建ServiceAccount

    apiVersion: v1
    kind: ServiceAccount
    metadata:name: secret-service-account
    secrets:- name: docker-creds
    # 这里可以一次性绑定多个Secret,对应不同的repo
    #  - name: quay-creds
    
  3. 最后在TaskRun中绑定serviceAccountName

    apiVersion: tekton.dev/v1beta1
    kind: TaskRun
    metadata:name: skopeo-run
    spec:serviceAccountName: secret-service-accountparams:- name: srcImageURLvalue: docker://docker.io/massivezh/kaniko-nocode:latest- name: destImageURLvalue: docker://docker.io/massivezh/kaniko-nocode:1taskRef:name: skopeo-copyworkspaces:- name: images-urlemptyDir: {}
  4. 查看运行结果

    # kubectl get taskrun
    NAME             SUCCEEDED   REASON      STARTTIME   COMPLETIONTIME
    skopeo-run       True        Succeeded   29m         29m
    

    docker hub已经有了tag:1的镜像

独立认证方式

这个使用workspace的方法,可能已经在其他地方看到过了

  1. 改造skopeo,增加一个workspace,将dockerconfig挂载到HOME目录

    # diff -u skopeo-copy.yaml workspaces-cred/skopeo-copy-mod.yaml
    --- skopeo-copy.yaml    2022-09-18 11:30:18.692333792 +0800
    +++ workspaces-cred/skopeo-copy-mod.yaml        2022-09-18 11:53:23.459643040 +0800
    @@ -22,6 +22,10 @@workspaces:- name: images-url
    +    - name: dockerconfig
    +      description: Includes a docker `config.json`
    +      optional: true
    +      mountPath: /tekton/home/.docker
    
  2. docker login手动登录产生/root/.docker/config.json

  3. config.json转化成secret

    # kubectl create secret generic dockerhub-secret --from-file=/root/.docker/config.json
    
  4. TaskRun中设置workspaces

    apiVersion: tekton.dev/v1beta1
    kind: TaskRun
    metadata:name: skopeo-run-mod
    spec:params:- name: srcImageURLvalue: docker://docker.io/massivezh/kaniko-nocode:latest- name: destImageURLvalue: docker://docker.io/massivezh/kaniko-nocode:2taskRef:name: skopeo-copy-modworkspaces:- name: images-urlemptyDir: {}- name: dockerconfigsecret:secretName: dockerhub-secret
  5. 查看运行结果

    # kubectl get taskrun
    NAME             SUCCEEDED   REASON      STARTTIME   COMPLETIONTIME
    skopeo-run-mod   True        Succeeded   3m26s       3m13s
    

    docker hub已经有了tag:2的镜像

一次修改多个tag

前面说的都是一次只打一个tag,如果需要批量处理打tag,需要设置images-url这个参数

首先创建一个configmap,里面对应的文件名必须是url.txt
把需要修改的tag列表全部写在这里面

#cat url.txt
docker://quay.io/temp/kubeconfigwriter:v1 docker://quay.io/skopeotest/kube:v1
docker://quay.io/temp/kubeconfigwriter:v2 docker://quay.io/skopeotest/kube:v2kubectl create configmap image-configmap --from-file=url.txt

默认一次只处理一个,这个值是空的

workspaces:- name: images-urlemptyDir: {}

我们替换成configmap包含url.txt文件

workspaces:- name: images-urlconfigmap:name: image-configmap

运行过程中这个url.txt会mount到pod里供skopeo使用。

参考:

https://hub.tekton.dev/tekton/task/skopeo-copy

https://github.com/tektoncd/catalog/tree/main/task/skopeo-copy/0.2

https://tekton.dev/docs/pipelines/auth/

Tekton笔记(四)之Authentication及catalog skopeo相关推荐

  1. C#可扩展编程之MEF学习笔记(四):见证奇迹的时刻

    前面三篇讲了MEF的基础和基本到导入导出方法,下面就是见证MEF真正魅力所在的时刻.如果没有看过前面的文章,请到我的博客首页查看. 前面我们都是在一个项目中写了一个类来测试的,但实际开发中,我们往往要 ...

  2. IOS学习笔记(四)之UITextField和UITextView控件学习

    IOS学习笔记(四)之UITextField和UITextView控件学习(博客地址:http://blog.csdn.net/developer_jiangqq) Author:hmjiangqq ...

  3. MSSQL编程笔记四 解决count distinct多个字段的方法

    MSSQL编程笔记四 解决count distinct多个字段的方法 参考文章: (1)MSSQL编程笔记四 解决count distinct多个字段的方法 (2)https://www.cnblog ...

  4. RabbitMQ学习笔记四:RabbitMQ命令(附疑难问题解决)

    RabbitMQ学习笔记四:RabbitMQ命令(附疑难问题解决) 参考文章: (1)RabbitMQ学习笔记四:RabbitMQ命令(附疑难问题解决) (2)https://www.cnblogs. ...

  5. JSP学习笔记(四十九):抛弃POI,使用iText生成Word文档

    POI操作excel的确很优秀,操作word的功能却不敢令人恭维.我们可以利用iText生成rtf文档,扩展名使用doc即可. 使用iText生成rtf,除了iText的包外,还需要额外的一个支持rt ...

  6. Ethernet/IP 学习笔记四

    Ethernet/IP 学习笔记四 EtherNet/IP Quick Start for Vendors Handbook (PUB213R0): https://www.odva.org/Port ...

  7. OpenCV学习笔记四-image的一些整体操作

    title: OpenCV学习笔记四-image的一些整体操作 categories: 编程 date: 2019-08-08 12:50:47 tags: OpenCV image的一些操作 sP4 ...

  8. 吴恩达《机器学习》学习笔记四——单变量线性回归(梯度下降法)代码

    吴恩达<机器学习>学习笔记四--单变量线性回归(梯度下降法)代码 一.问题介绍 二.解决过程及代码讲解 三.函数解释 1. pandas.read_csv()函数 2. DataFrame ...

  9. esp8266舵机驱动_arduino开发ESP8266学习笔记四—–舵机

    arduino开发ESP8266学习笔记四-–舵机 使用时发现会有ESP8266掉电的情况,应该是板上的稳压芯片的限流导致的,观测波形,发现当舵机运转时,电源线3.3V不再是稳定的3.3V,大概是在3 ...

最新文章

  1. sqlalchemy 网页_抓取网页数据,上班也能看股票
  2. 使用 trait 时报PHP Parse error: syntax error, unexpected 'use' (T_USE) 这个错误
  3. 土人系列AS入门教程--实战篇
  4. mysql proxy 读写分离 1
  5. delphi7存储过程传入数组_js数组方法reduce
  6. JS----javascript中使用reverse()方法反转数组
  7. 【转】学会这13个原则写UI界面文案,用户才能秒懂
  8. 【项目管理】项目干系人
  9. kvm虚拟化网卡、virbr0、网段修改
  10. 获取所有汉字与 Unicode 的对照表
  11. 云计算数据中心运维管理要点
  12. k8s关于Orphaned pod <pod_id> found,volume paths are still present on disk 的解决方法
  13. android仿微博头像_仿微博点击头像加载动画
  14. 美团餐饮SaaS基于StarRocks构建商家数据中台的探索
  15. 【活动报名】 拥抱公平《 Impact Tech, She Can 》
  16. 读《证券市场基础知识》(2012)-1 [概念篇]
  17. 三种代码版本控制系统的简介 以及 SVN的安装
  18. SpringBoot 直接访问静态资源
  19. 人防消防给水排水和灭火设备
  20. Effective STL 精华版读书笔记

热门文章

  1. 尝试Ping百度域名后的思考
  2. 【Swing】JTextArea文本域组件
  3. 计算机组成原理(8)CPU——基本结构
  4. C++17 文件与目录操作 <filesystem>
  5. Android系统分析之带着问题看事件分发机制
  6. php实现远程下载文件到本地服务器指定目录
  7. 纯前端,js导出页面为pdf
  8. 按照计算机名共享打印机,添加网络共享打印机
  9. loadrunner录制网页脚本时打不开或打开慢
  10. 高德地图完整功能的html,揭秘高德地图八大不为人知的强大功能