Die*_*ndt 9 deployment tcp github amazon-ec2 github-actions
我刚刚在我的项目上创建了操作并配置了那里的所有内容,但不幸的是,我在“部署文件”部分> ssh:连接到主机 ec2-MYIP.us-east-2.compute.amazonaws 中收到类似这样的消息.com 端口 22:操作超时

好消息是我知道发生了什么事。我必须允许以下入站规则:
类型:SSH / 协议:TCP / 帖子范围:22 / 来源:::/0;

正如你在这里看到的,在不限制源IP的情况下它工作得很好>

但显然出于安全原因我不想这样做,所以我需要找出我需要放在那里的来源。我已经尝试了很多Github IP地址,但都没有成功。
这里有谁知道它以受保护的方式工作的正确来源是什么,或者我如何找到它?
我正在使用的操作 > https://github.com/wlixcc/SFTP-Deploy-Action
kac*_*ow6 11
相对于 riQQ 的改进答案:在工作流程中使用public-ip 操作动态检索 Github Action 运行器的 IP 地址,并在 SSH 步骤之前和之后更新 EC2 服务器的安全组入口规则。
您的 EC2 实例永远不会暴露给 SSH 端口上的公共 IP 地址。
注意:您还需要在运行器上设置 AWS 凭证,并具有更新关联 EC2 安全组的权限。
您的工作流程应该如下所示:
deploy:
name: deploy
runs-on: ubuntu-latest
env:
AWS_INSTANCE_SG_ID: <your-ec2-security-group-id>
steps:
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: <your-ci-aws-access-key>
aws-secret-access-key: <your-ci-aws-secret-key>
aws-region: <your-ec2-aws-region>
- name: get runner ip address
id: ip
uses: haythem/public-ip@v1.2
- name: whitelist runner ip address
run: |
aws ec2 authorize-security-group-ingress \
--group-id $AWS_INSTANCE_SG_ID \
--protocol tcp \
--port 22 \
--cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: ssh into your ec2 and do whatever
run: |
...do whatever you need to do...
- name: revoke runner ip address
run: |
aws ec2 revoke-security-group-ingress \
--group-id $AWS_INSTANCE_SG_ID \
--protocol tcp \
--port 22 \
--cidr ${{ steps.ip.outputs.ipv4 }}/32
Run Code Online (Sandbox Code Playgroud)
GitHub 托管运行器的 IP 地址记录在此处:https: //docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners#ip-addresses
Windows 和 Ubuntu 运行程序托管在 Azure 中,并具有与 Azure 数据中心相同的 IP 地址范围。
[...]
Microsoft 每周更新 JSON 文件中的 Azure IP 地址范围,您可以从Azure IP 范围和服务标签 - 公共云网站下载该文件。如果您需要允许列表来防止未经授权访问您的内部资源,则可以使用此 IP 地址范围。
| 归档时间: |
|
| 查看次数: |
4201 次 |
| 最近记录: |