Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] t2d: add ssh key to authorized_keys #212

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/travis2docker/templates/Dockerfile_deployv
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ RUN . /home/odoo/build.sh && \
configure_vim && \
configure_zsh && \
chown_all && \
set_authorized_keys && \
mv /entrypoint_image /deployv_entrypoint_image && \
mv /entry_point.py /deployv_entry_point.py && \
mkdir /run/sshd
Expand Down
20 changes: 0 additions & 20 deletions src/travis2docker/templates/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,6 @@ EOF
# alias odoo
}

set_authorized_keys(){
YELLOW='\033[0;33m'
NC='\033[0m'

AUTH_FILE="${HOME}/.ssh/authorized_keys"
ED_KEY="${HOME}/.ssh/id_ed25519.pub"
RSA_KEY="${HOME}/.ssh/id_rsa.pub"

echo "INFO: Adding public key to ~/.ssh/authorized_keys"
if [ -f "${ED_KEY}" ]; then
tee -a "${AUTH_FILE}" < "${ED_KEY}"
elif [ -f "${RSA_KEY}" ]; then
printf "${YELLOW}WARNING: RSA keys are deprecated, consider changing to ed25519\n${NC}"
tee -a "${AUTH_FILE}" < "${RSA_KEY}"
else
echo "INFO: No public key found. No key added to ~/.ssh/authorized_keys"
fi
}


# You can add new packages here
install_dev_tools(){
apt update -qq
Expand Down
23 changes: 23 additions & 0 deletions src/travis2docker/travis2docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def compute_dockerfile(self, skip_after_success=False):
copies = []
for copy_path, dest in self.copy_paths:
copies.append((self.copy_path(copy_path), dest))
self.set_authorized_key()
kwargs = {
'runs': [],
'copies': copies,
Expand Down Expand Up @@ -381,3 +382,25 @@ def copy_path(self, path):
else:
raise UserWarning("Just directory or file is supported to copy [%s]" % src)
return os.path.relpath(dest_path, self.curr_work_path)

def set_authorized_key(self):
ssh_dir = os.path.expanduser("~/.ssh")
ed_key = os.path.join(ssh_dir, "id_ed25519.pub")
rsa_key = os.path.join(ssh_dir, "id_rsa.pub")

to_copy = False
if os.path.isfile(ed_key):
to_copy = ed_key
elif os.path.isfile(rsa_key):
print("RSA keys are deprecated, consider changing to ed25519")
to_copy = rsa_key

if not to_copy:
print("No public key found. No key added to ~/.ssh/authorized_keys. SSH login won't work.")
return

with open(to_copy, "r", encoding="utf-8") as key_fd:
pub_key = key_fd.read()

with open(os.path.join(self.curr_work_path, ".ssh", "authorized_keys"), "w", encoding="utf-8") as auth_fd:
auth_fd.write(pub_key)