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

klam-ssh support for CoreOS #187

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
27d5e08
Merge remote-tracking branch 'adobe-platform/master'
Apr 27, 2016
32ba74a
Initial check-in of klam-ssh support
Apr 27, 2016
957e3fb
klam-ssh additions
Apr 29, 2016
f80f050
Merge remote-tracking branch 'adobe-platform/master'
Apr 29, 2016
3a1a4b9
Last few refinements
May 3, 2016
dc90b55
Merge remote-tracking branch 'adobe-platform/master'
May 3, 2016
a457ce5
make scripts executable
May 3, 2016
e41b189
Merge remote-tracking branch 'adobe-platform/master'
May 4, 2016
3b26a28
update from master; fixes from comments in PR
May 4, 2016
285bcc8
Modify global prompt for klam-ssh
May 4, 2016
25a6ac4
setting default klam-ssh image value
May 4, 2016
1695dff
Merge remote-tracking branch 'adobe-platform/master'
May 10, 2016
8fd283f
Merge remote-tracking branch 'adobe-platform/master'
May 12, 2016
05ec34d
etcd2 setup for bastion host as well
May 12, 2016
a2dbc4d
Merge remote-tracking branch 'adobe-platform/master'
May 12, 2016
2df21da
Merge remote-tracking branch 'adobe-platform/master'
May 13, 2016
dc94557
Merge remote-tracking branch 'adobe-platform/master'
May 16, 2016
3b5a4d0
Bastion support in mesos-systemd
May 16, 2016
0c9ce40
Fixing klam-ssh installation issues due to reliance on values from se…
May 16, 2016
c0b2691
Merge remote-tracking branch 'adobe-platform/master'
May 16, 2016
0d8aa6f
something's not right...
May 16, 2016
94a8485
Revert "something's not right..."
May 16, 2016
e7843af
Rearranging the script order
May 16, 2016
685f787
update-ssh-keys is causing problems
May 16, 2016
f87bb3d
Merge remote-tracking branch 'adobe-platform/master'
May 17, 2016
2c2917f
Merge remote-tracking branch 'adobe-platform/master'
May 19, 2016
09c83cc
Bastion host ssh helper script
May 19, 2016
947b01a
Merge remote-tracking branch 'adobe-platform/master'
May 24, 2016
2f66d37
Updating the ssh client config script to use the Bastion as a forward…
May 24, 2016
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
2 changes: 1 addition & 1 deletion v3/profile.d/profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ fi
# set the prompt for non-root users
if [[ ${EUID} != 0 ]]; then
source /etc/environment
export PS1="\[\\033[01;32m\]\u@\h\[\\033[01;34m\] \[\\033[01;30m\]$NODE_TIER-$NODE_PRODUCT-$ZONE-$NODE_ROLE \[\\033[01;34m\]\w \$\[\\033[00m\] "
export PS1="\[\\033[01;32m\]$(who -m | awk '{print $1}')@\h\[\\033[01;34m\] \[\\033[01;30m\]$NODE_TIER-$NODE_PRODUCT-$ZONE-$NODE_ROLE \[\\033[01;34m\]\w \$\[\\033[00m\] "
fi
144 changes: 144 additions & 0 deletions v3/setup/klam-ssh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/bin/bash -xe

etcdctl set /images/klam-ssh "adobecloudops/klam-ssh:latest"

AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
REGION=${AZ::-1}
ROLE_NAME="$(etcdctl get /klam-ssh/config/role-name)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the KLAM Role is created in the infrastructure stack, it should be added as an environment variable here: https://github.com/adobe-platform/infrastructure/blob/master/v2/src/userdata/templates/write_files/environment/shared.yml

Otherwise, we will have to have users pull their KLAM role out of the infrastructure stack and insert it into secrets.

ENCRYPTION_ID="$(etcdctl get /klam-ssh/config/encryption-id)"
ENCRYPTION_KEY="$(etcdctl get /klam-ssh/config/encryption-key)"
KEY_LOCATION_PREFIX="$(etcdctl get /klam-ssh/config/key-location-prefix)"
IMAGE="$(etcdctl get /images/klam-ssh)"


case $REGION in
"eu-west-1")
KEY_LOCATION="-ew1" ;;
"ap-northeast-1")
KEY_LOCATION="-an1" ;;
"us-east-1")
KEY_LOCATION="-ue1" ;;
"us-west-1")
KEY_LOCATION="-uw1" ;;
"us-west-2")
KEY_LOCATION="-uw2" ;;
*)
echo "An incorrect region value specified"
exit 1
;;
esac

# create nsswitch.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a huge nitpick but there has to be a better way to do this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If "unhappy"; then
how about a case statement?
elif "unsatisfied"; then
how about a case statement?
else
you get a case statement
exit 0

cat << EOT >> /home/core/nsswitch.conf
passwd: files usrfiles ato
shadow: files usrfiles ato
group: files usrfiles ato

hosts: files usrfiles dns
networks: files usrfiles dns

services: files usrfiles
protocols: files usrfiles
rpc: files usrfiles

ethers: files
netmasks: files
netgroup: nisplus
bootparams: files
automount: files nisplus
aliases: files nisplus
EOT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much cleaner! :)


# create klam-ssh.conf
cat << EOT >> /home/core/klam-ssh.conf
{
key_location: ${KEY_LOCATION_PREFIX}${KEY_LOCATION},
role_name: ${ROLE_NAME},
encryption_id: ${ENCRYPTION_ID},
encryption_key: ${ENCRYPTION_KEY},
resource_location: amazon,
time_skew: permissive,
s3_region: ${REGION}
}
EOT

