You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#customer intent: As an Azure DevOps user, I want to understand how pipeline templates can help increase security, so I can use templates to do security tasks and help prevent malicious code infiltration and execution.
8
9
---
9
10
10
11
# Templates for security
@@ -79,18 +80,20 @@ YAML pipeline syntax includes several built-in protections. `Extends` templates
79
80
80
81
### Step targets
81
82
82
-
You can restrict specified steps to run in a container rather than on the host. Steps in containers can't access the agent's host, so they can't modify agent configuration or leave malicious code for later execution.
83
+
You can restrict specified steps to run in a container rather than on the host. Steps in containers can't access the agent host, so they can't modify agent configuration or leave malicious code for later execution.
83
84
84
-
For example, you can prevent open network access from within a container, so user steps can't retrieve packages from unauthorized sources or upload code and secrets to external locations. The following example pipeline demonstrates running a step on the agent host before running a step inside a container.
85
+
For example, you can run user steps in a container to prevent them from accessing the network, so they can't retrieve packages from unauthorized sources or upload code and secrets to external locations.
86
+
87
+
The following example pipeline runs a step on the agent host that could potentially alter the host network, followed by a step inside a container that limits network access.
85
88
86
89
```yaml
87
90
resources:
88
91
containers:
89
92
- container: builder
90
93
image: mysecurebuildcontainer:latest
91
94
steps:
92
-
- script: echo This step runs on the agent host, so could use commands to tear down or limit the host network
93
-
- script: echo This step runs inside the builder container, which limits network access
95
+
- script: echo This step runs on the agent host
96
+
- script: echo This step runs inside the builder container
94
97
target: builder
95
98
```
96
99
@@ -130,9 +133,9 @@ extends:
130
133
131
134
### Agent logging command restrictions
132
135
133
-
User steps request services by using *logging commands*, which are specially formatted strings printed to standard output. You can restrict the services that logging commands provide for user steps. In `restricted` mode, most agent services such as uploading artifacts and attaching test results are unavailable.
136
+
User steps request services by using *logging commands*, which are specially formatted strings printed to standard output. You can restrict the services that logging commands provide for user steps. In `restricted` mode, most agent services such as uploading artifacts and attaching test results are unavailable for logging commands.
134
137
135
-
In the following example, the `target` property instructs the agent not to allow publishing artifacts, so the artifact publishing task fails.
138
+
In the following example, the `target` property instructs the agent to restrict publishing artifacts, so the artifact publishing task fails.
136
139
137
140
```yaml
138
141
- task: PublishBuildArtifacts@1
@@ -144,11 +147,11 @@ In the following example, the `target` property instructs the agent not to allow
144
147
145
148
#### Variables in logging commands
146
149
147
-
The `setvariable` command remains permissible in `restricted` mode, so tasks that output user-provided data, such as open issues retrieved via a REST API, might be vulnerable to injection attacks. Malicious user content could set variables that export as environment variables to subsequent tasks and compromise the agent host.
150
+
The `setvariable` command remains permissible in `restricted` mode, so tasks that output user-provided data, such as open issues retrieved via a REST API, might be vulnerable to injection attacks. Malicious user content could set variables that export to subsequent tasks as environment variables and could compromise the agent host.
148
151
149
152
To mitigate this risk, you can explicitly declare the variables that are settable by using the `setvariable` logging command. If you specify an empty list in `settableVariables`, all variable setting is disallowed.
150
153
151
-
The following example restricts the `settableVariables` to `expectedVar` or a variable prefixed with `ok`. The task fails because it attempts to set a different variable called `BadVar`.
154
+
The following example restricts the `settableVariables` to `expectedVar` and any variable prefixed with `ok`. The task fails because it attempts to set a different variable called `BadVar`.
152
155
153
156
```yaml
154
157
- task: PowerShell@2
@@ -268,7 +271,7 @@ You can configure [approvals and checks](../process/approvals.md) for your agent
268
271
269
272
To enforce the use of a specific template, configure the [required template](../process/approvals.md#required-template) check on the service connection for a resource. This check applies only when the pipeline extends from a template.
270
273
271
-
When you view the pipeline job, you can monitor the check's status. If the pipeline doesn't extend from the required template, the check fails. The run stops and notifies you of the failed check.
274
+
When you view the pipeline job, you can monitor the check's status. If the pipeline doesn't extend from the required template, the check fails.
272
275
273
276
:::image type="content" source="../process/media/approval-fail.png" alt-text="Screenshot showing a failed approval check.":::
274
277
@@ -298,7 +301,7 @@ steps:
298
301
- script: echo ${{ parameters.image }}
299
302
```
300
303
301
-
The following example pipeline extends the *params.yml* template and requires it for approval. To demonstrate a pipeline failure, comment out the reference to *params.yml*.
304
+
The following example pipeline extends the *params.yml* template and requires it for approval. To demonstrate a pipeline failure, comment out the `extends` reference to *params.yml*.
0 commit comments