Skip to content

Use Git + SSH to do authentication - #2

Open
sourishkrout wants to merge 1 commit into
cambridge-healthcare:masterfrom
sourishkrout:master
Open

Use Git + SSH to do authentication#2
sourishkrout wants to merge 1 commit into
cambridge-healthcare:masterfrom
sourishkrout:master

Conversation

@sourishkrout

Copy link
Copy Markdown

Really love dockerize! Nice work. :-)

We're exclusively relying on SSH to authenticate (agent forwarding) with github to avoid having to keep credentials stored persistently on remote servers. I've added a bunch of code to check for ssh auth first before going down the road of using credentials.

I'm not very good at shell scripting so any pointers are appreciated. I'd love to see git/ssh support merged eventually though.

Please let me know.
Sebastian

@gerhard

gerhard commented Dec 22, 2013

Copy link
Copy Markdown
Contributor

Sebastian, this is a great PR and very relevant, thank you.

Dockerize was created to simplify the interaction between Jenkins and Docker, in a continuous delivery environment. There are a few blog posts which go into more depth, but this one explains the whole setup best. In my experience, using application tokens for Jenkins when integrating with github is a lot more straightforward than setting up the Jenkins user with an SSH key. Your use-case is a different one, but just as valid. I will definitely merge this in, let me just make a few code suggestions first.

Comment thread libexec/dockerize-github

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think that this message is useful for someone that just wants the end-result of this command. It's a detail which is relevant for the developer, sure, so a comment would be more appropriate IMO.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree. Couldn't manage to have ssh not print the message down below. That's why I had this message. Any idea how to get this to go to /dev/null?

Pseudo-terminal will not be allocated because stdin is not a terminal.
Hi sourishkrout! You've successfully authenticated, but GitHub does not provide shell access.
Skipping github credentials. Using ssh agent instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've only just noticed that you're checking for the exit code to be 1. The only successful error code is 0, so anything else points to an error. In this specific case, GitHub is saying that it doesn't allow shell access. Using 1 for the exit code is appropriate as given the ssh command, one would expect a TTY. I think this is more robust:

github_ssh_connection="$(ssh -Aq -o BatchMode=yes -o ConnectTimeout=1 git@github.com 2>&1)"

if [[ $github_ssh_connection =~ "successfully authenticated" ]]
then
  # ...
fi

The ssh command explained.

@sourishkrout

Copy link
Copy Markdown
Author

Thank you for your feedback!

I'll push a consolidated diff once I'll hear back from you on my questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants