Skip to content
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

Release version v0.1.1 #37

Merged
merged 103 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
89f493c
Readme
lablans Apr 11, 2023
dd0ec24
Rebuild cache
lablans Apr 11, 2023
40db842
Merge pull request #9 from samply/fix-ci
Threated Apr 11, 2023
aa4d58e
Add testing to CI
Threated Apr 11, 2023
0995460
wait for beam-connect container
Threated Apr 11, 2023
2c3a5f2
start and test in seperate steps
Threated Apr 12, 2023
9a3a654
wait for containers
Threated Apr 12, 2023
6cf4ff3
ping beam-connect
Threated Apr 12, 2023
f4a32d0
show logs
Threated Apr 12, 2023
ff1b533
show logs
Threated Apr 12, 2023
30f465c
use distroless in tests
Threated Apr 12, 2023
25f490a
comment out logs
Threated Apr 12, 2023
feba785
remove check for proxy auth header
Threated Apr 26, 2023
92ccca4
imporve logging
Threated Apr 27, 2023
a077722
Merge pull request #11 from samply/feature/logging
Threated Apr 27, 2023
05f08c2
Merge branch 'develop' into no-auth
Threated Apr 27, 2023
932071f
switch to tracing
Threated Apr 27, 2023
3b6bc57
Merge pull request #13 from samply/fix/logging
Threated Apr 27, 2023
45ceda5
Merge branch 'develop' into no-auth
Threated Apr 27, 2023
e523125
Fix log message
Threated Apr 28, 2023
5da9266
Merge branch 'develop' into no-auth
Threated Apr 28, 2023
e0d973e
Prevent spam requests from beam connect to beam
Threated Apr 28, 2023
c9bf09b
Merge pull request #14 from samply/fix/spam
Threated Apr 28, 2023
ec89e66
Merge latest imporvements from develop
Threated Apr 28, 2023
edee273
Add CONNECT Diagnostics
TKussel May 2, 2023
3454493
Build correct uri
Threated May 3, 2023
673c542
fix ubuntu certs
Threated May 3, 2023
42ecdce
wip https support
Threated May 3, 2023
4185b07
working tls
Threated May 4, 2023
de0fa0b
set authority and scheme in https requests
Threated May 4, 2023
fb173c8
Clean up
Threated May 4, 2023
2b56e75
refactor
Threated May 4, 2023
1ebf860
Fix container build to link correct libssl
Threated May 4, 2023
1a7f3d9
Exit early when trying to initialize tlc acceptor
Threated May 4, 2023
481452b
Add ssl files to cli options
Threated May 8, 2023
28ea2da
Merge pull request #10 from samply/feature/ci-tests
TKussel May 10, 2023
a1c0bcd
Remove finished todo
Threated May 24, 2023
0899ec4
Remove unused client in handler
Threated May 24, 2023
1a19a0c
Encode body as b64 encoded Vec
Threated May 10, 2023
80866ce
Merge pull request #15 from samply/fix-connect
TKussel May 25, 2023
10b44e1
Revert to using auth
Threated Jun 7, 2023
ae0a306
Merge pull request #17 from samply/feature/https
Threated Jun 7, 2023
6a5f856
Polling and http execution
Threated Jun 7, 2023
da917cb
Update start script
Threated Jun 9, 2023
9aaadfa
Working http via sockets
Threated Jun 9, 2023
793c1b1
Fix conditional compilation
Threated Jun 9, 2023
c227216
spwan tokio task for each socket task
Threated Jun 9, 2023
84757d0
Add rust tests
Threated Jun 9, 2023
503cf6f
Dont do all requests via https
Threated Jun 9, 2023
87bd020
Test ws in rust
Threated Jun 9, 2023
4b0c79c
ws echo server
Threated Jun 9, 2023
feb6024
Use postman instead of httpbin
Threated Jun 12, 2023
1b12361
http upgrades
Threated Jun 12, 2023
6b7fbfe
Remove old python tests
Threated Jun 12, 2023
e24dbd3
Clean up unwrap and names
Threated Jun 12, 2023
82f4d2d
Fix typos
Threated Jun 12, 2023
a2395e2
Build feature in CI
Threated Jun 12, 2023
83475b9
Update beam tag based on feature for tests
Threated Jun 12, 2023
8c6c283
Default to empty string
Threated Jun 12, 2023
2d3f639
Fix empty string
Threated Jun 12, 2023
a728198
Merge pull request #19 from samply/feature/sockets
Threated Jun 12, 2023
8cdc88a
Update sockets branch as it is merged now
Threated Jun 23, 2023
a24c508
Start replacing beam-shared with beam-lib
Threated Jul 17, 2023
52c4316
Migrate most stuff to beam-lib
Threated Jul 18, 2023
34c3366
Implement path redirects via config
Threated Jul 18, 2023
37ce82e
Add parsing tests
Threated Jul 18, 2023
ebdbe63
Add integration tests
Threated Jul 19, 2023
5be6d4d
Fix query params
Threated Jul 19, 2023
720c766
Merge pull request #20 from samply/fix/beam-lib
TKussel Jul 20, 2023
6f7bd78
Add internal path redirection to example local targets
TKussel Jul 20, 2023
8a2fb72
Merge pull request #21 from samply/feature/redirects
TKussel Jul 20, 2023
711b24c
Don't depend on cross image
lablans Jul 20, 2023
fa5f97b
Merge pull request #22 from samply/feature/redirects
TKussel Aug 1, 2023
9e14db2
Merge pull request #23 from samply/dont-depend-on-cross-image
lablans Aug 3, 2023
f3daa49
Fix no-auth
Threated Aug 21, 2023
cfa91c1
Merge pull request #26 from samply/fix/no-auth
TKussel Aug 21, 2023
83cdd5c
Merge pull request #27 from samply/dont-depend-on-cross-image
Threated Aug 21, 2023
cfb74b6
Use local http(s) echo service for tests
Threated Aug 21, 2023
35b1886
Fix ws tests
Threated Aug 22, 2023
e77db37
Make no-auth a config option
Threated Aug 22, 2023
85598bf
Merge pull request #29 from samply/fix/tests
Threated Aug 22, 2023
37b9dc3
Merge pull request #30 from samply/no-auth
TKussel Aug 22, 2023
dfbf69b
Add `NO_AUTH` to readme
TKussel Aug 22, 2023
decc7a7
Remove beam shared and use reqwest
Threated Aug 22, 2023
f12b204
Remove useless client libs
Threated Aug 22, 2023
91cdd0f
Remove remove redundant images in docker-compose
Threated Aug 23, 2023
2ad55d9
Replace hyper_serde with http_serde
Threated Aug 23, 2023
b6abf13
Fix socket https connections
Threated Aug 23, 2023
d521f09
Remove tower deps
Threated Aug 23, 2023
17d04c3
fix url override
Threated Aug 23, 2023
7247d8c
Add http echo test to no_proxy envs
TKussel Aug 23, 2023
9ac7c22
Remove duplicate NO_PROXY env from docker-compose
TKussel Aug 23, 2023
127748d
Merge pull request #31 from samply/refactor
TKussel Aug 23, 2023
88ac2bb
If authority is empty, use 'host' header
TKussel Sep 1, 2023
8c141f4
Fix /site endpoint behaviour
TKussel Sep 1, 2023
c6a240b
fix sites endpoint
TKussel Sep 5, 2023
c2bee08
Add sockets features to beamlib
TKussel Sep 5, 2023
fea3cbe
Merge pull request #32 from samply/fix/parse-host
TKussel Sep 5, 2023
fb2c77e
Dont depend on claps `once_cell`
Threated Sep 5, 2023
ad32718
feat: Support upgrading a request to https
Threated Dec 19, 2023
22dfea2
Trigger CI
Threated Dec 19, 2023
145ad0e
Merge pull request #36 from samply/feature/force-https
TKussel Dec 19, 2023
0457c32
Bump version number
TKussel Dec 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ jobs:

