这是当前运行迁移的PRISMA操作文件:

name: Deploy Prisma Migration
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3
      - name: Setup Node
        uses: actions/setup-node@v3
      - name: Install dependencies
        run: npm install
      - name: Apply all pending migrations to the database
        run: npx prisma migrate deploy
        env:
          DATABASE_URL: ${{ secrets.DATABASE_URL }}

但它失败了,因为我不允许来自外部使用或来self 连接的EC2实例的IP.

是否还有其他方法,例如从EC2通过SSH tunel (因为我已经通过EC2连接到RDS)

推荐答案

是否还有其他方法,例如从EC2建立SSH tunel

您可以使用PgAdmin中的SSH tunel 跟踪this question.

The same idea would apply for Prisma, which acts as a client that needs to connect to a database.
The main requirement is establishing a secure connection from an external network (GitHub Actions runner in your case) to the RDS instance, which is restricted to external access. That is where the SSH tunnel comes in, providing a secure pathway through an allowed intermediary (the EC2 instance).

You would need to create an SSH key pair on your local machine or GitHub runner. That key will be used to establish a secure SSH connection to the EC2 instance. (ssh-keygen). Make sure your EC2 instance has SSH enabled and can access the RDS database, as seen in this answer. Add the public key you generated to the ~/.ssh/authorized_keys file on the EC2 instance to allow access.
Add the private key, EC2 instance's IP address or hostname, and username as secrets in your GitHub repository settings. These will be used to establish the SSH connection.

您的GitHub工作流应该将私钥 echo 到文件中,设置适当的权限,然后使用SSH命令创建 tunel :

- name: Set up SSH Tunnel for Database Access
  run: |
    echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
    ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} -L local_port:RDS_endpoint:RDS_port -N &
    sleep 5

当您的GitHub操作工作流运行时,它应该创建到EC2实例的SSH tunel ,而EC2实例又可以访问RDS数据库.这使得您的数据库操作可以安全地执行,而不会将RDS实例expose 给公共互联网.

Database相关问答推荐

Power BI中的计数

在使用FT.AGGREGATE聚合数据时,如何在Redis上解析ISO 8601时间?

Metasploit 数据库警告

存储过程的缺点

主必须包括表的分区位置错误中的所有列?

某些网站不允许在密码中使用句点是否有原因?

SQL查询7天前的数据

如何在大型数据库中使用 typeahead.js

为什么有人需要内存数据库?

为什么会一直出现Table is marked for deletion的消息?

使用 typeORM 搜索早于日期的数据

如何从 PostgreSQL 数据库中的文本文件加载数据?

如何在 Windows 中将用户添加到 PostgreSQL?

我如何做大于/小于使用 MongoDB?

mysql 无法从存储引擎读取自增值

显式事务回滚是否必要?

最佳用户角色权限数据库设计实践?

多个和单个索引

我将如何为读写操作实现单独的数据库?

如何将空值传递给外键字段?