Project

General

Profile

Actions

action #174592

closed

coordination #58184: [saga][epic][use case] full version control awareness within openQA

coordination #152847: [epic] version control awareness within openQA for test distributions

"fatal: could not read Username for 'https://github.com': Permission denied" for automatically git cloned os-autoinst-needles-openQA needles repo size:S

Added by okurz about 2 months ago. Updated 7 days ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Feature requests
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Observation

Trying to remove old unused needles from https://openqa.opensuse.org/admin/needles for I encountered the error "Unable to push Git commit (/var/lib/openqa/share/tests/openqa/needles): fatal: could not read Username for 'https://github.com': Permission denied". The needles repository was automatically cloned due to https://github.com/os-autoinst/os-autoinst-distri-openQA/blob/master/scenario-definitions.yaml#L10 . We should ensure that https://openqa.opensuse.org/admin/needles can be used to remove needles for this automatically cloned repo.

Acceptance criteria

  • AC1: os-autoinst-needles-openQA needles can be removed using https://openqa.opensuse.org/admin/needles
  • AC2: os-autoinst-needles-openQA is still automatically checked out if not existent on an openQA server and AC1 is still true
  • AC3: git commands will never attempt to prompt for http or ssh credentials

Suggestions

  • Can we just put an ssh remote into the scenario definitions?
    • We should probably document that one has to do this somewhere.
  • Simply use the git config to automatically push via ssh: git config --global url."git@github.com:".pushInsteadOf https://github.com/
  [url "git@github.com:"]
        pushInsteadOf = https://github.com/

Files


Related issues 1 (0 open1 closed)

Copied from openQA Project (public) - action #156922: Run os-autoinst-distri-openQA directly from git without anything related in o3:/var/lib/openqa/share/tests size:SResolveddheidler

Actions
Actions #1

Updated by okurz about 2 months ago

  • Copied from action #156922: Run os-autoinst-distri-openQA directly from git without anything related in o3:/var/lib/openqa/share/tests size:S added
Actions #2

Updated by mkittler 29 days ago

  • Subject changed from "fatal: could not read Username for 'https://github.com': Permission denied" for automatically git cloned os-autoinst-needles-openQA needles repo to "fatal: could not read Username for 'https://github.com': Permission denied" for automatically git cloned os-autoinst-needles-openQA needles repo size:S
  • Description updated (diff)
  • Status changed from New to Workable
Actions #3

Updated by tinita 21 days ago

  • Description updated (diff)
Actions #4

Updated by ybonatakis 17 days ago

  • Assignee set to ybonatakis
Actions #5

Updated by tinita 16 days ago

My suggestion would be to add an instruction like the following to the openQA docs:

To be able to push via ssh, but still clone with http, configure git for the user geekotest with a url rewrite like the following:

git config --global url."git@github.com:".pushInsteadOf https://github.com/

This should work for most people, and if it isn't, then we can always work on something better.

The next alternative would be to let the user configure a mapping for github, gitlab etc. in openqa.ini and then do a local git config ... call during the clone phase.

Actions #6

Updated by ybonatakis 14 days ago · Edited

  • Status changed from Workable to Feedback

Things we tried with @Titina to reproduce the problem

  • made sure that the openqa.ini has the following setups scm = git [scm git] update_remote = origin git_auto_clone = yes git_auto_update = yes Some intermmediate steps: delete the openqa/share/tests/opensuse/products/openqa, edit the scenario_definition.yml and use a fork repo for NEEDLE_DIR and then clone a openqa_to_openqa job git remote points to an https.

then we ensure that needles repo contains no changes (it fails for different error), before every test

Then find some needles in admin/needles and tried to delete.
The result was an active task on UI minions which I couldnt kill. The command from the logs was hanging

[info] Running cmd: git -C /home/iob/opt/openqadev/varlib/openqa/share/tests/openqa/needles push

As @tinita guess that was because it is waiting for authentication.
Verified running the command mannually the service run.

