From 1d09fa090c04cc395594147b55c5b9c891534f57 Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Thu, 2 Sep 2021 12:19:28 -0500 Subject: [PATCH] Add auth to template for 22_test_configs.sh This adds the following vairables to be used with the 22_test_configs.sh script, so that it can generate configs which have access to private repos. * AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_TYPE * AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_KEY_PASSWORD * AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_KEY_PATH * AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_HTTP_PASSWORD * AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_SSH_PASSWORD * AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_USERNAME Relates-To: #627 Change-Id: I791e45eb6747e76f0e69a7cdcfde90db570fa1d1 --- pkg/config/repo.go | 9 ++++++--- tools/deployment/22_test_configs.sh | 1 + tools/deployment/templates/airshipconfig_template | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/config/repo.go b/pkg/config/repo.go index 7d8ee6505..44354713b 100644 --- a/pkg/config/repo.go +++ b/pkg/config/repo.go @@ -34,6 +34,7 @@ const ( SSHAuth = "ssh-key" SSHPass = "ssh-pass" HTTPBasic = "http-basic" + NoAuth = "none" ) // remoteName is a remote name that airshipctl work with during document pull @@ -57,7 +58,7 @@ type Repository struct { // RepoAuth struct describes method of authentication against given repository type RepoAuth struct { // Type of authentication method to be used with given repository - // supported types are "ssh-key", "ssh-pass", "http-basic" + // supported types are "ssh-key", "ssh-pass", "http-basic", "none" Type string `json:"type,omitempty"` //KeyPassword is a password decrypt ssh private key (used with ssh-key auth type) KeyPassword string `json:"keyPass,omitempty"` @@ -139,7 +140,7 @@ func (rf *RepoFetch) Validate() error { // RepoAuth methods var ( - AllowedAuthTypes = []string{SSHAuth, SSHPass, HTTPBasic} + AllowedAuthTypes = []string{SSHAuth, SSHPass, HTTPBasic, NoAuth} ) // String returns repository authentication details in string format @@ -172,6 +173,8 @@ func (auth *RepoAuth) Validate() error { if auth.KeyPath != "" || auth.KeyPassword != "" || auth.HTTPPassword != "" { return NewErrIncompatibleAuthOptions([]string{"ssh-key, key-pass, http-pass"}, auth.Type) } + case NoAuth: + return nil } return nil } @@ -224,7 +227,7 @@ func (repo *Repository) Validate() error { // ToAuth returns an implementation of transport.AuthMethod for // the given auth type to establish an ssh connection func (repo *Repository) ToAuth() (transport.AuthMethod, error) { - if repo.Auth == nil { + if repo.Auth == nil || repo.Auth.Type == NoAuth { return nil, nil } switch repo.Auth.Type { diff --git a/tools/deployment/22_test_configs.sh b/tools/deployment/22_test_configs.sh index 1acfd2045..47daca41b 100755 --- a/tools/deployment/22_test_configs.sh +++ b/tools/deployment/22_test_configs.sh @@ -39,6 +39,7 @@ export AIRSHIP_CONFIG_PHASE_REPO_BRANCH=${BRANCH:-"master"} export AIRSHIP_CONFIG_PHASE_REPO_URL=${AIRSHIP_CONFIG_PHASE_REPO_URL:-"https://review.opendev.org/airship/airshipctl"} export AIRSHIP_CONFIG_PHASE_REPO_NAME=${AIRSHIP_CONFIG_PHASE_REPO_NAME:-"airshipctl"} export AIRSHIP_CONFIG_MANIFEST_DIRECTORY=${AIRSHIP_CONFIG_MANIFEST_DIRECTORY:-"/tmp/airship"} +export AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_TYPE=${AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_TYPE:-"none"} export EXTERNAL_KUBECONFIG=${EXTERNAL_KUBECONFIG:-""} # Remove the contents of the .airship folder, preserving the kustomize plugin directory diff --git a/tools/deployment/templates/airshipconfig_template b/tools/deployment/templates/airshipconfig_template index 0a5c4311b..9b3d5e6f5 100644 --- a/tools/deployment/templates/airshipconfig_template +++ b/tools/deployment/templates/airshipconfig_template @@ -26,5 +26,12 @@ manifests: remoteRef: "" tag: "" url: ${AIRSHIP_CONFIG_PHASE_REPO_URL} + auth: + type: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_TYPE" + keyPass: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_KEY_PASSWORD" + sshKey: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_KEY_PATH" + httpPass: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_HTTP_PASSWORD" + sshPass: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_SSH_PASSWORD" + username: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_USERNAME" metadataPath: ${AIRSHIP_CONFIG_METADATA_PATH} targetPath: ${AIRSHIP_CONFIG_MANIFEST_DIRECTORY}