# Create directory structure
mkdir -p /opt/klam/lib /opt/klam/lib64 /etc/ld.so.conf.d

# Docker volume mount
docker create --name klam-ssh ${IMAGE}

# Copy libnss_ato library
docker cp klam-ssh:/tmp/klam-build/coreos/libnss_ato.so.2 /opt/klam/lib64

# Create symlink
ln -sf /opt/klam/lib64/libnss_ato.so.2 /opt/klam/lib64/libnss_ato.so

# Docker remove container
docker rm klam-ssh

# Move the ld.so.conf file to the correct location
echo "/opt/klam/lib64" > /etc/ld.so.conf.d/klam.conf
ldconfig
ldconfig -p | grep klam

# Validate that the files exist in the correct folder
ls -l /opt/klam/lib64/libnss_ato.so*

# Create the klamfed home directory
useradd -p "*" -U -G sudo -u 5000 -m klamfed -s /bin/bash
mkdir -p /home/klamfed
usermod -p "*" klamfed
usermod -U klamfed
update-ssh-keys -u klamfed

# Add klamfed to wheel
usermod -a -G wheel klamfed

# Add klamfed to sudo
usermod -a -G sudo klamfed

# Add passwordless sudo to klamfed
echo "klamfed ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/klamfed

# Validate that the klamfed user has the correct uid value (5000) and home directory
id klamfed
ls -ld /home/klamfed

# Re-link nsswitch.conf
mv -f /home/core/nsswitch.conf /etc/nsswitch.conf
cat /etc/nsswitch.conf

# generate the ATO config
grep klamfed /etc/passwd > /opt/klam/lib/klam-ato.conf

# Validate that the contents of /opt/klam/lib/klam-ato.conf
cat /opt/klam/lib/klam-ato.conf

# Move klam-ssh.conf
mv -f /home/core/klam-ssh.conf /opt/klam/lib/klam-ssh.conf
cat /opt/klam/lib/klam-ssh.conf

# update /etc/ssh/sshd_config
cp /etc/ssh/sshd_config sshd_config
echo 'AuthorizedKeysCommand /opt/klam/lib/authorizedkeys_command.sh' >> sshd_config
echo 'AuthorizedKeysCommandUser root' >> sshd_config
mv -f sshd_config /etc/ssh/sshd_config
cat /etc/ssh/sshd_config

# Change ownership of authorizedkeys_command
chown root:root /home/core/mesos-systemd/v3/util/authorizedkeys_command.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh...does this actually work? And why is this needed?


# Relocate authorizedkeys_command
mv /home/core/mesos-systemd/v3/util/authorizedkeys_command.sh /opt/klam/lib

# Change ownership of downloadS3
chown root:root /home/core/mesos-systemd/v3/util/downloadS3.sh

# Relocate downloadS3.sh
mv /home/core/mesos-systemd/v3/util/downloadS3.sh /opt/klam/lib

# Restart SSHD
systemctl restart sshd.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to conflict with the existing service which restarts sshd? Can we reduce how many times we are restarting it by making sure all the conf changes are made first, then restarting it once?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so? It shouldn't just because this will run serially. @eadasiak can you test and confirm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflict was probably the wrong word; I'm thinking more of the fact that ssh is being restarted twice. We already have to wait about five minutes before we can SSH in to an instance, this might make that longer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The restart is actually quite fast though. We see the daemon restart when fleet is restarted and it's near instantaneous to establish a new connection

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to find where the other sshd restart happens. This particular restart is really fast, but if the sequence of events is such that the setup scripts occur before the other service restart, I can strike this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with leaving this here; was just thinking about optimizing it, but if you say it's fast, LGTM


echo "KLAM SSH BOOTSTRAP COMPLETE"
12 changes: 12 additions & 0 deletions v3/util/authorizedkeys_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

ROLE_NAME="$(etcdctl get /klam-ssh/config/role-name)"
ENCRYPTION_ID="$(etcdctl get /klam-ssh/config/encryption-id)"
ENCRYPTION_KEY="$(etcdctl get /klam-ssh/config/encryption-key)"
KEY_LOCATION_PREFIX="$(etcdctl get /klam-ssh/config/key-location-prefix)"
IMAGE="$(etcdctl get /images/klam-ssh)"

echo "Running authorizedkeys_command for $1" | systemd-cat -p info -t klam-ssh

docker run --rm -e ROLE_NAME=${ROLE_NAME} -e ENCRYPTION_ID=${ENCRYPTION_ID} -e ENCRYPTION_KEY=${ENCRYPTION_KEY} -e KEY_LOCATION_PREFIX=${KEY_LOCATION_PREFIX} ${IMAGE} /usr/lib/klam/getKeys.py $1
exit 0
10 changes: 10 additions & 0 deletions v3/util/downloadS3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

ROLE_NAME="$(etcdctl get /klam-ssh/config/role-name)"
ENCRYPTION_ID="$(etcdctl get /klam-ssh/config/encryption-id)"
ENCRYPTION_KEY="$(etcdctl get /klam-ssh/config/encryption-key)"
KEY_LOCATION_PREFIX="$(etcdctl get /klam-ssh/config/key-location-prefix)"
IMAGE="$(etcdctl get /images/klam-ssh)"

docker run --rm -e ROLE_NAME=${ROLE_NAME} -e ENCRYPTION_ID=${ENCRYPTION_ID} -e ENCRYPTION_KEY=${ENCRYPTION_KEY} -e KEY_LOCATION_PREFIX=${KEY_LOCATION_PREFIX} ${IMAGE} /usr/lib/klam/downloadS3.py
exit 0