Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Sync with master (again) [skip ci] #14

Merged
merged 61 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
7c83eff
add a custom interface for the resolver instead of forcing *net.Resol…
JulesDT Apr 14, 2023
65b5bdb
feature/add prometheus metrics (#179)
jmcconnell26 May 19, 2023
aa75ca1
Use ElementsMatch to ignore order
kevinv-stripe May 24, 2023
31f4a3c
Just use require
kevinv-stripe May 24, 2023
c227b0d
Merge pull request #190 from stripe/kevinv/fix-test-map-keys
kevinv-stripe May 24, 2023
445d0d6
Move the custom request handler call after the main acl check
sergeyrud-stripe May 24, 2023
8dd3072
Merge pull request #189 from stripe/sergeyrud-move-custom-request-han…
kevinv-stripe May 31, 2023
604044b
Use local server instead of httpbin (#192)
cmoresco-stripe Jun 23, 2023
81a59fd
Do not return a denyError for DNS resolution failures (#194)
cds2-stripe Jul 13, 2023
6f13b30
add AcceptResponseHandler to modify accepted responses (#196)
cmoresco-stripe Jul 26, 2023
14a7af2
Update docs to clarify global_deny_list (#197)
cmoresco-stripe Jul 27, 2023
48069eb
Use AcceptResponseHandler in goproxy https CONNECT hook (#199)
cmoresco-stripe Aug 3, 2023
c86310d
Export SmokescreenContext type (#200)
cmoresco-stripe Aug 4, 2023
4bc8d89
generate new test pki (#206)
cds2-stripe Nov 7, 2023
d4766a6
allow listen address specification for prom (#203)
ne-bknn Nov 8, 2023
8cceb4f
Bump golang.org/x/net from 0.7.0 to 0.17.0 (#204)
dependabot[bot] Nov 8, 2023
997578a
bump go versions (#207)
cds2-stripe Nov 8, 2023
1a9dea7
update dependency
xieyuxi-stripe Nov 13, 2023
df2fa89
configure addr in smokescreen and add unit test
xieyuxi-stripe Nov 13, 2023
3f8bcc3
use fmt
xieyuxi-stripe Nov 14, 2023
413045a
try this workaround
xieyuxi-stripe Nov 14, 2023
892f9cb
variable name change
xieyuxi-stripe Nov 14, 2023
4cae3b1
Merge pull request #208 from stripe/xieyuxi-configurable-proxy-addrs
xieyuxi-stripe Nov 15, 2023
8c0fa26
Update docs to disambiguate ACL vs --deny-address behavior (#210)
cmoresco-stripe Dec 1, 2023
2457d2f
fix fields bug
jjiang-stripe Aug 4, 2023
bc280e3
remove extra field setting
jjiang-stripe Aug 4, 2023
24ee0c8
trigger build
jjiang-stripe Feb 15, 2024
fbd1ea7
Merge pull request #201 from stripe/jjiang/fix-logging-addrs
jjiang-stripe Feb 15, 2024
5c3d435
Add support for Smokescreen -> HTTPS CONNECT Proxy ACLs (#213)
pspieker-stripe Feb 16, 2024
3e74045
Bump goproxy version to incorporate CONNECT proxy header changes
pspieker-stripe Feb 16, 2024
44dbbfa
WIP
pspieker-stripe Feb 16, 2024
065ad0e
Merge pull request #215 from stripe/bump-gp-version
pspieker-stripe Feb 16, 2024
eb1ac09
Bump google.golang.org/protobuf from 1.28.1 to 1.33.0 (#216)
dependabot[bot] Apr 23, 2024
85c4c64
Add support for username / password auth in URLs to external CONNECT …
pspieker-stripe Jul 11, 2024
d593d0e
Ensure proxy passed in X-Upstream-Https-Proxy is parsable
gauthamw-stripe Sep 4, 2024
149b19d
Merge pull request #224 from stripe/gauthamw/https-proxy
gauthamw-stripe Sep 4, 2024
ac11203
Update Github build workflows (#228)
harold-stripe Sep 17, 2024
1477610
Use goveralls parallel build
harold-s Sep 17, 2024
735a6e8
Merge pull request #229 from stripe/harold/goveralls-build
harold-stripe Sep 17, 2024
506e362
go get -d github.com/stripe/goproxy@latest && go mod vendor
harold-s Sep 9, 2024
734c343
Add MITM support to Smokescreen
harold-s Sep 10, 2024
4e1b3e2
Use MitmTLSConfig in the config instead of MitmCa
harold-s Sep 12, 2024
ddde90f
PR feedback + remove CloseIdleConnections
harold-s Sep 13, 2024
92537ef
Refactor allowed_domains_mitm to mitm_domains
harold-s Sep 17, 2024
4cf6e0b
Rename ValidateRule
harold-s Sep 17, 2024
dab4bde
Merge pull request #225 from stripe/harold/mitm_support
harold-stripe Sep 17, 2024
3713647
Add Support for Reject Handler with Context
saurabhbhatia-stripe Oct 3, 2024
0c4798d
Update comment
saurabhbhatia-stripe Oct 4, 2024
b3a45df
Block smokescreen init incase of invalid config
saurabhbhatia-stripe Oct 4, 2024
97f1857
fix: fix slice init length
cuishuang Oct 4, 2024
04ce070
Remove duplicate validation
saurabhbhatia-stripe Oct 8, 2024
f6f8191
Merge pull request #232 from stripe/saurabhbhatia/add-reject-handler
saurabhbhatia-stripe Oct 8, 2024
bc38d13
Make SmokeScreen Fields Public
saurabhbhatia-stripe Oct 10, 2024
a6b1a34
Revert Role fixes
saurabhbhatia-stripe Oct 10, 2024
c75cffb
Revert Role fixes
saurabhbhatia-stripe Oct 10, 2024
688e70b
Merge pull request #234 from stripe/saurabhbhatia/smokescreen-ctx-cha…
saurabhbhatia-stripe Oct 11, 2024
9556eb9
Update goproxy version to v0.0.0-20241017101008-e12ef0653f22 (#235)
saurabhbhatia-stripe Oct 17, 2024
5b0cc7a
Adding [allow|deny]_addresses settings to yaml config file
eastebry Oct 18, 2024
523d927
Update goproxy version to v0.0.0-20241022131412-58117846327a (#238)
saurabhbhatia-stripe Oct 23, 2024
1c315f8
Merge pull request #237 from eastebry/master
jjiang-stripe Nov 4, 2024
bffe947
Merge pull request #233 from cuishuang/master
jjiang-stripe Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 22 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
on: [push, pull_request]
name: Test
# Workaround for coveralls error "Can't add a job to a build that is already closed"
# See https://github.com/lemurheavy/coveralls-public/issues/1716
env:
COVERALLS_SERVICE_NUMBER: ${{ github.run_id }}-${{ github.run_attempt }}
COVERALLS_PARALLEL: true
jobs:
test:
strategy:
matrix:
go-version: ['1.19', '1.20']
go-version: ['1.21', '1.22', '1.23']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Setup env
Expand All @@ -23,13 +28,24 @@ jobs:
go test -race -v -timeout 2m -failfast -covermode atomic -coverprofile=.covprofile ./... -tags=nointegration
# Run integration tests hermetically to avoid nondeterministic races on environment variables
go test -race -v -timeout 2m -failfast ./cmd/... -run TestSmokescreenIntegration
go test -race -v -timeout 2m -failfast ./cmd/... -run TestInvalidUpstreamProxyConfiguratedFromEnv
go test -race -v -timeout 2m -failfast ./cmd/... -run TestInvalidUpstreamProxyConfiguration
go test -race -v -timeout 2m -failfast ./cmd/... -run TestClientHalfCloseConnection
- name: Install goveralls
env:
GO111MODULE: off
run: go get github.com/mattn/goveralls
run: go install github.com/mattn/goveralls@latest
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=.covprofile -service=github
finish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest
- name: Close goveralls parallel build
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=.covprofile -service=github -parallel-finish=true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.swp
*.swo
*.swn
*debug.test*
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "smokescreen",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "./",
"args": ["--config-file", "config.yaml", "--egress-acl-file", "acl.yaml"]
}
]
}
308 changes: 308 additions & 0 deletions Development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@

# Development and Testing

## Testing
```bash
go test ./...
```

## Running locally

This section describes how to run Smokescreen locally with different scenarios and using `curl` as a client.

- [HTTP Proxy](#http-proxy)
- [HTTP CONNECT Proxy](#http-connect-proxy)
- [Monitor metrics Smokescreen emits](#monitor-metrics-smokescreen-emits)
- [HTTP CONNECT Proxy over TLS](#http-connect-proxy-over-tls)
- [MITM (Man in the middle) Proxy](#mitm-man-in-the-middle-proxy)
- [MITM (Man in the middle) Proxy over TLS](#mitm-man-in-the-middle-proxy-over-tls)

### HTTP Proxy

#### Configurations

```yaml
# config.yaml
---
allow_missing_role: true # skip mTLS client validation (use default ACL)
```

```yaml
# acl.yaml
---
version: v1
services: []
default:
name: default
project: security
action: enforce
allowed_domains:
- example.com
```

#### Run

```bash
# Run smokescreen (in a different shell)
go run . --config-file config.yaml --egress-acl-file acl.yaml

# Curl
curl -x localhost:4750 http://example.com
# Curl with ALL_PROXY
ALL_PROXY=localhost:4750 curl -v http://example.com
```

### HTTP CONNECT Proxy

#### Configurations

```yaml
# config.yaml
---
allow_missing_role: true # skip mTLS client validation (use default ACL)
```

```yaml
# acl.yaml
---
version: v1
services: []
default:
name: default
project: security
action: enforce
allowed_domains:
- api.github.com
```

#### Run

```bash
# Run smokescreen (in a different shell)
go run . --config-file config.yaml --egress-acl-file acl.yaml

# Curl
curl --proxytunnel -x localhost:4750 https://api.github.com/zen
# Curl with HTTPS_PROXY
HTTPS_PROXY=localhost:4750 curl https://api.github.com/zen
```

### Monitor metrics Smokescreen emits

#### Configurations

```yaml
# config.yaml
---
allow_missing_role: true # skip mTLS client validation (use default ACL)
statsd_address: 127.0.0.1:8200
```

```yaml
# acl.yaml
---
version: v1
services: []
default:
name: default
project: security
action: enforce
allowed_domains:
- api.github.com
```

#### Run

```bash
# Listen to a local port with nc (in a different shell)
nc -uklv 127.0.0.1 8200

# Run smokescreen (in a different shell)
go run . --config-file config.yaml --egress-acl-file acl.yaml

# Curl
curl --proxytunnel -x localhost:4750 https://api.github.com/zen
# Curl with HTTPS_PROXY
HTTPS_PROXY=localhost:4750 curl https://api.github.com/zen
```

### HTTP CONNECT Proxy over TLS

#### Set-up

##### Generate certificates
```bash
mkdir -p mtls_setup
# Private keys for CAs
openssl genrsa -out mtls_setup/server-ca.key 2048
openssl genrsa -out mtls_setup/client-ca.key 2048

# Generate client and server CA certificates
openssl req -new -x509 -nodes -days 1000 -key mtls_setup/server-ca.key -out mtls_setup/server-ca.crt \
-subj "/C=AQ/ST=Petrel Island/L=Dumont-d'Urville
/O=Penguin/OU=Publishing house/CN=server CA"

openssl req -new -x509 -nodes -days 1000 -key mtls_setup/client-ca.key -out mtls_setup/client-ca.crt \
-subj "/C=MA/ST=Tarfaya/L=Tarfaya/O=Fennec/OU=Aviator/CN=Client CA"

# Generate a certificate signing request (client CN is localhost which is used by smokescreen as the service name by default)
openssl req -newkey rsa:2048 -nodes -keyout mtls_setup/server.key -out mtls_setup/server.req \
-subj "/C=AQ/ST=Petrel Island/L=Dumont-d'Urville/O=Chionis/OU=Publishing house/CN=server req"
openssl req -newkey rsa:2048 -nodes -keyout mtls_setup/client.key -out mtls_setup/client.req \
-subj "/C=MA/ST=Tarfaya/L=Tarfaya/O=Addax/OU=Writer/CN=localhost"

# Have the CA sign the certificate requests and output the certificates.
echo "authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
" > mtls_setup/localhost.ext

openssl x509 -req -in mtls_setup/server.req -days 1000 -CA mtls_setup/server-ca.crt -CAkey mtls_setup/server-ca.key -set_serial 01 -out mtls_setup/server.crt -extfile mtls_setup/localhost.ext

openssl x509 -req -in mtls_setup/client.req -days 1000 -CA mtls_setup/client-ca.crt -CAkey mtls_setup/client-ca.key -set_serial 01 -out mtls_setup/client.crt
```

##### Configurations

```yaml
# config.yaml
---
tls:
cert_file: "mtls_setup/server.crt"
key_file: "mtls_setup/server.key"
client_ca_files:
- "mtls_setup/client-ca.crt"
```

```yaml
# acl.yaml
---
version: v1
services:
- name: localhost
project: github
action: enforce
allowed_domains:
- api.github.com
default:
name: default
project: security
action: enforce
allowed_domains: []
```

#### Run

```bash
# Run smokescreen (in a different shell)
go run . --config-file config.yaml --egress-acl-file acl.yaml

# Curl
curl --proxytunnel -x https://localhost:4750 --proxy-cacert mtls_setup/server-ca.crt --proxy-cert mtls_setup/client.crt --proxy-key mtls_setup/client.key https://api.github.com/zen
# Curl with HTTPS_PROXY
HTTPS_PROXY=https://localhost:4750 curl --proxy-cacert mtls_setup/server-ca.crt --proxy-cert mtls_setup/client.crt --proxy-key mtls_setup/client.key https://api.github.com/zen
```

### MITM (Man in the middle) Proxy

#### Set-up

```yaml
# config.yaml
---
allow_missing_role: true # skip mTLS client validation (use default ACL)
# Re-using goproxy library CA and key
mitm_ca_cert_file: "vendor/github.com/stripe/goproxy/ca.pem"
mitm_ca_key_file: "vendor/github.com/stripe/goproxy/key.pem"
```

```yaml
# acl.yaml
---
version: v1
services: []
default:
name: default
project: security
action: enforce
allowed_domains:
- wttr.in
mitm_domains:
- domain: wttr.in
add_headers:
Accept-Language: el
detailed_http_logs: true
detailed_http_logs_full_headers:
- User-Agent
```

#### Run

```bash
# Run smokescreen (in a different shell)
go run . --config-file config.yaml --egress-acl-file acl.yaml

# Curl (weather should be in Greek since we set the Accept-Language header)
curl --proxytunnel -x localhost:4750 --cacert vendor/github.com/stripe/goproxy/ca.pem https://wttr.in
# Curl with HTTPS_PROXY
HTTPS_PROXY=localhost:4750 curl --cacert vendor/github.com/stripe/goproxy/ca.pem https://wttr.in
```

### MITM (Man in the middle) Proxy over TLS

#### Set-up

Please generate the certificates from the TLS Generate certificates section.

```yaml
# config.yaml
---
tls:
cert_file: "mtls_setup/server.crt"
key_file: "mtls_setup/server.key"
client_ca_files:
- "mtls_setup/client-ca.crt"
# Re-using goproxy library CA and key
mitm_ca_cert_file: "vendor/github.com/stripe/goproxy/ca.pem"
mitm_ca_key_file: "vendor/github.com/stripe/goproxy/key.pem"
```

```yaml
# acl.yaml
---
version: v1
services:
- name: localhost
project: github
action: enforce
allowed_domains:
- wttr.in
mitm_domains:
- domain: wttr.in
add_headers:
Accept-Language: el
detailed_http_logs: true
detailed_http_logs_full_headers:
- User-Agent
default:
name: default
project: security
action: enforce
allowed_domains: []
```

#### Run

```bash
# Run smokescreen (in a different shell)
go run . --config-file config.yaml --egress-acl-file acl.yaml

# Curl (weather should be in Greek since we set the Accept-Language header)
curl --proxytunnel -x https://localhost:4750 --cacert vendor/github.com/stripe/goproxy/ca.pem --proxy-cacert mtls_setup/server-ca.crt --proxy-cert mtls_setup/client.crt --proxy-key mtls_setup/client.key https://wttr.in
# Curl with HTTPS_PROXY
HTTPS_PROXY=https://localhost:4750 curl --cacert vendor/github.com/stripe/goproxy/ca.pem --proxy-cacert mtls_setup/server-ca.crt --proxy-cert mtls_setup/client.crt --proxy-key mtls_setup/client.key https://wttr.in
```
Loading
Loading