snyk 1.754.0 → 1.758.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/cli/917.index.js +211 -63
  2. package/dist/cli/917.index.js.map +1 -1
  3. package/dist/cli/commands/test/iac-local-execution/assert-iac-options-flag.d.ts +4 -1
  4. package/dist/cli/commands/test/iac-local-execution/index.d.ts +6 -2
  5. package/dist/cli/commands/test/iac-local-execution/measurable-methods.d.ts +1 -1
  6. package/dist/cli/commands/test/iac-local-execution/oci-pull.d.ts +9 -3
  7. package/dist/cli/commands/test/iac-local-execution/types.d.ts +11 -4
  8. package/dist/cli/index.js +8 -4
  9. package/dist/cli/index.js.map +1 -1
  10. package/dist/lib/analytics/index.d.ts +0 -9
  11. package/dist/lib/errors/unsupported-entitlement-error.d.ts +6 -0
  12. package/dist/lib/errors/unsupported-feature-flag-error.d.ts +1 -0
  13. package/help/commands-docs/_EXAMPLES.md +9 -0
  14. package/help/commands-docs/config.md +9 -0
  15. package/help/commands-docs/iac-examples.md +3 -0
  16. package/help/commands-docs/iac.md +8 -0
  17. package/help/commands-man/snyk-auth.1 +1 -1
  18. package/help/commands-man/snyk-code.1 +1 -1
  19. package/help/commands-man/snyk-config.1 +10 -1
  20. package/help/commands-man/snyk-container.1 +1 -1
  21. package/help/commands-man/snyk-help.1 +1 -1
  22. package/help/commands-man/snyk-iac.1 +11 -1
  23. package/help/commands-man/snyk-ignore.1 +1 -1
  24. package/help/commands-man/snyk-monitor.1 +1 -1
  25. package/help/commands-man/snyk-policy.1 +1 -1
  26. package/help/commands-man/snyk-protect.1 +1 -1
  27. package/help/commands-man/snyk-test.1 +1 -1
  28. package/help/commands-man/snyk-wizard.1 +1 -1
  29. package/help/commands-man/snyk-woof.1 +1 -1
  30. package/help/commands-man/snyk.1 +10 -1
  31. package/help/commands-md/snyk-config.md +9 -0
  32. package/help/commands-md/snyk-iac.md +11 -0
  33. package/help/commands-md/snyk.md +9 -0
  34. package/help/commands-txt/snyk-auth.txt +58 -58
  35. package/help/commands-txt/snyk-code.txt +65 -65
  36. package/help/commands-txt/snyk-config.txt +86 -74
  37. package/help/commands-txt/snyk-container.txt +74 -74
  38. package/help/commands-txt/snyk-help.txt +52 -52
  39. package/help/commands-txt/snyk-iac.txt +109 -95
  40. package/help/commands-txt/snyk-ignore.txt +72 -72
  41. package/help/commands-txt/snyk-monitor.txt +199 -199
  42. package/help/commands-txt/snyk-policy.txt +53 -53
  43. package/help/commands-txt/snyk-protect.txt +53 -53
  44. package/help/commands-txt/snyk-test.txt +199 -199
  45. package/help/commands-txt/snyk-wizard.txt +54 -54
  46. package/help/commands-txt/snyk-woof.txt +53 -53
  47. package/help/commands-txt/snyk.txt +236 -222
  48. package/package.json +2 -2
@@ -112,7 +112,7 @@ exports.performanceAnalyticsObject = {
112
112
  "use strict";
113
113
 
114
114
  Object.defineProperty(exports, "__esModule", ({ value: true }));
115
- exports.assertIaCOptionsFlags = exports.FlagValueError = exports.FlagError = void 0;
115
+ exports.assertIaCOptionsFlags = exports.UnsupportedEntitlementFlagError = exports.FlagValueError = exports.FlagError = void 0;
116
116
  const errors_1 = __webpack_require__(55191);
117
117
  const args_1 = __webpack_require__(94765);
118
118
  const error_utils_1 = __webpack_require__(23872);
@@ -177,6 +177,16 @@ class FlagValueError extends errors_1.CustomError {
177
177
  }
178
178
  }