At the end I tried to apply the suggested workaround (git config --global url."git@github.com:".pushInsteadOf https://github.com/)
The result was again the same, waiting for a passphase.

We didnt manage to see any error (log level set to trace) about authentication, neither in the gru logs or the UI logs.

first I need instructions to reproduce the reported error.
I think it would be nice to improve the logging in stage as even trace does provide much help

Actions #7

Updated by tinita 14 days ago

At the end I tried to apply the suggested workaround (git config --global url."git@github.com:".pushInsteadOf https://github.com/)
The result was again the same, waiting for a passphase.

This would of course have to documented - the geekotest user would need a key without a passphrase.
That's already the case currently, when you clone over ssh explicitly.

Actions #8

Updated by tinita 14 days ago

first I need instructions to reproduce the reported error.

You could at least try the same thing on o3 to see what's happening there. If noone enabled the url rewrite there in the meantime, you will hopefully see the same as @okurz

Actions #9

Updated by tinita 14 days ago

It should be possible to prevent the password prompt for the ssh with the ssh_batchmode - have a look elsewhere in OpenQA::Git, where we already use this. Then it would fail immediately instead of prompting for password or passphrase.

For preventing the http credentials prompt, I just tried out the following:

% export GIT_TERMINAL_PROMPT=false
% export GIT_ASKPASS=
% git push origin testpush
fatal: could not read Username for 'https://github.com': terminal prompts disabled

So I suggest we set those variables in OpenQA::Git as well

Updated by livdywan 14 days ago

tinita wrote in #note-8:

first I need instructions to reproduce the reported error.

You could at least try the same thing on o3 to see what's happening there. If noone enabled the url rewrite there in the meantime, you will hopefully see the same as @okurz



I wasn't able to. Maybe a more specific case needs to be found to reproduce? Not sure how I would see from the needle editor if it should be affected?

Actions #11

Updated by okurz 14 days ago

  • Status changed from Feedback to Workable

The alp project is probably not using an automatically git cloned repo so that shouldn't reproduce the problem. Seems I was missing a word though in https://progress.opensuse.org/issues/174592#Observation where it says "Trying to remove old unused needles from https://openqa.opensuse.org/admin/needles for I encountered". Seems it's missing something after "for". Right now I can't find any needles from directory "openqa" listed on https://openqa.opensuse.org/admin/needles . That is what I suggest to do to be able to cover ACs

Updated by tinita 14 days ago · Edited

I attached screenshots that should make it clear how to reproduce the error on o3. (it's important to select a os-autoinst-needles-openQA needle as this is using a http checkout!)
The difference is really only that on o3 it doesn't prompt for credentials, while on @ybonatakis' machine it did.
That's interesting, and I don't know why, maybe there is some kind of difference in the git config on o3; however, we can apply the fix anyway. If we first apply my suggesstions from https://progress.opensuse.org/issues/174592#note-9 with setting the env vars, we should also be able to reproduce it on other hosts.

I can take over the ticket if it isn't clear.

Actions #13

Updated by okurz 14 days ago

  • Status changed from Workable to In Progress
Actions #14

Updated by ybonatakis 13 days ago

reproduced in O3 problem

ybonatakis@ariel:/var/lib/openqa/share/tests/openqa/needles> sudo -u geekotest git config --list
http.version=HTTP/1.1
http.postbuffer=524288000
push.default=matching
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/os-autoinst/os-autoinst-needles-openQA
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
ybonatakis@ariel:/var/lib/openqa/share/tests/openqa/needles> sudo -u geekotest git config --global --list
push.default=matching

and indeed using `git config url."git@github.com:".pushInsteadOf https://github.com/ looks like worked.

ybonatakis@ariel:/var/lib/openqa/share/tests/openqa/needles> sudo -u geekotest git -C /var/lib/openqa/share/tests/openqa/needles push
Username for 'https://github.com': ^C
ybonatakis@ariel:/var/lib/openqa/share/tests/openqa/needles> sudo -u geekotest git config --global url."git@github.com:".pushInsteadOf https://github.com/
error: could not lock config file /var/lib/openqa/.gitconfig: Permission denied
ybonatakis@ariel:/var/lib/openqa/share/tests/openqa/needles> sudo -u geekotest git config url."git@github.com:".pushInsteadOf https://github.com/
ybonatakis@ariel:/var/lib/openqa/share/tests/openqa/needles> sudo -u geekotest git -C /var/lib/openqa/share/tests/openqa/needles push
Everything up-to-date  ## that was because the needle was already pushed previous from the UI

the config is still in place in O3 and the deletion commit is https://github.com/os-autoinst/os-autoinst-needles-openQA/commit/285a320c734cbb41090e924c636796729eda38cc

Actions #15

Updated by ybonatakis 13 days ago

tinita wrote in #note-9:

It should be possible to prevent the password prompt for the ssh with the ssh_batchmode - have a look elsewhere in OpenQA::Git, where we already use this. Then it would fail immediately instead of prompting for password or passphrase.

For preventing the http credentials prompt, I just tried out the following:

% export GIT_TERMINAL_PROMPT=false
% export GIT_ASKPASS=
% git push origin testpush
fatal: could not read Username for 'https://github.com': terminal prompts disabled

So I suggest we set those variables in OpenQA::Git as well

According to my last comment I guess this is not needed.
Just thinking what I can provide or improve in the repo now

Actions #16

Updated by tinita 13 days ago · Edited

ybonatakis wrote in #note-15:

tinita wrote in #note-9:

So I suggest we set those variables in OpenQA::Git as well

According to my last comment I guess this is not needed.
Just thinking what I can provide or improve in the repo now

It is needed. You complained yesterday that the process was hanging. We want users to prevent from experiencing that, right?
So that if they don't have that git config, or if they don't have an ssh key (or one with a passphrase) that the process doesn't hang.

Please add those variables in OpenQA::Git, like I suggested, and also use ssh_batchmode for the git push, so we can guarantee git never asks for credentials.

edit: and I suggest to rename ssh_batchmode to just batchmode, since it will add variables for git http and ssh.

Actions #17

Updated by tinita 13 days ago

  • Description updated (diff)
Actions #18

Updated by openqa_review 13 days ago

  • Due date set to 2025-02-08

Setting due date based on mean cycle time of SUSE QE Tools

Actions #19

Updated by tinita 10 days ago

As requested, here is how I determined which env vars are needed to prevent git from prompting:

% git push origin testpush    # opens a gui prompt which I close
error: unable to read askpass response from '/usr/libexec/ssh/ssh-askpass'
Username for 'https://github.com': ^C

% GIT_ASKPASS= git push origin testpush     # opens a gui prompt which I close
Username for 'https://github.com': ^C

% GIT_TERMINAL_PROMPT=false git push origin testpush    # opens a gui prompt which I close
error: unable to read askpass response from '/usr/libexec/ssh/ssh-askpass'
fatal: could not read Username for 'https://github.com': terminal prompts disabled

% GIT_ASKPASS= GIT_TERMINAL_PROMPT=false git push origin testpush
fatal: could not read Username for 'https://github.com': terminal prompts disabled

So only the combination of the two variables does not prompt at all, which is what we want.

Actions #20

Updated by ybonatakis 10 days ago

tinita wrote in #note-19:

As requested, here is how I determined which env vars are needed to prevent git from prompting:

% git push origin testpush    # opens a gui prompt which I close
error: unable to read askpass response from '/usr/libexec/ssh/ssh-askpass'
Username for 'https://github.com': ^C

% GIT_ASKPASS= git push origin testpush     # opens a gui prompt which I close
Username for 'https://github.com': ^C

% GIT_TERMINAL_PROMPT=false git push origin testpush    # opens a gui prompt which I close
error: unable to read askpass response from '/usr/libexec/ssh/ssh-askpass'
fatal: could not read Username for 'https://github.com': terminal prompts disabled

% GIT_ASKPASS= GIT_TERMINAL_PROMPT=false git push origin testpush
fatal: could not read Username for 'https://github.com': terminal prompts disabled

So only the combination of the two variables does not prompt at all, which is what we want.

I asked for GIT_ASKPASS= because the documentation says that if it is empty is treated as not set at all, which falls back in the default behavior. for info.

So if I understand correctly we want just to avoid the "hidden" prompt, and in place just make it print a message. I still not sure if this is the best, so bear with me as i try to think of somethning else. if not...

Actions #21

Updated by tinita 10 days ago · Edited

ybonatakis wrote in #note-20:

tinita wrote in #note-19:

I asked for GIT_ASKPASS= because the documentation says that if it is empty is treated as not set at all, which falls back in the default behavior. for info.

https://git-scm.com/docs/gitcredentials/2.42.0

If the GIT_ASKPASS environment variable is set, the program specified by the variable is invoked. A suitable prompt is provided to the program on the command line, and the user’s input is read from its standard output.

You can just set it to echo if you like that better.

So if I understand correctly we want just to avoid the "hidden" prompt, and in place just make it print a message.

yes, we want to avoid that git prompts and waits for user input, which leaves the process hanging.

And I showed how to do that.

Actions #22

Updated by ybonatakis 10 days ago

tinita wrote in #note-21:

ybonatakis wrote in #note-20:

tinita wrote in #note-19:

I asked for GIT_ASKPASS= because the documentation says that if it is empty is treated as not set at all, which falls back in the default behavior. for info.

https://git-scm.com/docs/gitcredentials/2.42.0

If the GIT_ASKPASS environment variable is set, the program specified by the variable is invoked. A suitable prompt is provided to the program on the command line, and the user’s input is read from its standard output.

You can just set it to echo if you like that better.

So if I understand correctly we want just to avoid the "hidden" prompt, and in place just make it print a message.

yes, we want to avoid that git prompts and waits for user input, which leaves the process hanging.

And I showed how to do that.

Tina dont take it wrong but this had confused me. the ticket opened because there is a Username for 'https://github.com': Permission denied". From the descussion on slack is clear that there is no password prompt which makes the task to hang. there is your suggestion but seems to be something else.

give me some time to put some things together (if there is time until tomorrow) and lets have a chat. (keep in mind that I wont be available in the morning)

Actions #23

Updated by tinita 10 days ago

There are two tasks:

git prompts for password, process hanging

This only happens in some environments. Not in o3.
We observed this when trying out deleting needles in the openQA instance on your machine.
But it should be prevented by my suggestion above. It's nice that it doesn't happen in o3, but we can't rely this to be true on any openQA instance, right? openQA is a software that is not only used on o3 and osd.

Repos cloned via http should allow a push via ssh

This is the original problem why the ticket was created.

We normally, historically, clone needles via ssh to allow geekotest to automatically push (ssh key without passphrase).
For our new automatic git clone feature, using CASEDIR=https://... and NEEDLES_DIR=https://... in the scenario definitions, we want that people can specify http urls that are used to fetch. But they should be able to automatically push via ssh, even if the clone was done via http.
For that the pushInsteadOf is needed, which we should put into the openQA documentation: https://open.qa/docs/#_setting_up_git_support
People who setup an instance and want to use the git support are supposed to read that, so we can just add it there.

Actions #24

Updated by okurz 10 days ago

tinita wrote in #note-23:

For that the pushInsteadOf is needed, which we should put into the openQA documentation: https://open.qa/docs/#_setting_up_git_support
People who setup an instance and want to use the git support are supposed to read that, so we can just add it there.

Can we also point to that documentation within the error message?

Actions #25

Updated by tinita 10 days ago

okurz wrote in #note-24:

Can we also point to that documentation within the error message?

sure.

Actions #26

Updated by ybonatakis 10 days ago

I think I have something to propose but I need some time. give me some time and I will provide a draft later in the afternoon

Actions #27

Updated by ybonatakis 9 days ago

I fought all day with this. I was targeting to catch the prompt in the $stdout but I think is not possible(or so easy)
I come up with the minimum PoC proposal. Code/Commit is not ready for review. it is provided for some discussion

https://github.com/os-autoinst/openQA/pull/6140

Actions #28

Updated by tinita 9 days ago

An alternative for AC3: https://github.com/os-autoinst/openQA/pull/6141 Prevent git from prompting for credentials
tested successfully on my local instance

Actions #29

Updated by okurz 9 days ago

  • Assignee changed from ybonatakis to tinita
Actions #30

Updated by tinita 9 days ago

https://github.com/os-autoinst/openQA/pull/6142 Add docs about automatically using git ssh urls for pushing
todo: link to docs in error message

Actions #32

Updated by tinita 8 days ago · Edited

https://github.com/os-autoinst/openQA/pull/6144 Add link to docs if git push failed

Actions #33

Updated by tinita 8 days ago

And regarding the question about setting to the empty string via GIT_ASKPASS=: that still means that GIT_ASKPASS is set. It's just the empty string.
You can also unset such a variable again, with unset GIT_ASKPASS.

btw, something I learned along the way: how to tell the difference (unset vs. set and empty) with bash:
See also

Actions #34

Updated by tinita 8 days ago

  • Status changed from In Progress to Feedback

I added the following to ~geekotest/.gitconfig:

[url "git@github.com:"]
        # Enable automatic pushing via ssh for repos cloned with https
        pushInsteadOf = https://github.com/
Actions #35

Updated by tinita 7 days ago

  • Status changed from Feedback to Resolved
Actions #36

Updated by okurz 7 days ago

  • Due date deleted (2025-02-08)
Actions

Also available in: Atom PDF