Skip to content

Commit 9b9ff8e

Browse files
David Pineaualexandre-merle
authored andcommitted
Auth: File backend: use new auth config file
- Use new auth config file in Config.js - Define a new env variable to change the path of the authentication config file - Update backend.js to use the new authentication data API - Update tests to remove references to the old, inconsistent auth config file format.
1 parent 3b960fb commit 9b9ff8e

6 files changed

Lines changed: 46 additions & 107 deletions

File tree

lib/Config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import assert from 'assert';
22
import fs from 'fs';
33
import path from 'path';
44

5+
import authDataChecker from './auth/in_memory/checker';
6+
57
/**
68
* Reads from a config file and returns the content as a config object
79
*/
@@ -175,11 +177,15 @@ class Config {
175177
if (auth === 'file' || auth === 'mem') {
176178
// Auth only checks for 'mem' since mem === file
177179
auth = 'mem';
178-
let authfile = `${__dirname}/auth/in_memory/vault.json`;
180+
let authfile = `${__dirname}/../conf/authdata.json`;
179181
if (process.env.S3AUTH_CONFIG) {
180182
authfile = process.env.S3AUTH_CONFIG;
181183
}
182-
this.authData = require(authfile);
184+
const authData = require(authfile);
185+
if (authDataChecker(authData)) {
186+
throw new Error('bad config: invalid auth config file.');
187+
}
188+
this.authData = authData;
183189
}
184190
if (process.env.S3SPROXYD) {
185191
data = process.env.S3SPROXYD;

lib/auth/in_memory/backend.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { errors } from 'arsenal';
22
import crypto from 'crypto';
33

44
import config from '../../Config';
5+
import Index from './index';
56

67
import { calculateSigningKey, hashSignature } from './vaultUtilities';
78

9+
const authIndex = new Index(config.authData);
10+
811
const backend = {
912
/** verifySignatureV2
1013
* @param {string} stringToSign - string to sign built per AWS rules
@@ -16,21 +19,22 @@ const backend = {
1619
*/
1720
verifySignatureV2: (stringToSign, signatureFromRequest,
1821
accessKey, options, callback) => {
19-
const account = config.authData.accountsKeyedbyAccessKey[accessKey];
20-
if (!account) {
22+
const entity = authIndex.getByKey(accessKey);
23+
if (!entity) {
2124
return callback(errors.InvalidAccessKeyId);
2225
}
23-
const secretKey = account.secretKey;
26+
const secretKey = entity.keys
27+
.filter(kv => kv.access === accessKey)[0].secret;
2428
const reconstructedSig =
2529
hashSignature(stringToSign, secretKey, options.algo);
2630
if (signatureFromRequest !== reconstructedSig) {
2731
return callback(errors.SignatureDoesNotMatch);
2832
}
2933
const userInfoToSend = {
30-
accountDisplayName: account.displayName,
31-
canonicalID: account.canonicalID,
32-
arn: account.arn,
33-
IAMdisplayName: account.IAMdisplayName,
34+
accountDisplayName: entity.accountDisplayName,
35+
canonicalID: entity.canonicalID,
36+
arn: entity.arn,
37+
IAMdisplayName: entity.IAMdisplayName,
3438
};
3539
const vaultReturnObject = {
3640
message: {
@@ -54,22 +58,23 @@ const backend = {
5458
*/
5559
verifySignatureV4: (stringToSign, signatureFromRequest, accessKey,
5660
region, scopeDate, options, callback) => {
57-
const account = config.authData.accountsKeyedbyAccessKey[accessKey];
58-
if (!account) {
61+
const entity = authIndex.getByKey(accessKey);
62+
if (!entity) {
5963
return callback(errors.InvalidAccessKeyId);
6064
}
61-
const secretKey = account.secretKey;
65+
const secretKey = entity.keys
66+
.filter(kv => kv.access === accessKey)[0].secret;
6267
const signingKey = calculateSigningKey(secretKey, region, scopeDate);
6368
const reconstructedSig = crypto.createHmac('sha256', signingKey)
6469
.update(stringToSign).digest('hex');
6570
if (signatureFromRequest !== reconstructedSig) {
6671
return callback(errors.SignatureDoesNotMatch);
6772
}
6873
const userInfoToSend = {
69-
accountDisplayName: account.displayName,
70-
canonicalID: account.canonicalID,
71-
arn: account.arn,
72-
IAMdisplayName: account.IAMdisplayName,
74+
accountDisplayName: entity.accountDisplayName,
75+
canonicalID: entity.canonicalID,
76+
arn: entity.arn,
77+
IAMdisplayName: entity.IAMdisplayName,
7378
};
7479
const vaultReturnObject = {
7580
message: {
@@ -92,13 +97,10 @@ const backend = {
9297
getCanonicalIds: (emails, log, cb) => {
9398
const results = {};
9499
emails.forEach(email => {
95-
const lowercasedEmail = email.toLowerCase();
96-
if (!config.authData.accountsKeyedbyEmail[lowercasedEmail]) {
100+
if (!authIndex.getByEmail(email)) {
97101
results[email] = 'NotFound';
98102
} else {
99-
results[email] =
100-
config.authData.accountsKeyedbyEmail[lowercasedEmail]
101-
.canonicalID;
103+
results[email] = authIndex.getByEmail(email).canonicalID;
102104
}
103105
});
104106
const vaultReturnObject = {
@@ -123,8 +125,7 @@ const backend = {
123125
getEmailAddresses: (canonicalIDs, options, cb) => {
124126
const results = {};
125127
canonicalIDs.forEach(canonicalId => {
126-
const foundAccount = config.authData
127-
.accountsKeyedbyCanID[canonicalId];
128+
const foundAccount = authIndex.getByCanId(canonicalId);
128129
if (!foundAccount || !foundAccount.email) {
129130
results[canonicalId] = 'NotFound';
130131
} else {

lib/auth/in_memory/vault.json

Lines changed: 0 additions & 79 deletions
This file was deleted.

tests/functional/s3curl/tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const aclBucket = 'acluniverse';
2323
const nonexist = 'nonexist';
2424
const prefix = 'topLevel';
2525
const delimiter = '/';
26-
const ownerCanonicalId = 'accessKey1canonicalID';
26+
const ownerCanonicalId = '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d52'
27+
+ '18e7cd47ef2be';
2728
const endpoint = `${transport}://${ipAddress}:8000`;
2829

2930
function diff(putFile, receivedFile, done) {

tests/unit/api/bucketDelete.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ describe('bucketDelete API', () => {
4747
assert.deepStrictEqual(err, errors.BucketNotEmpty);
4848
metadata.getBucket(bucketName, log, (err, md) => {
4949
assert.strictEqual(md.getName(), bucketName);
50-
metadata.listObject(usersBucket, canonicalID,
50+
metadata.listObject(usersBucket,
51+
authInfo.getCanonicalID(),
5152
null, null, null, log, (err, listResponse) => {
5253
assert.strictEqual(listResponse.Contents.length,
5354
1);

tests/unit/helpers.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export function shuffle(array) {
2121
array.forEach((item, currentIndex, array) => {
2222
randomIndex = Math.floor(Math.random() * length);
2323
temporaryValue = array[currentIndex];
24+
// eslint-disable-next-line no-param-reassign
2425
array[currentIndex] = array[randomIndex];
26+
// eslint-disable-next-line no-param-reassign
2527
array[randomIndex] = temporaryValue;
2628
});
2729
return array;
@@ -36,10 +38,17 @@ export function timeDiff(startTime) {
3638
}
3739

3840
export function makeAuthInfo(accessKey) {
39-
const canonicalID = accessKey === constants.publicId ?
40-
constants.publicId : `${accessKey}canonicalID`;
41+
const canIdMap = {
42+
accessKey1: '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7'
43+
+ 'cd47ef2be',
44+
accessKey2: '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7'
45+
+ 'cd47ef2bf',
46+
default: `${accessKey}canonicalID`,
47+
};
48+
canIdMap[constants.publicId] = constants.publicId;
49+
4150
return new AuthInfo({
42-
canonicalID,
51+
canonicalID: canIdMap[accessKey] || canIdMap.default,
4352
shortid: 'shortid',
4453
email: `${accessKey}@l.com`,
4554
accountDisplayName: `${accessKey}displayName`,

0 commit comments

Comments
 (0)