jenkins-x / jx

Jenkins X provides automated CI+CD for Kubernetes with Preview Environments on Pull Requests using Cloud Native pipelines from Tekton
https://jenkins-x.io/
Apache License 2.0
4.57k stars 787 forks source link

jx boot does not use owner consistently and breaks installation #7342

Closed mgoltzsche closed 3 years ago

mgoltzsche commented 4 years ago

Summary

When installing Jenkins X using jx boot and providing the own (GitHub) user as owner and a separate (GitHub) account for the pipeline bot as well as the bot account's token Jenkins X creates the environment repositories within the pipeline bot's account instead of the one that has been specified as owner but in the k8s Environment resources it maps to repositories owned by the specified owner. Therefore the Jenkins X installation is broken since it tries to create PRs in the repos listed in the k8s Environment resources that don't exist under that name. This is more a usability issue but jx should behave consistently and prevent the user from misconfiguring it.

Steps to reproduce the behavior

Run jx boot and specify your account as owner and a separate account as bot - using an access token created with the bot account.

Expected behavior

Jenkins X should create the environment repositories under the organization the user specified as owner. If it lacks permissions to do so it should tell the user or request the necessary information but not install it in an inconsistent way that does not work.

Actual behavior

It creates the environment repositories under the organization the provided pipeline bot's token has been created with but maps them to the user-specified owner within Environment resources resulting in a broken Jenkins X installation:

...
? Git Owner name for environment repositories mgoltzsche
...
? Comma-separated git provider usernames of approvers for development environment repository mgoltzsche
...
? Pipeline bot Git username max-pipeline-bot
? Pipeline bot Git email address <SEPARATE_BOT_EMAIL_ADDRESS>
? Pipeline bot Git token [? for help] *** <TOKEN_CREATED_WITH_BOT_ACCOUNT>

Afterwards e.g. the dev environment repo has been created under https://github.com/max-pipeline-bot/environment-tf-jx-vast-feline-dev while the corresponding Environment points to:

$ kubectl -n jx get environment dev -o jsonpath='{.spec.source.url}'
https://github.com/mgoltzsche/environment-tf-jx-vast-feline-dev.git

Jx version

The output of jx version is:

jx                 2.1.65
Kubernetes cluster v1.14.10-gke.36
kubectl            v1.13.2
helm client        2.12.2
git                2.17.1
Operating System   Ubuntu 18.04.4 LTS

Kubernetes cluster

CJXD 10 cluster on GKE created with terraform module 1.4.0

Operating system / Environment

Ubuntu 18.04

Workaround

