Skip to content

Commit

Permalink
Optional usage of ssh keys
Browse files Browse the repository at this point in the history
  • Loading branch information
valtri committed Aug 8, 2017
1 parent 2e40774 commit c3d8f0d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.n

RUN /usr/sbin/sshd-keygen \
&& useradd -m -d /home/jenkins -s /bin/bash jenkins \
&& echo "jenkins:jenkins" | chpasswd \
&& sed -i '/root\tALL=/a jenkins ALL=(ALL) NOPASSWD: ALL' /etc/sudoers

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]
COPY docker-entry.sh /
CMD ["/docker-entry.sh", "/usr/sbin/sshd", "-D"]
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@ In Jenkins:

* for example with *Docker Plugin*

Credentials:
## Simple way

* jenkins/jenkins
Initial password is created during start, but only if */context/.ssh* directory is not found locally:

Manual launch:
* user: **jenkins**
* password: **jenkins**

Steps:

docker pull valtri/docker-jenkins-centos
docker run -itd --name jenkins-centos valtri/docker-jenkins-centos

## Recommended way

Access using ssh keys and no password will be created.

Steps:

ssh-keygen -t rsa -f jenkins_node
mkdir -p context/.ssh
#SELinux: chcon -Rt svirt_sandbox_file_t context/
cp -p jenkins_node.pub context/.ssh/authorized_keys

docker pull valtri/docker-jenkins-centos
docker run -itd --name jenkins-contos valtri/docker-jenkins-centos
docker run -itd --name jenkins-centos --volume `pwd`/context:/context:ro valtri/docker-jenkins-centos

# Tags

Expand Down
16 changes: 16 additions & 0 deletions docker-entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /bin/bash -e

if ! test -d ~jenkins/.ssh; then
if test -d /context -a -d /context/.ssh; then
cp -va /context/.ssh ~jenkins/
else
mkdir ~jenkins/.ssh
echo "Settings jenkins password"
echo "jenkins:jenkins" | chpasswd
fi

chmod 0700 ~jenkins/.ssh
chown -R jenkins:jenkins ~jenkins/.ssh
fi

exec "$@"

0 comments on commit c3d8f0d

Please sign in to comment.