1047 Commits

Author SHA1 Message Date
Shawn Pearce
ee59afd5ab Rename CapabilityControl to AccountLimits
The class no longer controls capabilities. It now only provides
limits over server resources consumed during a request.

Change-Id: I70408bd5dda68b05502c4ece989b60f55793a8dd
2017-06-29 12:23:42 +00:00
Edwin Kempin
e7e9fbbf23 Migrate accounts to NoteDb (part 2)
This is the second part of migrating accounts from ReviewDb to NoteDb.

This change:
* migrates the accounts from ReviewDb to NoteDb (for single instance
  Gerrit servers)
* adds a configuration parameter (user.readAccountsFromGit) that
  controls whether external IDs are read from ReviewDb or NoteDb

AccountIT is now loading external IDs of an account directly from NoteDb
instead of retrieving them via the account cache. This is because for
the test deleteUserBranchWithAccessDatabaseCapability() the admin
account gets deleted by deleting its user branch and then the @After
restoreExternalIds() method couldn't delete the external IDs of that
account anymore (because the account was deleted it couldn't be
retrieved via the account cache anymore).

Change-Id: I41fa3a6bdb76f497c79a05bdc76e97a7e73624a6
Signed-off-by: Edwin Kempin <ekempin@google.com>
2017-06-27 15:56:38 +02:00
Edwin Kempin
a80101b895 Migrate accounts to NoteDb (part 1)
Always write account updates to both backends, ReviewDb and NoteDb.

In NoteDb accounts are represented as user branches in the All-Users
repository. Optionally a user branch can contain a 'account.config' file
that stores account properties, such as full name, preferred email,
status and the active flag. The timestamp of the first commit on a user
branch denotes the registration date. The initial commit on the user
branch may be empty (since having an 'account.config' is optional).

The 'account.config' file is a git config file that has one 'account'
section with the properties of the account:

  [account]
    active = false
    fullName = John Doe
    preferredEmail = john.doe@foo.com
    status = Overloaded with reviews

All keys are optional. This means 'account.config' may not exist on the
user branch if no properties are set.

If no value for 'active' is specified, by default the account is
considered as active.

AccountsUpdate is now sending RefUpdatedEvent's when an account is
updated. ReindexAfterRefUpdate receives the events and takes care to
evict the updated accounts from the account cache, which in turn
triggers reindex of the accounts. This is why AccountsUpdate no longer
needs to evict the updated accounts itself from the account cache. Since
AccountsUpdate doesn't reindex accounts on its own anymore the
ServerNoReindex factory can be removed.

To support a live migration on a multi-master Gerrit installation, the
migration of accounts from ReviewDb to NoteDb is done in 3 steps:
- part 1 (this change):
  * always write to both backends (ReviewDb and NoteDb)
  * always read accounts from ReviewDb
  * upgraded instances write to both backends, old instances only
    write to ReviewDb
  * after upgrading all instances (all still read from ReviewDb)
    run a batch to copy all accounts from the ReviewDb to NoteDb
- part 2 (next change):
  * bump the database schema version
  * migrate the accounts from ReviewDb to NoteDb (for single instance
    Gerrit servers)
  * config option to control whether accounts are read from ReviewDb or
    NoteDb
- part 3:
  * remove config option to control whether accounts are read from
    ReviewDb or NoteDb and always read from NoteDb
  * delete the database table

Change-Id: I2e0b13feb3465e086b49b2de2439a56696b5fba9
Signed-off-by: Edwin Kempin <ekempin@google.com>
2017-06-27 15:56:32 +02:00
David Pursehouse
f80e91155b Merge "Remove CapabilityControl from CurrentUser" 2017-06-21 23:41:43 +00:00
Dave Borowitz
36b9d3e991 NotesBranchUtil: Don't retry automatically
The retry mechanism in NotesBranchUtil is inflexible, and only retries a
fixed number of times on lock failure, with a fixed wait in between, up
to 250ms total. Now that we have RetryHelper available globally, make
use of that instead. This allows us to eliminate a lot of code from
NotesBranchUtil, which is a good thing, since this extra code also has
some bugs. For example, it doesn't handle all possible
RefUpdate.Results.

This is a philosophical difference in how to approach retries, which
requires fixing downstream code, including in the reviewnotes plugin.
RetryHelper is designed to be run at the highest level, completely
reopening the repository, to ensure we get the latest ref state and
start with a fresh inserter.

Since we now expect downstream plugins to use RetryHelper, export
guava-retrying from the plugin API.

