davido / gerrit-oauth-provider

OAuth2 authentication provider for Gerrit Code Review. Please upload changes for review to: https://gerrit-review.googlesource.com/#/admin/projects/plugins/oauth
Apache License 2.0
140 stars 84 forks source link

How to install this plugin in docker? #163

Closed pplmx closed 2 years ago

pplmx commented 2 years ago
  1. mapping /opt/gerrit/plugins:/var/gerrit/plugins
  2. copy oauth.jar to /opt/gerrit/plugins
  3. login to gerrit container at the directory /var/gerrit/bin/
  4. run java -jar gerrit.war init -d gerrit

It doesn't show the information you showed in the doc

Here is my operation log

bash-4.4$ java -jar gerrit.war init -d gerrit
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2022-02-23 09:59:08,960] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /var/gerrit/bin/gerrit/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 3.5.0.1
***

*** Git Repositories
***

Location of Git repositories   [git]:

*** JGit Configuration
***

Auto-configured "receive.autogc = false" to disable auto-gc after git-receive-pack.

*** Index
***

Type                           [lucene]:

*** User Authentication
***

Authentication method          [openid/?]: oauth
Git/HTTP authentication        [http/?]: oauth
*WARNING* Please make sure that your chosen OAuth provider
supports Git token authentication.
Enable signed push support     [y/N]?

*** Review Labels
***

Install Verified label         [y/N]?

*** Email Delivery
***

SMTP server hostname           [localhost]:
SMTP server port               [(default)]:
SMTP encryption                [none/?]:
SMTP username                  :

*** Container Process
***

Run as                         [gerrit]:
Java runtime                   [/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-3.el8_5.x86_64]:
Copy gerrit.war to gerrit/bin/gerrit.war [Y/n]?
Copying gerrit.war to gerrit/bin/gerrit.war

*** SSH Daemon
***

Listen on address              [*]:
Listen on port                 [29418]:
Generating SSH host key ... rsa... ed25519... ecdsa 256... ecdsa 384... ecdsa 521... done

*** HTTP Daemon
***

