Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jx import creates git repos as public, they should be private by default instead #5186

Closed
rawlingsj opened this issue Aug 23, 2019 · 13 comments · Fixed by #5284 or #5523
Closed

jx import creates git repos as public, they should be private by default instead #5186

rawlingsj opened this issue Aug 23, 2019 · 13 comments · Fixed by #5284 or #5523
Assignees
Labels
area/fox area/import kind/enhancement An enhancement of an existing feature priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now.
Milestone

Comments

@rawlingsj
Copy link
Member

rawlingsj commented Aug 23, 2019

Summary

We should assume repos should be private by default else code and secrets could be accidentally leaked.

Expected behaviour

When importing a project, create Git repo as PRIVATE
When creating a new cluster environment repos are PRIVATE

Actual behaviour

When importing a project, Git repo is PUBLIC and not unsecured.

@rawlingsj
Copy link
Member Author

/area import
/priority critical-urgent

@jenkins-x-bot jenkins-x-bot added area/import priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. labels Aug 23, 2019
@deanesmith deanesmith added the kind/enhancement An enhancement of an existing feature label Aug 23, 2019
@pmuir pmuir added the backlog label Aug 23, 2019
@hferentschik
Copy link

Are this not really two issues? One for jx import and the repo which is created there and one for j jx boot and the env repos created during this process?

@hferentschik
Copy link

That said, it seems creation of repositories goes via gits.PickNewGitRepository which takes a gits.GitRepositoryOptions which contains a flag to make the repo private. So maybe we can update all callers to this functions in one go?

@hferentschik hferentschik self-assigned this Aug 26, 2019
@hferentschik
Copy link

There is potential usability issue. The free option for Organizations on GitHub does not allow private repositories, so when trying to for example import an application one gets:

? Which organisation do you want to use? hf-bee
Using Git provider github at https://github.com
? Using organisation: hf-bee
? Enter the new repository name:  foo
Creating repository hf-bee/foo
error: Failed to create repository hf-bee/foo due to: POST https://api.github.com/orgs/hf-bee/repos: 422 Visibility can't be private. Please upgrade your subscription to create a new private repository. []

If private repositories are supposed to be the default, how do we want to handle this? I wonder whether the import should really ask about an organization anyways, but rather for an owner of the new repository which might be a user or organization.

@Larzack
Copy link

Larzack commented Aug 26, 2019

