我们在Azure管道中使用S2i构建命令,并使用下面的命令任务。
`./s2i build http://azuredevopsrepos:8080/tfs/IT/_git/shoppingcart --ref=S2i registry.access.redhat.com/ubi8/dotnet-31 --copy shopping-service` 上面的命令询问任务执行时的用户名和密码,我们如何从正在执行的命令中提供git存储库的用户名和密码?
发布于 2022-09-09 13:23:00
Git凭据信息可以放在主目录中的.gitconfig文件中。
当我查看s2i cli的文档*2时,我找不到任何关于安全git的信息。
我意识到OpenShift BuildConfig在构建容器映像时使用了.gitconfig文件。
*1:https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
*2:https://github.com/openshift/source-to-image/blob/master/docs/cli.md#s2i-build
发布于 2022-09-21 15:54:06
我必须承认,我不熟悉Azure管道,但是如果这是在OpenShift上运行一个构建,您可以使用oc创建一个使用凭据的秘密。
oc create secret generic azure-git-credentials --from-literal=username=<your-username> --from-literal=password=<PAT> --type=kubernetes.io/basic-auth将上面创建的秘密链接到构建器服务帐户,这个帐户是OpenShift在运行新构建时默认在幕后使用的帐户。
oc secrets link builder azure-git-credentials最后,您将希望将此源秘密链接到构建配置。
oc set build-secret --source bc/<your-build-config> azure-git-credentials下次运行构建时,应该从构建配置中的源秘密中获取凭据。
您也可以在OpenShift上的UI中执行此操作,下面的步骤是上面所做工作的副本,请选择一个,而不是两者。
从YAML创建一个秘密,在指定的位置修改下面的内容:
kind: Secret
apiVersion: v1
metadata:
name: azure-git-credentials
namespace: <your-namespace>
data:
password: <base64-encoded-password-or-PAT>
username: <base64-encoded-username>
type: kubernetes.io/basic-auth然后在ServiceAccounts关于OpenShift的部分下,查找和编辑'builder‘服务帐户。
kind: ServiceAccount
apiVersion: v1
metadata:
name: builder
namespace: xxxxxx
secrets:
- name: azure-git-credentials ### only add this line, do not edit anything else.最后,编辑构建配置以找到git条目所在的位置,并添加源秘密条目:
source:
git:
uri: "https://github.com/user/app.git"
### Add the entries below ###
sourceSecret:
name: "azure-git-credentials"https://stackoverflow.com/questions/73624180
复制相似问题