-
Notifications
You must be signed in to change notification settings - Fork 3
MANTA-5522 Add lib/scope-schema.js as the single source of truth for bucket scope schema #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cneira
wants to merge
8
commits into
master
Choose a base branch
from
accesskey-per-bucket
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+866
−14
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5577741
Add MahiClient.prototype.cachePush for direct Redis key writes
cneira 62c2486
fixup
cneira 99b3889
fix: rename /scope-revoke to /key-revoke endpoint path
cneira dfc265e
cachePush: validate scope at client boundary
cneira ff9ed82
lint: fix qs shadowing, trailing whitespace, typeof parens
cneira 47d6052
Fix for format issue were lines were being truncated at 60 cols
cneira 0e112fa
test: add unit tests for scope-schema validateScope
cneira d8f6826
bump up package version
cneira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ var LRU = require('lru-cache'); | |
| var httpSignature = require('http-signature'); | ||
| var qs = require('querystring'); | ||
| var restify = require('restify'); | ||
| var scopeSchema = require('./scope-schema.js'); | ||
| var sprintf = require('util').format; | ||
|
|
||
|
|
||
|
|
@@ -797,7 +798,7 @@ MahiClient.prototype.getLookup = function getLookup(opts, cb) { | |
| * | ||
| * accessKeyId: AWS access key ID (e.g., "AKIA123456789EXAMPLE") | ||
| * cb: callback in the form fn(err, userInfo) | ||
| * | ||
| * | ||
| * Returns user object without access key secrets: | ||
| * { | ||
| * type: "account", | ||
|
|
@@ -811,14 +812,14 @@ MahiClient.prototype.getLookup = function getLookup(opts, cb) { | |
| * AccessKeyNotFoundError | ||
| * RedisError | ||
| */ | ||
| MahiClient.prototype.getUserByAccessKey = function | ||
| MahiClient.prototype.getUserByAccessKey = function | ||
| getUserByAccessKey(accessKeyId, cb) { | ||
| assert.string(accessKeyId, 'accessKeyId'); | ||
| assert.func(cb, 'callback'); | ||
|
|
||
| var self = this; | ||
| var path = sprintf('/aws-auth/%s', accessKeyId); | ||
|
|
||
| self.http.get(path, function (err, req, res, obj) { | ||
| if (err) { | ||
| cb(err); | ||
|
|
@@ -831,42 +832,41 @@ MahiClient.prototype.getUserByAccessKey = function | |
|
|
||
| /** | ||
| * Verify AWS Signature Version 4 authentication | ||
| * | ||
| * | ||
| * request: HTTP request object with AWS4-HMAC-SHA256 authorization header | ||
| * cb: callback in the form fn(err, result) | ||
| * | ||
| * Returns: | ||
| * { | ||
| * valid: true, | ||
| * accessKeyId: "AKIA123456789EXAMPLE", | ||
| * accessKeyId: "AKIA123456789EXAMPLE", | ||
| * userUuid: "user-uuid" | ||
| * } | ||
| * | ||
| * errors: | ||
| * InvalidSignatureError | ||
| * AccessKeyNotFoundError | ||
| * AccessKeyNotFoundError | ||
| * RequestTimeTooSkewedError | ||
| */ | ||
| MahiClient.prototype.verifySigV4 = function verifySigV4(request, cb) { | ||
| assert.object(request, 'request'); | ||
| assert.func(cb, 'callback'); | ||
|
|
||
| var self = this; | ||
|
|
||
| // Forward the original headers to mahi for SigV4 verification | ||
| var requestOptions = { | ||
| path: '/aws-verify', | ||
| headers: request.headers | ||
| }; | ||
|
|
||
| // Add request method and URL as query parameters since mahi needs them for verification | ||
| var qs = require('querystring'); | ||
|
|
||
| /* Add method and URL as query parameters for mahi verification */ | ||
| var queryParams = { | ||
| method: request.method, | ||
| url: request.url | ||
| }; | ||
| requestOptions.path += '?' + qs.stringify(queryParams); | ||
|
|
||
| self.http.post(requestOptions, {}, function (err, req, res, obj) { | ||
| if (err) { | ||
| cb(err); | ||
|
|
@@ -877,6 +877,118 @@ MahiClient.prototype.verifySigV4 = function verifySigV4(request, cb) { | |
| }; | ||
|
|
||
|
|
||
| /** | ||
| * @brief Push an access key to mahi's Redis cache | ||
| * | ||
| * Writes the key directly to Redis, bypassing the | ||
| * UFDS replication delay. Best-effort: errors are | ||
| * logged but not propagated to the caller. | ||
| * | ||
| * @param {Object} opts | ||
| * opts.accesskeyid: {string} Key ID (required) | ||
| * opts.accesskeysecret: {string} Secret (required) | ||
| * opts.ownerUuid: {string} Owner UUID (required) | ||
| * opts.status: {string} 'Active' or 'Inactive' | ||
| * opts.scope: {string|null} Scope JSON | ||
| * @param {Function} cb - callback(err) | ||
| */ | ||
| MahiClient.prototype.cachePush = | ||
|
danmcd marked this conversation as resolved.
|
||
| function cachePush(opts, cb) { | ||
| assert.object(opts, 'opts'); | ||
| assert.string(opts.accesskeyid, 'opts.accesskeyid'); | ||
| assert.string(opts.accesskeysecret, | ||
| 'opts.accesskeysecret'); | ||
| assert.string(opts.ownerUuid, 'opts.ownerUuid'); | ||
| assert.optionalString(opts.status, 'opts.status'); | ||
| assert.optionalString(opts.scope, 'opts.scope'); | ||
| assert.func(cb, 'callback'); | ||
|
|
||
| /* | ||
| * Validate scope at the client boundary to prevent | ||
| * malformed scope strings from poisoning the Redis | ||
| * cache. Null/undefined scope is valid (unrestricted | ||
| * key). | ||
| */ | ||
| if (opts.scope) { | ||
| var parsed = scopeSchema.parseScope(opts.scope); | ||
| if (parsed === null) { | ||
| cb(new Error('cachePush: opts.scope is not' + | ||
| ' valid scope JSON')); | ||
| return; | ||
| } | ||
| var result = scopeSchema.validateScope(parsed); | ||
| if (!result.valid) { | ||
| cb(new Error('cachePush: invalid scope: ' + | ||
| result.error)); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| var self = this; | ||
| var path = sprintf('/cache-push/%s', | ||
| opts.accesskeyid); | ||
| var body = { | ||
| accesskeysecret: opts.accesskeysecret, | ||
| ownerUuid: opts.ownerUuid, | ||
| status: opts.status || 'Active', | ||
| scope: opts.scope || null | ||
| }; | ||
|
|
||
| self.http.post(path, body, | ||
| function (err, req, res, obj) { | ||
| if (err) { | ||
| if (self.http.log) { | ||
| self.http.log.warn({ | ||
| err: err, | ||
| accesskeyid: opts.accesskeyid | ||
| }, 'cachePush: mahi call failed' + | ||
| ' (non-fatal)'); | ||
| } | ||
| cb(err); | ||
| return; | ||
| } | ||
| cb(null, obj); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * @brief Revoke an access key from mahi's Redis cache | ||
| * | ||
| * Deletes the key immediately from Redis, bypassing | ||
| * the UFDS replication delay. Best-effort: errors | ||
| * are logged but not propagated. | ||
| * | ||
| * @param {string} accesskeyid - Key ID to revoke | ||
| * @param {Function} cb - callback(err) | ||
| */ | ||
| MahiClient.prototype.scopeRevoke = | ||
| function scopeRevoke(accesskeyid, cb) { | ||
| assert.string(accesskeyid, 'accesskeyid'); | ||
| assert.func(cb, 'callback'); | ||
|
|
||
| var self = this; | ||
| var path = sprintf('/key-revoke/%s', | ||
| accesskeyid); | ||
|
|
||
| self.http.post(path, {}, | ||
| function (err, req, res, obj) { | ||
| if (err) { | ||
| if (self.http.log) { | ||
| self.http.log.warn({ | ||
| err: err, | ||
| accesskeyid: accesskeyid | ||
| }, 'scopeRevoke: mahi call failed' + | ||
| ' (non-fatal)'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, wouldn't this line and the prior on join together so it looks like: |
||
| } | ||
| cb(err); | ||
| return; | ||
| } | ||
| cb(null, obj); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| module.exports = { | ||
| MahiClient: MahiClient, | ||
| createClient: function (opts) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the coordination problem due to the "microservices" nature of current Manta & Triton?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the scope-schema to be in sync between consumers, so we share this here.