Is it possible to catch this response ( 422 Visibility can't be private ) and then set up the repo to public.

But for payed accounts, it should be private by default.

@hferentschik
Copy link

Is it possible to catch this response ( 422 Visibility can't be private ) and then set up the repo to public.

There might be a way to check, not sure, but I think if private is the new default, creating public repos should not happen automatically. In this case we need imo some explicit user confirmation.

hferentschik added a commit to hferentschik/jx that referenced this issue Aug 27, 2019
@pmuir pmuir added this to the Sprint 13 milestone Aug 27, 2019
@pmuir
Copy link
Contributor

pmuir commented Aug 27, 2019

jx boot and the env repos created during this process?
Also for jx install

There might be a way to check, not sure, but I think if private is the new default, creating public repos should not happen automatically. In this case we need imo some explicit user confirmation.

The idiomatic way in Go would be to check the error text.

I think a confirmation at this point would be reasonable.

@hferentschik
Copy link

The idiomatic way in Go would be to check the error text.

Not sure whether this would be idiomatic, but that's one option. The rub is that this error might differ by provider so it might be better to add some check/validation beforehand to check whether a user can create a given repository. So we could add something like AllowPrivateRepos to GitProvider.

The other issues is that once the error occurs, the directory is in a bad state. Some directories and commits got already created, so if when then tries to do something like jx import --git-private=false . the import will fail with an error that for example the charts directory already exists. So part of the error handling would be to reset the import directory into its initial state.

Overall we would:

  • switch logic and flags to create repositories private per default
  • handle errors when private repositories cannot be created, potentially even trying to figure out whether a user can create private repositories prior trying to create them
  • make sure state is properly reset when error occurs

@hferentschik
Copy link

I also suggest to change:

Which organisation do you want to use to something like Who should be the owner of the created repository. I believe the use of organization is misleading at this point. It does not really have to be an organization. I believe jx boot already made a similar change where it does not ask for a "organization", but rather "owner" of the env repositories. WDYT?

@hferentschik
Copy link

Actually, I'd also like to switch the field GitPrivate to GitPublic. Given the null value of a bool, one can never really tell whether a value of false for GitPrivate is really explicitly false or false as a default. In this case we should error to the safer side.

I know we don't have #5222 in place, but the longer we wait the harder it might get. With the boot approach the CRD should just be overwritten anyways on an upgrade. cc @daveconde

@pmuir
Copy link
Contributor

pmuir commented Aug 28, 2019

Not sure whether this would be idiomatic, but that's one option.

All I mean by that is it's the way I've seen e.g. the SDK handle this sort of thing.

But in this case it certainly seems like it won't be enough.

Which organisation do you want to use to something like Who should be the owner of the created repository.

Agreed.

Actually, I'd also like to switch the field GitPrivate to GitPublic. Given the null value of a bool, one can never really tell whether a value of false for GitPrivate is really explicitly false or false as a default. In this case we should error to the safer side.

One way around this is to write migration code for the GitPrivate field into the marshaller. You can use this to set the default of GitPublic to be the inverse of the current value of GitPrivate. I did something similar (handling the misnaming of the spec field) here

func (u *User) UnmarshalJSON(bs []byte) error {
- in your case it's way simpler as the value is plain bool.

@hferentschik
Copy link

One way around this is to write migration code for the GitPrivate field into the marshaller. You can use this to set the default of GitPublic to be the inverse of the current value of GitPrivate. I did something similar (handling the misnaming of the spec field) here

func (u *User) UnmarshalJSON(bs []byte) error {
- in your case it's way simpler as the value is plain bool.

Ohh, nice one. That would work.

hferentschik added a commit to hferentschik/jx that referenced this issue Aug 29, 2019
hferentschik added a commit to hferentschik/jx that referenced this issue Aug 29, 2019
hferentschik added a commit to hferentschik/jx that referenced this issue Aug 29, 2019
hferentschik added a commit to hferentschik/jx that referenced this issue Aug 30, 2019
hferentschik added a commit to hferentschik/jx that referenced this issue Sep 11, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
hferentschik added a commit to hferentschik/jx that referenced this issue Sep 11, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
hferentschik added a commit to hferentschik/jx that referenced this issue Sep 11, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
hferentschik added a commit to hferentschik/jx that referenced this issue Sep 12, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
hferentschik added a commit to hferentschik/jx that referenced this issue Sep 12, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
jenkins-x-bot pushed a commit that referenced this issue Sep 12, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes #5186
hferentschik added a commit to hferentschik/jenkins-x-versions that referenced this issue Sep 13, 2019
@hferentschik hferentschik reopened this Sep 17, 2019
@hferentschik
Copy link

hferentschik commented Sep 17, 2019

Re-opening this issue due to #5513 and #5507.

commit 026e029 reverted the originally merged commits for this issue

hferentschik added a commit to hferentschik/jx that referenced this issue Sep 17, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
hferentschik added a commit to hferentschik/jx that referenced this issue Sep 18, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
jenkins-x-bot pushed a commit that referenced this issue Sep 18, 2019
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes #5186
hferentschik added a commit to hferentschik/jenkins-x-versions that referenced this issue Sep 19, 2019
daveconde pushed a commit to daveconde/jx that referenced this issue Apr 7, 2020
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
daveconde pushed a commit to daveconde/jx that referenced this issue Apr 7, 2020
- this applies for all env respostories as well as repositories
  created as part of `jx import`

fixes jenkins-x#5186
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/fox area/import kind/enhancement An enhancement of an existing feature priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now.
Projects
None yet
7 participants