【问题标题】:Storing SSH Private Key in GitLab repository variables在 GitLab 存储库变量中存储 SSH 私钥
【发布时间】:2020-11-06 15:35:33
【问题描述】:

使用 GitLab CI,我想将生产代码推送到远程虚拟主机。

为了连接 SSH,我将密钥对的私钥存储在 GitLab 存储库的变量中。我还将公钥复制到服务器的授权密钥中。这是(部分)我的.gitlab-ci.yml

image: ubuntu

before_script:
  # Setup SSH credentials and known host
  - which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
  - mkdir -p ~/.ssh
  - echo "$SSH_PRIVATE" | tr -d '\r' > ~/.ssh/id_rsa
  - chmod 700 ~/.ssh/id_rsa
  - eval "$(ssh-agent -s)"
  - ssh-add ~/.ssh/id_rsa
  - echo "$SSH_KNOWN_HOSTS"
  - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts

这种方法有效,但我质疑它的安全性。我的私钥这样安全吗?我还能如何实现我正在寻找的结果?

编辑:我特别质疑这种方法在生产环境中的安全性。

【问题讨论】:

    标签: ssh gitlab


    【解决方案1】:

    【讨论】:

    • 如果变量包含换行符,则不能屏蔽包含私钥的变量。
    • @Clockwork 确实如此。并非没有预处理和后处理,如stackoverflow.com/a/54675024/6309
    猜你喜欢
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 2015-05-06
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多