-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1224 from ORNL/1180-refactor-authz
[DAPS, Foxx] - 1180 refactor Part 2 authz
- Loading branch information
Showing
12 changed files
with
1,415 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,8 @@ const router = createRouter(); | |
const joi = require("joi"); | ||
const g_db = require("@arangodb").db; | ||
const g_lib = require("./support"); | ||
const pathModule = require("./posix_path"); // Replace with the actual file name | ||
const Record = require("./record"); // Replace with the actual file name | ||
const authzModule = require("./authz"); // Replace with the actual file name | ||
const authzModule = require("./authz"); | ||
const { Repo, PathType } = require("./repo"); | ||
|
||
module.exports = router; | ||
|
||
|
@@ -26,109 +25,36 @@ router | |
); | ||
|
||
// Client will contain the following information | ||
// { | ||
// "_key" : "bob", | ||
// "_id" : "u/bob", | ||
// "name" : "bob junior ", | ||
// "name_first" : "bob", | ||
// "name_last" : "jones", | ||
// "is_admin" : true, | ||
// "max_coll" : 50, | ||
// "max_proj" : 10, | ||
// "max_sav_qry" : 20, | ||
// : | ||
// "email" : "[email protected]" | ||
// } | ||
const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); | ||
|
||
// Will split a posix path into an array | ||
// E.g. | ||
// req.queryParams.file = "/usr/local/bin" | ||
// const path_components = pathModule.splitPOSIXPath(req.queryParams.file); | ||
// | ||
// Path components will be | ||
// ["usr", "local", "bin"] | ||
const path_components = pathModule.splitPOSIXPath(req.queryParams.file); | ||
const data_key = path_components.at(-1); | ||
let record = new Record(data_key); | ||
|
||
// Special case - allow unknown client to read a publicly accessible record | ||
// if record exists and if it is a public record | ||
// "_key" : "bob", | ||
// "_id" : "u/bob", | ||
// "name" : "bob junior ", | ||
// "name_first" : "bob", | ||
// "name_last" : "jones", | ||
// "is_admin" : true, | ||
// "max_coll" : 50, | ||
// "max_proj" : 10, | ||
// "max_sav_qry" : 20, | ||
// : | ||
// "email" : "[email protected]" | ||
const client = g_lib.getUserFromClientID_noexcept(req.queryParams.client); | ||
if (!client) { | ||
if (record.exists()) { | ||
if (req.queryParams.act != "read" || !g_lib.hasPublicRead(record.id())) { | ||
console.log( | ||
"AUTHZ act: " + | ||
req.queryParams.act + | ||
" client: " + | ||
client._id + | ||
" path " + | ||
req.queryParams.file + | ||
" FAILED", | ||
); | ||
throw g_lib.ERR_PERM_DENIED; | ||
} | ||
} | ||
} else { | ||
// Actions: read, write, create, delete, chdir, lookup | ||
let req_perm = 0; | ||
switch (req.queryParams.act) { | ||
case "read": | ||
req_perm = g_lib.PERM_RD_DATA; | ||
break; | ||
case "write": | ||
break; | ||
case "create": | ||
req_perm = g_lib.PERM_WR_DATA; | ||
break; | ||
case "delete": | ||
throw g_lib.ERR_PERM_DENIED; | ||
case "chdir": | ||
break; | ||
case "lookup": | ||
// For TESTING, allow these actions | ||
return; | ||
default: | ||
throw [ | ||
g_lib.ERR_INVALID_PARAM, | ||
"Invalid gridFTP action: ", | ||
req.queryParams.act, | ||
]; | ||
} | ||
|
||
// This will tell us if the action on the record is authorized | ||
// we still do not know if the path is correct. | ||
if (record.exists()) { | ||
if (!authzModule.isRecordActionAuthorized(client, data_key, req_perm)) { | ||
console.log( | ||
"AUTHZ act: " + | ||
req.queryParams.act + | ||
" client: " + | ||
client._id + | ||
" path " + | ||
req.queryParams.file + | ||
" FAILED", | ||
); | ||
throw g_lib.ERR_PERM_DENIED; | ||
} | ||
} | ||
console.log( | ||
"AUTHZ act: " + | ||
req.queryParams.act + | ||
" client: " + | ||
+req.queryParams.client + | ||
" path " + | ||
req.queryParams.file + | ||
" FAILED", | ||
); | ||
throw [g_lib.ERR_PERM_DENIED, "Unknown client: " + req.queryParams.client]; | ||
} | ||
let repo = new Repo(req.queryParams.repo); | ||
let path_type = repo.pathType(req.queryParams.file); | ||
|
||
if (record.exists()) { | ||
if (!record.isPathConsistent(req.queryParams.file)) { | ||
console.log( | ||
"AUTHZ act: " + | ||
req.queryParams.act + | ||
" client: " + | ||
client._id + | ||
" path " + | ||
req.queryParams.file + | ||
" FAILED", | ||
); | ||
throw [record.error(), record.errorMessage()]; | ||
} | ||
} else { | ||
// If the record does not exist then the path would noe be consistent. | ||
// If the provided path is not within the repo throw an error | ||
if (path_type === PathType.UNKNOWN) { | ||
console.log( | ||
"AUTHZ act: " + | ||
req.queryParams.act + | ||
|
@@ -138,7 +64,22 @@ router | |
req.queryParams.file + | ||
" FAILED", | ||
); | ||
throw [g_lib.ERR_PERM_DENIED, "Invalid record specified: " + req.queryParams.file]; | ||
throw [ | ||
g_lib.ERR_PERM_DENIED, | ||
"Unknown path, or path is not consistent with supported repository folder hierarchy: " + | ||
req.queryParams.file, | ||
]; | ||
} | ||
|
||
// Determine permissions associated with path provided | ||
// Actions: read, write, create, delete, chdir, lookup | ||
if (Object.keys(authzModule.authz_strategy).includes(req.queryParams.act)) { | ||
authzModule.authz_strategy[req.queryParams.act][path_type]( | ||
client, | ||
req.queryParams.file, | ||
); | ||
} else { | ||
throw [g_lib.ERR_INVALID_PARAM, "Invalid gridFTP action: ", req.queryParams.act]; | ||
} | ||
console.log( | ||
"AUTHZ act: " + | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.