-
-
Notifications
You must be signed in to change notification settings - Fork 109
Support host-specific proxies with proxy config YAML #837
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
Open
ikreymer
wants to merge
14
commits into
main
Choose a base branch
from
proxy-pac-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8537d06
support for multiple proxies via proxy PAC script!
ikreymer 094497a
move generateProxyPac into server
ikreymer 5524c3a
allow overrides of default proxy
ikreymer 81623d1
allow empty proxyServerConfig
ikreymer c799f81
refactor to support named mapping, which supports url, privateKeyFile…
ikreymer 72f11e9
add docs
ikreymer 97160ce
tests: add proxy host match tests with bad / good auth, test only som…
ikreymer aac7d7f
tests: update exit codes for proxy exit code
ikreymer ccbb24b
don't comment out
ikreymer 1ae6bb6
check for error status to determine if proxy error
ikreymer c78a3b3
fix tests?
ikreymer 28829c3
undo delete line
ikreymer d688041
merge fix
ikreymer 41e23b8
Update docs/docs/user-guide/proxies.md
ikreymer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,56 @@ The above proxy settings also apply to [Browser Profile Creation](browser-profil | |
docker run -p 6080:6080 -p 9223:9223 -v $PWD/crawls/profiles:/crawls/profiles -v $PWD/my-proxy-private-key:/tmp/private-key -v $PWD/known_hosts:/tmp/known_hosts webrecorder/browsertrix-crawler create-login-profile --url https://example.com/ --proxyServer ssh://[email protected] --sshProxyPrivateKeyFile /tmp/private-key --sshProxyKnownHostsFile /tmp/known_hosts | ||
``` | ||
|
||
## Host-Specific Proxies | ||
|
||
With the 1.7.0 release, the crawler also supports running with multiple proxies, defined in a separate proxy YAML config file. The file contains a match hosts section, matching hosts by regex to named proxies. | ||
|
||
For example, the following YAML file can be passed to `--proxyConfigFile` option: | ||
|
||
```yaml | ||
matchHosts: | ||
# load all URLs from example.com through 'example-1-proxy' | ||
example.com/.*: example-1-proxy | ||
|
||
# load all URLS from https://my-social.example.com/.*/posts/ through | ||
# a different proxy | ||
https://my-social.example.com/.*/posts/: social-proxy | ||
|
||
# optional default proxy | ||
"": default-proxy | ||
|
||
proxies: | ||
# SOCKS5 proxy just needs a URL | ||
example-1-proxy: socks5://username:[email protected] | ||
|
||
# SSH proxy also should have at least a 'privateKeyFile' | ||
social-proxy: | ||
url: ssh://[email protected] | ||
privateKeyFile: /proxies/social-proxy-private-key | ||
# optional | ||
publicHostsFile: /proxies/social-proxy-public-hosts | ||
|
||
default-proxy: | ||
url: ssh://[email protected] | ||
privateKeyFile: /proxies/default-proxy-private-key | ||
``` | ||
|
||
If the above config is stored in `./proxies/proxyConfig.yaml` along with the SSH private keys and known public hosts | ||
files, the crawler can be started with: | ||
|
||
```sh | ||
docker run -v $PWD/crawls:/crawls -v $PWD/proxies:/proxies -it webrecorder/browsertrix-crawler --url https://example.com/ --proxyServerConfig /proxies/proxyConfig.yaml | ||
``` | ||
|
||
Note that if SSH proxies are provided, an SSH tunnel must be opened for each one before the crawl starts. | ||
The crawl will not start if any of the SSH proxy connections fail, even if a host-specific proxy is not actually used. | ||
SOCKS5 and HTTP proxy connections are attempted only on first use. | ||
|
||
The same `--proxyServerConfig` option can also be used in browser profile creation with the `create-login-profile` command in the same way. | ||
|
||
### Proxy Precedence | ||
|
||
If both `--proxyServerConfig` and `--proxyServer`/`PROXY_SERVER` env var are specified, the single `--proxyServer` | ||
option takes precedence. | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import { | |
logger, | ||
} from "./logger.js"; | ||
import { SaveState } from "./state.js"; | ||
import { loadProxyConfig } from "./proxy.js"; | ||
|
||
// ============================================================================ | ||
export type CrawlerArgs = ReturnType<typeof parseArgs> & { | ||
|
@@ -641,6 +642,12 @@ class ArgParser { | |
type: "string", | ||
}, | ||
|
||
proxyServerConfig: { | ||
describe: | ||
"if set, path to yaml/json file that configures multiple path servers per URL regex", | ||
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. Same question about JSON support as above |
||
type: "string", | ||
}, | ||
|
||
dryRun: { | ||
describe: | ||
"If true, no archive data is written to disk, only pages and logs (and optionally saved state).", | ||
|
@@ -778,6 +785,8 @@ class ArgParser { | |
argv.emulateDevice = { viewport: null }; | ||
} | ||
|
||
loadProxyConfig(argv); | ||
|
||
if (argv.lang) { | ||
if (!ISO6391.validate(argv.lang)) { | ||
logger.fatal("Invalid ISO-639-1 country code for --lang: " + argv.lang); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this actually support JSON? From docs and code I'm only seeing YAML support
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.
YAML is supposed to be a superset of JSON, as of 1.2 at least! (Although there are some edge-cases, but not sure we need to worry about, according to: https://news.ycombinator.com/item?id=30052633)
We could attempt to parse as JSON if YAML parsing fails.
FWIW, the main config is also parsed via a YAML parser but is stored as JSON in Browsertrix - we have not had any issues with it.