Skip to content

Commit bb9275c

Browse files
committed
fix(cli): disable FIPS support for garbage collection
Some S3 APIs in SDKv2 have a bug that always requires them to use a MD5 checksum. GC is using them, so we will temporarily disable the feature in FIPS environments.
1 parent f99eb4e commit bb9275c

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

packages/aws-cdk/lib/api/aws-auth/sdk.ts

+23-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ if (!regionUtil.getEndpointSuffix) {
2121
throw new Error('This version of AWS SDK for JS does not have the \'getEndpointSuffix\' function!');
2222
}
2323

24+
export interface S3ClientOptions {
25+
/**
26+
* If APIs are used that require MD5 checksums.
27+
*
28+
* Some S3 APIs in SDKv2 have a bug that always requires them to use a MD5 checksum.
29+
* These APIs are not going to be supported in a FIPS environment.
30+
*/
31+
needsMd5Checksums?: boolean;
32+
}
33+
2434
export interface ISDK {
2535
/**
2636
* The region this SDK has been instantiated for
@@ -56,7 +66,7 @@ export interface ISDK {
5666
ec2(): AWS.EC2;
5767
iam(): AWS.IAM;
5868
ssm(): AWS.SSM;
59-
s3(): AWS.S3;
69+
s3(options?: S3ClientOptions): AWS.S3;
6070
route53(): AWS.Route53;
6171
ecr(): AWS.ECR;
6272
ecs(): AWS.ECS;
@@ -173,19 +183,24 @@ export class SDK implements ISDK {
173183
return this.wrapServiceErrorHandling(new AWS.SSM(this.config));
174184
}
175185

176-
public s3(): AWS.S3 {
177-
return this.wrapServiceErrorHandling(new AWS.S3({
186+
public s3({
187+
needsMd5Checksums: apiRequiresMd5Checksum = false,
188+
}: S3ClientOptions = {}): AWS.S3 {
189+
const config = { ...this.config };
190+
191+
if (!apiRequiresMd5Checksum) {
178192
// In FIPS enabled environments, the MD5 algorithm is not available for use in crypto module.
179193
// However by default the S3 client is using an MD5 checksum for content integrity checking.
180194
// While this usage is technically allowed in FIPS (MD5 is only prohibited for cryptographic use),
181195
// in practice it is just easier to use an allowed checksum mechanism.
182196
// We are disabling the S3 content checksums, and are re-enabling the regular SigV4 body signing.
183197
// SigV4 uses SHA256 for their content checksum. This configuration matches the default behavior
184-
// of the AWS SDKv3 and is a safe choice for all users.
185-
s3DisableBodySigning: false,
186-
computeChecksums: false,
187-
...this.config,
188-
}));
198+
// of the AWS SDKv3 and is a safe choice for all users, except in the above APIs.
199+
config.s3DisableBodySigning = false;
200+
config.computeChecksums = false;
201+
}
202+
203+
return this.wrapServiceErrorHandling(new AWS.S3(config));
189204
}
190205

191206
public route53(): AWS.Route53 {

packages/aws-cdk/lib/api/garbage-collection/garbage-collector.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as crypto from 'node:crypto';
12
import * as cxapi from '@aws-cdk/cx-api';
23
import { S3 } from 'aws-sdk';
34
import * as chalk from 'chalk';
@@ -162,7 +163,19 @@ export class GarbageCollector {
162163
// SDKs
163164
const sdk = (await this.props.sdkProvider.forEnvironment(this.props.resolvedEnvironment, Mode.ForWriting)).sdk;
164165
const cfn = sdk.cloudFormation();
165-
const s3 = sdk.s3();
166+
167+
// Some S3 APIs in SDKv2 have a bug that always requires them to use a MD5 checksum.
168+
// These APIs are not going to be supported in a FIPS environment.
169+
// We fail with a nice error message.
170+
// Once we switch this code to SDKv3, this can be made work again by adding
171+
// `ChecksumAlgorithm: 'SHA256'` to the affected APIs.
172+
// Currently known to affect only DeleteObjects (note the plural)
173+
if (crypto.getFips() === 1) {
174+
throw new Error('Garbage Collection is currently not supported in FIPS environments');
175+
}
176+
const s3 = sdk.s3({
177+
needsMd5Checksums: true,
178+
});
166179

167180
const qualifier = await this.bootstrapQualifier(sdk, this.bootstrapStackName);
168181
const activeAssets = new ActiveAssetCache();

0 commit comments

Comments
 (0)