配置存储库访问权限 - Amazon EKS
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

帮助改进此页面

要帮助改进本用户指南,请选择位于每个页面右侧窗格中的在 GitHub 上编辑此页面链接。

配置存储库访问权限

在部署应用程序之前,请配置 Argo CD 以访问 Git 存储库和 Helm 图表注册表。Argo CD 支持针对 GitHub、GitLab、Bitbucket、Amazon CodeCommit 和 Amazon ECR 的多种身份验证方法。

注意

若要与 Amazon 服务直接集成(ECR Helm 图表、CodeCommit 存储库和 CodeConnections),您可以直接在 Application 资源中引用它们,而无需创建存储库配置。功能角色必须具有必要的 IAM 权限。有关详细信息,请参阅 配置 Argo CD 权限

先决条件

  • 已创建具有 Argo CD 功能的 EKS 集群

  • Git 存储库包含 Kubernetes 清单

  • 已配置 kubectl 以与集群通信

注意

要在多个存储库中重复使用凭证,可以使用存储库凭证模板(repocreds)。有关更多信息,请参阅 Argo CD 文档中的 Private Repositories

身份验证方法

方法 用例 所需的 IAM 权限

与 Amazon 服务直接集成

CodeCommit

直接与 Amazon CodeCommit Git 存储库集成。无需配置存储库。

codecommit:GitPull

CodeConnections

通过托管身份验证连接到 GitHub、GitLab 或 Bitbucket。需要进行连接设置。

codeconnections:UseConnection

ECR Helm 图表

直接与 Amazon ECR 集成以获取 OCI Helm 图表。无需配置存储库。

ecr:GetAuthorizationToken, ecr:BatchGetImage, ecr:GetDownloadUrlForLayer

使用凭证配置存储库

Amazon Secrets Manager(用户名/令牌)

存储个人访问令牌或密码

secretsmanager:GetSecretValue

Amazon Secrets Manager(SSH 密钥)

使用 SSH 密钥身份验证

secretsmanager:GetSecretValue

Amazon Secrets Manager(GitHub 应用程序)

使用私有密钥对 GitHub 应用程序进行身份验证

secretsmanager:GetSecretValue

Kubernetes Secret

使用集群内密钥的标准 Argo CD 方法

无(仅限信任策略)

直接访问 Amazon 服务

对于 Amazon 服务,您可以直接在 Application 资源中引用它们,而无需创建存储库配置。功能角色必须具有必要的 IAM 权限。

CodeCommit 存储库

直接在应用程序中引用 CodeCommit 存储库:

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: my-app namespace: argocd spec: source: repoURL: https://git-codecommit.region.amazonaws.com/v1/repos/repository-name targetRevision: main path: kubernetes/manifests

所需的功能角色权限:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codecommit:GitPull", "Resource": "arn:aws:codecommit:region:account-id:repository-name" } ] }

CodeConnections

通过 CodeConnections 引用 GitHub、GitLab 或 Bitbucket 存储库。存储库 URL 格式派生自 CodeConnections 连接 ARN。

存储库 URL 格式为:

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: my-app namespace: argocd spec: source: repoURL: https://codeconnections.region.amazonaws.com/git-http/account-id/region/connection-id/owner/repository.git targetRevision: main path: kubernetes/manifests

所需的功能角色权限:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "codeconnections:UseConnection", "Resource": "arn:aws:codeconnections:region:account-id:connection/connection-id" } ] }

ECR Helm 图表

ECR 将 Helm 图表存储为 OCI 构件。Argo CD 支持两种引用方式:

Helm 格式(建议用于 Helm 图表):

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: my-app-helm namespace: argocd spec: source: repoURL: account-id.dkr.ecr.region.amazonaws.com/repository-name targetRevision: chart-version chart: chart-name helm: valueFiles: - values.yaml

注意:使用 Helm 格式时,请勿包含 oci:// 前缀。使用 chart 字段指定图表名称。

OCI 格式(适用于包含 Kubernetes 清单的 OCI 构件):

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: my-app-oci namespace: argocd spec: source: repoURL: oci://account-id.dkr.ecr.region.amazonaws.com/repository-name targetRevision: artifact-version path: path-to-manifests

注意:使用 OCI 格式时,请包含 oci:// 前缀。请使用 path 字段而非 chart

所需的功能角色权限:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ecr:GetAuthorizationToken", "ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer" ], "Resource": "*" } ] }

使用 Amazon Secrets Manager

将存储库凭证存储在 Secrets Manager 中,然后在 Argo CD 存储库配置中引用它们。

用户名和令牌身份验证

对于使用个人访问令牌或密码的 HTTPS 存储库:

在 Secrets Manager 中创建 Secret

aws secretsmanager create-secret \ --name argocd/my-repo \ --description "GitHub credentials for Argo CD" \ --secret-string '{"username":"your-username","token":"your-personal-access-token"}'

可选 TLS 客户端证书字段(适用于私有 Git 服务器):