build-rust:
name: Build (Rust)
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
matrix:
arch:
- amd64
- arm64
features:
- sockets
- ""

steps:
- name: Set arch ${{ matrix.arch }}
Expand Down Expand Up @@ -61,44 +64,76 @@ jobs:
echo "profilestr=--profile $PROFILE" >> $GITHUB_ENV
fi
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.arch }}-${{ env.PROFILE }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
target: ${{ env.rustarch }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.arch }}-${{ env.PROFILE }}
prefix-key: v1-rust-${{ matrix.features && format('features_{0}', matrix.features) || 'nofeatures' }} # Increase to invalidate old caches.
- name: Build (${{ matrix.arch }})
uses: actions-rs/cargo@v1
with:
use-cross: ${{ env.is_cross }}
command: build
args: --target ${{ env.rustarch }} ${{ env.profilestr }}
args: --target ${{ env.rustarch }} ${{ matrix.features && format('--features {0}', matrix.features) }} ${{ env.profilestr }}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: binaries-${{ matrix.arch }}
name: binaries-${{ matrix.arch }}-${{ matrix.features }}
path: |
target/${{ env.rustarch }}/${{ env.PROFILE }}/connect

test:
name: Run tests
needs: [ build-rust ]
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

strategy:
matrix:
features:
- ""
- "sockets"

