Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,461,074
Community Members
 
Community Events
176
Community Groups

Copy generated SSH public key with ssh-copy-id from pipeline image to remote server

I created a custom docker image based on Alpine. Moreover, I added a Python script to read secrets from our Vault server and use Rsync to deploy the repository to our servers.

Testing this script in a server or my own workstation was successful. However, When I tried to use it in Bitbucket pipeline it wasn't able to copy the public ssh key (generated from bitbucket ssh tab in pipeline settings). I went through the running image with some command to search for the keys and I find only the private key and no public key. I checked also some pipeline images from this project but still have the same issue. I am using the script from rsync deploy pipeline which looks like this:



#!/bin/bash## Bitbucket Pipelines#

source
"$(dirname "$0")/common.sh"

info
"Executing the pipe..."

setup_ssh_dir() {

INJECTED_SSH_CONFIG_DIR=
"/opt/atlassian/pipelines/agent/ssh"

# The default ssh key with open perms readable by alt uids

IDENTITY_FILE=
"${INJECTED_SSH_CONFIG_DIR}/id_rsa_tmp"

# The default known_hosts file

KNOWN_HOSTS_FILE=
"${INJECTED_SSH_CONFIG_DIR}/known_hosts"
mkdir -p ~/.ssh || debug "adding ssh keys to existing ~/.ssh"
touch
~/.ssh/authorized_keys chmod -R 700 ~/.ssh

if [ ! -f ${IDENTITY_FILE} ]; then
error
"No default SSH key configured in Pipelines."
exit 1 else debug "Using default ssh key"

cp
${IDENTITY_FILE} ~/.ssh/pipelines_id
chmod 600
~/.ssh/pipelines_id
ssh-keygen -y -f
~/.ssh/pipelines_id > ~/.ssh/pipelines_id.pub
fi

if [ ! -f ${KNOWN_HOSTS_FILE} ]; then
error
"No SSH known_hosts configured in Pipelines."
exit 2
fi

cat
${KNOWN_HOSTS_FILE} >> ~/.ssh/known_hosts

if [ -f ~/.ssh/config ]; then

debug
"Appending to existing ~/.ssh/config file"

fi

echo "IdentityFile ~/.ssh/pipelines_id" > ~/.ssh/config
chmod -R go-rwx
~/.ssh/

}

enable_debug
setup_ssh_dir


The result I am getting when I execute an ssh-copy-id of the copied key:

 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/pipelines_id.pub"
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/pipelines_id.pub"

 Am I doing something wrong and why there is no trace of the public key inside the image when it runs in the pipeline. And what's the right way to copy it on pipeline execution. 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events