Skip to content

Commit ccd03cc

Browse files
feat: remove deprecated managed IaC drift detection (#4908)
* feat: remove deprecated managed IaC drift detection managed drift detection has been deprecated with e6ad44a and is now being removed after a 90-day period. * fix: linting issues * fix: iac update-exclude-policy acceptance test * feat: fail `iac describe` when `--only-managed` flag provided * feat: upgrade iac describe to driftctl 0.40.0 * chore: ignore false-positive secret leaks from test fixtures * chore: add gitleaks ignore line after rebase
1 parent 62175e6 commit ccd03cc

18 files changed

+88
-753
lines changed

.gitleaksignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,6 @@ cba65a3a91c64db2ee92c87e5972602b6c959586:test/fixtures/sast/sample-analyze-folde
7979
c2de35484dcad696a6ee32f2fa317d5cfaffc133:test/fixtures/code/sample-analyze-folders-response.json:generic-api-key:3
8080
668e99c11a12699d9b1aca20cf48e1969055acf5:test/fixtures/sast/sample-analyze-scm-project-response.json:generic-api-key:4
8181
0fb9746f823f48b2802269569e8575f4dfd3d95d:help/cli-commands/iac-test.md:snyk-api-token:219
82+
168e6f2b48bc294e558d648626a1e00ccd85decc:test/jest/unit/lib/iac/drift/fixtures/all.console:aws-access-token:98
83+
4c12242de73be79ebd768468e065790f0b9d23a7:test/jest/unit/lib/iac/drift/fixtures/all.console:aws-access-token:98
84+
25f37b4c609380452b0b96c3853b69e4dc29bb48:test/jest/unit/lib/iac/drift/fixtures/all.console:aws-access-token:98

package-lock.json

Lines changed: 0 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"glob": "^7.1.7",
8585
"global-agent": "^2.1.12",
8686
"jest-json-schema": "^6.1.0",
87-
"jsondiffpatch": "^0.4.1",
8887
"lodash.assign": "^4.2.0",
8988
"lodash.camelcase": "^4.3.0",
9089
"lodash.capitalize": "^4.2.1",

src/cli/commands/describe.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@ import {
66
parseDriftAnalysisResults,
77
processAnalysis,
88
} from '../../lib/iac/drift';
9+
import { CustomError } from '../../lib/errors';
910
import { getIacOrgSettings } from './test/iac/local-execution/org-settings/get-iac-org-settings';
1011
import { UnsupportedEntitlementCommandError } from './test/iac/local-execution/assert-iac-options-flag';
1112
import config from '../../lib/config';
1213
import { addIacDriftAnalytics } from './test/iac/local-execution/analytics';
1314
import * as analytics from '../../lib/analytics';
1415
import { findAndLoadPolicy } from '../../lib/policy';
15-
import { DescribeRequiredArgumentError } from '../../lib/errors/describe-required-argument-error';
16-
import help from './help';
1716
import { DCTL_EXIT_CODES, runDriftCTL } from '../../lib/iac/drift/driftctl';
17+
import { IaCErrorCodes } from './test/iac/local-execution/types';
18+
import { getErrorStringCode } from './test/iac/local-execution/error-utils';
1819

20+
export class FlagError extends CustomError {
21+
constructor(flag: string) {
22+
const msg = `Unsupported flag "${flag}" provided. Run snyk iac describe --help for supported flags`;
23+
super(msg);
24+
this.code = IaCErrorCodes.FlagError;
25+
this.strCode = getErrorStringCode(this.code);
26+
this.userMessage = msg;
27+
}
28+
}
1929
export default async (...args: MethodArgs): Promise<any> => {
2030
const { options } = processCommandArgs(...args);
2131

@@ -25,6 +35,10 @@ export default async (...args: MethodArgs): Promise<any> => {
2535
return legacyError('describe');
2636
}
2737

38+
if (options['only-managed']) {
39+
return Promise.reject(new FlagError('only-managed'));
40+
}
41+
2842
// Ensure that we are allowed to run that command
2943
// by checking the entitlement
3044
const orgPublicId = options.org ?? config.org;
@@ -57,11 +71,6 @@ export default async (...args: MethodArgs): Promise<any> => {
5771
const output = await processAnalysis(options, describe);
5872
process.stdout.write(output);
5973
} catch (e) {
60-
if (e instanceof DescribeRequiredArgumentError) {
61-
// when missing a required arg we will display help to explain
62-
const helpMsg = await help('iac', 'describe');
63-
console.log(helpMsg);
64-
}
6574
return Promise.reject(e);
6675
}
6776
};

src/cli/commands/test/iac/local-execution/analytics.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export function addIacDriftAnalytics(
9191
analytics.add('iac-drift-total-unmanaged', analysis.summary.total_unmanaged);
9292
analytics.add('iac-drift-total-managed', analysis.summary.total_managed);
9393
analytics.add('iac-drift-total-missing', analysis.summary.total_missing);
94-
analytics.add('iac-drift-total-changed', analysis.summary.total_changed);
9594
analytics.add(
9695
'iac-drift-iac-source-count',
9796
analysis.summary.total_iac_source_count,

src/lib/errors/describe-exclusive-argument-error.ts

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

src/lib/errors/describe-required-argument-error.ts

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

src/lib/iac/drift.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,14 @@ import {
33
DescribeOptions,
44
DriftAnalysis,
55
DriftctlExecutionResult,
6-
DriftCTLOptions,
76
GenDriftIgnoreOptions,
87
} from './types';
98
import { Policy } from '../policy/find-and-load-policy';
10-
import { DescribeExclusiveArgumentError } from '../errors/describe-exclusive-argument-error';
11-
import { DescribeRequiredArgumentError } from '../errors/describe-required-argument-error';
129
import snykLogoSVG from './assets/snyk-logo';
1310
import snykFaviconBase64 from './assets/snyk-favicon';
1411
import { getHumanReadableAnalysis } from './drift/output';
1512
import { runDriftCTL } from './drift/driftctl';
1613

17-
export const DescribeExclusiveArgs = [
18-
'all',
19-
'only-managed',
20-
'drift',
21-
'only-unmanaged',
22-
];
23-
24-
export const DescribeRequiredArgs = [
25-
'all',
26-
'only-managed',
27-
'drift',
28-
'only-unmanaged',
29-
];
30-
31-
export const validateArgs = (options: DriftCTLOptions): void => {
32-
if (options.kind === 'describe') {
33-
return validateDescribeArgs(options as DescribeOptions);
34-
}
35-
};
36-
37-
const validateDescribeArgs = (options: DescribeOptions): void => {
38-
// Check that there is no more than one of the exclusive arguments
39-
let count = 0;
40-
for (const describeExclusiveArg of DescribeExclusiveArgs) {
41-
if (options[describeExclusiveArg]) {
42-
count++;
43-
}
44-
}
45-
if (count > 1) {
46-
throw new DescribeExclusiveArgumentError();
47-
}
48-
49-
// Check we have one of the required arguments
50-
count = 0;
51-
for (const describeRequiredArgs of DescribeRequiredArgs) {
52-
if (options[describeRequiredArgs]) {
53-
count++;
54-
}
55-
}
56-
if (count === 0) {
57-
throw new DescribeRequiredArgumentError();
58-
}
59-
};
60-
6114
export const parseDriftAnalysisResults = (input: string): DriftAnalysis => {
6215
return JSON.parse(input) as DriftAnalysis;
6316
};
@@ -78,10 +31,6 @@ export const updateExcludeInPolicy = (
7831
const excludedResources = driftignoreFromPolicy(policy);
7932
const addResource = (res) => excludedResources.push(`${res.type}.${res.id}`);
8033

81-
if (!options['exclude-changed'] && analysis.summary.total_changed > 0) {
82-
analysis.differences?.forEach((change) => addResource(change.res));
83-
}
84-
8534
if (!options['exclude-missing'] && analysis.summary.total_missing > 0) {
8635
analysis.missing?.forEach((res) => addResource(res));
8736
}

src/lib/iac/drift/driftctl.ts

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
createIgnorePattern,
1515
verifyServiceMappingExists,
1616
} from '../service-mappings';
17-
import { validateArgs } from '../drift';
1817
import * as debugLib from 'debug';
1918
import { makeRequest } from '../../request';
2019
import * as child_process from 'child_process';
@@ -36,29 +35,29 @@ export const DCTL_EXIT_CODES = {
3635
EXIT_ERROR: 2,
3736
};
3837

39-
export const driftctlVersion = 'v0.36.0';
38+
export const driftctlVersion = 'v0.40.0';
4039

4140
const driftctlChecksums = {
4241
driftctl_darwin_amd64:
43-
'c9b44613694931d5033d16cf6396c2611d115f3c6971c8215c04b6ce321e9bb5',
42+
'4eb86bd4a1e965c2552879795434143f1db974b2d795581b9ddb69d0bd8a245a',
4443
'driftctl_windows_386.exe':
45-
'e37505fa9875b3d3c29fdfffebbe03f60154aae3e8d7057cad469dfceec47151',
44+
'a02f079cb128ba46396db9654bc8bb8066ebde0539ebbeb401a40a81dfc8f733',
4645
driftctl_darwin_arm64:
47-
'a18cb7039bf67bf0addf628887cfd12488895492d7e0c3a31a0a51005bc0d583',
46+
'dfdee8138eb817cc066b8bf915c808fbd53536ee1757b34ca6e518e1c2ad1ba5',
4847
driftctl_linux_arm64:
49-
'6dcc235d511546cc3573f5a7b3fc2a825a4dff7e08df481a55f5826ac6802059',
48+
'8816f1378138c2ce585c762e109b5fdd41b7144b915e97759ceae946db023540',
5049
'driftctl_windows_arm.exe':
51-
'c7bf2d1f268a5c4b6985d02a0d2e98ecf43ef5bc4de14360568f0233e206e471',
50+
'6217151b4168e93ffdd6e005cb1cf03768f371cd6b412f53605fde46343c08d1',
5251
driftctl_linux_amd64:
53-
'f2b388a6f92772e35320cb2240b68dab2c62c87d4a84ffc88bb42020cb0ab805',
52+
'84e2462454956a4df794a24e0f4d2351299212d772b8602fc5070e6174ac1324',
5453
'driftctl_windows_amd64.exe':
55-
'696e067ee37c156b175c51e55481e823fb8601c8d69133cb12ba8a3f2e22aa68',
54+
'1561fd04e3d428c39ae95f81214517bbf62e8333156bf538a2d385005e350c8b',
5655
'driftctl_windows_arm64.exe':
57-
'5531adc30e0d1431b692062bbc7c91536d86f5f5d212a5bd3083fec6007f0be5',
56+
'76f939d836da64fa9dab63f0eeffd09a0de7e353b034296b8f1582cdff6f2a61',
5857
driftctl_linux_arm:
59-
'c6bcd8987f633d310b9872c5635112d8fd479f4117518aa4864fa38874c7869e',
58+
'7f669ca49e152779a09587ff0e58dedd3996229cc8ff3e5cdc371895eaa994f6',
6059
driftctl_linux_386:
61-
'864ff0810466ed2917b3347866b5da80fae43e2487b18a563f1d7f299e5f1518',
60+
'e6bbdf341148e81511d30dd5afe2fa2ef08f3b0b75079bf0bde2b790d75beb8a',
6261
};
6362

6463
const dctlBaseUrl = 'https://static.snyk.io/cli/driftctl/';
@@ -150,14 +149,6 @@ const generateScanFlags = async (
150149
args.push('--strict');
151150
}
152151

153-
if (options.deep || options.all) {
154-
args.push('--deep');
155-
}
156-
157-
if (options['only-managed'] || options.drift) {
158-
args.push('--only-managed');
159-
}
160-
161152
if (options['only-unmanaged']) {
162153
args.push('--only-unmanaged');
163154
}
@@ -238,24 +229,6 @@ export const runDriftCTL = async ({
238229
stdio?: StdioOptions;
239230
}): Promise<DriftctlExecutionResult> => {
240231
const path = await findOrDownload();
241-
await validateArgs(options);
242-
243-
if (options.kind === 'describe') {
244-
const descOptions = options as DescribeOptions;
245-
246-
if (
247-
descOptions.deep ||
248-
descOptions.all ||
249-
descOptions['only-managed'] ||
250-
descOptions.drift
251-
) {
252-
process.stderr.write(
253-
`DEPRECATION NOTICE: Drift detection of managed resources,\n` +
254-
`including --only-managed and --drift has been deprecated.\n` +
255-
`The end-of-life date for drift detection of managed resources is September 30. 2023.\n\n`,
256-
);
257-
}
258-
}
259232

260233
const args = await generateArgs(options, driftIgnore);
261234

0 commit comments

Comments
 (0)