Skip to content

Commit 7aa11b1

Browse files
authored
Merge pull request #97 from bufferoverflow/feat/remove-legacy-mode
feat: get rid of legacy mode
2 parents d3d083b + ab36d30 commit 7aa11b1

File tree

2 files changed

+14
-40
lines changed

2 files changed

+14
-40
lines changed

README.md

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ the following:
1717

1818
> This is experimental!
1919
20-
## Gitlab Version Compatibility
21-
22-
- If `legacy_mode: false` or undefined (default mode): Gitlab 11.2+
23-
- If `legacy_mode: true`: Gitlab 9.0+
24-
2520
## Use it
2621

2722
You need at least node version 8.x.x, codename **carbon**.
@@ -91,18 +86,14 @@ yarn publish --registry http://localhost:4873
9186

9287
## Access Levels
9388

94-
Access and publish access rights depend on the mode used.
89+
Access and publish access rights are mapped following the rules below.
9590

9691
verdaccio-gitlab access control will only be applied to package sections that
9792
are marked with `gitlab: true` as in the configuration sample above. If you
9893
wish to disable gitlab authentication to any package config, just remove the
9994
element from the config.
10095

101-
### Normal Mode (default)
102-
103-
In normal mode, packages are available:
104-
105-
#### Access
96+
### Access
10697

10798
*access* is allowed depending on the following verdaccio `package` configuration
10899
directives:
@@ -114,7 +105,7 @@ directives:
114105
Please note that no group or package name mapping is applied on access, any
115106
user successfully authenticated can access all packages.
116107

117-
#### Publish
108+
### Publish
118109

119110
*publish* is allowed if the package name matches the logged in user
120111
id, if the package name or scope of the package matches one of the
@@ -137,11 +128,6 @@ For instance, assuming the following configuration:
137128
- `@group3/project`
138129
- error if the user tries to publish any package under `@group2/**`
139130

140-
### Legacy Mode
141-
142-
If using the legacy mode, the system behaves as in normal mode with
143-
fixed configuration `auth.gitlab.publish` = `$owner`
144-
145131
## Configuration Options
146132

147133
The full set of configuration options is:
@@ -153,7 +139,6 @@ auth:
153139
authCache:
154140
enabled: <boolean>
155141
ttl: <integer>
156-
legacy_mode: <boolean>
157142
publish: <string>
158143
```
159144
@@ -163,8 +148,7 @@ auth:
163148
| `url` | `<empty>` | url | mandatory, the url of the gitlab server |
164149
| `authCache: enabled` | `true` | boolean | activate in-memory authentication cache |
165150
| `authCache: ttl` | `300` (`0`=unlimited) | integer | time-to-live of entries in the authentication cache, in seconds |
166-
| `legacy_mode` | `false` | boolean | gitlab versions pre-11.2 do not support groups api queries based on access level; this enables the legacy behaviour of only allowing npm publish operations on groups where the logged in user has owner rights |
167-
| `publish` | `$maintainer` | [`$guest`, `$reporter`, `$developer`, `$maintainer`, `$owner`] | group minimum access level of the logged in user required for npm publish operations (does not apply in legacy mode) |
151+
| `publish` | `$maintainer` | [`$guest`, `$reporter`, `$developer`, `$maintainer`, `$owner`] | group minimum access level of the logged in user required for npm publish operations |
168152
<!-- markdownlint-enable MD013 -->
169153

170154
## Authentication Cache

src/gitlab.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export type VerdaccioGitlabConfig = {
1616
enabled?: boolean;
1717
ttl?: number;
1818
};
19-
legacy_mode?: boolean;
2019
publish?: VerdaccioGitlabAccessLevel;
2120
};
2221

@@ -65,20 +64,16 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
6564
this.logger.info(`[gitlab] initialized auth cache with ttl: ${ttl} seconds`);
6665
}
6766

68-
if (this.config.legacy_mode) {
69-
this.publishLevel = '$owner';
70-
this.logger.info('[gitlab] legacy mode pre-gitlab v11.2 active, publish is only allowed to group owners');
71-
} else {
72-
this.publishLevel = '$maintainer';
73-
if (this.config.publish) {
74-
this.publishLevel = this.config.publish;
75-
}
7667

77-
if (!Object.keys(ACCESS_LEVEL_MAPPING).includes(this.publishLevel)) {
78-
throw Error(`[gitlab] invalid publish access level configuration: ${this.publishLevel}`);
79-
}
80-
this.logger.info(`[gitlab] publish control level: ${this.publishLevel}`);
68+
this.publishLevel = '$maintainer';
69+
if (this.config.publish) {
70+
this.publishLevel = this.config.publish;
8171
}
72+
73+
if (!Object.keys(ACCESS_LEVEL_MAPPING).includes(this.publishLevel)) {
74+
throw Error(`[gitlab] invalid publish access level configuration: ${this.publishLevel}`);
75+
}
76+
this.logger.info(`[gitlab] publish control level: ${this.publishLevel}`);
8277
}
8378

8479
authenticate(user: string, password: string, cb: Callback) {
@@ -111,13 +106,8 @@ export default class VerdaccioGitLab implements VerdaccioGitLabPlugin {
111106
// Set the groups of an authenticated user, in normal mode:
112107
// - for access, depending on the package settings in verdaccio
113108
// - for publish, the logged in user id and all the groups they can reach as configured with access level `$auth.gitlab.publish`
114-
//
115-
// In legacy mode, the groups are:
116-
// - for access, depending on the package settings in verdaccio
117-
// - for publish, the logged in user id and all the groups they can reach as fixed `$auth.gitlab.publish` = `$owner`
118-
const gitlabPublishQueryParams = this.config.legacy_mode
119-
? { owned: true }
120-
: { min_access_level: publishLevelId };
109+
const gitlabPublishQueryParams = { min_access_level: publishLevelId };
110+
121111
// @ts-ignore
122112
this.logger.trace('[gitlab] querying gitlab user groups with params:', gitlabPublishQueryParams);
123113

0 commit comments

Comments
 (0)