-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Card origin_devexp_286 - Added ssh key-based access to private git repository documentation #339
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,6 +115,7 @@ following format: | |
| "auth": "YWRfbGzhcGU6R2labnRib21ifTE=", <2> | ||
| "email": "[email protected]" <3> | ||
| } | ||
| } | ||
| ---- | ||
|
|
||
| <1> URL of the registry. | ||
|
|
@@ -164,3 +165,113 @@ $ osc create -f secret.json | |
| Once you have the `*Secret*` created, you can add a `PushSecretName` field into | ||
| `Output` section inside the `BuildConfig` and set it to the name of the | ||
| `*Secret*` that you created, in this case `*dockerhub*`. | ||
|
|
||
| [#using-private-repositories-for-builds] | ||
| == Using private repositories for builds | ||
|
|
||
| If you want to build your application from a private repository you must | ||
| supply valid credentials. Currently only SSH key based authentication is supported. | ||
| The keys used to access that repository live in `$HOME/.ssh/` directory. | ||
| They are usually named `id_dsa.pub`, `id_ecdsa.pub`, `id_ed25519.pub` or `id_rsa.pub`. | ||
| If you don't have any, you can generate them with the following command: | ||
|
|
||
| ==== | ||
|
|
||
| ---- | ||
| $ ssh-keygen -t rsa -C "[email protected]" | ||
| ---- | ||
| ==== | ||
|
|
||
| Once that's done you're going to get two files: one containing your public key (as | ||
| explained above) and one containing a corresponding private key (one of `id_dsa`, `id_ecdsa`, | ||
| `id_ed25519` or `id_rsa`). With both of these in place you should consult your | ||
| source control management (SCM) system's manual on how to upload the public key. | ||
| The private one will be used to access your private repository. | ||
|
|
||
| Kubernetes provides the | ||
| https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/design/secrets.md[Secret] | ||
| resource, which you can use to store your keys. You must create the `*Secret*` first | ||
| before builds can use your ssh key for accessing your private repository. | ||
| The `*data*` field for the `*Secret*` object must contain your private key | ||
| with the value set to the base64-encoded content of that file. For example: | ||
|
|
||
| ==== | ||
|
|
||
| ---- | ||
| $ base64 -w 0 $HOME/.ssh/id_rsa | ||
| 6yJodHRwc1ovL2zuZGV4LmRvY21lci5aby92MS8iOnsiYXV0aCI6ImJXWnZhblJwYXpwdVoybGxkR2d4TUE9PSIsImVtYWlsIj8ibWlAbWlmby5zayJ9fQ== | ||
| ---- | ||
| ==== | ||
|
|
||
| Copy the value returned from `base64` command and paste it into `ssh-privatekey` field | ||
| in `*_secret.json_*` file: | ||
|
|
||
| ==== | ||
|
|
||
| ---- | ||
| { | ||
| "apiVersion": "v1beta3", | ||
| "kind": "Secret", | ||
| "metadata": { | ||
| "name": "scmsecret" | ||
| }, | ||
| "data": { | ||
| "ssh-privatekey": "6yJodHRwc1ovL2zuZGV4LmRvY21lci5aby92MS8iOnsiYXV0aCI6ImJXWnZhblJwYXpwdVoybGxkR2d4TUE9PSIsImVtYWlsIj8ibWlAbWlmby5zayJ9fQ==" | ||
| } | ||
| } | ||
|
|
||
| ---- | ||
| ==== | ||
|
|
||
| You can then create the `*Secret*` from the *_secret.json_* file using the following command: | ||
|
|
||
| ==== | ||
|
|
||
| ---- | ||
| $ osc create -f secret.json | ||
| ---- | ||
| ==== | ||
|
|
||
| Once you have the `*Secret*` created, you can add a `SourceSecretName` field into | ||
| `Source` section inside the `BuildConfig` and set it to the name of the | ||
| `*Secret*` that you created, in this case `*scmsecret*`: | ||
|
|
||
| ==== | ||
|
|
||
| ---- | ||
| { | ||
| "apiVersion": "v1beta3", | ||
| "kind": "BuildConfig", | ||
| "metadata": { | ||
| "name": "sample-build", | ||
| }, | ||
| "parameters": { | ||
| "output": { | ||
| "to": { | ||
| "name": "sample-image" | ||
| } | ||
| }, | ||
| "source": { | ||
| "git": { | ||
| "uri": "[email protected]:user/app.git" | ||
| }, | ||
| "sourceSecretName": "scmsecret", | ||
| "type": "Git" | ||
| }, | ||
| "strategy": { | ||
| "stiStrategy": { | ||
| "from": { | ||
| "kind": "ImageStreamTag", | ||
| "name": "python-33-centos7:latest" | ||
| } | ||
| }, | ||
| "type": "STI" | ||
| } | ||
| } | ||
| ---- | ||
| ==== | ||
|
|
||
| [NOTE] | ||
| ==== | ||
| The URL of private repository is usually in the form `[email protected]:username/repository` | ||
| ==== | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably worth giving a full end to end example here... ie show examples/commands/json for how to convert a keyfile to base64, put the value into a Secret json definition, create the secret in openshift, reference the secret in a build.