steps:
- name: Not implemented yet
run: echo "This will be implemented soonish"
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: binaries-amd64-${{ matrix.features }}
path: artifacts/binaries-amd64/
- name: Set diffrent image tag
run: |
if [[ ${{ format('"{0}"', matrix.features) }} == 'sockets' ]]; then
echo "TAG=develop-sockets" >> $GITHUB_ENV
fi
- name: Start containers
run: ./dev/start ci
# - name: Show logs
# working-directory: ./dev
# run: |
# sleep 3
# docker compose logs
- name: Run tests
run: cargo test ${{ format('--features "{0}"', matrix.features) }}

docker:
needs: [ build-rust, pre-check, test ]

strategy:
matrix:
features:
- ""
- "sockets"

# This workflow defines how a maven package is built, tested and published.
# Visit: https://github.com/samply/github-workflows/blob/develop/.github/workflows/docker-ci.yml, for more information
uses: samply/github-workflows/.github/workflows/docker-ci.yml@main
with:
# The Docker Hub Repository you want eventually push to, e.g samply/share-client
image-name: "samply/beam-connect"
image-tag-suffix: ${{ matrix.features && format('-{0}', matrix.features) }}
# Define special prefixes for docker tags. They will prefix each images tag.
# image-tag-prefix: "foo"
# Define the build context of your image, typically default '.' will be enough
Expand All @@ -107,9 +142,8 @@ jobs:
build-file: './Dockerfile.ci'
# NOTE: This doesn't work currently
# A list of build arguments, passed to the docker build
# build-args: |
# PROFILE=${{ env.PROFILE }}
# COMPONENT=broker
build-args: |
FEATURE=-${{ matrix.features }}
# Define the target platforms of the docker build (default "linux/amd64,linux/arm64/v8")
# build-platforms: "linux/amd64,linux/arm64"
# If your actions generate an artifact in a previous build step, you can tell this workflow to download it
Expand Down
34 changes: 20 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "connect"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
license = "Apache-2.0"

Expand All @@ -18,30 +18,36 @@ inherits = "release"
strip = false

[dependencies]
shared = { git = "https://github.com/samply/beam", branch="develop" }
beam-lib = { git = "https://github.com/samply/beam", branch="develop", features = ["strict-ids"] }

#axum = "0.5.12"
tokio = { version = "1", features = ["macros","rt-multi-thread","signal"] }
hyper = { version = "0", features = ["full"] }
tower-http = { version = "0", features = ["trace"] }
tower = "*"
hyper = { version = "0.14", features = ["full"] }

# HTTP client with proxy support
hyper-tls = "0.5.0"
hyper-proxy = "0.9.1"
mz-http-proxy = { version = "0.1.0", features = ["hyper"] }
reqwest = { version = "0.11.19", features = ["json", "stream"] }

log = "*"
pretty_env_logger = "*"
tracing = "0.1"

serde = "*"
serde_json = "*"
hyper_serde = "0.13"

clap = {version = "4", features = ["derive"]}
clap = { version = "4", features = ["derive", "env"] }

thiserror = "*"
http-serde = "1.1.2"
http-serde = "1.1"
tokio-native-tls = "0.3.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
anyhow = "1"
openssl = "*" # Already used by native_tls which does not reexport it. This is used for b64 en/decode

[features]
sockets = ["beam-lib/sockets"]

[build-dependencies]
build-data = "0"

[dev-dependencies]
once_cell = "1"
futures-util = "0.3.28"
paste = "1.0.12"
tokio-tungstenite = "0.20.0"
4 changes: 2 additions & 2 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[target.aarch64-unknown-linux-gnu]
image = "ghcr.io/lablans/cross-test:aarch64-unknown-linux-gnu"
pre-build = ["dpkg --add-architecture arm64 && apt-get update && apt-get install --assume-yes libssl-dev:arm64 && rm -rf /var/lib/apt/lists/*"]

