Permission denied in Gitlab Runner

Viewed 1581

I have a Gitlab runner running in a VPS, now is facing this error:

Running on vps...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /home/gitlab-runner/builds/-Jgf7oJG/0/agency/project/app/.git/
Checking out 67b23db2 as testing...
Removing .env
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
$ mkdir -p ~/.ssh
$ echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
$ chmod 700 ~/.ssh/id_rsa
$ eval "$(ssh-agent -s)"
Agent pid 929369
$ ssh-add ~/.ssh/id_rsa
Identity added: /home/gitlab-runner/.ssh/id_rsa (/home/gitlab-runner/.ssh/id_rsa)
$ ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
bash: line 133: /home/gitlab-runner/.ssh/known_hosts: Permission denied
Cleaning up file based variables
00:00
ERROR: Job failed: exit status 1

I've tryed with the following commands inside the vps that have the runner:

$ sudo usermod -a -G sudo gitlab-runner

$ sudo visudo

And adding this to the bottom of the file. gitlab-runner ALL=(ALL) NOPASSWD: ALL

2 Answers

make sure that your known_hosts file has the following group & permissions.

-rw-r--r-- 1 gitlab-runner gitlab-runner 444 Aug 2 00:00 known_hosts

from sshd manual

     ~/.ssh/known_hosts
             Contains a list of host keys for all hosts the user has logged into that are not already in the systemwide list of known host keys.  The format of this file is described above.  This file should be writable only by root/the owner and
             can, but need not be, world-readable.

chmod 600/644 for ~/.ssh/known_hosts

Related