Skip to content

Commit

Permalink
Preparing for the next release
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Woods authored and Christopher Woods committed Oct 25, 2024
1 parent 5d22e0c commit 0536136
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 45 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Fixed bug in parsing command line options for bridge
- Added support for getting the client IP address from a proxy header (e.g. `X-Forwarded-For`)
- Cleaned up port handling, so URLs with default ports don't have the ports specified

## [0.0.8] - 2024-10-24
### Added
Expand Down
2 changes: 1 addition & 1 deletion bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "op-bridge"
version = "0.0.1"
version = "0.0.9"
description = "An example of an OpenPortal user portal to OpenPortal bridge"
edition = "2021"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async fn main() -> Result<()> {
Some("127.0.0.1".to_owned()),
Some(8044),
None,
None,
Some("http://localhost:3000".to_owned()),
Some("127.0.0.1".to_owned()),
Some(3000),
Expand Down
2 changes: 1 addition & 1 deletion cluster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "op-cluster"
version = "0.0.1"
version = "0.0.9"
description = "An example of an OpenPortal HPC cluster platform agent"
edition = "2021"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions cluster/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async fn main() -> Result<()> {
Some("127.0.0.1".to_owned()),
Some(8045),
None,
None,
Some(AgentType::Platform),
);

Expand Down
2 changes: 1 addition & 1 deletion docs/cmdline/cluster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "example-cluster"
version = "0.0.1"
version = "0.0.9"
description = "templemeads command line example - cluster agent"
edition = "2021"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions docs/cmdline/cluster/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async fn main() -> Result<()> {
Some("127.0.0.1".to_owned()),
Some(8091),
None,
None,
Some(AgentType::Instance),
);

Expand Down
2 changes: 1 addition & 1 deletion docs/cmdline/portal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "example-portal"
version = "0.0.1"
version = "0.0.9"
description = "templemeads command line example - portal agent"
edition = "2021"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions docs/cmdline/portal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async fn main() -> Result<()> {
Some("127.0.0.1".to_owned()),
Some(8090),
None,
None,
Some(AgentType::Portal),
);

Expand Down
2 changes: 1 addition & 1 deletion docs/echo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "example-echo"
version = "0.0.1"
version = "0.0.9"
description = "Paddington Echo Service example"
edition = "2021"
license = "MIT"
Expand Down
3 changes: 2 additions & 1 deletion docs/echo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ async fn run_client(invitation: &Path) -> Result<(), Error> {
"127.0.0.1",
&6502,
&None,
&None,
)?;

// now give the invitation to connect to the server to the client
Expand Down Expand Up @@ -262,7 +263,7 @@ async fn run_server(
invitation: &Path,
) -> Result<(), Error> {
// create the echo-server service
let mut service = ServiceConfig::new("echo-server", url, ip, port, &None)?;
let mut service = ServiceConfig::new("echo-server", url, ip, port, &None, &None)?;

let invite = service.add_client("echo-client", range)?;

Expand Down
2 changes: 1 addition & 1 deletion docs/job/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "example-job"
version = "0.0.1"
version = "0.0.9"
description = "templemeads job example"
edition = "2021"
license = "MIT"
Expand Down
3 changes: 2 additions & 1 deletion docs/job/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ async fn run_cluster(invitation: &Path) -> Result<(), Error> {
"127.0.0.1",
&6502,
&None,
&None,
)?;

// now give the invitation to connect to the server to the client
Expand Down Expand Up @@ -260,7 +261,7 @@ async fn run_portal(
invitation: &Path,
) -> Result<(), Error> {
// create a paddington service configuration for the portal agent
let mut service = ServiceConfig::new("portal", url, ip, port, &None)?;
let mut service = ServiceConfig::new("portal", url, ip, port, &None, &None)?;

// add the cluster to the portal, returning an invitation
let invite = service.add_client("cluster", range)?;
Expand Down
2 changes: 1 addition & 1 deletion filesystem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "op-filesystem"
version = "0.0.1"
version = "0.0.9"
description = "Agent that interfaces OpenPortal with a filesystem"
edition = "2021"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions filesystem/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async fn main() -> Result<()> {
Some("127.0.0.1".to_owned()),
Some(8047),
None,
None,
Some(AgentType::Filesystem),
);

Expand Down
2 changes: 1 addition & 1 deletion freeipa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "op-freeipa"
version = "0.0.1"
version = "0.0.9"
description = "Agent that interfaces OpenPortal with FreeIPA"
edition = "2021"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions freeipa/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async fn main() -> Result<()> {
Some("127.0.0.1".to_owned()),
Some(8046),
None,
None,
Some(AgentType::Account),
);

Expand Down
5 changes: 3 additions & 2 deletions paddington/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "paddington"
version = "0.0.1"
version = "0.0.9"
description = "A library for implementing the OpenPortal communication protocol"
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -32,9 +32,10 @@ serde_json = "1.0.120"
serde_with = { version="3.9.0", features = ["hex"] }
thiserror = "1.0.63"
tokio = { version = "1.0", features = ["full", "tracing"] }
tokio-tungstenite = { version = "0.23.1", features = ["rustls-tls-native-roots"] }
tokio-tungstenite = { version = "0.24.0", features = ["rustls-tls-native-roots"] }
toml = "0.8.16"
tracing = "0.1.40"
tungstenite = "0.24.0"
url = {version="2.5.2", features=["serde"]}

[lints.rust]
Expand Down
54 changes: 42 additions & 12 deletions paddington/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct Defaults {
ip: String,
port: u16,
healthcheck_port: Option<u16>,
proxy_header: Option<String>,
}

impl Defaults {
Expand All @@ -84,6 +85,7 @@ impl Defaults {
ip: Option<String>,
port: Option<u16>,
healthcheck_port: Option<u16>,
proxy_header: Option<String>,
) -> Self {
let config_file = config_file.unwrap_or(
dirs::config_local_dir()
Expand All @@ -102,6 +104,7 @@ impl Defaults {
ip: ip.unwrap_or("127.0.0.1".to_owned()),
port: port.unwrap_or(8042),
healthcheck_port,
proxy_header,
}
}

Expand Down Expand Up @@ -439,6 +442,7 @@ pub struct ServiceConfig {
ip: IpAddr,
port: u16,
heathcheck_port: Option<u16>,
proxy_header: Option<String>,

servers: Vec<ServerConfig>,
clients: Vec<ClientConfig>,
Expand All @@ -452,6 +456,7 @@ impl ServiceConfig {
ip: &str,
port: &u16,
healthcheck_port: &Option<u16>,
proxy_header: &Option<String>,
) -> Result<Self, Error> {
Ok(ServiceConfig {
name: name.to_string(),
Expand All @@ -461,6 +466,7 @@ impl ServiceConfig {
.with_context(|| format!("Could not parse IP address: {}", ip))?,
port: *port,
heathcheck_port: *healthcheck_port,
proxy_header: proxy_header.clone(),
servers: Vec::new(),
clients: Vec::new(),
encryption: None,
Expand Down Expand Up @@ -531,6 +537,10 @@ impl ServiceConfig {
self.heathcheck_port
}

pub fn proxy_header(&self) -> Option<String> {
self.proxy_header.clone()
}

pub fn add_client(&mut self, name: &str, ip: &str) -> Result<Invite, Error> {
let ip = IpOrRange::new(ip)
.with_context(|| format!("Could not parse into an IP address or IP range: {}", ip))?;
Expand Down Expand Up @@ -612,6 +622,7 @@ impl ServiceConfig {
ip: IpAddr,
port: u16,
healthcheck_port: &Option<u16>,
proxy_header: &Option<String>,
) -> Result<ServiceConfig, Error> {
// see if this config_dir exists - return an error if it does
let config_file = path::absolute(config_file).with_context(|| {
Expand All @@ -625,7 +636,14 @@ impl ServiceConfig {
return Err(Error::NotExists(config_file.to_string_lossy().to_string()));
}

let config = ServiceConfig::new(&name, &url, &ip.to_string(), &port, healthcheck_port)?;
let config = ServiceConfig::new(
&name,
&url,
&ip.to_string(),
&port,
healthcheck_port,
proxy_header,
)?;
save::<ServiceConfig>(config.clone(), &config_file)?;

// check we can read the config and return it
Expand Down Expand Up @@ -688,17 +706,29 @@ mod tests {

#[test]
fn test_invitations() {
let mut primary =
ServiceConfig::new("primary", "http://localhost", "127.0.0.1", &5544, &None)
.unwrap_or_else(|e| {
unreachable!("Cannot create service config: {}", e);
});

let mut secondary =
ServiceConfig::new("secondary", "http://localhost", "127.0.0.1", &5545, &None)
.unwrap_or_else(|e| {
unreachable!("Cannot create service config: {}", e);
});
let mut primary = ServiceConfig::new(
"primary",
"http://localhost",
"127.0.0.1",
&5544,
&None,
&None,
)
.unwrap_or_else(|e| {
unreachable!("Cannot create service config: {}", e);
});

let mut secondary = ServiceConfig::new(
"secondary",
"http://localhost",
"127.0.0.1",
&5545,
&None,
&None,
)
.unwrap_or_else(|e| {
unreachable!("Cannot create service config: {}", e);
});

// introduce the secondary to the primary
let invite = primary
Expand Down
56 changes: 44 additions & 12 deletions paddington/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ use futures_channel::mpsc::{unbounded, UnboundedSender};
use futures_util::{future, pin_mut, stream::TryStreamExt};
use secrecy::ExposeSecret;
use serde::{de::DeserializeOwned, Serialize};
use std::sync::Arc;
use tokio::net::TcpStream;
use tokio::sync::Mutex as TokioMutex;
use tokio_tungstenite::connect_async;
use tokio_tungstenite::tungstenite::protocol::Message as TokioMessage;

use std::sync::Arc;
use tungstenite::handshake::server::{
ErrorResponse as HandshakeErrorResponse, Request as HandshakeRequest,
Response as HandshakeResponse,
};

use crate::command::Command;
use crate::config::{ClientConfig, PeerConfig, ServiceConfig};
Expand Down Expand Up @@ -358,10 +361,48 @@ impl Connection {
// we now know we are the only ones handling the connection,
// and are safe to update the keys etc.

let addr: std::net::SocketAddr = stream
let mut addr: std::net::SocketAddr = stream
.peer_addr()
.with_context(|| "Error getting the peer address. Ensure the connection is open.")?;

let proxy_header = self.config.proxy_header();
let mut proxy_client = None;

let process_headers = |request: &HandshakeRequest,
response: HandshakeResponse|
-> Result<HandshakeResponse, HandshakeErrorResponse> {
if let Some(proxy_header) = proxy_header {
if let Some(value) = request
.headers()
.get(proxy_header)
.and_then(|value| value.to_str().ok())
{
proxy_client = Some(value.to_string());
}
}

Ok(response)
};

let ws_stream = tokio_tungstenite::accept_hdr_async(stream, process_headers)
.await
.with_context(|| {
format!(
"Error accepting WebSocket connection from: {}. Closing connection.",
addr
)
})?;

if let Some(proxy_client) = proxy_client {
tracing::info!("Proxy client: {:?}", proxy_client);
addr = proxy_client.parse().with_context(|| {
format!(
"Error parsing proxy client address: {}. Closing connection.",
proxy_client
)
})?;
}

tracing::info!("Accepted connection from peer: {}", addr);

let clients: Vec<ClientConfig> = self
Expand All @@ -379,15 +420,6 @@ impl Connection {
));
}

let ws_stream = tokio_tungstenite::accept_async(stream)
.await
.with_context(|| {
format!(
"Error accepting WebSocket connection from: {}. Closing connection.",
addr
)
})?;

// Split the WebSocket stream into incoming and outgoing parts
let (mut outgoing, mut incoming) = ws_stream.split();

Expand Down
Loading

0 comments on commit 0536136

Please sign in to comment.