Change-Id: I8a93e20f811a7c67c5cfd9cdf630afac7327c64f
2017-06-21 09:07:29 -04:00
Shawn Pearce
6302ccb2bb Remove CapabilityControl from CurrentUser
Drop the capabilities reference from all user objects.  Most global
capabilities can be checked with the PermissionBackend.

QoS, query limits, and emailing reviewers still require the capability
object.  Bundle its factory into the call sites that need it.

Continue caching the CapabilityControl in an opaque property on the
CurrentUser, and also in the DefaultPermissionBackend.WithUserImpl.
Both of these sites reduce evaluations for critical properties like
"administrateServer".

Change-Id: I5aae8200e0a579ac1295a3fb7005703fd39d2696
2017-06-21 19:51:20 +09:00
Han-Wen Nienhuys
4daf68c8b8 Add threadPriority argument to createQueue.
This stops ScheduledThreadPoolExecutor API usage from leaking beyond WorkQueue.

Change-Id: I9c7b141272a6d547c4f2c39c28a5ea60ada944d7
2017-06-19 18:49:57 +02:00
Han-Wen Nienhuys
40270c4bef Avoid referencing gerrit specific Executor.
WorkQueue.Executor is a thin layer on top of
ScheduledThreadPoolExecutor. Since it is a class, rather than an
implementation, it is impossible to inject a wrapper around an
existing implementation.

This change is one step towards enabling this.

Change-Id: Id6b1d0fd10b5f8549cbc76a4867b3afb750aca02
2017-06-14 14:24:21 +02:00
Shawn Pearce
ab841f6946 Convert VisibleRefFilter to assisted factory
Callers have to pass a number of arguments to build and configure the
VisibleRefFilter.  Instead of forcing callers to pass around many
arguments, use an assisted injection factory to create the instance.

Rely on the context Provider<ReviewDb> and Provider<CurrentUser> to
gain database access and user identity within the filter. Given all
current call sites, these should already be populated.

Change-Id: I8197ee773c94f16472d53162fb70791c45899c1b
2017-06-14 09:51:27 +00:00
Edwin Kempin
fd8fa32db1 Remove more finals from method signatures
Change-Id: I5849ebf378469dcfd5b89bed88c6f7dedf67f7ba
Signed-off-by: Edwin Kempin <ekempin@google.com>
2017-06-14 09:39:19 +02:00
Han-Wen Nienhuys
b0fb0a7a96 Remove 'final' from method signatures across gerrit.
Change-Id: I986a5507aa26ceb28305a7b08991e85238bde0e3
2017-06-14 09:18:42 +02:00
David Pursehouse
a20767c849 Merge branch 'stable-2.14'
* stable-2.14:
  Add support for 384 and 521 bit ECSDA keys

Change-Id: I27e81740f219cc70e3ff1112c82c8105daf91505
2017-05-31 11:03:47 +09:00
Paladox none
56517ff895 Add support for 384 and 521 bit ECSDA keys
Previously only the 256 bit key was generated.

Change-Id: I37b97088537e1508076264c6eeacd0487b15ae3d
2017-05-31 10:32:42 +09:00
ekempin
ebd874618f Merge changes from topic 'migrate-external-ids-3'
* changes:
  Allow to update external IDs by push
  Migrate external IDs to NoteDb (part 3)
2017-05-11 13:51:21 +00:00
David Pursehouse
c3c8c884e8 Merge branch 'stable-2.14'
* stable-2.14:
  SshDaemon: Set NIO2_READ_TIMEOUT to sshd.idleTimeout

Change-Id: If04a5494bcd9a5a6149387156438534cf79adf0b
2017-05-11 16:08:14 +09:00
David Pursehouse
471fe93e30 SshDaemon: Set NIO2_READ_TIMEOUT to sshd.idleTimeout
As described in SSHD-715 [1] the NIO2_READ_TIMEOUT parameter was
introduced in sshd version 1.3.

[1] https://issues.apache.org/jira/browse/SSHD-715

Bug: Issue 6173
Change-Id: I6f930cafef9583a83aed2e6d05ff2a9f27c33cb8
2017-05-11 05:44:45 +00:00
Edwin Kempin
276b8a897f Migrate external IDs to NoteDb (part 3)
This is the third part of migrating external IDs from ReviewDb to
NoteDb.

This change:
* changes the code to always read external IDs from NoteDb (the
  user.readExternalIdsFromGit configuration parameter is removed)
* bumps the database schema version
* deletes the database table for external IDs

