Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c44a4b0

Browse files
committed
Refactor provisioners documentation
Refactor the provisioners documentation to improve clarity and guidance on setting up external provisioners. This includes: - Emphasizing the benefits of using external provisioners over built-in ones. - Streamlining instructions for setting up provisioners with scoped keys. - Encouraging use of organization-scoped or user-scoped provisioners. - Adding examples and instructions for different setup environments. - Organizing content for better navigation and understanding.
1 parent 4c42089 commit c44a4b0

File tree

2 files changed

+193
-67
lines changed

2 files changed

+193
-67
lines changed

docs/admin/provisioners.md

Lines changed: 145 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,120 @@
1-
# Provisioners
1+
# External provisioners
22

33
By default, the Coder server runs
44
[built-in provisioner daemons](../reference/cli/server.md#provisioner-daemons),
55
which execute `terraform` during workspace and template builds. However, there
6-
are sometimes benefits to running external provisioner daemons:
6+
are often benefits to running external provisioner daemons:
77

88
- **Secure build environments:** Run build jobs in isolated containers,
9-
preventing malicious templates from gaining shell access to the Coder host.
9+
preventing malicious templates from gaining sh access to the Coder host.
1010

1111
- **Isolate APIs:** Deploy provisioners in isolated environments (on-prem, AWS,
1212
Azure) instead of exposing APIs (Docker, Kubernetes, VMware) to the Coder
13-
server. See [Provider Authentication](../admin/external-auth.md) for more
14-
details.
13+
server. See
14+
[Provider Authentication](../admin/templates/extending-templates/provider-authentication.md)
15+
for more details.
1516

1617
- **Isolate secrets**: Keep Coder unaware of cloud secrets, manage/rotate
1718
secrets on provisioner servers.
1819

1920
- **Reduce server load**: External provisioners reduce load and build queue
2021
times from the Coder server. See
21-
[Scaling Coder](../admin/infrastructure/scale-utility.md#recent-scale-tests)
22-
for more details.
22+
[Scaling Coder](../admin/infrastructure/README.md#scale-tests) for more
23+
details.
2324

24-
Each provisioner can run a single
25+
Each provisioner runs a single
2526
[concurrent workspace build](../admin/infrastructure/scale-testing.md#control-plane-provisionerd).
2627
For example, running 30 provisioner containers will allow 30 users to start
2728
workspaces at the same time.
2829

2930
Provisioners are started with the
30-
31-
[coder provisionerd start](../reference/cli/provisioner_start.md) command.
31+
[`coder provisioner start`](../reference/cli/provisioner_start.md) command in
32+
the [full Coder binary](https://github.com/coder/coder/releases). Keep reading
33+
to learn how to start provisioners via Docker, Kubernetes, Systemd, etc.
3234

3335
## Authentication
3436

3537
The provisioner daemon must authenticate with your Coder deployment.
3638

37-
Set a
38-
[provisioner daemon pre-shared key (PSK)](../reference/cli/server.md#--provisioner-daemon-psk)
39-
on the Coder server and start the provisioner with
40-
`coder provisionerd start --psk <your-psk>`. If you are
41-
[installing with Helm](../install/kubernetes.md#install-coder-with-helm), see
42-
the [Helm example](#example-running-an-external-provisioner-with-helm) below.
39+
<div class="tabs">
4340

44-
> Coder still supports authenticating the provisioner daemon with a
45-
> [token](../reference/cli/tokens.md) from a user with the Template Admin or
46-
> Owner role. This method is deprecated in favor of the PSK, which only has
47-
> permission to access provisioner daemon APIs. We recommend migrating to the
48-
> PSK as soon as practical.
41+
## Scoped Key (Recommended)
4942

50-
## Types of provisioners
43+
We recommend creating finely-scoped keys for provisioners. Keys are scoped to an
44+
organization.
5145

52-
Provisioners can broadly be categorized by scope: `organization` or `user`. The
53-
scope of a provisioner can be specified with
54-
[`-tag=scope=<scope>`](../reference/cli/provisioner_start.md#t---tag) when
55-
starting the provisioner daemon. Only users with at least the
56-
[Template Admin](../admin/users/groups-roles.md#roles) role or higher may create
57-
organization-scoped provisioner daemons.
46+
```sh
47+
coder provisioner keys create my-key \
48+
--org default
5849

59-
There are two exceptions:
50+
Successfully created provisioner key my-key! Save this authentication token, it will not be shown again.
6051

61-
- [Built-in provisioners](../reference/cli/server.md#provisioner-daemons) are
62-
always organization-scoped.
63-
- External provisioners started using a
64-
[pre-shared key (PSK)](../reference/cli/provisioner_start.md#psk) are always
65-
organization-scoped.
52+
<key omitted>
53+
```
6654

67-
### Organization-Scoped Provisioners
55+
Or, restrict the provisioner to jobs with specific tags
6856

69-
**Organization-scoped Provisioners** can pick up build jobs created by any user.
70-
These provisioners always have the implicit tags `scope=organization owner=""`.
57+
```sh
58+
coder provisioner keys create kubernetes-key \
59+
--org default \
60+
--tag environment=kubernetes
61+
62+
Successfully created provisioner key kubernetes-key! Save this authentication token, it will not be shown again.
7163

72-
```shell
73-
coder provisionerd start
64+
<key omitted>
7465
```
7566

76-
### User-scoped Provisioners
67+
To start the provisioner:
7768

78-
**User-scoped Provisioners** can only pick up build jobs created from
79-
user-tagged templates. Unlike the other provisioner types, any Coder user can
80-
run user provisioners, but they have no impact unless there exists at least one
81-
template with the `scope=user` provisioner tag.
69+
```sh
70+
export CODER_URL=https://<your-coder-url>
71+
export CODER_PROVISIONER_DAEMON_KEY=<key>
72+
coder provisioner start
73+
```
8274

83-
```shell
84-
coder provisionerd start \
85-
--tag scope=user
75+
Keep reading to see instructions for running provisioners on
76+
Kubernetes/Docker/etc.
8677

87-
# In another terminal, create/push
88-
# a template that requires user provisioners
89-
coder templates push on-prem \
90-
--provisioner-tag scope=user
78+
## User Tokens
79+
80+
A user account with the role `Template Admin` or `Owner` can start provisioners
81+
using their user account. This may be beneficial if you are running provisioners
82+
via [automation](../reference/README.md).
83+
84+
```sh
85+
coder login https://<your-coder-url>
86+
coder provisioner start
87+
```
88+
89+
To start a provisioner with specific tags:
90+
91+
```sh
92+
coder login https://<your-coder-url>
93+
coder provisioner start \
94+
--tag environment=kubernetes
9195
```
9296

93-
### Provisioner Tags
97+
Note: Any user can start [user-scoped provisioners](#User-scoped-Provisioners),
98+
but this will also require a template on your deployment with the corresponding
99+
tags.
100+
101+
## Global PSK
102+
103+
A deployment-wide PSK can be used to authenticate any provisioner. We do not
104+
recommend this approach anymore, as it makes key rotation or isolating
105+
provisioners far more difficult. To use a global PSK, set a
106+
[provisioner daemon pre-shared key (PSK)](../reference/cli/server.md#--provisioner-daemon-psk)
107+
on the Coder server.
108+
109+
Next, start the provisioner:
110+
111+
```sh
112+
coder provisioner start --psk <your-psk>
113+
```
114+
115+
</div>
116+
117+
## Provisioner Tags
94118

95119
You can use **provisioner tags** to control which provisioners can pick up build
96120
jobs from templates (and corresponding workspaces) with matching explicit tags.
@@ -105,10 +129,10 @@ automatically.
105129

106130
For example:
107131

108-
```shell
132+
```sh
109133
# Start a provisioner with the explicit tags
110134
# environment=on_prem and datacenter=chicago
111-
coder provisionerd start \
135+
coder provisioner start \
112136
--tag environment=on_prem \
113137
--tag datacenter=chicago
114138

@@ -124,6 +148,10 @@ coder templates push on-prem-chicago \
124148
--provisioner-tag datacenter=chicago
125149
```
126150

151+
Alternatively, a template can target a provisioner via
152+
[workspace tags](https://github.com/coder/coder/tree/main/examples/workspace-tags)
153+
inside the Terraform.
154+
127155
A provisioner can run a given build job if one of the below is true:
128156

129157
1. A job with no explicit tags can only be run on a provisioner with no explicit
@@ -171,9 +199,59 @@ This is illustrated in the below table:
171199
> copy the output:
172200
>
173201
> ```
174-
> go test -v -count=1 ./coderd/provisionerdserver/ -test.run='^TestAcquirer_MatchTags/GenTable$'
202+
> go test -v -count=1 ./coderd/provisionerserver/ -test.run='^TestAcquirer_MatchTags/GenTable$'
175203
> ```
176204
205+
## Types of provisioners
206+
207+
Provisioners can broadly be categorized by scope: `organization` or `user`. The
208+
scope of a provisioner can be specified with
209+
[`-tag=scope=<scope>`](../reference/cli/provisioner_start.md#t---tag) when
210+
starting the provisioner daemon. Only users with at least the
211+
[Template Admin](./users/README.md#roles) role or higher may create
212+
organization-scoped provisioner daemons.
213+
214+
There are two exceptions:
215+
216+
- [Built-in provisioners](../reference/cli/server.md#provisioner-daemons) are
217+
always organization-scoped.
218+
- External provisioners started using a
219+
[pre-shared key (PSK)](../reference/cli/provisioner_start.md#psk) are always
220+
organization-scoped.
221+
222+
### Organization-Scoped Provisioners
223+
224+
**Organization-scoped Provisioners** can pick up build jobs created by any user.
225+
These provisioners always have the implicit tags `scope=organization owner=""`.
226+
227+
```sh
228+
coder provisioner start --org <organization_name>
229+
```
230+
231+
If you omit the `--org` argument, the provisioner will be assigned to the
232+
default organization.
233+
234+
```sh
235+
coder provisioner start
236+
```
237+
238+
### User-scoped Provisioners
239+
240+
**User-scoped Provisioners** can only pick up build jobs created from
241+
user-tagged templates. Unlike the other provisioner types, any Coder user can
242+
run user provisioners, but they have no impact unless there exists at least one
243+
template with the `scope=user` provisioner tag.
244+
245+
```sh
246+
coder provisioner start \
247+
--tag scope=user
248+
249+
# In another terminal, create/push
250+
# a template that requires user provisioners
251+
coder templates push on-prem \
252+
--provisioner-tag scope=user
253+
```
254+
177255
## Example: Running an external provisioner with Helm
178256

179257
Coder provides a Helm chart for running external provisioner daemons, which you
@@ -182,21 +260,21 @@ will use in concert with the Helm chart for deploying the Coder server.
182260
1. Create a long, random pre-shared key (PSK) and store it in a Kubernetes
183261
secret
184262

185-
```shell
263+
```sh
186264
kubectl create secret generic coder-provisioner-psk --from-literal=psk=`head /dev/urandom | base64 | tr -dc A-Za-z0-9 | head -c 26`
187265
```
188266

189267
1. Modify your Coder `values.yaml` to include
190268

191269
```yaml
192-
provisionerDaemon:
270+
provisioneraemon:
193271
pskSecretName: "coder-provisioner-psk"
194272
```
195273
196274
1. Redeploy Coder with the new `values.yaml` to roll out the PSK. You can omit
197275
`--version <your version>` to also upgrade Coder to the latest version.
198276

199-
```shell
277+
```sh
200278
helm upgrade coder coder-v2/coder \
201279
--namespace coder \
202280
--version <your version> \
@@ -212,7 +290,7 @@ will use in concert with the Helm chart for deploying the Coder server.
212290
- name: CODER_URL
213291
value: "https://coder.example.com"
214292
replicaCount: 10
215-
provisionerDaemon:
293+
provisioneraemon:
216294
pskSecretName: "coder-provisioner-psk"
217295
tags:
218296
location: auh
@@ -230,7 +308,7 @@ will use in concert with the Helm chart for deploying the Coder server.
230308

231309
1. Install the provisioner daemon chart
232310

233-
```shell
311+
```sh
234312
helm install coder-provisioner coder-v2/coder-provisioner \
235313
--namespace coder \
236314
--version <your version> \
@@ -239,35 +317,35 @@ will use in concert with the Helm chart for deploying the Coder server.
239317

240318
You can verify that your provisioner daemons have successfully connected to
241319
Coderd by looking for a debug log message that says
242-
`provisionerd: successfully connected to coderd` from each Pod.
320+
`provisioner: successfully connected to coderd` from each Pod.
243321

244322
## Example: Running an external provisioner on a VM
245323

246-
```shell
324+
```sh
247325
curl -L https://coder.com/install.sh | sh
248326
export CODER_URL=https://coder.example.com
249327
export CODER_SESSION_TOKEN=your_token
250-
coder provisionerd start
328+
coder provisioner start
251329
```
252330

253331
## Example: Running an external provisioner via Docker
254332

255-
```shell
333+
```sh
256334
docker run --rm -it \
257335
-e CODER_URL=https://coder.example.com/ \
258336
-e CODER_SESSION_TOKEN=your_token \
259337
--entrypoint /opt/coder \
260338
ghcr.io/coder/coder:latest \
261-
provisionerd start
339+
provisioner start
262340
```
263341

264342
## Disable built-in provisioners
265343

266344
As mentioned above, the Coder server will run built-in provisioners by default.
267345
This can be disabled with a server-wide
268-
[flag or environment variable](../reference/cli/server.md#--provisioner-daemons).
346+
[flag or environment variable](../reference/cli/server.md#provisioner-daemons).
269347

270-
```shell
348+
```sh
271349
coder server --provisioner-daemons=0
272350
```
273351

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Provider Authentication
2+
3+
<blockquote class="danger">
4+
<p>
5+
Do not store secrets in templates. Assume every user has cleartext access
6+
to every template.
7+
</p>
8+
</blockquote>
9+
10+
The Coder server's
11+
[provisioner](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/provisioner)
12+
process needs to authenticate with other provider APIs to provision workspaces.
13+
There are two approaches to do this:
14+
15+
- Pass credentials to the provisioner as parameters.
16+
- Preferred: Execute the Coder server in an environment that is authenticated
17+
with the provider.
18+
19+
We encourage the latter approach where supported:
20+
21+
- Simplifies the template.
22+
- Keeps provider credentials out of Coder's database, making it a less valuable
23+
target for attackers.
24+
- Compatible with agent-based authentication schemes, which handle credential
25+
rotation or ensure the credentials are not written to disk.
26+
27+
Generally, you can set up an environment to provide credentials to Coder in
28+
these ways:
29+
30+
- A well-known location on disk. For example, `~/.aws/credentials` for AWS on
31+
POSIX systems.
32+
- Environment variables.
33+
34+
It is usually sufficient to authenticate using the CLI or SDK for the provider
35+
before running Coder, but check the Terraform provider's documentation for
36+
details.
37+
38+
These platforms have Terraform providers that support authenticated
39+
environments:
40+
41+
- [Google Cloud](https://registry.terraform.io/providers/hashicorp/google/latest/docs)
42+
- [Amazon Web Services](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
43+
- [Microsoft Azure](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs)
44+
- [Kubernetes](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs)
45+
46+
Other providers might also support authenticated environments. Check the
47+
[documentation of the Terraform provider](https://registry.terraform.io/browse/providers)
48+
for details.

0 commit comments

Comments
 (0)