Skip to content

Commit

Permalink
fix(cli): assume role calls are skipping the proxy (#32291)
Browse files Browse the repository at this point in the history
`STSClientConfig` and `NodeHttpHandlerOptions` are different types, but all have optional properties only. That means that a call like this:

```ts
const credentials = await fromTemporaryCredentials({
  masterCredentials: mainCredentials.credentials,
  params: {
    RoleArn: roleArn,
    ExternalId: externalId,
    RoleSessionName: `aws-cdk-${safeUsername()}`,
    ...additionalOptions,
    TransitiveTagKeys: additionalOptions?.Tags ? additionalOptions.Tags.map((t) => t.Key!) : undefined,
  },
  clientConfig: {
    region,
    ...this.requestHandler, // type NodeHttpHandlerOptions
  },
})();
```

compiles just fine, when the intention was to write:

```ts
fromTemporaryCredentials({
  ...
  clientConfig: {
    region,
    requestHandler: this.requestHandler, // type NodeHttpHandlerOptions
  },
});
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
otaviomacedo authored Nov 27, 2024
1 parent deeb2ad commit 6c0f74e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync, promises as fs } from 'fs';
import * as querystring from 'node:querystring';
import * as os from 'os';
import * as path from 'path';
import {
Expand All @@ -23,6 +24,7 @@ import { PutObjectLockConfigurationCommand } from '@aws-sdk/client-s3';
import { CreateTopicCommand, DeleteTopicCommand } from '@aws-sdk/client-sns';
import { AssumeRoleCommand, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
import * as mockttp from 'mockttp';
import { CompletedRequest } from 'mockttp';
import {
cloneDirectory,
integTest,
Expand Down Expand Up @@ -2846,10 +2848,19 @@ integTest('requests go through a proxy when configured',
});
} finally {
await fs.rm(certDir, { recursive: true, force: true });
await proxyServer.stop();
}

// Checking that there was some interaction with the proxy
const requests = await endpoint.getSeenRequests();
expect(requests.length).toBeGreaterThan(0);
const actionsUsed = actions(await endpoint.getSeenRequests());
expect(actionsUsed).toContain('AssumeRole');
expect(actionsUsed).toContain('CreateChangeSet');
}),
);

function actions(requests: CompletedRequest[]): string[] {
return [...new Set(requests
.map(req => req.body.buffer.toString('utf-8'))
.map(body => querystring.decode(body))
.map(x => x.Action as string)
.filter(action => action != null))];
}
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/api/aws-auth/sdk-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export class SdkProvider {
},
clientConfig: {
region,
...this.requestHandler,
requestHandler: this.requestHandler,
},
})();

Expand Down

0 comments on commit 6c0f74e

Please # to comment.