carvel-dev / vendir

Easy way to vendor portions of git repos, github releases, helm charts, docker image contents, etc. declaratively
https://carvel.dev/vendir
Apache License 2.0
268 stars 46 forks source link

Vendir is failing to fetch content if private-key does not have newline at the end #350

Closed kumaritanushree closed 5 months ago

kumaritanushree commented 5 months ago

What steps did you take: Steps to reproduce the issue: -> Copy the content from file ~/.ssh/id_rsa (assuming this is the private key file on your system) -> encode the key by running cmd: pbpaste | base64 -> create vendir.yml

apiVersion: v1
kind: Secret
metadata:
  name: http-auth
data:
  ssh-privatekey:  <paste encoded value of private-key>
---
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: vendor
  contents:
  - path: dump
    git:
      url: git@github.com:carvel-dev/vendir.git
      ref: origin/develop
      secretRef:
        name: http-auth

-> run vendir sync and you will see the error:

Load key "/Users/ktanushree/code_work/test-repo/.vendir-tmp/incoming/git-auth/private-key": invalid format
  git@github.com: Permission denied (publickey).
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.

vendir: Error: Syncing directory 'vendor':
  Syncing directory 'dump' with git contents:
    Fetching git repository:
      Git [fetch origin main]: exit status 128 (stderr: Load key "/Users/ktanushree/code_work/test-repo/.vendir-tmp/incoming/git-auth/private-key": invalid format
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
)

Note: pbpaste does not add new line but if you will use cat instead of pbpaste you will see newline will get added to your private key. You can try same steps just encode your private key by running command: cat ~/.ssh/id_rsa | base64. This will work fine.

What happened: [A small description of the issue]

What did you expect: Vedir should work fine with/without newline in privatekey.

Anything else you would like to add: Git actually does not work if privatekey does not have newline at the end. So add newline when vendir is writing privateKey in file. Private key with multiple newline also accepted by git.

Environment:


Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible" 👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.