blob: 4614031c5c33b9fd6f64f2c4faca13da7083872c [file] [view]
@PLUGIN@ Configuration
======================
CIDR policy evaluation order:
1. Global block list — deny
2. Global allow list non-match — deny
3. Project policy disabled — allow
4. Invalid project policy — deny (`ENFORCE`) or allow (`LOG_ONLY`)
5. Project block list — deny (`ENFORCE`) or allow (`LOG_ONLY`)
6. Project allow list non-match — deny (`ENFORCE`) or allow (`LOG_ONLY`)
7. Otherwise — allow
All decisions are recorded in metrics; enable `logDecisions` for decision logs.
Block lists take precedence over allow lists. Empty allow lists impose no
restriction. An allow outcome delegates to Gerrit's normal permissions.
See the global settings below for missing-peer and global-policy errors.
Installation in `gerrit.config`
-------------------------------
Copy `access-ipsubnet.jar` into `$site_path/lib/` and add these settings to
`etc/gerrit.config`. The module must replace the system `PermissionBackend`
binding; loading the jar from `$site_path/plugins/` cannot do that.
```ini
[gerrit]
installModule = com.googlesource.gerrit.modules.access.ipsubnet.IpSubnetAccessModule
[httpd]
filterClass = com.googlesource.gerrit.modules.access.ipsubnet.IpSubnetHttpFilter
```
Restart Gerrit after installation or changes to these settings; plugin or
config reload is not sufficient.
The HTTP filter is required for anonymous HTTP project permission checks,
including change-search visibility checks. Without it, those checks follow
`failClosedOnMissingRemotePeer`. Authenticated HTTP and SSH use
`IdentifiedUser.getRemotePeer()`; SSH does not need the HTTP filter. The
filter uses Gerrit's transport peer provider, not forwarding headers directly.
See [proxy requirements](about.md) when Gerrit is behind a proxy.
Global settings in `gerrit.config`
-----------------------------------
```ini
[plugin "@PLUGIN@"]
failClosedOnMissingRemotePeer = false
logDecisions = false
failClosedOnGlobalPolicyError = true
globalPolicyPath = etc/@PLUGIN@.config
globalMode = ENFORCE
```
plugin.@PLUGIN@.failClosedOnMissingRemotePeer
: Controls project permission checks whose checked user has no resolvable
remote IP. With `false`, these checks bypass both global and project IP
policy. With `true`:
| Checked user without a peer | Behavior |
| --- | --- |
| Current identified or anonymous request user | Deny |
| Explicit `user()` check for the current account or anonymous request user | Deny |
| `absentUser()` check for the current account | Deny |
| Other-account inquiry or internal server identity | Delegate to Gerrit's normal permissions |
Other-account inquiries do not borrow the request user's peer. A
same-account `absentUser()` check retains it. Background work running as
the current identified account can still be denied; `AccessPath.UNKNOWN`
does not exempt it.
Default: `false`.
plugin.@PLUGIN@.logDecisions
: When `true`, emit a structured log line for each IP-policy decision at
project permission scope.
Decision metrics are incremented regardless of this setting.
Default: `false`.
plugin.@PLUGIN@.failClosedOnGlobalPolicyError
: When `true`, deny access to all projects if the global policy file
cannot be read or parsed, provided the checked user has a resolvable IP.
Missing-peer checks follow `failClosedOnMissingRemotePeer` instead.
When `false`, ignore the failed global policy and still evaluate
per-project rules. A missing global file is an empty policy, not an
error, in either mode.
Default: `true`.
plugin.@PLUGIN@.globalPolicyPath
: Path to the global policy file, resolved relative to the Gerrit site
directory.
Default: `etc/@PLUGIN@.config`.
plugin.@PLUGIN@.globalMode
: Default mode for enabled per-project policy: `ENFORCE` denies policy
violations; `LOG_ONLY` allows them and records the decision in metrics
(and logs when `logDecisions = true`). An explicit project `mode`,
including one inherited from a parent, overrides this default.
Missing or blank values default to `ENFORCE`; unrecognized values emit
a warning and fall back to `ENFORCE`.
Default: `ENFORCE`.
This setting affects only policy in `refs/meta/config:project.config`.
CIDR lists in the global file's `[global]` and `[project "name"]`
sections are always enforced, even with `globalMode = LOG_ONLY`.
It does not enable per-project policy; `enabled = true` is still needed.
Global policy file (`etc/@PLUGIN@.config`)
------------------------------------------
```ini
[global]
blockedSubnet = 203.0.113.0/24
allowedSubnet = 10.0.0.0/8
[project "sensitive/project-a"]
blockedSubnet = 10.10.50.0/24
allowedSubnet = 192.168.10.0/24
```
The `[global]` section applies to every project. Each `[project "name"]`
subsection adds extra rules for that specific project. Its allowed and
blocked CIDR lists are unioned with the corresponding `[global]` lists;
they do not replace the global rules. In this example, `sensitive/project-a`
allows both `10.0.0.0/8` and `192.168.10.0/24`, except for blocked addresses.
A narrower project allow entry such as `10.10.0.0/16` would not restrict
`10.0.0.0/8`: the broader global entry would still match.
To narrow access, configure an enabled `ENFORCE` policy with the narrower
allow list in `refs/meta/config:project.config` (directly or inherited from
a parent). Both the global and per-project allow checks must then pass.
Project owners can change that per-project policy; the global-file union
alone cannot express an additional, admin-only project allow restriction.
The global policy file is loaded at startup. After editing it, run the SSH
command `gerrit reload-config` to refresh the policy on each Gerrit server;
no change to `gerrit.config` is necessary. File edits alone do not take effect.
Permission checks use an in-memory snapshot, without filesystem polling.
A policy-only reload may print `No config entries updated!` because the
listener does not change `gerrit.config` settings. Check the server logs for
the policy reload result.
A failed reload (including a previously present file that is now missing,
an unreadable file, or an invalid file) retains the current policy and
reports an error in the server logs. To intentionally clear the global
rules, empty the file and reload rather than deleting it.
A file that has never been present remains optional on reload and does not
produce an error.
At startup, a missing file still means no global rules; an unreadable or
invalid file follows `failClosedOnGlobalPolicyError`. A successful reload
can recover from an invalid startup policy. This command reloads the policy
contents, not the module or its `gerrit.config` settings; changing those
settings still requires a restart.
global.blockedSubnet / project.NAME.blockedSubnet
: IPv4 or IPv6 CIDR prefix to deny. Deny project permission checks for a
matching address regardless of any allow list. May be specified
multiple times.
global.allowedSubnet / project.NAME.allowedSubnet
: IPv4 or IPv6 CIDR prefix to allow. When at least one `allowedSubnet`
is configured, deny project permission checks whose checked user's
address does not match any entry. May be specified multiple times.
Per-project policy (`refs/meta/config:project.config`)
-------------------------------------------------------
```ini
[plugin "@PLUGIN@"]
enabled = true
mode = ENFORCE
allowedSubnet = 10.0.0.0/8
blockedSubnet = 10.2.4.0/24
```
Each unset setting is inherited from parent projects. A locally configured
CIDR list replaces the inherited list for that setting. Updates follow
Gerrit's project cache lifecycle. These settings affect only per-project
policy; global policy is evaluated first and remains enforced in either
project mode, even when per-project policy is disabled.
plugin.@PLUGIN@.enabled
: When `false`, skip per-project IP policy.
Default: `false`.
plugin.@PLUGIN@.mode
: `ENFORCE` — deny access on a per-project policy violation.
`LOG_ONLY` — do not deny on a per-project violation, including invalid
project CIDRs. Record the violation in decision metrics; emit a log
line when `logDecisions = true`.
When no nonblank explicit or inherited project mode is configured, use
`plugin.@PLUGIN@.globalMode` (default `ENFORCE`). Invalid mode values
produce an invalid project policy evaluated using that global default.
plugin.@PLUGIN@.allowedSubnet
: IPv4 or IPv6 CIDR prefix to allow. Same semantics as the global policy.
May be specified multiple times; subject to `enabled` and `mode`.
plugin.@PLUGIN@.blockedSubnet
: IPv4 or IPv6 CIDR prefix to deny. Same semantics as the global policy.
May be specified multiple times; subject to `enabled` and `mode`.