无法通过 GitHub 操作使用 AWS CodeArtifact 进行身份验证 高级步骤GitHub 操作代码

问题描述

我无法从 GitHub 操作中对 AWS CodeArtifact 进行身份验证。 AWS 响应始终为 401。

我正在执行以下步骤:

<div id="map-canvas"></div>

<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap" async defer></script>

并且它一直在 steps: - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ secrets.AWS_REGION }} - run: aws configure --profile my-custom-profile set region ${{ secrets.AWS_REGION }} - run: aws configure --profile my-custom-profile set role_arn ${{ secrets.AWS_ARN }} - run: aws configure --profile my-custom-profile set source_profile default - run: dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider - run: dotnet codeartifact-creds install - run: dotnet codeartifact-creds configure set profile my-custom-profile - uses: actions/checkout@v2 - name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.100 - name: Restore dependencies run: dotnet restore 行消亡:

enter image description here

任何人都可以建议我做错了哪些步骤 - 或者 - 遗漏了吗?

旁注:在这一切之前,花了一些时间,但我最终让它在我的本地主机 Windows 开发机器上运行。所以我存档的凭据似乎有效。

解决方法

以下是在 GitHub 操作中使用 AWS CodeArtifact 进行身份验证的步骤。

高级步骤

  • 使用 ./aws/credentials 个人资料/信用创建一些 [default]
  • 使用一些特定的 AWS CodeArtifact 凭证创建一个 config 文件。
  • 从 AWS CodeArtifact 获取身份验证令牌
  • 将此身份验证令牌保存到环境变量中
  • 拉下所有代码。这需要在您开始使用“nuget 源”之前发生。
  • 使用身份验证令牌将 AWS CodeArtifact nuget 源手动添加到您的 nuget 源。
  • 检查 AWS CodeArtifact 现在是否在 nuget 源列表中。
  • dotnet 还原。

GitHub 操作代码

注意:用您自己的自定义 AWS 设置等替换 <domain><some-id> 等内容。

    - run: |
        echo '[default]' >> ~/.aws/credentials
        echo 'aws_access_key_id=${{ secrets.AWS_ACCESS_KEY_ID }}' >> ~/.aws/credentials
        echo 'aws_secret_access_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}' >> ~/.aws/credentials

    - run: |
        aws configure --profile nuget-read set region us-east-1
        aws configure --profile nuget-read set role_arn arn:aws:iam::<some-id>:role/nuget-read
        aws configure --profile nuget-read set source_profile default
        aws configure list

    - run: aws codeartifact get-authorization-token --domain <some domain> --profile nuget-read > at.json
    - run: echo "AUTH_TOKEN= $(jq '.authorizationToken' at.json)" >> $GITHUB_ENV

    - uses: actions/checkout@v2

    - run: dotnet nuget add source https://<domain>-<id>.d.codeartifact.<aws region>.amazonaws.com/nuget/cosmos-nuget/v3/index.json --name <name of this nuget source. It can be anything> --password ${{ env.AUTH_TOKEN }} --username aws --store-password-in-clear-text

    - run: dotnet nuget list source

    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.100
    
    - name: Restore dependencies
      run: dotnet restore

手动添加 nuget 源时请注意 --store-password-in-clear-text。这是废话,但至少需要在 linux 机器上工作。否则,它无法添加源,因为它不知道如何对其进行加密或其他什么。


所以可能有更好的方法来做到这一点,但至少现在有效!