Skip to content

Commit cc007d0

Browse files
authored
Merge pull request #100 from microsoft/serait/containerMappingDefault
Enable container-mapping tool by default
2 parents 3d86faf + 481b67d commit cc007d0

17 files changed

+80
-356
lines changed

README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,8 @@ To upload results to the Security tab of your repo, run the `github/codeql-actio
5050

5151
## Advanced
5252

53-
To configure **Container Mapping** to send to **Microsoft Defender for DevOps**, include `container-mapping` as a tool:
54-
```yaml
55-
- uses: microsoft/security-devops-action@v1
56-
id: msdo
57-
with:
58-
includeTools: container-mapping
59-
```
53+
To only run specific analyzers, use the `tools` command. This command is a comma-seperated list of tools to run. For example, to run only the `container-mapping` tool, configure this action as follows:
6054

61-
This will run all the analyzers defined by the configured or defaulted policy in addition to `container-mapping`. To only run this feature, define `container-mapping` as the only `tool` to run:
6255
```yaml
6356
- uses: microsoft/security-devops-action@v1
6457
id: msdo
@@ -77,6 +70,7 @@ This will run all the analyzers defined by the configured or defaulted policy in
7770
| [Template Analyzer](https://github.com/Azure/template-analyzer) | Infrastructure-as-code (IaC), ARM templates, Bicep files | [MIT License](https://github.com/Azure/template-analyzer/blob/main/LICENSE.txt) |
7871
| [Terrascan](https://github.com/accurics/terrascan) | Infrastructure-as-code (IaC), Terraform (HCL2), Kubernetes (JSON/YAML), Helm v3, Kustomize, Dockerfiles, Cloudformation | [Apache License 2.0](https://github.com/accurics/terrascan/blob/master/LICENSE) |
7972
| [Trivy](https://github.com/aquasecurity/trivy) | container images, file systems, and git repositories | [Apache License 2.0](https://github.com/aquasecurity/trivy/blob/main/LICENSE) |
73+
| [container-mapping](https://learn.microsoft.com/en-us/azure/defender-for-cloud/container-image-mapping) | container images and registries (only available for DevOps security enabled CSPM plans) | [MIT License](https://github.com/microsoft/security-devops-action/blob/main/LICENSE) |
8074

8175
# More Information
8276

action.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ branding:
66
color: 'black'
77
inputs:
88
command:
9-
description: The command to run. Defaults to run.
10-
default: all
11-
options:
12-
- all
13-
- run
14-
- pre-job
15-
- post-job
9+
description: Deprecated, do not use.
1610
config:
1711
description: A file path to a .gdnconfig file.
1812
policy:
@@ -25,7 +19,7 @@ inputs:
2519
tools:
2620
description: A comma separated list of analyzer to run. Example bandit, binskim, container-mapping, eslint, templateanalyzer, terrascan, trivy.
2721
includeTools:
28-
description: A comma separated list of analyzers to run in addition to the default set defined by the policy. Limited to container-mapping
22+
description: Deprecated
2923
outputs:
3024
sarifFile:
3125
description: A file path to a SARIF results file.

lib/index.js

-131
This file was deleted.

lib/main.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3333
};
3434
Object.defineProperty(exports, "__esModule", { value: true });
3535
const core = __importStar(require("@actions/core"));
36-
const index_1 = require("./index");
36+
const msdo_1 = require("./msdo");
37+
const msdo_interface_1 = require("./msdo-interface");
38+
const common = __importStar(require("@microsoft/security-devops-actions-toolkit/msdo-common"));
3739
const msdo_helpers_1 = require("./msdo-helpers");
38-
const runner = msdo_helpers_1.RunnerType.Main;
3940
function runMain() {
4041
return __awaiter(this, void 0, void 0, function* () {
41-
yield (0, index_1.run)(runner);
42+
if (shouldRunMain()) {
43+
yield (0, msdo_interface_1.getExecutor)(msdo_1.MicrosoftSecurityDevOps).runMain();
44+
}
45+
else {
46+
console.log("Scanning is not enabled. Skipping...");
47+
}
4248
});
4349
}
4450
runMain().catch(error => {
4551
core.setFailed(error);
4652
});
53+
function shouldRunMain() {
54+
let toolsString = core.getInput('tools');
55+
if (!common.isNullOrWhiteSpace(toolsString)) {
56+
let tools = toolsString.split(',');
57+
if (tools.length == 1 && tools[0].trim() == msdo_helpers_1.Tools.ContainerMapping) {
58+
return false;
59+
}
60+
}
61+
return true;
62+
}

lib/msdo-helpers.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6-
exports.writeToOutStream = exports.getEncodedContent = exports.encode = exports.Constants = exports.Tools = exports.CommandType = exports.RunnerType = exports.Inputs = void 0;
6+
exports.writeToOutStream = exports.getEncodedContent = exports.encode = exports.Constants = exports.Tools = exports.RunnerType = exports.Inputs = void 0;
77
const os_1 = __importDefault(require("os"));
88
var Inputs;
99
(function (Inputs) {
@@ -21,13 +21,6 @@ var RunnerType;
2121
RunnerType["Pre"] = "pre";
2222
RunnerType["Post"] = "post";
2323
})(RunnerType || (exports.RunnerType = RunnerType = {}));
24-
var CommandType;
25-
(function (CommandType) {
26-
CommandType["All"] = "all";
27-
CommandType["PreJob"] = "pre-job";
28-
CommandType["PostJob"] = "post-job";
29-
CommandType["Run"] = "run";
30-
})(CommandType || (exports.CommandType = CommandType = {}));
3124
var Tools;
3225
(function (Tools) {
3326
Tools["Bandit"] = "bandit";

lib/msdo-interface.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.getExecutor = void 0;
4+
function getExecutor(runner) {
5+
return new runner();
6+
}
7+
exports.getExecutor = getExecutor;

lib/msdo.js

-17
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,6 @@ class MicrosoftSecurityDevOps {
104104
}
105105
}
106106
}
107-
let includeToolsString = core.getInput('includeTools');
108-
if (!common.isNullOrWhiteSpace(includeToolsString)) {
109-
let includeTools = includeToolsString.split(',');
110-
for (let i = 0; i < includeTools.length; i++) {
111-
let includeTool = includeTools[i];
112-
let toolTrimmed = includeTool.trim();
113-
if (!common.isNullOrWhiteSpace(includeTool)
114-
&& includeTool != msdo_helpers_1.Tools.ContainerMapping
115-
&& includedTools.indexOf(toolTrimmed) == -1) {
116-
if (includedTools.length == 0) {
117-
args.push('--tool');
118-
}
119-
args.push(toolTrimmed);
120-
includedTools.push(toolTrimmed);
121-
}
122-
}
123-
}
124107
args.push('--github');
125108
yield client.run(args, 'microsoft/security-devops-action');
126109
});

lib/post.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3333
};
3434
Object.defineProperty(exports, "__esModule", { value: true });
3535
const core = __importStar(require("@actions/core"));
36-
const index_1 = require("./index");
37-
const msdo_helpers_1 = require("./msdo-helpers");
38-
const runner = msdo_helpers_1.RunnerType.Post;
36+
const container_mapping_1 = require("./container-mapping");
37+
const msdo_interface_1 = require("./msdo-interface");
3938
function runPost() {
4039
return __awaiter(this, void 0, void 0, function* () {
41-
yield (0, index_1.run)(runner);
40+
yield (0, msdo_interface_1.getExecutor)(container_mapping_1.ContainerMapping).runPostJob();
4241
});
4342
}
4443
runPost().catch((error) => {

lib/pre.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3333
};
3434
Object.defineProperty(exports, "__esModule", { value: true });
3535
const core = __importStar(require("@actions/core"));
36-
const index_1 = require("./index");
37-
const msdo_helpers_1 = require("./msdo-helpers");
38-
const runner = msdo_helpers_1.RunnerType.Pre;
36+
const container_mapping_1 = require("./container-mapping");
37+
const msdo_interface_1 = require("./msdo-interface");
3938
function runPre() {
4039
return __awaiter(this, void 0, void 0, function* () {
41-
yield (0, index_1.run)(runner);
40+
yield (0, msdo_interface_1.getExecutor)(container_mapping_1.ContainerMapping).runPreJob();
4241
});
4342
}
4443
runPre().catch((error) => {

src/container-mapping.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { CommandType, Constants, getEncodedContent, writeToOutStream } from "./msdo-helpers";
21
import { IMicrosoftSecurityDevOps } from "./msdo-interface";
32
import * as https from "https";
43
import * as core from '@actions/core';

0 commit comments

Comments
 (0)