PaaS/CI CD

SSH key로 Github 인증 받기

armyost 2024. 12. 28. 19:40
728x90

 

 

우선 내 로컬 혹은 서버 (어디든 무관하다.) 에서 SSH 접속을 위한 RSA Key를 생성한다. 이때 필자는 key의 이름을 GH_RO_key_rsa 라고 하겠다.

imacs-imac:~ scott$ ssh-keygen -t rsa
 Generating public/private rsa key pair.
 Enter file in which to save the key (/~/~/.ssh/id_rsa): /~/~/.ssh/GH_RO_key_rsa
 Enter passphrase (empty for no passphrase): 
 Enter same passphrase again: 
 Your identification has been saved in /~/~/.ssh/GH_RO_key_rsa.
 Your public key has been saved in /~/~/.ssh/GH_RO_key_rsa.pub.
 The key fingerprint is:
 SHA256:0v0koHVNHdJ~~~~~~~~~~~~~~~~~~~~~~~~~~ scott@imacs-imac.lan
 The key's randomart image is:
 +---[RSA 2048]----+
 |         .===+o. |
 |           *o+o.o|
 |        o + E ooo|
 |       + + * ..o |
 |      o S + + + o|
 |       .   + + Bo|
 |          . o.=.=|
 |         . *oo.. |
 |        ..=...   |
 +----[SHA256]-----+
 imacs-imac:~ scott$

 

 

그리고 github.com을 known_hosts에 등록해준다.

# ssh-keyscan github.com > /tmp/known_hosts
# github.com:22 SSH-2.0-babeld-778045a0
# github.com:22 SSH-2.0-babeld-778045a0
# github.com:22 SSH-2.0-babeld-778045a0
# 
This copies the ssh key f

 

 

생성한 위 두 정보로 secret을 생성한다. 

# kubectl create secret generic github-creds --from-file=ssh=.ssh/GH_RO_key_rsa --from-file=known_hosts=/tmp/known_hosts
 secret/github-creds created

 

 

이 생성한 secret은 Gitssh 가 필요한 서비스들에서 volume으로 mount하여 사용하게 된다. 

예를들어 Gitsync과 같은 곳에서 말이다.

https://armyost.tistory.com/514

 

ArgoCD) Git-Sync를 통하여 주기적으로 git repo fetch 받아오게 하기

가끔식 kustomization이나 Submodule과 같은 경우 다른 Repository의 최신 버전을 참고해야 할 때가 있다.  이때는 ArgoCD 의 구성요소중 argocd-repo-server를 활용하여야 한다. 참고로 argocd-repo-server는 argocd에

armyost.tistory.com

 

이제 Github에 등록할 차례이다. 

 

생성한 public key의 값을 확인하고 복사해둔다. 나중에 Github에 등록할 정보이다.

 

# cat ~/.ssh/GH_RO_key_rsa.pub

 

특정 계정에 적용해도 되며, 혹은 특정 Repo에 적용해도 된다. 

 

Github repo에서 Settings의 Deploy keys에서 방금 복사한 값으로 등록하자.