Behind reverse proxy           [y/N]?
Use SSL (https://)             [y/N]?
Listen on address              [*]:
Listen on port                 [8080]:
Canonical URL                  [http://72318470031d:8080/]:

*** Cache
***

*** Plugins
***

Installing plugins.
Install plugin codemirror-editor version v3.5.0.1 [y/N]? y
Installed codemirror-editor v3.5.0.1
Install plugin commit-message-length-validator version v3.5.0.1 [y/N]? y
Installed commit-message-length-validator v3.5.0.1
Install plugin delete-project version v3.5.0.1 [y/N]? y
Installed delete-project v3.5.0.1
Install plugin download-commands version v3.5.0.1 [y/N]? y
Installed download-commands v3.5.0.1
Install plugin gitiles version v3.5.0.1 [y/N]? y
Installed gitiles v3.5.0.1
Install plugin hooks version v3.5.0.1 [y/N]? y
Installed hooks v3.5.0.1
Install plugin plugin-manager version v3.5.0.1 [y/N]? y
Installed plugin-manager v3.5.0.1
Install plugin replication version v3.5.0.1 [y/N]? y
Installed replication v3.5.0.1
Install plugin reviewnotes version v3.5.0.1 [y/N]? y
Installed reviewnotes v3.5.0.1
Install plugin singleusergroup version v3.5.0.1 [y/N]? y
Installed singleusergroup v3.5.0.1
Install plugin webhooks version v3.5.0.1 [y/N]? y
Installed webhooks v3.5.0.1
Initializing plugins.

============================================================================
Welcome to the Gerrit community

Find more information on the homepage: https://www.gerritcodereview.com
Discuss Gerrit on the mailing list: https://groups.google.com/g/repo-discuss
============================================================================
Initialized /var/gerrit/bin/gerrit
Init complete, reindexing accounts with: reindex --site-path gerrit --threads 1 --index accountsReindexed 0 documents in accounts index in 0.0s (0.0/s)
Index accounts in version 11 is ready
Cache Statistics at the end of reindexing accounts
  Name                          |Entries              |  AvgGet |Hit Ratio|
                                |   Mem   Disk   Space|         |Mem  Disk|
--------------------------------+---------------------+---------+---------+
  groups_external               |                     |         |         |
  groups_bysubgroup             |                     |         |         |
  change_notes                  |                     |         |         |
  groups_byuuid                 |                     |         |         |
  default_preferences           |                     |         |         |
  prolog_rules                  |                     |         |         |
  groups                        |                     |         |         |
  projects                      |                     |         |         |
  groups_byname                 |                     |         |         |
  groups_external_persisted     |                     |         |         |
  groups_bymember               |                     |         |         |
  project_list                  |                     |         |         |
  permission_sort               |                     |         |         |
  external_ids_map              |                     |         |         |
D diff_summary                  |                0.00k|         |         |
D pure_revert                   |                0.00k|         |         |
D groups_byuuid_persisted       |                0.00k|         |         |
D change_kind                   |                0.00k|         |         |
D mergeability                  |                0.00k|         |         |
D conflicts                     |                0.00k|         |         |
D diff_intraline                |                0.00k|         |         |
D approvals                     |                0.00k|         |         |
D git_tags                      |                0.00k|         |         |
D gerrit_file_diff              |                0.00k|         |         |
D git_file_diff                 |                0.00k|         |         |
D accounts                      |                0.00k|         |         |
D persisted_projects            |                0.00k|         |         |
D git_modified_files            |                0.00k|         |         |
D modified_files                |                0.00k|         |         |

Collecting projects:    2 changes with: reindex --site-path gerrit --threads 1 --index changes
Reindexing changes: done
Reindexed 0 documents in changes index in 0.1s (0.0/s)
Index changes in version 71 is ready
Cache Statistics at the end of reindexing changes
  Name                          |Entries              |  AvgGet |Hit Ratio|
                                |   Mem   Disk   Space|         |Mem  Disk|
--------------------------------+---------------------+---------+---------+
  groups_external               |                     |         |         |
  groups_bysubgroup             |                     |         |         |
  change_notes                  |                     |         |         |
  groups_byuuid                 |                     |         |         |
  default_preferences           |                     |         |         |
  prolog_rules                  |                     |         |         |
  groups                        |                     |         |         |
  projects                      |                     |         |         |
  groups_byname                 |                     |         |         |
  groups_external_persisted     |                     |         |         |
  groups_bymember               |                     |         |         |
  project_list                  |     1               |  24.2ms | 50%     |
  permission_sort               |                     |         |         |
  external_ids_map              |                     |         |         |
D diff_summary                  |                0.00k|         |         |
D pure_revert                   |                0.00k|         |         |
D groups_byuuid_persisted       |                0.00k|         |         |
D change_kind                   |                0.00k|         |         |
D mergeability                  |                0.00k|         |         |
D conflicts                     |                0.00k|         |         |
D diff_intraline                |                0.00k|         |         |
D approvals                     |                0.00k|         |         |
D git_tags                      |                0.00k|         |         |
D gerrit_file_diff              |                0.00k|         |         |
D git_file_diff                 |                0.00k|         |         |
D accounts                      |                0.00k|         |         |
D persisted_projects            |                0.00k|         |         |
D git_modified_files            |                0.00k|         |         |
D modified_files                |                0.00k|         |         |

Reindexing groups:      100% (2/2)ith: reindex --site-path gerrit --threads 1 --index groups
Reindexed 2 documents in groups index in 0.6s (3.6/s)
Index groups in version 8 is ready
Cache Statistics at the end of reindexing groups
  Name                          |Entries              |  AvgGet |Hit Ratio|
                                |   Mem   Disk   Space|         |Mem  Disk|
--------------------------------+---------------------+---------+---------+
  groups_external               |                     |         |         |
  groups_bysubgroup             |                     |         |         |
  change_notes                  |                     |         |         |
  groups_byuuid                 |                     | 390.4ms |  0%     |
  default_preferences           |                     |         |         |
  prolog_rules                  |                     |         |         |
  groups                        |                     |         |         |
  projects                      |                     |         |         |
  groups_byname                 |                     |         |         |
  groups_external_persisted     |                     |         |         |
  groups_bymember               |                     |         |         |
  project_list                  |                     |         |         |
  permission_sort               |                     |         |         |
  external_ids_map              |                     |         |         |
D diff_summary                  |                0.00k|         |         |
D pure_revert                   |                0.00k|         |         |
D groups_byuuid_persisted       |                0.00k| 344.1ms |  0%     |
D change_kind                   |                0.00k|         |         |
D mergeability                  |                0.00k|         |         |
D conflicts                     |                0.00k|         |         |
D diff_intraline                |                0.00k|         |         |
D approvals                     |                0.00k|         |         |
D git_tags                      |                0.00k|         |         |
D gerrit_file_diff              |                0.00k|         |         |
D git_file_diff                 |                0.00k|         |         |
D accounts                      |                0.00k|         |         |
D persisted_projects            |                0.00k|         |         |
D git_modified_files            |                0.00k|         |         |
D modified_files                |                0.00k|         |         |

Reindexing projects:    100% (2/2) with: reindex --site-path gerrit --threads 1 --index projects
Reindexed 2 documents in projects index in 1.6s (1.2/s)
Index projects in version 4 is ready
Cache Statistics at the end of reindexing projects
  Name                          |Entries              |  AvgGet |Hit Ratio|
                                |   Mem   Disk   Space|         |Mem  Disk|
--------------------------------+---------------------+---------+---------+
  groups_external               |                     |         |         |
  groups_bysubgroup             |                     |         |         |
  change_notes                  |                     |         |         |
  groups_byuuid                 |                     |         |         |
  default_preferences           |                     |         |         |
  prolog_rules                  |                     |         |         |
  groups                        |                     |         |         |
  projects                      |     2               | 489.8ms | 33%     |
  groups_byname                 |                     |         |         |
  groups_external_persisted     |                     |         |         |
  groups_bymember               |                     |         |         |
  project_list                  |     1               |   4.5ms |  0%     |
  permission_sort               |                     |         |         |
  external_ids_map              |                     |         |         |
D diff_summary                  |                0.00k|         |         |
D pure_revert                   |                0.00k|         |         |
D groups_byuuid_persisted       |            2   0.90k|         |         |
D change_kind                   |                0.00k|         |         |
D mergeability                  |                0.00k|         |         |
D conflicts                     |                0.00k|         |         |
D diff_intraline                |                0.00k|         |         |
D approvals                     |                0.00k|         |         |
D git_tags                      |                0.00k|         |         |
D gerrit_file_diff              |                0.00k|         |         |
D git_file_diff                 |                0.00k|         |         |
D accounts                      |                0.00k|         |         |
D persisted_projects            |                0.00k| 233.3ms |  0%     |
D git_modified_files            |                0.00k|         |         |
D modified_files                |                0.00k|         |         |

bash-4.4$ java -jar gerrit.war ls
plugins/codemirror-editor.jar
plugins/commit-message-length-validator.jar
plugins/delete-project.jar
plugins/download-commands.jar
plugins/gitiles.jar
plugins/hooks.jar
plugins/plugin-manager.jar
plugins/replication.jar
plugins/reviewnotes.jar
plugins/singleusergroup.jar
plugins/webhooks.jar
extra/jetty7/gerrit-jetty.sh
extra/jetty7/gerrit.xml
extra/jetty7/jetty_sslproxy.xml
LICENSES.txt
pplmx commented 2 years ago

image

davido commented 2 years ago

copy oauth.jar to /opt/gerrit/plugins

Where is the oauth.jar is coming from? Is it corrupt? Where is the source? Show me the content?

Can you take Docker out of the picture and try it locally? Does it work?

Have you tried this jar: [1] or this jar: [2]?

[1] https://github.com/davido/gerrit-oauth-provider/releases/tag/v3.5.1 [2] https://gerrit-ci.gerritforge.com/view/Plugins-stable-3.5/job/plugin-oauth-bazel-master-stable-3.5/lastSuccessfulBuild/artifact/bazel-bin/plugins/oauth/oauth.jar

pplmx commented 2 years ago
  1. my oauth.jar is v3.5.1 (release), which is just be renamed
  2. I tried this Plugins-stable-3.5, which still doesn't be installed
  3. run it locally, it works fine
pplmx commented 2 years ago

Hi, @davido Thanks for your help :) I have found the root cause: GERRIT_SITE isn't be set rightly. Right way:

docker container exec -it gerrit-gerrit-1 bash
export GERRIT_SITE=/var/gerrit
java -jar /var/gerrit/bin/gerrit*.war init -d $GERRIT_SITE
davido commented 2 years ago

Thanks for confirming, that the root cause was not related to this plugin.