Skip to content

Commit 603e164

Browse files
remove todo from vault-238
ISSUE: BB-730
1 parent 73afa1d commit 603e164

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

bin/ensureServiceUser

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ class PolicyHandler extends BaseHandler {
164164
const res = await this.stsClient.send(command);
165165
accountId = res.Account;
166166
} catch (err) {
167-
// Workaround a Vault issue on 8.3 branch
168-
// https://scality.atlassian.net/browse/VAULT-238
169-
accountId = '000000000000';
167+
this.log.error('failed to get caller identity', {
168+
error: errorUtils.reshapeExceptionError(err),
169+
});
170+
throw err;
170171
}
171172
}
172173

extensions/utils/VaultClientWrapper.js

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { fromTemporaryCredentials } = require('@aws-sdk/credential-providers');
2-
const { errorUtils } = require('arsenal');
2+
const { GetCallerIdentityCommand } = require('@aws-sdk/client-sts');
33

44
const { authTypeAssumeRole, authTypeNone } = require('../../lib/constants');
55
const VaultClientCache = require('../../lib/clients/VaultClientCache');
@@ -44,10 +44,10 @@ class VaultClientWrapper {
4444
}
4545

4646
const stsWithCreds = CredentialsManager.resolveExternalFileSync(sts, this.logger);
47+
const endpoint = `${sts.transport || 'https'}://${sts.host}:${sts.port}`;
4748

48-
// FIXME: works with vault 7.10 but not 8.3 (return 501)
49-
// https://scality.atlassian.net/browse/VAULT-238
50-
this._tempCredsPromise = Promise.resolve({ Account: '000000000000' })
49+
const getCallerIdentity = new GetCallerIdentityCommand({});
50+
this._tempCredsPromise = stsWithCreds.send(getCallerIdentity)
5151
.then(res => {
5252
const roleArn = `arn:aws:iam::${res.Account}:role/${roleName}`;
5353
const roleSessionName = `${this._clientId}`;
@@ -57,50 +57,43 @@ class VaultClientWrapper {
5757
secretAccessKey: stsWithCreds.secretKey,
5858
};
5959

60-
// Create a credential provider that assumes the role
61-
return fromTemporaryCredentials({
62-
masterCredentials,
60+
const creds = fromTemporaryCredentials({
6361
params: {
6462
RoleArn: roleArn,
6563
RoleSessionName: roleSessionName,
66-
// default expiration: 1 hour
6764
},
6865
clientConfig: {
69-
endpoint: `${this._transport}://${sts.host}:${sts.port}`,
70-
region: 'us-east-1',
71-
tls: this._transport === 'https',
72-
maxAttempts: 1,
73-
requestHandler: {
74-
httpAgent: this._transport === 'http' ? this.stsAgent : undefined,
75-
httpsAgent: this._transport === 'https' ? this.stsAgent : undefined,
76-
connectionTimeout: 0,
77-
socketTimeout: 0,
78-
},
66+
endpoint,
67+
region: sts.region,
68+
credentials: masterCredentials,
69+
requestHandler: this.stsAgent,
7970
},
8071
});
72+
return creds();
8173
})
82-
.then(creds => {
83-
this._tempCredsPromiseResolved = true;
84-
return creds;
74+
.then(res => {
75+
this._tempCreds = {
76+
accessKey: res.accessKeyId,
77+
secretKey: res.secretAccessKey,
78+
sessionToken: res.sessionToken,
79+
};
8580
})
8681
.catch(err => {
87-
if (err.retryable) {
88-
const retryDelayMs = 5000;
89-
90-
this.logger.error('could not set up temporary credentials, retrying', {
91-
retryDelayMs,
92-
error: errorUtils.reshapeExceptionError(err),
93-
});
94-
95-
setTimeout(() => this._storeAWSCredentialsPromise(), retryDelayMs);
96-
} else {
97-
this.logger.error('could not set up temporary credentials', {
98-
error: errorUtils.reshapeExceptionError(err),
99-
});
100-
}
82+
this.logger.error('failed to get temporary credentials', {
83+
error: errorUtils.reshapeExceptionError(err),
84+
});
85+
throw err;
10186
});
10287
}
10388

89+
getSTSCredentials() {
90+
if (this._authConfig.type !== authTypeAssumeRole) {
91+
return null;
92+
}
93+
94+
return this._tempCreds;
95+
}
96+
10497
getAccountId(canonicalId, cb) {
10598
this.getAccountIds([canonicalId], (err, res) => {
10699
if (err) {

0 commit comments

Comments
 (0)