Skip to content

Commit bee58dd

Browse files
nitrosxJunjiequanmartin-trajanovskibpedersen2
authored
Add "create dataset privileged" groups and review dataset authorization (#818)
* Enhanced authorization for all services * Fixed failing API tests due to authorization modification. --------- Co-authored-by: Jay Quan <[email protected]> Co-authored-by: Martin Trajanovski <[email protected]> Co-authored-by: Björn Pedersen <[email protected]> Co-authored-by: Martin <[email protected]>
1 parent 41195c4 commit bee58dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3467
-1084
lines changed

.github/workflows/auto-merge-dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
GITHUB_TOKEN: ${{secrets.PR_APPROVE_TOKEN}}
4141

4242
## NOTE: Requirements for merge has to be configured in the Branch protection rule page.
43-
## To do so, go to repository > Settings > Branches > Edit
43+
## To do so, go to repository > Settings > Branches > Edit.
4444
- name: Enable auto-merge for Dependabot PRs
4545
if: ${{ contains(github.event.pull_request.title, 'bump')}}
4646
run: gh pr merge --auto --merge "$PR_URL"

.github/workflows/test.yml

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ jobs:
146146
DOI_PREFIX: DOI.SAMPLE.PREFIX
147147
METADATA_KEYS_RETURN_LIMIT: 100
148148
METADATA_PARENT_INSTANCES_RETURN_LIMIT: 100
149-
ADMIN_GROUPS: admin,ingestor,archivemanager
150-
CREATE_DATASET_GROUPS: group1,group2,group3
149+
ADMIN_GROUPS: admin,ingestor
151150
DELETE_GROUPS: archivemanager
151+
CREATE_DATASET_GROUPS: group1,group2,group3
152+
CREATE_DATASET_WITH_PID_GROUPS: "group2"
152153
ACCESS_GROUPS_STATIC_VALUES: "ess"
153-
CREATE_DATASET_WITH_PID_GROUPS: "group2,group3"
154+
PROPOSAL_GROUPS: "proposalingestor"
155+
SAMPLE_GROUPS: ""
154156
DATASET_CREATION_VALIDATION_ENABLED: true
155157
DATASET_CREATION_VALIDATION_REGEX: "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$"
156158
ES_HOST: https://localhost:9200
@@ -168,63 +170,6 @@ jobs:
168170
# Start mongo container and app before running api tests
169171
run: |
170172
cp CI/ESS/docker-compose.api.yaml docker-compose.yaml
173+
cp functionalAccounts.json.test functionalAccounts.json
171174
docker-compose up --build -d
172175
npm run test:api
173-
174-
e2e_tests:
175-
name: E2E Tests
176-
runs-on: ubuntu-latest
177-
steps:
178-
- name: Checkout code
179-
uses: actions/checkout@v4
180-
181-
- name: Set up Node.js
182-
uses: actions/setup-node@v4
183-
with:
184-
node-version: ${{ env.NODE_VERSION }}
185-
186-
- name: Configure sysctl limits for elastic search
187-
run: |
188-
sudo swapoff -a
189-
sudo sysctl -w vm.swappiness=1
190-
sudo sysctl -w fs.file-max=262144
191-
sudo sysctl -w vm.max_map_count=262144
192-
193-
- name: Run stack in docker-compose
194-
run: |
195-
cp CI/E2E/docker-compose.yaml docker-compose.yaml
196-
docker-compose pull
197-
docker-compose build --no-cache
198-
docker-compose up &
199-
200-
- name: Checkout frontend repo
201-
uses: actions/checkout@v4
202-
with:
203-
repository: scicatproject/frontend
204-
path: frontend
205-
fetch-depth: 1
206-
207-
- name: Wait for Backend
208-
run: |
209-
npm install -g wait-on && \
210-
wait-on http://localhost:3000/api/v3/health --timeout 200000
211-
212-
- name: Run Cypress tests
213-
uses: cypress-io/github-action@v6
214-
with:
215-
working-directory: frontend
216-
config-file: CI/ESS/e2e/cypress.github.ts
217-
install-command: npm install --omit peer
218-
browser: chrome
219-
220-
- uses: actions/upload-artifact@v3
221-
if: failure()
222-
with:
223-
name: cypress-screenshots
224-
path: frontend/cypress/screenshots/
225-
226-
- uses: actions/upload-artifact@v3
227-
if: failure()
228-
with:
229-
name: cypress-videos
230-
path: frontend/cypress/videos/

functionalAccounts.json.test

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[
2+
{
3+
"username": "admin",
4+
"email": "[email protected]",
5+
"password": "am2jf70TPNZsSan",
6+
"role": "admin",
7+
"global": true
8+
},
9+
{
10+
"username": "ingestor",
11+
"email": "[email protected]",
12+
"password": "aman",
13+
"role": "ingestor",
14+
"global": false
15+
},
16+
{
17+
"username": "archiveManager",
18+
"email": "[email protected]",
19+
"password": "aman",
20+
"role": "archivemanager",
21+
"global": false
22+
},
23+
{
24+
"username": "proposalIngestor",
25+
"email": "[email protected]",
26+
"password": "aman",
27+
"role": "proposalingestor",
28+
"global": false
29+
},
30+
{
31+
"username": "user1",
32+
"email": "[email protected]",
33+
"password": "a609316768619f154ef58db4d847b75e",
34+
"role": "group1",
35+
"global": false
36+
},
37+
{
38+
"username": "user2",
39+
"email": "[email protected]",
40+
"password": "f522d1d715970073a6413474ca0e0f63",
41+
"role": "group2",
42+
"global": false
43+
},
44+
{
45+
"username": "user3",
46+
"email": "[email protected]",
47+
"password": "70dc489e8ee823ae815e18d664424df2",
48+
"role": "group3",
49+
"global": false
50+
},
51+
{
52+
"username": "user4",
53+
"email": "[email protected]",
54+
"password": "0014890e7020f515b92b767227ef2dfa",
55+
"role": "group4",
56+
"global": false
57+
},
58+
{
59+
"username": "user5.1",
60+
"email": "[email protected]",
61+
"password": "359a5fda99bfe5dbc42ee9b3ede77fb7",
62+
"role": "group5",
63+
"global": false
64+
},
65+
{
66+
"username": "user5.2",
67+
"email": "[email protected]",
68+
"password": "f3ebd2e4def95db59ef95ee32ef45242",
69+
"role": "group5",
70+
"global": false
71+
}
72+
]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"test:api": "npm run test:api:jest --maxWorkers=50% && concurrently -k -s first \"wait-on http://localhost:3000/explorer/ && npm run test:api:mocha\" \"npm run start\"",
2828
"test:api:jest": "jest --config ./test/config/jest-e2e.json --maxWorkers=50%",
2929
"test:api:mocha": "mocha --config ./test/config/.mocharc.json",
30-
"prepare:local": "docker-compose -f CI/E2E/docker-compose-local.yaml --env-file CI/E2E/.env.elastic-search up -d && cp functionalAccounts.json.example functionalAccounts.json"
30+
"prepare:local": "docker-compose -f CI/E2E/docker-compose-local.yaml --env-file CI/E2E/.env.elastic-search up -d && cp functionalAccounts.json.test functionalAccounts.json"
3131
},
3232
"dependencies": {
3333
"@casl/ability": "^6.3.2",

src/auth/access-group-provider/access-group-from-static-values.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export class AccessGroupFromStaticValuesService extends AccessGroupService {
1111
}
1212

1313
async getAccessGroups(): Promise<string[]> {
14-
Logger.log(
15-
"Static access group getAccessGroups : " +
16-
this.staticAccessGroups.join(","),
17-
);
14+
// Logger.log(
15+
// "Static access group getAccessGroups : " +
16+
// this.staticAccessGroups.join(","),
17+
// );
1818
return this.staticAccessGroups;
1919
}
2020
}