Pushing to the refs/meta/external-ids branch is still prevented by a
commit validator. Since all external IDs are now in NoteDb only we
could allow pushing to refs/meta/external-ids. However we would still
like to do validation of the branch content and reject invalid content
(e.g. invalid Git config files, usage of non-existing account IDs
etc.) and such a validator is not implemented yet (but can be
implemented in a follow-up change).

Change-Id: Id9e5574a1d8d82f4f48fbb0b6dadc0e27d138a28
Signed-off-by: Edwin Kempin <ekempin@google.com>
2017-05-10 08:51:44 +02:00
David Pursehouse
9cbfae0ada Merge branch 'stable-2.14'
* stable-2.14:
  ReviewersUtil: Fix candidate list multiplier comment
  Replace FileInputStream and FileOutputStream with static Files methods

Change-Id: I5c4e04457b680db7709c522f17cfef1bef91a60f
2017-05-10 15:47:26 +09:00
Hector Oswaldo Caballero
db21e3add0 Replace FileInputStream and FileOutputStream with static Files methods
FileInputStream and FileOutputStream rely on finalize() method to ensure
resources are closed. This implies they are added to the finalizer queue
which causes additional work for the JVM GC process.

This is an open bug on the OpenJDK [1] and the recommended workaround is
to use the Files.newInputStream and Files.newOutputStream static methods
instead.

[1] https://bugs.openjdk.java.net/browse/JDK-8080225

Change-Id: I3cef6fcf198dde2be7cd15bded8d2fa247177654
2017-05-10 00:10:52 +00:00
David Pursehouse
75c9189fc2 Merge branch 'stable-2.14'
* stable-2.14:
  Use account cache instead of ReviewDb in MailProcessor
  Change log message to reflect IMAP RFC
  Get rid of calls to SecurityUtils.isBouncyCastleRegistered()
  SshDaemon: Improve log message when formatting ssh host key fails

Change-Id: Ibbc3a1d32c7127335840233d66324fca7f664e12
2017-05-08 23:09:30 +09:00
David Pursehouse
7b38f47e56 Get rid of calls to SecurityUtils.isBouncyCastleRegistered()
Since we now ship BouncyCastle in the .war file, this will always
return true.  Remove the code that is now redundant.

Change-Id: I35d6191b6f5e4cea40a022236cbc848eb01d7ba1
2017-05-08 19:44:57 +09:00
David Pursehouse
b139a0c9d4 SshDaemon: Improve log message when formatting ssh host key fails
Include the key string, which will help to track down which one
failed, and omit the entire stack trace, which doesn't actually
provide any useful information.

Change-Id: I67c1fbe75c99f8cda6dbebe27c050e338e571315
2017-05-08 16:51:09 +09:00
David Pursehouse
1fc7804c26 Merge branch 'stable-2.14'
* stable-2.14:
  Use 'Merge list' as display name for /MERGE_LIST
  DatabasePubKeyAuth: Also look for ecdsa keys and ed25519 keys
  SshDaemon: Also look for ecdsa keys and ed25519 keys
  InitSshd: Generate ecdsa and ed25519 keys if the host supports them
  Speed up reviewer suggestion
  Relocate setting page base to app initialization
  Allow multiple Servlet filters on Jetty HTTPD

Change-Id: I22fa3777ea8150a89e4c66d5d32535caee1b5a76
2017-05-08 11:16:59 +09:00
Paladox none
99550098d4 DatabasePubKeyAuth: Also look for ecdsa keys and ed25519 keys
Change-Id: I13ca777bfd9f4b27d6579fdb8db5a9c0fb1102d3
2017-05-08 01:40:09 +00:00
Paladox none
acf39dacf5 SshDaemon: Also look for ecdsa keys and ed25519 keys
Change-Id: Iac0cf87aea6c6f4267d83f1d017cef869e7abc1b
2017-05-08 01:39:38 +00:00
Paladox none
c3319bf15e InitSshd: Generate ecdsa and ed25519 keys if the host supports them
Change-Id: Iad0fdea4f2acb97207d553ed30fdfbf9b0d83067
2017-05-08 08:54:41 +09:00
Dave Borowitz
ae52afc058 Convert most ChangeApi handlers to retrying wrappers
Excludes a few that will require more work to plumb the
BatchUpdate.Factory into the class that actually does the work.

