-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): Load abac config from policy service (#351)
New parameters for tdf/client allow looking up attribute definitions and KAS grants to autoconfigure with just attribute URLs. - New arguments to cli `encrypt` - `encrypt --autoconfigure` enables attribute lookup during encrypt and corresponding updates to the KAO - `--policyEndpoint` allows KAS and policy service to be hosted separately. if not set, it is inferred by removing `/kas` off of the end of the `--kasEndpoint` argument. - New cli command, `attrs`, which prints out the JSON hydrated version of the attributes from the policy service
- Loading branch information
1 parent
6eb70c1
commit 48b2442
Showing
13 changed files
with
671 additions
and
3,392 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { AuthProvider } from '../auth/auth.js'; | ||
import { rstrip } from '../utils.js'; | ||
import { GetAttributeValuesByFqnsResponse, Value } from './attributes.js'; | ||
|
||
export async function attributeFQNsAsValues( | ||
kasUrl: string, | ||
authProvider: AuthProvider, | ||
...fqns: string[] | ||
): Promise<Value[]> { | ||
const avs = new URLSearchParams(); | ||
for (const fqn of fqns) { | ||
avs.append('fqns', fqn); | ||
} | ||
avs.append('withValue.withKeyAccessGrants', 'true'); | ||
avs.append('withValue.withAttribute.withKeyAccessGrants', 'true'); | ||
const uNoSlash = rstrip(kasUrl, '/'); | ||
const uNoKas = uNoSlash.endsWith('/kas') ? uNoSlash.slice(0, -4) : uNoSlash; | ||
const url = `${uNoKas}/attributes/*/fqn?${avs}`; | ||
const req = await authProvider.withCreds({ | ||
url, | ||
headers: {}, | ||
method: 'GET', | ||
}); | ||
let response: Response; | ||
try { | ||
response = await fetch(req.url, { | ||
mode: 'cors', | ||
credentials: 'same-origin', | ||
headers: req.headers, | ||
redirect: 'follow', | ||
referrerPolicy: 'no-referrer', | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`${req.method} ${req.url} => ${response.status} ${response.statusText}`); | ||
} | ||
} catch (e) { | ||
console.error(`network error [${req.method} ${req.url}]`, e); | ||
throw e; | ||
} | ||
|
||
let resp: GetAttributeValuesByFqnsResponse; | ||
try { | ||
resp = (await response.json()) as GetAttributeValuesByFqnsResponse; | ||
} catch (e) { | ||
console.error(`response parse error [${req.method} ${req.url}]`, e); | ||
throw e; | ||
} | ||
|
||
const values: Value[] = []; | ||
for (const [fqn, av] of Object.entries(resp.fqnAttributeValues)) { | ||
if (!av.value) { | ||
console.log(`Missing value definition for [${fqn}]; is this a valid attribute?`); | ||
continue; | ||
} | ||
if (av.attribute && !av.value.attribute) { | ||
av.value.attribute = av.attribute; | ||
} | ||
values.push(av.value); | ||
} | ||
return values; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.