src/auth/auth.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Logger } from "@nestjs/common";
1+
import { HttpException, HttpStatus, Injectable, Logger } from "@nestjs/common";
22
import { ConfigService } from "@nestjs/config";
33
import { JwtService } from "@nestjs/jwt";
44
import { compare } from "bcrypt";
@@ -77,6 +77,9 @@ export class AuthService {
7777

7878
async additionalLogoutTasks(req: Request, logoutURL: string) {
7979
const user = req.user as Omit<User, "password">;
80+
if (!user) {
81+
throw new HttpException(`Not logged in`, HttpStatus.UNAUTHORIZED);
82+
}
8083
if (user?.authStrategy === "oidc") {
8184
const oidcConfig = this.configService.get<OidcConfig>("oidc");
8285
const autoLogout: boolean = parseBoolean(oidcConfig?.autoLogout || true);

src/auth/guards/jwt-auth.guard.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@ export class JwtAuthGuard extends AuthGuard("jwt") {
2929
info: unknown,
3030
context: ExecutionContext,
3131
) {
32-
const allowAny = this.reflector.get<string[]>(
33-
"allow-any",
34-
context.getHandler(),
35-
);
32+
// const allowAny = this.reflector.get<string[]>(
33+
// "allow-any",
34+
// context.getHandler(),
35+
// );
3636

3737
if (user) {
3838
return user;
3939
}
40-
if (allowAny) {
41-
return null;
42-
}
43-
throw new UnauthorizedException();
40+
// if (allowAny) {
41+
// return null;
42+
// }
43+
// throw new UnauthorizedException();
44+
return null;
4445
}
4546
}

0 commit comments

Comments
 (0)