179
179
  exports.FlagValueError = FlagValueError;
180
+ class UnsupportedEntitlementFlagError extends errors_1.CustomError {
181
+ constructor(key, entitlementName) {
182
+ const flag = getFlagName(key);
183
+ super(`Unsupported flag: ${flag} - Missing the ${entitlementName} entitlement`);
184
+ this.code = types_1.IaCErrorCodes.UnsupportedEntitlementFlagError;
185
+ this.strCode = error_utils_1.getErrorStringCode(this.code);
186
+ this.userMessage = `Flag "${flag}" is currently not supported for this org. To enable it, please contact snyk support.`;
187
+ }
188
+ }
189
+ exports.UnsupportedEntitlementFlagError = UnsupportedEntitlementFlagError;
180
190
  /**
181
191
  * Validates the command line flags passed to the snyk iac test
182
192
  * command. The current argument parsing is very permissive and
@@ -655,7 +665,7 @@ exports.computeCustomRulesBundleChecksum = computeCustomRulesBundleChecksum;
655
665
  "use strict";
656
666
 
657
667
  Object.defineProperty(exports, "__esModule", ({ value: true }));
658
- exports.FailedToExecuteCustomRulesError = exports.FailedToPullCustomBundleError = exports.isValidURL = exports.removeFileContent = exports.test = void 0;
668
+ exports.FailedToExecuteCustomRulesError = exports.FailedToPullCustomBundleError = exports.pullIaCCustomRules = exports.isValidURL = exports.removeFileContent = exports.test = void 0;
659
669
  const detect_1 = __webpack_require__(45318);
660
670
  const types_1 = __webpack_require__(42258);
661
671
  const analytics_1 = __webpack_require__(22716);
@@ -664,63 +674,32 @@ const policy_1 = __webpack_require__(25476);
664
674
  const measurable_methods_1 = __webpack_require__(78272);
665
675
  const feature_flags_1 = __webpack_require__(63011);
666
676
  const assert_iac_options_flag_1 = __webpack_require__(68590);
677
+ const user_config_1 = __webpack_require__(28137);
667
678
  const config_1 = __webpack_require__(22541);
668
679
  const policy_2 = __webpack_require__(32615);
669
680
  const errors_1 = __webpack_require__(55191);
670
681
  const error_utils_1 = __webpack_require__(23872);
671
682
  const oci_pull_1 = __webpack_require__(5029);
683
+ const unsupported_entitlement_error_1 = __webpack_require__(78673);
672
684
  // this method executes the local processing engine and then formats the results to adapt with the CLI output.
673
685
  // this flow is the default GA flow for IAC scanning.
674
686
  async function test(pathToScan, options) {
675
- var _a, _b, _c;
687
+ var _a;
676
688
  try {
677
- const org = (_a = options.org) !== null && _a !== void 0 ? _a : config_1.default.org;
678
- const iacOrgSettings = await measurable_methods_1.getIacOrgSettings(org);
679
- const customRulesPath = await customRulesPathForOrg(options.rules, org);
680
- const OCIRegistryURL = (((_b = iacOrgSettings.customRules) === null || _b === void 0 ? void 0 : _b.isEnabled) && ((_c = iacOrgSettings.customRules) === null || _c === void 0 ? void 0 : _c.ociRegistryURL)) ||
681
- process.env.OCI_REGISTRY_URL;
682
- if (OCIRegistryURL && customRulesPath) {
689
+ let customRulesPath;
690
+ const orgPublicId = (_a = options.org) !== null && _a !== void 0 ? _a : config_1.default.org;
691
+ const iacOrgSettings = await measurable_methods_1.getIacOrgSettings(orgPublicId);
692
+ if (options.rules) {
693
+ await assertRulesFlagAvailable(orgPublicId, iacOrgSettings);
694
+ customRulesPath = options.rules;
695
+ }
696
+ const isOCIRegistryURLProvided = checkOCIRegistryURLProvided(iacOrgSettings);
697
+ if (isOCIRegistryURLProvided && customRulesPath) {
683
698
  throw new FailedToExecuteCustomRulesError();
684
699
  }
685
- if (OCIRegistryURL) {
686
- if (!isValidURL(OCIRegistryURL)) {
687
- throw new oci_pull_1.InvalidRemoteRegistryURLError();
688
- }
689
- const URLComponents = oci_pull_1.extractURLComponents(OCIRegistryURL);
690
- const username = process.env.OCI_REGISTRY_USERNAME;
691
- const password = process.env.OCI_REGISTRY_PASSWORD;
692
- const opt = {
693
- username,
694
- password,
695
- reqOptions: {
696
- acceptManifest: types_1.manifestContentType,
697
- acceptLayer: types_1.layerContentType,
698
- indexContentType: '',
699
- },
700
- };
701
- try {
702
- await measurable_methods_1.pull(URLComponents, opt);
703
- }
704
- catch (err) {
705
- if (err.statusCode === 401) {
706
- throw new FailedToPullCustomBundleError('There was an authentication error. Incorrect credentials provided.');
707
- }
708
- else if (err.statusCode === 404) {
709
- throw new FailedToPullCustomBundleError('The remote repository could not be found. Please check the provided URL.');
710
- }
711
- else if (err instanceof oci_pull_1.InvalidManifestSchemaVersionError) {
712
- throw new FailedToPullCustomBundleError(err.message);
713
- }
714
- else if (err instanceof oci_pull_1.FailedToBuildOCIArtifactError) {
715
- throw new oci_pull_1.FailedToBuildOCIArtifactError();
716
- }
717
- else if (err instanceof oci_pull_1.InvalidRemoteRegistryURLError) {
718
- throw new oci_pull_1.InvalidRemoteRegistryURLError();
719
- }
720
- else {
721
- throw new FailedToPullCustomBundleError();
722
- }
723
- }
700
+ if (isOCIRegistryURLProvided) {
701
+ await assertPullAvailable(orgPublicId, iacOrgSettings);
702
+ await pullIaCCustomRules(iacOrgSettings);
724
703
  }
725
704
  else {
726
705
  await measurable_methods_1.initLocalCache({ customRulesPath });
@@ -729,7 +708,7 @@ async function test(pathToScan, options) {
729
708
  const filesToParse = await measurable_methods_1.loadFiles(pathToScan, options);
730
709
  const { parsedFiles, failedFiles } = await measurable_methods_1.parseFiles(filesToParse, options);
731
710
  // Duplicate all the files and run them through the custom engine.
732
- if (customRulesPath || OCIRegistryURL) {
711
+ if (customRulesPath || isOCIRegistryURLProvided) {
733
712
  parsedFiles.push(...parsedFiles.map((file) => ({
734
713
  ...file,
735
714
  engineType: types_1.EngineType.Custom,
@@ -764,15 +743,6 @@ async function test(pathToScan, options) {
764
743
  }
765
744
  }
766
745
  exports.test = test;
767
- async function customRulesPathForOrg(customRulesPath, publicOrgId) {
768
- if (!customRulesPath)
769
- return;
770
- const isCustomRulesSupported = (await feature_flags_1.isFeatureFlagSupportedForOrg('iacCustomRules', publicOrgId)).ok;
771
- if (isCustomRulesSupported) {
772
- return customRulesPath;
773
- }
774
- throw new assert_iac_options_flag_1.FlagError('rules', 'iacCustomRules');
775
- }
776
746
  function removeFileContent({ filePath, fileType, failureReason, projectType, }) {
777
747
  return {
778
748
  filePath,
@@ -782,10 +752,10 @@ function removeFileContent({ filePath, fileType, failureReason, projectType, })
782
752
  };
783
753
  }
784
754
  exports.removeFileContent = removeFileContent;
785
- function isValidURL(string) {
755
+ function isValidURL(str) {
786
756
  let url;
787
757
  try {
788
- url = new URL(string);
758
+ url = new URL(str);
789
759
  }
790
760
  catch (e) {
791
761
  return false;
@@ -793,6 +763,144 @@ function isValidURL(string) {
793
763
  return url.protocol === 'http:' || url.protocol === 'https:';
794
764
  }
795
765
  exports.isValidURL = isValidURL;
766
+ /**
767
+ * Checks if the OCI registry URL has been provided.
768
+ */
769
+ function checkOCIRegistryURLProvided(iacOrgSettings) {
770
+ return (checkOCIRegistryURLExistsInSettings(iacOrgSettings) ||
771
+ !!user_config_1.config.get('oci-registry-url'));
772
+ }
773
+ /**
774
+ * Checks if the OCI registry URL was provided in the org's IaC settings.
775
+ */
776
+ function checkOCIRegistryURLExistsInSettings(iacOrgSettings) {
777
+ var _a, _b;
778
+ return (!!((_a = iacOrgSettings.customRules) === null || _a === void 0 ? void 0 : _a.isEnabled) &&
779
+ !!((_b = iacOrgSettings.customRules) === null || _b === void 0 ? void 0 : _b.ociRegistryURL));
780
+ }
781
+ /**
782
+ * Extracts the OCI registry URL components from the org's IaC settings.
783
+ */
784
+ function getOCIRegistryURLComponentsFromSettings(iacOrgSettings) {
785
+ const settingsOCIRegistryURL = iacOrgSettings.customRules.ociRegistryURL;
786
+ if (!isValidURL(settingsOCIRegistryURL)) {
787
+ throw new oci_pull_1.InvalidRemoteRegistryURLError();
788
+ }
789
+ return {
790
+ ...oci_pull_1.extractOCIRegistryURLComponents(settingsOCIRegistryURL),
791
+ tag: iacOrgSettings.customRules.ociRegistryTag || 'latest',
792
+ };
793
+ }
794
+ /**
795
+ * Extracts the OCI registry URL components from the environment variables.
796
+ */
797
+ function getOCIRegistryURLComponentsFromEnv() {
798
+ const envOCIRegistryURL = user_config_1.config.get('oci-registry-url');
799
+ if (!isValidURL(envOCIRegistryURL)) {
800
+ throw new oci_pull_1.InvalidRemoteRegistryURLError();
801
+ }
802
+ return oci_pull_1.extractOCIRegistryURLComponents(envOCIRegistryURL);
803
+ }
804
+ /**
805
+ * Gets the OCI registry URL components from either the env variables or the IaC org settings.
806
+ */
807
+ function getOCIRegistryURLComponents(iacOrgSettings) {
808
+ if (checkOCIRegistryURLExistsInSettings(iacOrgSettings)) {
809
+ return getOCIRegistryURLComponentsFromSettings(iacOrgSettings);
810
+ }
811
+ // Default is to get the URL from env variables.
812
+ return getOCIRegistryURLComponentsFromEnv();
813
+ }
814
+ /**
815
+ * Pull and store the IaC custom-rules bundle from the remote OCI Registry.
816
+ */
817
+ async function pullIaCCustomRules(iacOrgSettings) {
818
+ const ociRegistryURLComponents = getOCIRegistryURLComponents(iacOrgSettings);
819
+ const username = user_config_1.config.get('oci-registry-username');
820
+ const password = user_config_1.config.get('oci-registry-password');
821
+ const opt = {
822
+ username,
823
+ password,
824
+ reqOptions: {
825
+ acceptManifest: types_1.manifestContentType,
826
+ acceptLayer: types_1.layerContentType,
827
+ indexContentType: '',
828
+ },
829
+ };
830
+ try {
831
+ await measurable_methods_1.pull(ociRegistryURLComponents, opt);
832
+ }
833
+ catch (err) {
834
+ if (err.statusCode === 401) {
835
+ throw new FailedToPullCustomBundleError('There was an authentication error. Incorrect credentials provided.');
836
+ }
837
+ else if (err.statusCode === 404) {
838
+ throw new FailedToPullCustomBundleError('The remote repository could not be found. Please check the provided URL.');
839
+ }
840
+ else if (err instanceof oci_pull_1.InvalidManifestSchemaVersionError) {
841
+ throw new FailedToPullCustomBundleError(err.message);
842
+ }
843
+ else if (err instanceof oci_pull_1.FailedToBuildOCIArtifactError) {
844
+ throw new oci_pull_1.FailedToBuildOCIArtifactError();
845
+ }
846
+ else if (err instanceof oci_pull_1.InvalidRemoteRegistryURLError) {
847
+ throw new oci_pull_1.InvalidRemoteRegistryURLError();
848
+ }
849
+ else {
850
+ throw new FailedToPullCustomBundleError();
851
+ }
852
+ }
853
+ }
854
+ exports.pullIaCCustomRules = pullIaCCustomRules;
855
+ /**
856
+ * Asserts the custom-rules feature is available for the provided org.
857
+ */
858
+ async function assertCustomRulesAvailable(orgPublicId, iacOrgSettings) {
859
+ var _a;
860
+ const isCustomRulesEnabled = !!(await feature_flags_1.isFeatureFlagSupportedForOrg('iacCustomRules', orgPublicId)).ok;
861
+ if (!isCustomRulesEnabled) {
862
+ throw new errors_1.UnsupportedFeatureFlagError('iacCustomRules');
863
+ }
864
+ const isEntitledToCustomRules = !!((_a = iacOrgSettings.entitlements) === null || _a === void 0 ? void 0 : _a.iacCustomRulesEntitlement);
865
+ if (!isEntitledToCustomRules) {
866
+ throw new unsupported_entitlement_error_1.UnsupportedEntitlementError('iacCustomRulesEntitlement');
867
+ }
868
+ }
869
+ /**
870
+ * Asserts the --rules flag is available for the provided org.
871
+ */
872
+ async function assertRulesFlagAvailable(orgPublicId, iacOrgSettings) {
873
+ try {
874
+ await assertCustomRulesAvailable(orgPublicId, iacOrgSettings);
875
+ }
876
+ catch (err) {
877
+ if (err instanceof unsupported_entitlement_error_1.UnsupportedEntitlementError) {
878
+ throw new assert_iac_options_flag_1.UnsupportedEntitlementFlagError('rules', err.entitlement);
879
+ }
880
+ else if (err instanceof errors_1.UnsupportedFeatureFlagError) {
881
+ throw new assert_iac_options_flag_1.FlagError('rules', err.featureFlag);
882
+ }
883
+ else {
884
+ throw err;
885
+ }
886
+ }
887
+ }
888
+ /**
889
+ * Asserts the feature custom-rules bundles pulling feature is available for the provided org.
890
+ */
891
+ async function assertPullAvailable(orgPublicId, iacOrgSettings) {
892
+ try {
893
+ await assertCustomRulesAvailable(orgPublicId, iacOrgSettings);
894
+ }
895
+ catch (err) {
896
+ if (err instanceof unsupported_entitlement_error_1.UnsupportedEntitlementError) {
897
+ throw new oci_pull_1.UnsupportedEntitlementPullError(err.entitlement);
898
+ }
899
+ else if (err instanceof errors_1.UnsupportedFeatureFlagError) {
900
+ throw new oci_pull_1.UnsupportedFeatureFlagPullError(err.featureFlag);
901
+ }
902
+ }
903
+ }
796
904
  class FailedToPullCustomBundleError extends errors_1.CustomError {
797
905
  constructor(message) {
798
906
  super(message || 'Could not pull custom bundle');
@@ -1086,7 +1194,7 @@ exports.pull = measurableOciPull;
1086
1194
  "use strict";
1087
1195
 
1088
1196
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1089
- exports.InvalidRemoteRegistryURLError = exports.InvalidManifestSchemaVersionError = exports.FailedToBuildOCIArtifactError = exports.pull = exports.extractURLComponents = exports.CUSTOM_RULES_TARBALL = void 0;
1197
+ exports.UnsupportedEntitlementPullError = exports.UnsupportedFeatureFlagPullError = exports.InvalidRemoteRegistryURLError = exports.InvalidManifestSchemaVersionError = exports.FailedToBuildOCIArtifactError = exports.pull = exports.extractOCIRegistryURLComponents = exports.CUSTOM_RULES_TARBALL = void 0;
1090
1198
  const registryClient = __webpack_require__(28310);
1091
1199
  const fs_1 = __webpack_require__(35747);
1092
1200
  const path = __webpack_require__(85622);
@@ -1099,7 +1207,7 @@ const measurable_methods_1 = __webpack_require__(78272);
1099
1207
  const file_utils_1 = __webpack_require__(58486);
1100
1208
  const debug = Debug('iac-oci-pull');
1101
1209
  exports.CUSTOM_RULES_TARBALL = 'custom-bundle.tar.gz';
1102
- function extractURLComponents(OCIRegistryURL) {
1210
+ function extractOCIRegistryURLComponents(OCIRegistryURL) {
1103
1211
  try {
1104
1212
  const url = OCIRegistryURL.split('://')[1];
1105
1213
  const [registryBase, accountName, repoWithTag] = url.split('/');
@@ -1111,7 +1219,7 @@ function extractURLComponents(OCIRegistryURL) {
1111
1219
  throw new InvalidRemoteRegistryURLError();
1112
1220
  }
1113
1221
  }
1114
- exports.extractURLComponents = extractURLComponents;
1222
+ exports.extractOCIRegistryURLComponents = extractOCIRegistryURLComponents;
1115
1223
  /**
1116
1224
  * Downloads an OCI Artifact from a remote OCI Registry and writes it to the disk.
1117
1225
  * The artifact here is a custom rules bundle stored in a remote registry.
@@ -1171,6 +1279,24 @@ class InvalidRemoteRegistryURLError extends errors_1.CustomError {
1171
1279
  }
1172
1280
  }
1173
1281
  exports.InvalidRemoteRegistryURLError = InvalidRemoteRegistryURLError;
1282
+ class UnsupportedFeatureFlagPullError extends errors_1.CustomError {
1283
+ constructor(featureFlag) {
1284
+ super('OCI Pull not supported - Missing the ${featureFlag} feature flag');
1285
+ this.code = types_1.IaCErrorCodes.UnsupportedFeatureFlagPullError;
1286
+ this.strCode = error_utils_1.getErrorStringCode(this.code);
1287
+ this.userMessage = `The custom rules feature is not supported for this org - The feature flag '${featureFlag}' is not currently enabled. It can be enabled via Snyk Preview, if you are on the Enterprise Plan.`;
1288
+ }
1289
+ }
1290
+ exports.UnsupportedFeatureFlagPullError = UnsupportedFeatureFlagPullError;
1291
+ class UnsupportedEntitlementPullError extends errors_1.CustomError {
1292
+ constructor(entitlement) {
1293
+ super(`OCI Pull not supported - Missing the ${entitlement} entitlement`);
1294
+ this.code = types_1.IaCErrorCodes.UnsupportedEntitlementPullError;
1295
+ this.strCode = error_utils_1.getErrorStringCode(this.code);
1296
+ this.userMessage = `The custom rules feature is currently not supported for this org. To enable it, please contact snyk support.`;
1297
+ }
1298
+ }
1299
+ exports.UnsupportedEntitlementPullError = UnsupportedEntitlementPullError;
1174
1300
 
1175
1301
 
1176
1302
  /***/ }),
@@ -2206,6 +2332,28 @@ FailOnError.ERROR_MESSAGE = 'Invalid fail on argument, please use one of: ' +
2206
2332
  Object.keys(common_1.FAIL_ON).join(' | ');
2207
2333
 
2208
2334
 
2335
+ /***/ }),
2336
+
2337
+ /***/ 78673:
2338
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2339
+
2340
+ "use strict";
2341
+
2342
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2343
+ exports.UnsupportedEntitlementError = void 0;
2344
+ const custom_error_1 = __webpack_require__(17188);
2345
+ class UnsupportedEntitlementError extends custom_error_1.CustomError {
2346
+ constructor(entitlement, userMessage = `This feature is currently not enabled for your org. To enable it, please contact snyk support.`) {
2347
+ super('Unsupported feature - Missing the ${entitlementName} entitlement');
2348
+ this.entitlement = entitlement;
2349
+ this.code = UnsupportedEntitlementError.ERROR_CODE;
2350
+ this.userMessage = userMessage;
2351
+ }
2352
+ }
2353
+ exports.UnsupportedEntitlementError = UnsupportedEntitlementError;
2354
+ UnsupportedEntitlementError.ERROR_CODE = 403;
2355
+
2356
+
2209
2357
  /***/ }),
2210
2358
 
2211
2359
  /***/ 9401: