|
| 1 | +--- |
| 2 | +slug: /send-data/opentelemetry-collector/remote-management/ |
| 3 | +title: Setting Environment variable with secret values for Source Template |
| 4 | +sidebar_label: Setting env variables |
| 5 | +description: Steps for setting environment variable with secret value which can be used by source template at runtime in a remotely managed opentelemetry collector. |
| 6 | +--- |
| 7 | + |
| 8 | +import useBaseUrl from '@docusaurus/useBaseUrl'; |
| 9 | +import Tabs from '@theme/Tabs'; |
| 10 | +import TabItem from '@theme/TabItem'; |
| 11 | + |
| 12 | +<head> |
| 13 | + <meta name="robots" content="noindex" /> |
| 14 | +</head> |
| 15 | + |
| 16 | +<p><a href="/docs/beta"><span className="beta">Beta</span></a></p> |
| 17 | + |
| 18 | +Certain source template use receiver which use secret/sensitive values like password to pull the data from service and send it to Sumo Logic using OpenTelemetry collector. For example [PostgreSQL receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/postgresqlreceiver) uses PostgreSQL username and password to bring in metrics from PostgreSQL instance. |
| 19 | + |
| 20 | +Below are the steps to make things work for such source templates : |
| 21 | + |
| 22 | +1. Set env variable in OpenTelemetry Collector process. For example : SECRET_ENV_VAR=Welcome@123 . Where SECRET_ENV_VAR is the variable name and Welcome@123 is password. |
| 23 | +2. ST creation : While creating the source template you will need to provice the environment variable name instead of the actual password. In this case : SECRET_ENV_VAR and this will be part of the source template referring to the value of the environment variable like: |
| 24 | +`password: ${env:SECRET_ENV_VAR}` |
| 25 | +3. Once this source template gets pushed to the respective OpenTelemetry collector, the environment variable will get resolved at runtime and will be substituted with the actual password value to make the config work and pull the data to send it to Sumo Logic. |
| 26 | + |
| 27 | +This way your secret data is not shared with Sumo Logic. |
| 28 | + |
| 29 | +Below are the steps to set the environment variable in different operating systems : |
| 30 | + |
| 31 | +## Linux |
| 32 | +1. Under "/etc/otelcol-sumo/env" you will have `token.env` file. You can set an environment variable in this. For example |
| 33 | +`ENV_KEY=password` |
| 34 | +:::note |
| 35 | +This file is accessible to user/group created while OpenTelemetry collector is installed which is `otelcol-sumo`. You can use this user or any other admin user to access/edit token.env file. |
| 36 | +::: |
| 37 | +2. Restart the agent to load the newly added env variables to the OTRM agent process. Using the command : |
| 38 | +`sudo systemctl restart otelcol-sumo` |
| 39 | +3. Create a ST referring to above env variable (ENV_KEY) for password which will get remotely pushed to the OTRM agent. |
| 40 | + |
| 41 | +## Mac |
| 42 | +- You can set an environment variable in the OpenTelemetry agent by making changes to `/Library/LaunchDaemons/com.sumologic.otelcol-sumo.plist`. |
| 43 | +- This file already has the `SUMOLOGIC_INSTALLATION_TOKEN` set. Parallel to it we can set any environment variable. For example below, have set `MAC_ENV_VAR` in agent: |
| 44 | + |
| 45 | +``` |
| 46 | +<?xml version="1.0" encoding="UTF-8"?> |
| 47 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 48 | +<plist version="1.0"> |
| 49 | +<dict> |
| 50 | + <key>EnvironmentVariables</key> |
| 51 | + <dict> |
| 52 | + <key>SUMOLOGIC_INSTALLATION_TOKEN</key> |
| 53 | + <string>U1VNT3c2c2tv************************</string> |
| 54 | + <key>MAC_ENV_VAR</key> |
| 55 | + <string>etc</string> |
| 56 | + </dict> |
| 57 | + <key>GroupName</key> |
| 58 | + <string>_otelcol-sumo</string> |
| 59 | + <key>KeepAlive</key> |
| 60 | + <true/> |
| 61 | + <key>Label</key> |
| 62 | + <string>otelcol-sumo</string> |
| 63 | + <key>ProgramArguments</key> |
| 64 | + <array> |
| 65 | + <string>/usr/local/bin/otelcol-sumo</string> |
| 66 | + <string>--remote-config</string> |
| 67 | + <string>opamp:/etc/otelcol-sumo/sumologic.yaml</string> |
| 68 | + </array> |
| 69 | + <key>RunAtLoad</key> |
| 70 | + <true/> |
| 71 | + <key>StandardErrorPath</key> |
| 72 | + <string>/var/log/otelcol-sumo/otelcol-sumo.log</string> |
| 73 | + <key>StandardOutPath</key> |
| 74 | + <string>/var/log/otelcol-sumo/otelcol-sumo.log</string> |
| 75 | + <key>UserName</key> |
| 76 | + <string>_otelcol-sumo</string> |
| 77 | +</dict> |
| 78 | +</plist> |
| 79 | +``` |
| 80 | +- You then need to restart the OpenTelemetry collector on your mac machine using the below command : |
| 81 | +`sudo launchctl unload /Library/LaunchDaemons/com.sumologic.otelcol-sumo.plist && sudo launchctl load -w /Library/LaunchDaemons/com.sumologic.otelcol-sumo.plist` |
| 82 | + |
| 83 | +## Windows |
| 84 | +1. On your windows machine, open Registry Editor |
| 85 | +2. Go to `Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\OtelcolSumo` |
| 86 | +3. Right click on the right pane and select `New > Multi-String Value`. You can name this anything |
| 87 | +4. Right click on newly created entity in the step above and select `modify` |
| 88 | +5. You can set the environment variable as per your needs. For example in the below screenshot we have set `TEST_VAR` env variable with value `sumoemp`: |
| 89 | +<br/><img src={useBaseUrl('img/send-data/opentelemetry-collector/set_env_varibale_windows.png')} alt="linux-install" style={{border: '1px solid gray'}} width="800"/> |
| 90 | +6. Click on **OK**. |
| 91 | +7. **Optional Step** Since by default the variable set as part of registry are visible to all user, you can follow the below steps to manage the ACL of the service registry and environment variable set in above steps : |
| 92 | + - Right click on OtelcolSumo service in the left pane of the registry editor and click on permissions |
| 93 | + - Go to advance section by pressing Advanced button |
| 94 | + - Since the permissions are inherited by services from its parent by default, you will need to disable inheritance in the Advanced Security Settings popup. |
| 95 | + - While disabling inheritance you will get two options to either convert inherited permission or to remove inherit permissions and create the permission list from scrath. You can choose either of the two depending on your case. |
| 96 | + - You can then edit Users from this list to ensure appropriate access of this registry and environment variable set under it. |
| 97 | + |
| 98 | +<br/><img src={useBaseUrl('img/send-data/opentelemetry-collector/ACL_windows_registry.png')} alt="linux-install" style={{border: '1px solid gray'}} width="800"/> |
| 99 | + |
| 100 | +8. Restart the windows agent using the below command : |
| 101 | +`Restart-Service -Name OtelcolSumo` |
0 commit comments