Skip to content

Commit 3b5c590

Browse files
rseldnermdbirnstiehlbenironside
authored
environment variables in Synthetics run from Private locations (#3979)
Adding instructions for using environment variables in synthetics run from Private Locations --------- Co-authored-by: Mike Birnstiehl <[email protected]> Co-authored-by: Benjamin Ironside Goldstein <[email protected]>
1 parent 95dfe47 commit 3b5c590

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

solutions/observability/synthetics/work-with-params-secrets.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Params are viewable in plain-text by administrators and other users with `all` p
137137

138138
::::
139139

140+
### Use environment variables in Synthetics Projects
141+
140142
If you are managing monitors with a Synthetics project, you can use environment variables in your `synthetics.config.ts` or `synthetics.config.js` file.
141143

142144
The example below uses `process.env.MY_URL` to reference a variable named `MY_URL` defined in the environment and assigns its value to a param. That param can then be used in both lightweight and browser monitors that are managed in the Synthetics project:
@@ -148,3 +150,40 @@ export default {
148150
}
149151
};
150152
```
153+
154+
### Use environment variables with Private Locations
155+
156+
If you are using Kibana-managed monitors and running them on a Private Location, you can inject environment variables directly into the agent's runtime environment.
157+
This method allows you to keep sensitive values out of the {{kib}} UI. Instead, it stores those values on the infrastructure hosting the {{agent}}.
158+
159+
::::{warning}
160+
These variables are accessible to all monitors running on this specific Private Location.
161+
162+
::::
163+
164+
#### 1. Pass variables to the Private Location
165+
When starting your Private Location ({{agent}}) using Docker, use the `--env` flag to pass your variables.
166+
167+
168+
169+
```bash
170+
docker run \
171+
--env FLEET_ENROLL=1 \
172+
--env FLEET_URL={fleet_server_host_url} \
173+
--env FLEET_ENROLLMENT_TOKEN={enrollment_token} \
174+
--env MY_URL={secret_value} \
175+
--cap-add=NET_RAW \
176+
--cap-add=SETUID \
177+
-d --restart=unless-stopped \
178+
docker.elastic.co/elastic-agent/elastic-agent-complete:X.X.X
179+
```
180+
181+
#### 2. Reference variables in the inline script
182+
In the Synthetics **Monitors** editor in {{kib}}, you can now access these variables using `process.env`.
183+
184+
```js
185+
step('navigate to secure url', async () => {
186+
// The script reads the environment variable from the private location elastic agent container
187+
await page.goto(process.env.MY_URL);
188+
});
189+
```

0 commit comments

Comments
 (0)