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

[WIP] Add generic git task - with alternative auth #309

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions git-ssh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
git-clone ssh
====

Prepare secrets for ssh authentication.

### Prepare known_hosts file
Example using github.com as host

1. Create file with known_hosts (you may also want to verify this further)

ssh-keyscan github.com > ssh_known_hosts

2. Create secret from file

kubectl create secret generic github-known-hosts --from-file=ssh_known_hosts

### Generate and distribute SSH key pair
Generate a separate SSH key pair for Tekton

1. Generate keypair to local file

ssh-keygen -t rsa -b 4096 -f id_rsa -q -N ""

2. Create a secret from the private key

kubectl create secret generic github-private-key --from-file=id_rsa

3. Upload the public key id_rsa.pub to GitHub

Start with copying the content of the public key with

pbcopy < id_rsa.pub

And follow [Adding a new SSH key to your GitHub account](https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account)
~
28 changes: 28 additions & 0 deletions git-ssh/git-clone-ssh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: git-clone-ssh
spec:
workspaces:
- name: output
description: The git repo will be cloned onto the volume backing this workspace
params:
- name: url
type: string
description: git url to clone
steps:
- name: git-clone
image: bitnami/git:2.26.2
command: ['git', '-c', 'core.sshCommand=ssh -i /etc/ssh/id_rsa', 'clone', '$(params.url)', '$(workspaces.output.path)']
volumeMounts:
- mountPath: /etc/ssh
name: ssh-auth
volumes:
- name: ssh-auth
projected:
defaultMode: 0400
sources:
- secret:
name: github-known-hosts
- secret:
name: github-private-key
Copy link
Member Author

@jlpettersson jlpettersson May 10, 2020

Choose a reason for hiding this comment

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

both secret names should be params in a proper implementation.

  params:
  - name: known-hosts-secret
    type: string
    description: secret name of the SSH known_hosts file
  - name: private-key-secret
    type: string
    description: secret name of the SSH private key file

and in use

    projected:
      defaultMode: 0400
      sources:
      - secret:
          name: $(params.known-hosts-secret) 
      - secret:
          name: $(params.private-key-secret)

Copy link

Choose a reason for hiding this comment

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

Is this a limitation of Tekton at the moment - params can't be used as variables in volumes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is the Secret Name within a projected volume, were we don't have implemented variable substitution. But as the commit is implemented now, it is working. But for proper support, we should add variable substitution here, so that end-users can name the secrets how they want.