aws secretsmanager create-secret \ --name argocd/my-private-repo \ --secret-string '{ "username":"your-username", "token":"your-token", "tlsClientCertData":"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi4uLgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t", "tlsClientCertKey":"LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCi4uLgotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0t" }'
注意

tlsClientCertDatatlsClientCertKey 值必须采用 base64 编码。

创建引用 Secrets Manager 的 Repository Secret

apiVersion: v1 kind: Secret metadata: name: my-repo namespace: argocd labels: argocd.argoproj.io/secret-type: repository stringData: type: git url: https://github.com/your-org/your-repo secretArn: arn:aws:secretsmanager:us-west-2:111122223333:secret:argocd/my-repo-AbCdEf project: default

SSH 密钥身份验证

对于基于 SSH 的 Git 访问,请将私有密钥存储为纯文本(而非 JSON):

创建包含 SSH 私有密钥的 Secret

aws secretsmanager create-secret \ --name argocd/my-repo-ssh \ --description "SSH key for Argo CD" \ --secret-string "-----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn ... -----END OPENSSH PRIVATE KEY-----"

为 SSH 创建 Repository Secret

apiVersion: v1 kind: Secret metadata: name: my-repo-ssh namespace: argocd labels: argocd.argoproj.io/secret-type: repository stringData: type: git url: git@github.com:your-org/your-repo.git secretArn: arn:aws:secretsmanager:us-west-2:111122223333:secret:argocd/my-repo-ssh-AbCdEf project: default

GitHub 应用程序身份验证

对于使用私有密钥的 GitHub 应用程序身份验证:

创建包含 GitHub 应用程序凭证的 Secret

aws secretsmanager create-secret \ --name argocd/github-app \ --description "GitHub App credentials for Argo CD" \ --secret-string '{ "githubAppPrivateKeySecret":"LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQouLi4KLS0tLS1FTkQgUlNBIFBSSVZBVEUgS0VZLS0tLS0=", "githubAppID":"123456", "githubAppInstallationID":"12345678" }'
注意

githubAppPrivateKeySecret 值必须采用 base64 编码。

用于 GitHub Enterprise 的可选字段

aws secretsmanager create-secret \ --name argocd/github-enterprise-app \ --secret-string '{ "githubAppPrivateKeySecret":"LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQouLi4KLS0tLS1FTkQgUlNBIFBSSVZBVEUgS0VZLS0tLS0=", "githubAppID":"123456", "githubAppInstallationID":"12345678", "githubAppEnterpriseBaseUrl":"https://github.example.com/api/v3" }'

为 GitHub 应用程序创建 Repository Secret

apiVersion: v1 kind: Secret metadata: name: my-repo-github-app namespace: argocd labels: argocd.argoproj.io/secret-type: repository stringData: type: git url: https://github.com/your-org/your-repo secretArn: arn:aws:secretsmanager:us-west-2:111122223333:secret:argocd/github-app-AbCdEf project: default
重要

确保 IAM 功能角色拥有所创建密钥的 secretsmanager:GetSecretValue 权限。有关 IAM 策略配置,请参阅 Argo CD 注意事项

使用 Amazon CodeConnections

有关 CodeConnections 集成,请参阅使用 Amazon CodeConnections 连接到 Git 存储库

CodeConnections 为 GitHub、GitLab 和 Bitbucket 提供托管身份验证,无需存储凭证。

使用 Kubernetes Secrets

使用标准的 Argo CD 方法,将凭证直接存储在 Kubernetes 中。

对于使用个人访问令牌的 HTTPS

apiVersion: v1 kind: Secret metadata: name: my-repo namespace: argocd labels: argocd.argoproj.io/secret-type: repository stringData: type: git url: https://github.com/your-org/your-repo username: your-username password: your-personal-access-token

对于 SSH

apiVersion: v1 kind: Secret metadata: name: my-repo-ssh namespace: argocd labels: argocd.argoproj.io/secret-type: repository stringData: type: git url: git@github.com:your-org/your-repo.git sshPrivateKey: | -----BEGIN OPENSSH PRIVATE KEY----- ... your private key ... -----END OPENSSH PRIVATE KEY-----

公有存储库

公有存储库无需其他配置:

apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: public-app namespace: argocd spec: source: repoURL: https://github.com/argoproj/argocd-example-apps targetRevision: HEAD path: guestbook # ... rest of configuration

CodeCommit 存储库

对于 Amazon CodeCommit,授予 IAM 功能角色 CodeCommit 权限 (codecommit:GitPull)。

配置存储库:

apiVersion: v1 kind: Secret metadata: name: codecommit-repo namespace: argocd labels: argocd.argoproj.io/secret-type: repository stringData: type: git url: https://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo project: default

有关详细的 IAM 策略配置,请参阅 Argo CD 注意事项

验证存储库连接

通过 Argo CD 用户界面,在“设置 → 存储库”下检查连接状态。用户界面会显示连接状态和任何身份验证错误。

Repository Secret 不包含状态信息。

其他资源