Skip to content

Commit d1d4a23

Browse files
committed
Add parsing tokens from files or environment variables
1 parent be14d12 commit d1d4a23

File tree

6 files changed

+251
-36
lines changed

6 files changed

+251
-36
lines changed

Cargo.lock

+58-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,6 @@ vergen = { version = "7.4.2", default-features = false, features = [
136136
"cargo",
137137
] }
138138
anyhow = "1.0"
139+
140+
[dev-dependencies]
141+
serial_test = "3.1.1"

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,25 @@ Before heading to the full configuration specification, it's recommend to skim [
101101

102102
See [Transport](./docs/transport.md) for more details about encryption and the `transport` block.
103103

104+
Tokens can also be set through environment variables. The variable `RATHOLE_{service name in uppercase}_TOKEN` can be set or `RATHOLE_DEFAULT_TOKEN` for all services.
105+
Tokens are parsed in the following order for "servicex":
106+
1. (client/server).services.servicex.token
107+
2. (client/server).services.servicex.token_file
108+
3. RATHOLE_SERVICEX_TOKEN
109+
4. (client/server).default_token
110+
5. (client/server).default_token_file
111+
6. RATHOLE_DEFAULT_TOKEN
112+
113+
Tokens should be generated by yourself (not on someone's website or on random.com) using a cryptographic pseudorandom generator. On Linux, use `openssl rand -hex 64 > /path/to/key`. Make sure to do this on a system with high entropy.
114+
Most systems will have plenty of entropy. The random network delay between packets, using the computer and typing, access latency from your hdd all can be used to create entropy. Just use your system for anything other than extremely repetitive tasks and don't generate the key right after boot.
115+
104116
Here is the full configuration specification:
105117

106118
```toml
107119
[client]
108120
remote_addr = "example.com:2333" # Necessary. The address of the server
109121
default_token = "default_token_if_not_specify" # Optional. The default token of services, if they don't define their own ones
122+
default_token_file = "/path/to/token" # Optional. This will pull the default token from the path specified
110123
heartbeat_timeout = 40 # Optional. Set to 0 to disable the application-layer heartbeat test. The value must be greater than `server.heartbeat_interval`. Default: 40 seconds
111124
retry_interval = 1 # Optional. The interval between retry to connect to the server. Default: 1 second
112125

@@ -134,6 +147,7 @@ tls = true # If `true` then it will use settings in `client.transport.tls`
134147
[client.services.service1] # A service that needs forwarding. The name `service1` can change arbitrarily, as long as identical to the name in the server's configuration
135148
type = "tcp" # Optional. The protocol that needs forwarding. Possible values: ["tcp", "udp"]. Default: "tcp"
136149
token = "whatever" # Necessary if `client.default_token` not set
150+
token_file = "/path/to/token" # Necessary if token, default_token, the env var, and default_token_file are unset.
137151
local_addr = "127.0.0.1:1081" # Necessary. The address of the service that needs to be forwarded
138152
nodelay = true # Optional. Override the `client.transport.nodelay` per service
139153
retry_interval = 1 # Optional. The interval between retry to connect to the server. Default: inherits the global config
@@ -144,6 +158,7 @@ local_addr = "127.0.0.1:1082"
144158
[server]
145159
bind_addr = "0.0.0.0:2333" # Necessary. The address that the server listens for clients. Generally only the port needs to be change.
146160
default_token = "default_token_if_not_specify" # Optional
161+
default_token_file = "/path/to/token" # Optional. This will pull the default token from the path specified
147162
heartbeat_interval = 30 # Optional. The interval between two application-layer heartbeat. Set to 0 to disable sending heartbeat. Default: 30 seconds
148163

149164
[server.transport] # Same as `[client.transport]`
@@ -169,6 +184,7 @@ tls = true # If `true` then it will use settings in `server.transport.tls`
169184
[server.services.service1] # The service name must be identical to the client side
170185
type = "tcp" # Optional. Same as the client `[client.services.X.type]
171186
token = "whatever" # Necessary if `server.default_token` not set
187+
token_file = "/path/to/token" # Necessary if token, default_token, and default_token_file are unset.
172188
bind_addr = "0.0.0.0:8081" # Necessary. The address of the service is exposed at. Generally only the port needs to be change.
173189
nodelay = true # Optional. Same as the client
174190

0 commit comments

Comments
 (0)