gerrit installation automation add ssh keys

123 views
Skip to first unread message

Abhayadev S

unread,
Jan 15, 2021, 5:30:49 AM1/15/21
to Repo and Gerrit Discussion
Hi,

I am automating the installation steps of the gerrit and would want to the admin's ssh key automatically so that i could run more gerrit ssh commands later in my script.

Is there nay way to add an ssh key in to gerrit automatically using commands?

regards,
abhay

Matthias Sohn

unread,
Jan 15, 2021, 7:22:12 AM1/15/21
to Abhayadev S, Repo and Gerrit Discussion
you can add a ssh key for a Gerrit account using the set-account ssh command [1].
A similar command is available in the REST API [2].

Not sure if this answers your question.

-Matthias


Sven Selberg

unread,
Jan 15, 2021, 8:23:35 AM1/15/21
to Repo and Gerrit Discussion
On Friday, January 15, 2021 at 1:22:12 PM UTC+1 Matthias Sohn wrote:
On Fri, Jan 15, 2021 at 11:30 AM Abhayadev S <abhay...@gmail.com> wrote:
Hi,

I am automating the installation steps of the gerrit and would want to the admin's ssh key automatically so that i could run more gerrit ssh commands later in my script.

Is there nay way to add an ssh key in to gerrit automatically using commands?

you can add a ssh key for a Gerrit account using the set-account ssh command [1].

If the script is running on the Gerrit host, depending on which commands you are doing, you could be able to use the "user" "Gerrit Code Review" and Gerrit's host key.

    ssh -x -i $GERRIT_DIR/etc/ssh_host_rsa_key "Gerrit Code Review"@localhost -p 29418 $COMMAND

Abhayadev S

unread,
Jan 17, 2021, 7:57:26 AM1/17/21
to Repo and Gerrit Discussion
thank you all for the replies...

@sven i tried the command using the local host keys andit is asking for a passphrase !
i am not sure what is the passphrase gerrit had set for its keys !
is there any default passphrase?

Abhayadev S

unread,
Jan 17, 2021, 8:14:48 AM1/17/21
to Repo and Gerrit Discussion
oops i was using the wrong key !!!
ssh -x -i /home/gerrit/gerrit-site/etc/ssh_host_rsa_key.pub "Gerrit Code Review"@localhost -p 29418 gerrit ls-projects

and when i use the priv key it works !
ssh -x -i /home/gerrit/gerrit-site/etc/ssh_host_rsa_key "Gerrit Code Review"@localhost -p 29418 gerrit ls-projects

this listed all the projects... thanks for the support, appreciate it.

Abhayadev S

unread,
Jan 27, 2021, 8:47:03 AM1/27/21
to Repo and Gerrit Discussion
@sven
does this key has any acess limitation?
because when i used the command to create a group it returned "Unavailable" what does it mean !!!

+ gerrit_cmd ls-groups
+ ssh -i /home/gerrit/gerrit-site/etc/ssh_host_rsa_key -p 29418 'Gerrit Code Review@localhost' gerrit ls-groups
Administrators
Non-Interactive Users
test-admins
test-users
+ gerrit_cmd create-group test002
+ ssh -i /home/gerrit/gerrit-site/etc/ssh_host_rsa_key -p 29418 "Gerrit Code Review"@localhost gerrit create-group test002
unavailable
+ exit


in the server logs I see the reason as "Not Signed In" !!!

[2021-01-27T19:10:09.621+0530] [SSH gerrit create-group test002] ERROR com.google.gerrit.sshd.BaseCommand : Internal server error during gerrit create-group test002
com.google.gerrit.sshd.BaseCommand$Failure: unavailable
    at com.google.gerrit.sshd.commands.CreateGroupCommand.run(CreateGroupCommand.java:119)
    at com.google.gerrit.sshd.SshCommand.lambda$start$1(SshCommand.java:61)
    at com.google.gerrit.sshd.BaseCommand$TaskThunk.run(BaseCommand.java:473)
    at com.google.gerrit.server.logging.LoggingContextAwareRunnable.run(LoggingContextAwareRunnable.java:110)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at com.google.gerrit.server.git.WorkQueue$Task.run(WorkQueue.java:610)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) Not Signed In
  at com.google.gerrit.server.util.ThreadLocalRequestContext$1.provideCurrentUser(Unknown Source) (via modules: com.google.gerrit.server.config.GerritGlobalModule -> com.google.gerrit.server.util.ThreadLocalRequestContext$1)
  while locating com.google.gerrit.server.IdentifiedUser

1 error
    at com.google.inject.internal.InternalProvisionException.toProvisionException(InternalProvisionException.java:226)
    at com.google.inject.internal.InjectorImpl$1.get(InjectorImpl.java:1097)
    at com.google.gerrit.server.restapi.group.CreateGroup.apply(CreateGroup.java:168)
    at com.google.gerrit.sshd.commands.CreateGroupCommand.createGroup(CreateGroupCommand.java:135)
    at com.google.gerrit.sshd.commands.CreateGroupCommand.run(CreateGroupCommand.java:107)
    ... 11 more
Caused by: com.google.gerrit.exceptions.NotSignedInException: Not Signed In
    at com.google.gerrit.server.util.ThreadLocalRequestContext$1.provideCurrentUser(ThreadLocalRequestContext.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.google.inject.internal.ProviderMethod$ReflectionProviderMethod.doProvision(ProviderMethod.java:286)
    at com.google.inject.internal.ProviderMethod.doProvision(ProviderMethod.java:173)
    at com.google.inject.internal.InternalProviderInstanceBindingImpl$CyclicFactory.provision(InternalProviderInstanceBindingImpl.java:185)
    at com.google.inject.internal.InternalProviderInstanceBindingImpl$CyclicFactory.get(InternalProviderInstanceBindingImpl.java:162)
    at com.google.inject.internal.InjectorImpl$1.get(InjectorImpl.java:1094)
    ... 14 more

Sven Selberg

unread,
Jan 27, 2021, 9:00:13 AM1/27/21
to Repo and Gerrit Discussion
On Wednesday, January 27, 2021 at 2:47:03 PM UTC+1 abhay...@gmail.com wrote:
@sven
does this key has any acess limitation?

Yes. That's why I wrote "depending on which commands you are doing".
Don't know exactly what those limitations are, could be that it's restricted to read operations!

Abhayadev S

unread,
Jan 27, 2021, 1:19:46 PM1/27/21
to Repo and Gerrit Discussion
@sven, yes thats true thanks :)

I don't see any documentation about this user "Gerrit Code Review".. how did you know about this ;)?

Sven Selberg

unread,
Jan 28, 2021, 2:57:14 AM1/28/21
to Repo and Gerrit Discussion
On Wednesday, January 27, 2021 at 7:19:46 PM UTC+1 abhay...@gmail.com wrote:
@sven, yes thats true thanks :)

I don't see any documentation about this user "Gerrit Code Review".. how did you know about this ;)?
I don't know if there's a section about the special user anywhere in the documentation it's more mentioned in passing:

Message has been deleted

Abhayadev S

unread,
Jan 28, 2021, 12:32:41 PM1/28/21
to Repo and Gerrit Discussion
@sven thanks for sharing the links.
Reply all
Reply to author
Forward
0 new messages