Change-Id: Id8c679c91ed8ea142f1856fcc2d976c4fb609dc5
2017-05-04 12:53:40 -04:00
David Pursehouse
74e4876d88 Merge branch 'stable-2.14'
* stable-2.14:
  Move systemctl files to /init/ rather than /systemd/
  SitePathInitializer: Fix destination file name for gerrit.socket
  Clarify documentation for accountPatchReviewDb.url
  Add the new gerrit systemctl file to init
  Remove unneeded output in MigrateAccountPatchReviewDb
  ES: Implement online reindex for ElasticSearch
  JdbcAccountPatchReviewStore: Fix copyright year
  Fix documentation nits in pgm-MigrateAccountPatchReviewDb.txt
  Support Jdbc implementation of AccountPatchReviewStore
  ES: Temporarily disable server discovery

Change-Id: I1034869bc6146db929f6242610c9eb13a7b092f7
2017-04-26 14:05:54 +02:00
Dariusz Luksza
74bb6d6184 ES: Implement online reindex for ElasticSearch
Implement online reindexing for ElasticSearch based on the code for
Lucene online reindex.

Testing scenario:
 1. Start fresh Gerrit site with this patch
 2. Create account
 3. Verify data in ElasticSearch:
   curl http://localhost:9200/gerritaccounts_0004/
   curl http://localhost:9200/gerritaccounts_0004/_search
 4. Stop Gerrit
 5. Cherry pick change I77e1643cd1a7fbef9f4d2fa214823759188e9592
 6. Start Gerrit
 6. Wait for log message:
     Starting online reindex from schema version 4 to 5
 7. Verify state in ElasticSearch:
   curl http://localhost:9200/gerritaccounts_0005/
   curl http://localhost:9200/gerritaccounts_0005/_search

Entry for user account created in step 2 should have "elastic_online"
property with value "reindex work".

Change-Id: I9efcf5735e65b4f2dc2a97914d398f81656fc12a
2017-04-26 11:50:47 +02:00
Luca Milanesio
931fe95745 Move PluginPermissions to extension API
Allow plugins to define their own capability and permission and check
for current user satisfy them, consuming PluginPermission from the
plugin extension API.

Change-Id: Iabba0ffa2a7e40605b09b41c25ab147395bb5f8c
2017-04-25 14:36:18 +02:00
Shawn Pearce
8ea6df30a2 Convert parsing projects to use PermissionBackend
When parsing a project name from a command line argument or in the
REST API, check the caller has ACCESS permission using
PermissionBackend, failing if they don't.

In UploadArchive check READ permission to determine if the
reachability check can be skipped.

Change-Id: I8b9155834a4ab36b964e339f5d9e1d110f771158
2017-04-24 08:28:24 +00:00
Shawn Pearce
571f99c02a Convert ListChildProjects to PermissionBackend
Rewrite the code to use Java 8 streams and the new
PermissionBackend to filter batches of direct children
for ACCESS permission.

Change-Id: I7ca6b5566a6ec675760dc937db369e9150546dd3
2017-04-24 08:27:33 +00:00
Shawn Pearce
abab3e99d9 Convert SuggestParentCandidates to PermissionBackend
Define two ProjectPermissions:

  ACCESS - Caller can see at least one reference (or change) and
  should be able to learn the project exists, and use APIs that
  depend on that fact. Hidden projects are not accessible unless
  the user is an owner.

  READ - Caller can see all references in the project and can
  use things like GitwebServlet where filtering doesn't happen.
  Hidden projects are not readable unless the user is an owner.

Add a filter() method in PermissionBackend to support checking
a permission across many projects at once, and use this inside
of SuggestParentCandidates to filter results to only projects
that the caller has ACCESS permission to.

Change-Id: I1329a8df1e7858e02379b7a1a526ad4954f0e42a
2017-04-24 08:18:53 +00:00
Shawn Pearce
29d4523608 Convert administrateServer to PermissionBackend
Leave a poorly named backdoor in CapabilityControl for the existing
ProjectControl, RefControl, ChangeControl and GroupControl to test
administrator permission.

Update test expecting a failure when administateServer is not granted.

Change-Id: I0f523dbf26506ea53c38ffb02aeef74f3cf18ba6
2017-04-24 10:14:01 +02:00
David Pursehouse
b5798658f5 Merge changes from topic 'permission-backend'
* changes:
  Convert RequireCapability checks to PermissionBackend
  Change capabilities collection to parse using PermissionBackend
