-
Notifications
You must be signed in to change notification settings - Fork 179
environment variables in Synthetics run from Private locations #3979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
88ff062
8a95899
079fe30
60686d0
432f647
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -137,6 +137,8 @@ Params are viewable in plain-text by administrators and other users with `all` p | |||||||||
|
|
||||||||||
| :::: | ||||||||||
|
|
||||||||||
| ### Use environment variables in Synthetics Projects | ||||||||||
|
|
||||||||||
| If you are managing monitors with a Synthetics project, you can use environment variables in your `synthetics.config.ts` or `synthetics.config.js` file. | ||||||||||
|
|
||||||||||
| 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: | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mdbirnstiehl is there a good reason to use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I now see the whole page uses params. Not saying it needs to change. Just curious about it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, the setting in Kibana is Global parameters, but you pass |
||||||||||
|
|
@@ -148,3 +150,40 @@ export default { | |||||||||
| } | ||||||||||
| }; | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ### Use environment variables with Private Locations | ||||||||||
mdbirnstiehl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
| 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. | ||||||||||
mdbirnstiehl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| This method allows you to keep sensitive values out of the Kibana UI. Instead, it requires access to the infrastructure hosting the Elastic Agent. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| ::::{warning} | ||||||||||
| These variables will be accessible to **all** monitors running on **this specific** Private Location. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| :::: | ||||||||||
|
|
||||||||||
| #### 1. Pass variables to the Private Location | ||||||||||
| When starting your Private Location (Elastic Agent) using Docker, use the `--env` flag to pass your variables. | ||||||||||
|
Comment on lines
+164
to
+165
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| docker run \ | ||||||||||
| --env FLEET_ENROLL=1 \ | ||||||||||
| --env FLEET_URL={fleet_server_host_url} \ | ||||||||||
| --env FLEET_ENROLLMENT_TOKEN={enrollment_token} \ | ||||||||||
| --env MY_URL={secret_value} \ | ||||||||||
| --cap-add=NET_RAW \ | ||||||||||
| --cap-add=SETUID \ | ||||||||||
| -d --restart=unless-stopped \ | ||||||||||
| docker.elastic.co/elastic-agent/elastic-agent-complete:X.X.X | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| #### 2. Reference variables in the inline script | ||||||||||
| In the Synthetics Monitor editor in Kibana, you can now access these variables using `process.env`. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| ```js | ||||||||||
| step('navigate to secure url', async () => { | ||||||||||
| // The script reads the environment variable from the private location elastic agent container | ||||||||||
| await page.goto(process.env.MY_URL); | ||||||||||
| }); | ||||||||||
| ``` | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this suggestion is correct. The rest of the page is consistent in the usage of "Synthetics project"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, Synthetics project seems to be consistent through the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was writing Synthetics docs, I would use
Syntheticswhen referring to the Elastic Synthetics product andsyntheticwhen using it as an adjective like synthetic monitors. In this case, I would say it makes more sense to use "Synthetics project" because a "project" is an Elastic-specific concept unlike "monitor", which is generic concept in the world of synthetic monitoring.