在Tekton Pipeline参数中使用Kubernetes秘密价值

发布于 2025-02-11 17:52:28 字数 384 浏览 2 评论 0原文

我目前正在使用Tekton实施CI管道。我想知道是否有一种方法可以使用某种valuefromenv用于管道参数。

例如,要使用公司的Sonar主机来验证Sonarqube分析的任务,我需要登录令牌,我宁愿通过引用秘密插入它,而不是直接通过它。

由于我对Tekton是个新手,因此我不确定我是否还没有掌握Tekton的方式。我想到的两种可能性是:

  1. 一个“预任务”,在其步骤定义中读取ENV并将其发布为一个(然后可以用作下一个任务的参数)
  2. 将秘密作为任务的文件安装要加载秘密(例如cat ting it)

这两个想法都不觉得我应该这样做,但是也许我在这里错了。

任何帮助都将受到赞赏!

I am currently implementing a CI Pipeline using Tekton. I was wondering if there is a way to use some kind of valueFromEnv for pipeline params.

For example to authenticate a Task for sonarqube analysis with my company's sonar host i need the login token, which I would rather want to insert via reference to a secret than passing it directly.

As I am relatively new to tekton I am unsure if I just haven't grasped the tekton way of doing this. Two possibilities that crossed my mind were:

  1. A "Pre-Task" which reads the env in it's step definition and publishes it as a result (which then can be used as param to the next Task)
  2. Mounting the secret as a file for the Task to load the secret (e.g. by catting it)

Both of those ideas do not feel like I should do it this way, but maybe I am wrong here.

Any help is appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木森分化 2025-02-18 17:52:29

您的第一个想法不是不可能的,而是在我眼中也很丑陋。您可以通过DockerFile在图像中设置所需的ENV,然后在任务中以后使用它:

Docker文件(示例):

FROM gradle:7.4-jdk11    
USER root    
RUN apt-get update && apt-get install -y npm    

YOUR_VARIABLE_KEY="any VALUE"

之后您可以在脚本任务中使用它:

echo $YOUR_VARIABLE_KEY

推荐(适用于OpenShift)

清洁器方法是,将其定义为秘密(键/值),或将其定义为sealeedsecret(不透明),

可以直接在OpenShift-UI上的命名空间或代码中完成。

下一步是在您的任务中“绑定”它:

spec:
  description: |-
    any
  params:
    - name: any-secret-name
      default: "any-secret"
      type: string
  stepTemplate:
    name: ""
    resources:
      limits:
        cpu: 1500m
        memory: 4Gi
      requests:
        cpu: 250m
        memory: 500Mi
  steps:
    - image: $(params.BUILDER_IMAGE)
      name: posting
      resources:
        limits:
          cpu: 1500m
          memory: 4Gi
        requests:
          cpu: 250m
          memory: 500Mi
      env:
        - name: YOU_NAME_IT
          valueFrom:
            secretKeyRef:
              name: $(params.any-secret-name)
              key: "any-secret-key"
      script: |
        #!/usr/bin/env sh
        set -eu

        set +x
        echo $YOU_NAME_IT
        set -x

当意! set -x echo记录下来。

现在,我看到您可能无法在OpenShift中工作 - 这是Kubernetes页面: https:// /kubernetes.io/docs/concepts/configuration/secret/ =>使用秘密作为环境变量(与您的第一个想法接近 - 但整个页面看起来不错)

Your first Idea is not impossible, but in my eyes ugly as well. You can set the desired ENV in your image via DockerFile and use it later in the task:

Docker file (example):

FROM gradle:7.4-jdk11    
USER root    
RUN apt-get update && apt-get install -y npm    

YOUR_VARIABLE_KEY="any VALUE"

afterwards you can just use it in script tasks like:

echo $YOUR_VARIABLE_KEY

RECOMMENDED (for Openshift)

The cleaner way is, to define it as Secret (Key/value) or as a SealeedSecret (Opaque)

this can be done directly within the namespace on the openshift-UI or as Code.

Next step is to "bind" it in your task:

spec:
  description: |-
    any
  params:
    - name: any-secret-name
      default: "any-secret"
      type: string
  stepTemplate:
    name: ""
    resources:
      limits:
        cpu: 1500m
        memory: 4Gi
      requests:
        cpu: 250m
        memory: 500Mi
  steps:
    - image: $(params.BUILDER_IMAGE)
      name: posting
      resources:
        limits:
          cpu: 1500m
          memory: 4Gi
        requests:
          cpu: 250m
          memory: 500Mi
      env:
        - name: YOU_NAME_IT
          valueFrom:
            secretKeyRef:
              name: $(params.any-secret-name)
              key: "any-secret-key"
      script: |
        #!/usr/bin/env sh
        set -eu

        set +x
        echo $YOU_NAME_IT
        set -x

BEWARE!!! If you run it that way - nothing should be logged - if you leave out set +x before and set -x after the echo it is logged.

Now I saw you're may not working in openshift - here is the kubernetes page: https://kubernetes.io/docs/concepts/configuration/secret/ => Using Secrets as environment variables (is close to your first idea - but the whole page looks like good cookbook)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文