github - 使用 GitHub SSH 私钥初始化和拉取 terraform 公共模块
问题描述
上下文:我有 gitlab 跑步者正在执行terraform init
命令,该命令正在拉取所有必要的 terraform 模块。最近,我开始遇到 github 节流问题(每小时 60 次调用 github api)。所以我正在尝试重新配置我的管道,以便它使用 Github 用户的私钥。
目前,我的管道中有以下内容,但它似乎仍然无法正常工作,并且没有使用私钥来拉取 terraform 模块。
- GITHUB_SECRET=$(aws --region ${REGION} ssm get-parameters-by-path --path /github/umotifdev --with-decryption --query 'Parameters[*].{Name:Name,Value:Value}' --output json);
- PRIVATE_KEY=$(echo "${GITHUB_SECRET}" | jq -r '.[] | select(.Name == "/github/umotifdev/private_key").Value' | base64 -d);
- PUBLIC_KEY=$(echo "${GITHUB_SECRET}" | jq -r '.[] | select(.Name == "/github/umotifdev/public_key").Value' | base64 -d);
- mkdir -p ~/.ssh;
- echo "${PRIVATE_KEY}" | tr -d '\r' > ~/.ssh/id_rsa;
- chmod 700 ~/.ssh/id_rsa;
- eval $(ssh-agent -s);
- ssh-add ~/.ssh/id_rsa;
- ssh-keyscan -H 'github.com' >> ~/.ssh/known_hosts;
- ssh-keyscan github.com | sort -u - ~/.ssh/known_hosts -o ~/.ssh/known_host;
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config;
- echo ${PUBLIC_KEY} >> ~/.ssh/authorized_keys
我在管道中看到的错误类似于(基本上是来自 github 的限制):
Error: Failed to download module
Could not download module "vpc" (vpc.tf:17) source code from
"https://api.github.com/repos/terraform-aws-modules/terraform-aws-vpc/tarball/v2.21.0//*?archive=tar.gz":
bad response code: 403.
任何人都可以建议如何解决私钥不用于提取 terraform 模块的问题?
解决方案
推荐阅读
- javascript - 如何定位一个
在一个 - python - 在数据框中的一列中搜索特定单词
- delphi - Delphi 如何使用微软语音识别 API
- sql - SQL Server 将 FieldValue 转置为 FieldName
- python - 如何在 matplotlib.pyplot 中绘制递归函数?
- html - 通用标记/ vscode目录不起作用
- python - 如何在具有相似名称和相同类型的多个对象上调用方法?
- firebase - firebase.auth().signInWithEmailAndPassword 暴露了我的密码
- apache-spark - 逻辑回归的 PySpark mllib p 值
- java - 使用“+”号获取 API 请求在 Jmeter 中不起作用