Do not use your personal GitHub account as owner if you want to use a separate account for the bot (for a production cluster you shouldn't do that anyway). Add the bot account as well as the reviewer/approver account to the organization that should be the owner of your environment repositories.

ajeetraina commented 4 years ago

I faced similar issue(shown below). I was trying to setup Jenkins X for GKE while being on Mac. Was able to run terraform init && terraform apply. Then while running jx boot, it failed as shown below.

 jx version
Version        2.1.78+cjxd.11
Commit         e9838a161
Build date     2020-06-23T02:02:04Z
Go version     1.13.8
Git tree state clean

Below are the details:

Owner GIT User: ajeetraina
GitHub Bot: collabnix-bot
Github Bot Email: rainaXXXXXX1981@gmail.com
Collaborator: Collabnix
terraform version
Terraform v0.12.26
X_BOOT_START_STEP=verify-jenkins-x-environment JX_BOOT_END_STEP=verify-jenkins-x-environment jx boot --verbose
DEBUG: Overriding start-step with env var: 'verify-jenkins-x-environment'
DEBUG: Overriding end-step with env var: 'verify-jenkins-x-environment'
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git rev-parse --abbrev-ref HEAD
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git rev-parse --abbrev-ref HEAD
DEBUG: Current configuration dir: /Users/ajeetraina/.jx
DEBUG: VersionRepository: https://github.com/cloudbees/cloudbees-jenkins-x-versions.git git ref: v0.0.36
DEBUG: ? A local Jenkins X versions repository already exists, pulling the latest: Yes
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git fetch https://github.com/cloudbees/cloudbees-jenkins-x-versions.git --tags
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git fetch https://github.com/cloudbees/cloudbees-jenkins-x-versions.git v0.0.36
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git branch -r
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git checkout FETCH_HEAD
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git fetch --tags
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git describe v0.0.36 --abbrev=0 --contains
Attempting to resolve version for boot config https://github.com/collabnix-bot/environment-tf-jx-keen-alien-dev from https://github.com/cloudbees/cloudbees-jenkins-x-versions.git
WARNING: could not find a stable version from git of https://github.com/collabnix-bot/environment-tf-jx-keen-alien-dev from /Users/ajeetraina/.jx/jenkins-x-versions
For background see: https://jenkins-x.io/docs/concepts/version-stream/
Please lock this version down via the command: jx step create pr versions -k git -n https://github.com/collabnix-bot/environment-tf-jx-keen-alien-dev
WARNING: could not find a stable version for git repository: https://github.com/collabnix-bot/environment-tf-jx-keen-alien-dev in /Users/ajeetraina/.jx/jenkins-x-versions
WARNING: for background see: https://jenkins-x.io/docs/concepts/version-stream/
please lock this version down via the command: jx step create pr versions -k git -n github.com/collabnix-bot/environment-tf-jx-keen-alien-dev -v 1.2.3
no version for https://github.com/collabnix-bot/environment-tf-jx-keen-alien-dev found in version stream https://github.com/cloudbees/cloudbees-jenkins-x-versions.git, defaulting to master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git fetch --tags
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git tag --list master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git tag --list vmaster
DEBUG: finding tag for master: cannot resolve master to a single git object (searching for tag master and tag vmaster), found []
DEBUG: JX_LOG_LEVEL=error LC_ALL=C git merge-base --is-ancestor HEAD origin/master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git describe HEAD --abbrev=0 --contains
Local boot clone is out of date. It is based on HEAD, but the version stream is using origin/master. The clone will now be updated to origin/master.
Stashing any changes made in local boot clone.
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git stash push
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git reset --hard origin/master
DEBUG: JX_LOG_LEVEL=error LC_ALL=C git stash pop
Booting Jenkins X
DEBUG: Setting the dev namespace to: jx
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git rev-parse --abbrev-ref HEAD
DEBUG: Creating effective project configuration
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git fetch origin master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git checkout master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git branch --set-upstream-to origin/master master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git pull
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git fetch origin master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git checkout master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git branch --set-upstream-to origin/master master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git pull
DEBUG: creating effective project configuration
DEBUG: Setting build version
DEBUG: Creating Tekton CRDs
DEBUG: Tekton CRDs for collabnix-bot-environment-tf-jx-6gn6m-1 created
STEP: verify-jenkins-x-environment command: /bin/sh -c jx step verify env in dir: /Users/ajeetraina/gke/cloudbees-jenkins-x-boot-config with env: map[string]string{"APP_NAME":"environment-tf-jx-keen-alien-dev", "BRANCH_NAME":"master", "BUILD_NUMBER":"1", "CONFIG_BASE_REF":"master", "CONFIG_REPO_URL":"https://github.com/collabnix-bot/environment-tf-jx-keen-alien-dev", "DEPLOY_NAMESPACE":"jx", "DOCKER_REGISTRY":"", "GIT_AUTHOR_EMAIL":"rainaajeetsingh1981@gmail.com", "GIT_AUTHOR_NAME":"collabnix-bot", "GIT_COMMITTER_EMAIL":"rainaajeetsingh1981@gmail.com", "GIT_COMMITTER_NAME":"collabnix-bot", "JOB_NAME":"collabnix-bot/environment-tf-jx-keen-alien-dev/master", "JX_INTERPRET_PIPELINE":"true", "JX_LOG_LEVEL":"debug", "JX_NO_TILLER":"true", "PIPELINE_KIND":"release", "REPO_NAME":"environment-tf-jx-keen-alien-dev", "REPO_OWNER":"collabnix-bot", "VERSIONS_BASE_REF":"v0.0.36", "VERSIONS_REPO_URL":"https://github.com/cloudbees/cloudbees-jenkins-x-versions.git"}
Storing the requirements in team settings in the dev environment
DEBUG: Updating the TeamSettings with: &{AutoUpdate:{Enabled:false Schedule:} BootConfigURL:https://github.com/cloudbees/cloudbees-jenkins-x-boot-config.git BuildPacks:<nil> Cluster:{AzureConfig:0xc000b03e70 ChartRepository: GKEConfig:<nil> EnvironmentGitOwner:ajeetraina EnvironmentGitPublic:true GitPublic:false Provider:gke Namespace:jx ProjectID:famous-hull-276807 ClusterName:tf-jx-keen-alien VaultName: Region: Zone:us-central1-a GitName:github GitKind:github GitServer:https://github.com ExternalDNSSAName: Registry:docker.io VaultSAName: KanikoSAName: HelmMajorVersion: DevEnvApprovers:[ajeetraina] DockerRegistryOrg: StrictPermissions:false} Environments:[{Key:dev Owner: Repository:environment-tf-jx-keen-alien-dev GitServer: GitKind: Ingress:{ExternalDNS:false CloudDNSSecretName: Domain:104.155.161.48.nip.io IgnoreLoadBalancer:false Exposer: NamespaceSubDomain:-jx. TLS:{Enabled:false Email: Production:false SecretName:} DomainIssuerURL:} RemoteCluster:false PromotionStrategy: URLTemplate:} {Key:staging Owner: Repository:environment-tf-jx-keen-alien-staging GitServer: GitKind: Ingress:{ExternalDNS:false CloudDNSSecretName: Domain: IgnoreLoadBalancer:false Exposer: NamespaceSubDomain: TLS:{Enabled:false Email: Production:false SecretName:} DomainIssuerURL:} RemoteCluster:false PromotionStrategy: URLTemplate:} {Key:production Owner: Repository:environment-tf-jx-keen-alien-production GitServer: GitKind: Ingress:{ExternalDNS:false CloudDNSSecretName: Domain: IgnoreLoadBalancer:false Exposer: NamespaceSubDomain: TLS:{Enabled:false Email: Production:false SecretName:} DomainIssuerURL:} RemoteCluster:false PromotionStrategy: URLTemplate:}] GithubApp:<nil> GitOps:true Helmfile:false Kaniko:true Ingress:{ExternalDNS:false CloudDNSSecretName: Domain:104.155.161.48.nip.io IgnoreLoadBalancer:false Exposer: NamespaceSubDomain:-jx. TLS:{Enabled:false Email: Production:false SecretName:} DomainIssuerURL:} Repository:nexus SecretStorage:vault Storage:{Logs:{Enabled:true URL:gs://tf-jx-keen-alien-logs-19bf1c77-45f4-4833-ab68-f242b4b22} Reports:{Enabled:true URL:gs://tf-jx-keen-alien-reports-48597d50-3b8b-4287-96e4-e62f87} Repository:{Enabled:true URL:gs://tf-jx-keen-alien-repository-11718f97-7854-46e3-b182-458} Backup:{Enabled:false URL:}} Terraform:false Vault:{Name: Bucket: RecreateBucket:false Keyring: Key: DisableURLDiscovery:false AWSConfig:<nil> URL: ServiceAccount: Namespace: SecretEngineMountPoint: KubernetesAuthPath:} Velero:{Namespace: ServiceAccount: Schedule: TimeToLive:} VersionStream:{URL:https://github.com/cloudbees/cloudbees-jenkins-x-versions.git Ref:v0.0.36} Webhook:lighthouse}
Validating git repository for dev environment at URL https://github.com/ajeetraina/environment-tf-jx-keen-alien-dev.git
DEBUG: getting vault name for namespace jx
DEBUG: system vault name from config jx-vault-tf-jx-keen-al
DEBUG: Finding ingress url for jx-vault-tf-jx-keen-al in namespace jx
DEBUG: found service url http://vault-jx.104.155.161.48.nip.io
DEBUG: Connecting to vault on http://vault-jx.104.155.161.48.nip.io
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git config --get user.name
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git config --get user.email
DEBUG: Defined CONFIG_REPO_URL env variable value: https://github.com/collabnix-bot/environment-tf-jx-keen-alien-dev
DEBUG: Defined CONFIG_BASE_REF env variable value: master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git fetch --tags
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git tag --list master
DEBUG: LC_ALL=C JX_LOG_LEVEL=error git tag --list vmaster
DEBUG: finding tag for master: cannot resolve master to a single git object (searching for tag master and tag vmaster), found []
DEBUG: set commitish to 'origin/master'
DEBUG: getting repo ajeetraina/environment-tf-jx-keen-alien-dev
DEBUG: getting repository ajeetraina/environment-tf-jx-keen-alien-dev: failed to get repository ajeetraina/environment-tf-jx-keen-alien-dev due to: GET https://api.github.com/repos/ajeetraina/environment-tf-jx-keen-alien-dev: 404 Not Found []
DEBUG: repository owner for environment-tf-jx-keen-alien-dev is the authenticated user collabnix-bot, setting orgName to the empty string 'ajeetraina'
DEBUG: creating public repository environment-tf-jx-keen-alien-dev with orgName ''
error: handle dev environment repository: creating remote for dev environment environment-tf-jx-keen-alien-dev: duplicating https://github.com/collabnix-bot/environment-tf-jx-keen-alien-dev to ajeetraina/environment-tf-jx-keen-alien-dev: failed to create GitHub repo ajeetraina/environment-tf-jx-keen-alien-dev: failed to create public repository ajeetraina/environment-tf-jx-keen-alien-dev due to: POST https://api.github.com/user/repos: 422 Repository creation failed. [{Resource:Repository Field:name Code:custom Message:name already exists on this account}]
error: failed to interpret pipeline file jenkins-x.yml: failed to run '/bin/sh -c jx step verify env' command in directory '.', output: ''
[Captains-Bay]🚩 >
jenkins-x-bot commented 4 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with /close. Provide feedback via https://jenkins-x.io/community. /lifecycle stale

jenkins-x-bot commented 4 years ago

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity. If this issue is safe to close now please do so with /close. Provide feedback via https://jenkins-x.io/community. /lifecycle rotten

jenkins-x-bot commented 3 years ago

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten. Provide feedback via https://jenkins-x.io/community. /close

jenkins-x-bot commented 3 years ago

@jenkins-x-bot: Closing this issue.

In response to [this](https://github.com/jenkins-x/jx/issues/7342#issuecomment-734477244): >Rotten issues close after 30d of inactivity. >Reopen the issue with `/reopen`. >Mark the issue as fresh with `/remove-lifecycle rotten`. >Provide feedback via https://jenkins-x.io/community. >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [jenkins-x/lighthouse](https://github.com/jenkins-x/lighthouse/issues/new?title=Command%20issue:) repository.