Skip to content

Commit b18fbbb

Browse files
authored
ADO Debug Variable (#168)
1 parent 20feb8b commit b18fbbb

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

docs/content/en/rules/debug_enabled.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,24 @@ job_name:
6868
CI_DEBUG_TRACE: "true"
6969
CI_DEBUG_SERVICES: "true"
7070
```
71+
### Azure DevOps
72+
73+
In the pipeline file, remove the `system.debug` variable in the `variables` definition or set to false.
74+
75+
#### Recommended
76+
```yaml
77+
variables:
78+
system.debug: 'false' # Or, better, simply omit this variable as they default to `false` anyway.
79+
```
80+
81+
#### Anti-Pattern
82+
```yaml
83+
variables:
84+
system.debug: 'true'
85+
```
7186
7287
## See Also
7388
- https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging
7489
- https://docs.gitlab.com/ee/ci/variables/index.html#enable-debug-logging
7590
- https://docs.gitlab.com/ee/ci/variables/index.html#mask-a-cicd-variable
91+
- https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemdebug

models/azure_pipelines.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
type AzurePipeline struct {
1010
Path string `json:"path" yaml:"-"`
1111

12-
Stages []AzureStage `json:"stages"`
13-
Pr AzurePr `json:"pr"`
12+
Stages []AzureStage `json:"stages"`
13+
Pr AzurePr `json:"pr"`
14+
Variables map[string]string `json:"variables"`
1415
}
1516

1617
func (o AzurePipeline) IsValid() bool {

models/azure_pipelines_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ func TestAzurePipeline(t *testing.T) {
3232
},
3333
},
3434
},
35+
{
36+
input: `variables: {system.debug: true}`,
37+
expected: AzurePipeline{
38+
Stages: []AzureStage{
39+
{
40+
Stage: "",
41+
Jobs: []AzureJob{
42+
{
43+
Job: "",
44+
},
45+
},
46+
},
47+
},
48+
Variables: map[string]string{
49+
"system.debug": "true",
50+
},
51+
},
52+
},
3553
{
3654
input: `stages: [{stage: build, jobs: [{job: test, steps: [bash: asdf]}]}]`,
3755
expected: AzurePipeline{

opa/rego/rules/debug_enabled.rego

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,17 @@ results contains poutine.finding(rule, pkg.purl, {
8686
var := step.env[_]
8787
is_debug_enabled(var)
8888
}
89+
90+
results contains poutine.finding(rule, pkg.purl, {
91+
"path": pipeline.path,
92+
"job": "",
93+
"step": "1",
94+
"details": key,
95+
"line": 0,
96+
}) if {
97+
pkg := input.packages[_]
98+
pipeline := pkg.azure_pipelines[_]
99+
pipeline.variables[key]
100+
key == "system.debug"
101+
pipeline.variables[key] == "true"
102+
}

scanner/inventory_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,23 @@ func TestFindings(t *testing.T) {
358358
Purl: purl,
359359
Meta: opa.FindingMeta{
360360
Path: ".azure-pipelines.yml",
361-
Line: 11,
361+
Line: 14,
362362
Job: "build",
363363
Step: "1",
364364
Details: "Sources: Build.SourceBranch",
365365
},
366366
},
367+
{
368+
RuleId: "debug_enabled",
369+
Purl: purl,
370+
Meta: opa.FindingMeta{
371+
Path: ".azure-pipelines.yml",
372+
Line: 0,
373+
Job: "",
374+
Step: "1",
375+
Details: "system.debug",
376+
},
377+
},
367378
}
368379

369380
assert.Equal(t, len(findings), len(results.Findings))

scanner/testdata/.azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ pr:
33
include:
44
- master
55

6+
variables:
7+
system.debug: 'true'
8+
69
# implicit stage
710
jobs:
811
- job: build

0 commit comments

Comments
 (0)