forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: GitHub organization app for git cloning (argoproj#4348) (argopr…
…oj#5355) * Git GitHub App auth Signed-off-by: Slava Markeyev <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,902 additions
and
587 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -46,10 +46,10 @@ func NewRepoAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { | |
|
||
// For better readability and easier formatting | ||
var repoAddExamples = ` # Add a Git repository via SSH using a private key for authentication, ignoring the server's host key: | ||
argocd repo add [email protected]:repos/repo --insecure-ignore-host-key --ssh-private-key-path ~/id_rsa | ||
argocd repo add [email protected]:repos/repo --insecure-ignore-host-key --ssh-private-key-path ~/id_rsa | ||
# Add a Git repository via SSH on a non-default port - need to use ssh:// style URLs here | ||
argocd repo add ssh://[email protected]:2222/repos/repo --ssh-private-key-path ~/id_rsa | ||
# Add a Git repository via SSH on a non-default port - need to use ssh:// style URLs here | ||
argocd repo add ssh://[email protected]:2222/repos/repo --ssh-private-key-path ~/id_rsa | ||
# Add a private Git repository via HTTPS using username/password and TLS client certificates: | ||
argocd repo add https://git.example.com/repos/repo --username git --password secret --tls-client-cert-path ~/mycert.crt --tls-client-cert-key-path ~/mycert.key | ||
|
@@ -65,6 +65,12 @@ func NewRepoAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { | |
# Add a private Helm OCI-based repository named 'stable' via HTTPS | ||
argocd repo add helm-oci-registry.cn-zhangjiakou.cr.aliyuncs.com --type helm --name stable --enable-oci --username test --password test | ||
# Add a private Git repository on GitHub.com via GitHub App | ||
argocd repo add https://git.example.com/repos/repo --github-app-id 1 --github-app-installation-id 2 --github-app-private-key-path test.private-key.pem | ||
# Add a private Git repository on GitHub Enterprise via GitHub App | ||
argocd repo add https://ghe.example.com/repos/repo --github-app-id 1 --github-app-installation-id 2 --github-app-private-key-path test.private-key.pem --github-app-enterprise-base-url https://ghe.example.com/api/v3 | ||
` | ||
|
||
var command = &cobra.Command{ | ||
|
@@ -116,13 +122,28 @@ func NewRepoAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { | |
} | ||
} | ||
|
||
// Specifying github-app-private-key-path is only valid for HTTPS repositories | ||
if repoOpts.GithubAppPrivateKeyPath != "" { | ||
if git.IsHTTPSURL(repoOpts.Repo.Repo) { | ||
githubAppPrivateKey, err := ioutil.ReadFile(repoOpts.GithubAppPrivateKeyPath) | ||
errors.CheckError(err) | ||
repoOpts.Repo.GithubAppPrivateKey = string(githubAppPrivateKey) | ||
} else { | ||
err := fmt.Errorf("--github-app-private-key-path is only supported for HTTPS repositories") | ||
errors.CheckError(err) | ||
} | ||
} | ||
|
||
// Set repository connection properties only when creating repository, not | ||
// when creating repository credentials. | ||
// InsecureIgnoreHostKey is deprecated and only here for backwards compat | ||
repoOpts.Repo.InsecureIgnoreHostKey = repoOpts.InsecureIgnoreHostKey | ||
repoOpts.Repo.Insecure = repoOpts.InsecureSkipServerVerification | ||
repoOpts.Repo.EnableLFS = repoOpts.EnableLfs | ||
repoOpts.Repo.EnableOCI = repoOpts.EnableOci | ||
repoOpts.Repo.GithubAppId = repoOpts.GithubAppId | ||
repoOpts.Repo.GithubAppInstallationId = repoOpts.GithubAppInstallationId | ||
repoOpts.Repo.GitHubAppEnterpriseBaseURL = repoOpts.GitHubAppEnterpriseBaseURL | ||
|
||
if repoOpts.Repo.Type == "helm" && repoOpts.Repo.Name == "" { | ||
errors.CheckError(fmt.Errorf("Must specify --name for repos of type 'helm'")) | ||
|
@@ -145,16 +166,20 @@ func NewRepoAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { | |
// are high that we do not have the given URL pointing to a valid Git | ||
// repo anyway. | ||
repoAccessReq := repositorypkg.RepoAccessQuery{ | ||
Repo: repoOpts.Repo.Repo, | ||
Type: repoOpts.Repo.Type, | ||
Name: repoOpts.Repo.Name, | ||
Username: repoOpts.Repo.Username, | ||
Password: repoOpts.Repo.Password, | ||
SshPrivateKey: repoOpts.Repo.SSHPrivateKey, | ||
TlsClientCertData: repoOpts.Repo.TLSClientCertData, | ||
TlsClientCertKey: repoOpts.Repo.TLSClientCertKey, | ||
Insecure: repoOpts.Repo.IsInsecure(), | ||
EnableOci: repoOpts.Repo.EnableOCI, | ||
Repo: repoOpts.Repo.Repo, | ||
Type: repoOpts.Repo.Type, | ||
Name: repoOpts.Repo.Name, | ||
Username: repoOpts.Repo.Username, | ||
Password: repoOpts.Repo.Password, | ||
SshPrivateKey: repoOpts.Repo.SSHPrivateKey, | ||
TlsClientCertData: repoOpts.Repo.TLSClientCertData, | ||
TlsClientCertKey: repoOpts.Repo.TLSClientCertKey, | ||
Insecure: repoOpts.Repo.IsInsecure(), | ||
EnableOci: repoOpts.Repo.EnableOCI, | ||
GithubAppPrivateKey: repoOpts.Repo.GithubAppPrivateKey, | ||
GithubAppID: repoOpts.Repo.GithubAppId, | ||
GithubAppInstallationID: repoOpts.Repo.GithubAppInstallationId, | ||
GithubAppEnterpriseBaseUrl: repoOpts.Repo.GitHubAppEnterpriseBaseURL, | ||
} | ||
_, err := repoIf.ValidateAccess(context.Background(), &repoAccessReq) | ||
errors.CheckError(err) | ||
|
This file contains 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 |
---|---|---|
|
@@ -39,11 +39,12 @@ func NewRepoCredsCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command | |
// NewRepoCredsAddCommand returns a new instance of an `argocd repocreds add` command | ||
func NewRepoCredsAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { | ||
var ( | ||
repo appsv1.RepoCreds | ||
upsert bool | ||
sshPrivateKeyPath string | ||
tlsClientCertPath string | ||
tlsClientCertKeyPath string | ||
repo appsv1.RepoCreds | ||
upsert bool | ||
sshPrivateKeyPath string | ||
tlsClientCertPath string | ||
tlsClientCertKeyPath string | ||
githubAppPrivateKeyPath string | ||
) | ||
|
||
// For better readability and easier formatting | ||
|
@@ -52,6 +53,12 @@ func NewRepoCredsAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comma | |
# Add credentials with SSH private key authentication to use for all repositories under ssh://[email protected]/repos | ||
argocd repocreds add ssh://[email protected]/repos/ --ssh-private-key-path ~/.ssh/id_rsa | ||
# Add credentials with GitHub App authentication to use for all repositories under https://github.com/repos | ||
argocd repocreds add https://github.com/repos/ --github-app-id 1 --github-app-installation-id 2 --github-app-private-key-path test.private-key.pem | ||
# Add credentials with GitHub App authentication to use for all repositories under https://ghe.example.com/repos | ||
argocd repocreds add https://ghe.example.com/repos/ --github-app-id 1 --github-app-installation-id 2 --github-app-private-key-path test.private-key.pem --github-app-enterprise-base-url https://ghe.example.com/api/v3 | ||
` | ||
|
||
var command = &cobra.Command{ | ||
|
@@ -103,6 +110,18 @@ func NewRepoCredsAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comma | |
} | ||
} | ||
|
||
// Specifying github-app-private-key-path is only valid for HTTPS repositories | ||
if githubAppPrivateKeyPath != "" { | ||
if git.IsHTTPSURL(repo.URL) { | ||
githubAppPrivateKey, err := ioutil.ReadFile(githubAppPrivateKeyPath) | ||
errors.CheckError(err) | ||
repo.GithubAppPrivateKey = string(githubAppPrivateKey) | ||
} else { | ||
err := fmt.Errorf("--github-app-private-key-path is only supported for HTTPS repositories") | ||
errors.CheckError(err) | ||
} | ||
} | ||
|
||
conn, repoIf := argocdclient.NewClientOrDie(clientOpts).NewRepoCredsClientOrDie() | ||
defer io.Close(conn) | ||
|
||
|
@@ -127,6 +146,10 @@ func NewRepoCredsAddCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comma | |
command.Flags().StringVar(&sshPrivateKeyPath, "ssh-private-key-path", "", "path to the private ssh key (e.g. ~/.ssh/id_rsa)") | ||
command.Flags().StringVar(&tlsClientCertPath, "tls-client-cert-path", "", "path to the TLS client cert (must be PEM format)") | ||
command.Flags().StringVar(&tlsClientCertKeyPath, "tls-client-cert-key-path", "", "path to the TLS client cert's key path (must be PEM format)") | ||
command.Flags().Int64Var(&repo.GithubAppId, "github-app-id", 0, "id of the GitHub Application") | ||
command.Flags().Int64Var(&repo.GithubAppInstallationId, "github-app-installation-id", 0, "installation id of the GitHub Application") | ||
command.Flags().StringVar(&githubAppPrivateKeyPath, "github-app-private-key-path", "", "private key of the GitHub Application") | ||
command.Flags().StringVar(&repo.GitHubAppEnterpriseBaseURL, "github-app-enterprise-base-url", "", "base url to use when using GitHub Enterprise (e.g. https://ghe.example.com/api/v3") | ||
command.Flags().BoolVar(&upsert, "upsert", false, "Override an existing repository with the same name even if the spec differs") | ||
return command | ||
} | ||
|
This file contains 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
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Oops, something went wrong.