[target.x86_64-unknown-linux-gnu]
image = "ghcr.io/lablans/cross-test:x86_64-unknown-linux-gnu"
pre-build = ["dpkg --add-architecture amd64 && apt-get update && apt-get install --assume-yes libssl-dev:amd64 && rm -rf /var/lib/apt/lists/*"]
10 changes: 8 additions & 2 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
ARG IMGNAME=gcr.io/distroless/cc

FROM alpine AS chmodder
ARG FEATURE
ARG TARGETARCH
COPY /artifacts/binaries-$TARGETARCH/connect /app/
COPY /artifacts/binaries-$TARGETARCH$FEATURE/connect /app/
RUN chmod +x /app/*

FROM ${IMGNAME}
# FROM ${IMGNAME}
FROM ubuntu:latest
RUN apt update
RUN apt install -y ca-certificates
RUN apt install -y ssl-cert
RUN make-ssl-cert generate-default-snakeoil
#ARG COMPONENT
ARG TARGETARCH
#COPY /artifacts/binaries-$TARGETARCH/$COMPONENT /usr/local/bin/
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ The following command line parameters are required:
* `PROXY_URL`: The URL of the local Samply.Proxy which is used to connect to the Samply.Broker
* `APP_ID`: The BeamId of the Beam.Connect application
* `LOCAL_TARGETS_FILE`: The path to the local service resolution file (see [Routing Section](#Request-Routing)).
* `DISCOVERY_URL`: The URL that is queried to receive the central service discovery this may also be a local file (see [Routing Section](#Request-Routing)).
* `DISCOVERY_URL`: The URL (or local file) to be is queried to receive the central service discovery (see [Routing Section](#Request-Routing)).

The following command line parameter is only used in Receiver mode (see [Usage Section](#usage)):
* `PROXY_APIKEY`: In Receiver Mode, the API key with which this Beam.Connector is registered for listening at the Samply.Broker

The following command line parameter is optional, as it uses a default value:
* `BIND_ADDR`: The interface and port Beam.Connect is listening on. Defaults to `0.0.0.0:8062`.

If the following flag is optional.
* `NO_AUTH`: Samply.Beam.Connect does not require a `Proxy Authorization` header, i.e. it forwards requests without (client) authentication

All parameters can be given as environment variables instead.

### Run using Docker
Expand All @@ -58,9 +61,10 @@ docker run -e PROXY_URL='<PROXY_URL>' \
-e DISCOVERY_URL='<DISCOVERY_URL>' \
-e PROXY_APIKEY='<PROXY_APIKEY>' \
-e BIND_ADDR='<BIND_ADDR>' \
-e NO_AUTH='true' \
samply/beam-connect
```
Again, the last environment variable `PROXY_APIKEY` is only required for usage in Receiver Mode and `BIND_ADDR` is optional.
Again, the environment variable `PROXY_APIKEY` is only required for usage in Receiver Mode. `BIND_ADDR` and `NO_AUTH` are optional.

### Use Beam.Connect to forward a HTTP request
We give an example [cURL](https://curl.se/) request showing the usage of Beam.Connect to access an internal service within University Hospital #23 (`uk23`):
Expand All @@ -87,7 +91,14 @@ A mishap in communication will be returned as appropriate HTTP replies.

As described in the [command line parameter list](#run-as-an-application), the central cite discovery is fetched from a given URL or local json file. However, to spare the local services from the need to express outward facing connections themselves, Samply.Beam.Connect exports this received information as a local REST endpoint: `GET http://<beam_connect_url>:<beam_connect_port>/sites`. Note, that the information is only fetched at startup and remains static for the program's lifetime.

#### HTTPS support

Https is supported but requires setting up the following parameters:
* `SSL_CERT_PEM`: Location to the pem file used for incoming SSL connections.
* `SSL_CERT_KEY`: Location to the corresponding key file for the SSL connections.
* `TLS_CA_CERTIFICATES_DIR`: May need to be set if the local target uses a self signed certificate which is not trusted by beam-connect. In this case the certificate of the target must be placed inside `TLS_CA_CERTIFICATES_DIR` as a pem file in order to be trusted.

## Notes
At the moment Samply.Beam.Connect does not implement streaming and does not support HTTPS connections. In the intended usage scenario, both Samply.Beam.Connect and Samply.Beam.Proxy are positioned right next to each other in the same privileged network and thus speak plain HTTP. Of course, for outgoing traffic, the Samply.Proxy signs and encrypts the payloads on its own.
At the moment Samply.Beam.Connect does not implement streaming. In the intended usage scenario, both Samply.Beam.Connect and Samply.Beam.Proxy are positioned right next to each other in the same privileged network and thus speak plain HTTP or [HTTPS if configured](#https). Of course, for outgoing traffic, the Samply.Proxy signs and encrypts the payloads on its own.

In Receiving Mode, Beam.Connect only relays requests to allow-listed resources to mitigate possible misuse.
38 changes: 24 additions & 14 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.7"
services:
vault:
image: vault
image: hashicorp/vault
ports:
- 127.0.0.1:8200:8200
environment:
Expand All @@ -21,7 +21,6 @@ services:
BROKER_URL: ${BROKER_URL}
PKI_ADDRESS: http://vault:8200
no_proxy: vault
NO_PROXY: vault
PRIVKEY_FILE: /run/secrets/dummy.pem
BIND_ADDR: 0.0.0.0:8080
RUST_LOG: ${RUST_LOG}
Expand All @@ -37,12 +36,10 @@ services:
environment:
BROKER_URL: ${BROKER_URL}
PROXY_ID: ${PROXY1_ID}
APP_0_ID: ${APP1_ID_SHORT}
APP_0_KEY: ${APP_KEY}
APP_app1_KEY: ${APP_KEY}
PRIVKEY_FILE: /run/secrets/proxy1.pem
BIND_ADDR: 0.0.0.0:8081
RUST_LOG: ${RUST_LOG}
NO_PROXY: broker
no_proxy: broker
secrets:
- proxy1.pem
Expand All @@ -53,7 +50,6 @@ services:
build:
context: ../
dockerfile: Dockerfile.ci
image: samply/beam-connect:${TAG}
ports:
- 8062:8062
volumes:
Expand All @@ -64,19 +60,18 @@ services:
PROXY_APIKEY: ${APP_KEY}
DISCOVERY_URL: "./map/example_central_test.json"
RUST_LOG: ${RUST_LOG}
NO_PROXY: proxy1
no_proxy: proxy1
no_proxy: proxy1,my.example.com
connect2:
depends_on:
- proxy2
build:
context: ../
dockerfile: Dockerfile.ci
image: samply/beam-connect:${TAG}
ports:
- 8063:8063
volumes:
- ../examples/:/map
- ssl-cert:/custom-cert
environment:
PROXY_URL: "http://proxy2:8082"
BIND_ADDR: 0.0.0.0:8063
Expand All @@ -85,8 +80,8 @@ services:
DISCOVERY_URL: "./map/example_central_test.json"
LOCAL_TARGETS_FILE: "./map/example_local_test.json"
RUST_LOG: ${RUST_LOG}
NO_PROXY: proxy2
no_proxy: proxy2
no_proxy: proxy2,my.example.com
TLS_CA_CERTIFICATES_DIR: /custom-cert
proxy2:
depends_on: [broker]
image: samply/beam-proxy:${TAG}
Expand All @@ -95,16 +90,28 @@ services:
environment:
BROKER_URL: ${BROKER_URL}
PROXY_ID: ${PROXY2_ID}
APP_0_ID: ${APP2_ID_SHORT}
APP_0_KEY: ${APP_KEY}
APP_app2_KEY: ${APP_KEY}
PRIVKEY_FILE: /run/secrets/proxy2.pem
BIND_ADDR: 0.0.0.0:8082
RUST_LOG: ${RUST_LOG}
NO_PROXY: broker
no_proxy: broker
secrets:
- proxy2.pem
- root.crt.pem
ws-echo:
image: jmalloc/echo-server
environment:
PORT: 80
echo:
image: mendhak/http-https-echo
container_name: my.example.com # We set this so that we can connect via this common name so that the ssl cert CN matches
environment:
- HTTP_PORT=80
- HTTPS_PORT=443
volumes:
- ssl-cert:/app/custom-cert
entrypoint: ["sh", "-c", "cp ./fullchain.pem ./custom-cert/cert.pem && node ./index.js"]
user: "0:0"
secrets:
pki.secret:
file: ./pki/pki.secret
Expand All @@ -116,3 +123,6 @@ secrets:
file: ./pki/dummy.priv.pem
root.crt.pem:
file: ./pki/root.crt.pem

volumes:
ssl-cert:
Loading
Loading