2017-04-24 05:18:49 +00:00
Martin Fick
4c4acd6796 Delegate dynamicBeans for external plugins
When dynamicbeans are defined by an external plugin on commands from a
different plugin, instantiate the dynamic bean with a delegating
classloader which uses the command's classloader as the parent and
resolves resources via the dynamicbean's classloader.  Also instantiate
the dynamicbeans using the injector from the command.

Change-Id: If2cff8235a9680eb64c58b77f2d482c5896baf0f
2017-04-21 15:33:15 -06:00
Shawn Pearce
79a899e505 Convert RequireCapability checks to PermissionBackend
Replace CapabilityUtils with support in PermissionBackend to check if
the caller has at least one of the specified permissions parsed from
class annotation.

This enables hiding canPerform(String) from CapabilityControl, which
makes it much harder to bypass the PermissionBackend.

Assume anyone with ADMINISTRATE_SERVER also has any PluginPermission.
This is carried over from CapabilityUtils, which skip any further
checks when the user has canAdministrateServer.

Update the error message in GarbageCollectionIT to now be the generic
"maintain server not permitted".

Change-Id: I9458bd55fa1c9709557ae1ad95a57a1d968c52a3
2017-04-19 11:54:43 +02:00
David Pursehouse
eacabe9154 Merge changes from topic 'permission-backend'
* changes:
  Convert modifyAccount to PermissionBackend
  Convert maintainServer to PermissionBackend
  Convert viewQueue to PermissionBackend
2017-04-19 09:47:04 +00:00
Martin Fick
87df78a648 Merge "Allow plugins to output change query attributes" 2017-04-18 21:48:24 +00:00
Shawn Pearce
b168511335 Convert modifyAccount to PermissionBackend
Update a few test messages to reflect check throwing a generic
AuthException("modify account not permitted") instead of the
prior custom text.

Change-Id: Ie3ddd250289618a43d2708264863f2e850fd54cb
2017-04-18 10:28:00 +02:00
Shawn Pearce
a3efaba361 Convert maintainServer to PermissionBackend
Change-Id: I0b8bbd2df1f72f8e76b19b8baae01713403e628a
2017-04-18 10:28:00 +02:00
Shawn Pearce
53417fc605 Convert viewQueue to PermissionBackend
Change-Id: I993701da4a13275ade280674923a57c32cf145e6
2017-04-18 10:28:00 +02:00
Zac Livingston
cffb2459dc Allow plugins to output change query attributes
Create a ChangeAttributeFactory interface to allow
plugins to register to provide additonal attributes to be
output in a change query result.

Example Usage:
    https://gerrit-review.googlesource.com/#/c/102650/

Change-Id: I4a09d9abd8bda09a3ecde7ca203434d6ab8ab7be
2017-04-17 09:43:43 -06:00
Shawn Pearce
7eb31de4e3 Partially convert accessDatabase to PermissionBackend
The accessDatabase check is complicated inside VisibleRefsFilter
so for now it continues to use canAccessDatabase().

Change-Id: Ia4202a7f1658868f4d5698a1cb1db6ccaf5a062e
2017-04-14 14:50:54 +09:00
Shawn Pearce
f49c2a87ab Convert runAs to PermissionBackend
Change-Id: Ia08189d864388b45c7f11b41cc835fda57d7e03d
2017-04-14 14:50:53 +09:00
Hugo Arès
7dab2eb4d3 Remove duplicated code in set-project ssh command
Call rest api PutConfig which is doing the same thing as set-project ssh command.

Change-Id: I66b6bd570b5392bc63a74b892df11e856671942f
2017-04-13 16:40:39 +09:00
David Pursehouse
9cb2deacef Merge branch 'stable-2.14'
* stable-2.14:
  Allow project owner to use set-project ssh command

Change-Id: Ib21223da17ab1e7f92512f47bef6816542887abc
2017-04-12 11:32:02 +09:00
David Pursehouse
82393f6a8f Merge branch 'stable-2.13' into stable-2.14
* stable-2.13:
  Allow project owner to use set-project ssh command

Change-Id: I221769284f34901c07f7eba645eb3367c20ee982
2017-04-12 10:51:51 +09:00
Hugo Arès
36cc6fcc92 Allow project owner to use set-project ssh command
REST API and UI allow project owner to change the project settings so
fix inconsistency by allowing the same in the ssh command.

Change-Id: I123007629db87c1df6162cb1e56fc51bacff9631
2017-04-11 21:15:54 -04:00
Martin Fick
a085ff9fdd Merge "Add a BeanParseListener interface to DynamicOptions." 2017-04-11 19:23:12 +00:00