Skip to content

Commit 1bab183

Browse files
committed
Launch Nexus with both and HTTP and HTTPS server
1 parent 1f843f1 commit 1bab183

File tree

5 files changed

+85
-41
lines changed

5 files changed

+85
-41
lines changed

common/src/nexus_config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
88
use super::address::{Ipv6Subnet, RACK_PREFIX};
99
use super::postgres_config::PostgresConfigWithUrl;
10-
use dropshot::ConfigDropshot;
1110
use serde::{Deserialize, Serialize};
1211
use serde_with::serde_as;
1312
use serde_with::DisplayFromStr;
1413
use std::fmt;
14+
use std::net::IpAddr;
1515
use std::path::{Path, PathBuf};
1616
use uuid::Uuid;
1717

@@ -104,10 +104,10 @@ pub struct DeploymentConfig {
104104
pub id: Uuid,
105105
/// Uuid of the Rack where Nexus is executing.
106106
pub rack_id: Uuid,
107-
/// Dropshot configuration for external API server
108-
pub dropshot_external: ConfigDropshot,
109-
/// Dropshot configuration for internal API server
110-
pub dropshot_internal: ConfigDropshot,
107+
/// External address of Nexus.
108+
pub external_ip: IpAddr,
109+
/// Internal address of Nexus.
110+
pub internal_ip: IpAddr,
111111
/// Portion of the IP space to be managed by the Rack.
112112
pub subnet: Ipv6Subnet<RACK_PREFIX>,
113113
/// DB configuration.

nexus/src/lib.rs

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub use crucible_agent_client;
3434
use external_api::http_entrypoints::external_api;
3535
use internal_api::http_entrypoints::internal_api;
3636
use slog::Logger;
37+
use std::net::SocketAddr;
38+
use std::path::PathBuf;
3739
use std::sync::Arc;
3840

3941
#[macro_use]
@@ -71,7 +73,9 @@ pub fn run_openapi_internal() -> Result<(), String> {
7173
pub struct Server {
7274
/// shared state used by API request handlers
7375
pub apictx: Arc<ServerContext>,
74-
/// dropshot server for external API
76+
/// dropshot server for external API (encrypted)
77+
pub https_server_external: dropshot::HttpServer<Arc<ServerContext>>,
78+
/// dropshot server for external API (unencrypted)
7579
pub http_server_external: dropshot::HttpServer<Arc<ServerContext>>,
7680
/// dropshot server for internal API
7781
pub http_server_internal: dropshot::HttpServer<Arc<ServerContext>>,
@@ -92,26 +96,76 @@ impl Server {
9296
ServerContext::new(config.deployment.rack_id, ctxlog, &config)
9397
.await?;
9498

99+
// We launch separate dropshot servers for the "encrypted" and
100+
// "unencrypted" ports.
101+
102+
const HTTPS_PORT: u16 = 443;
103+
const HTTP_PORT: u16 = 80;
104+
105+
let dropshot_external_https_config = dropshot::ConfigDropshot {
106+
bind_address: SocketAddr::new(
107+
config.deployment.external_ip,
108+
HTTPS_PORT,
109+
),
110+
request_body_max_bytes: 1048576,
111+
tls: Some(dropshot::ConfigTls {
112+
cert_file: PathBuf::from("/var/nexus/certs/cert.pem"),
113+
key_file: PathBuf::from("/var/nexus/certs/key.pem"),
114+
}),
115+
};
116+
// TODO: Consider removing this interface when all clients are using
117+
// https?
118+
let dropshot_external_http_config = dropshot::ConfigDropshot {
119+
bind_address: SocketAddr::new(
120+
config.deployment.external_ip,
121+
HTTP_PORT,
122+
),
123+
request_body_max_bytes: 1048576,
124+
tls: None,
125+
};
126+
127+
let dropshot_internal_config = dropshot::ConfigDropshot {
128+
bind_address: SocketAddr::new(
129+
config.deployment.internal_ip,
130+
omicron_common::address::NEXUS_INTERNAL_PORT,
131+
),
132+
request_body_max_bytes: 1048576,
133+
..Default::default()
134+
};
135+
136+
let https_server_starter_external = dropshot::HttpServerStarter::new(
137+
&dropshot_external_https_config,
138+
external_api(),
139+
Arc::clone(&apictx),
140+
&log.new(o!("component" => "dropshot_external (encrypted)")),
141+
)
142+
.map_err(|error| format!("initializing external server: {}", error))?;
143+
let https_server_external = https_server_starter_external.start();
144+
95145
let http_server_starter_external = dropshot::HttpServerStarter::new(
96-
&config.deployment.dropshot_external,
146+
&dropshot_external_http_config,
97147
external_api(),
98148
Arc::clone(&apictx),
99-
&log.new(o!("component" => "dropshot_external")),
149+
&log.new(o!("component" => "dropshot_external (unencrypted)")),
100150
)
101151
.map_err(|error| format!("initializing external server: {}", error))?;
152+
let http_server_external = http_server_starter_external.start();
102153

103154
let http_server_starter_internal = dropshot::HttpServerStarter::new(
104-
&config.deployment.dropshot_internal,
155+
&dropshot_internal_config,
105156
internal_api(),
106157
Arc::clone(&apictx),
107158
&log.new(o!("component" => "dropshot_internal")),
108159
)
109160
.map_err(|error| format!("initializing internal server: {}", error))?;
110-
111-
let http_server_external = http_server_starter_external.start();
112161
let http_server_internal = http_server_starter_internal.start();
113162

114-
Ok(Server { apictx, http_server_external, http_server_internal })
163+
Ok(Server {
164+
apictx,
165+
https_server_external,
166+
http_server_external,
167+
http_server_internal,
168+
})
115169
}
116170

117171
/// Wait for the given server to shut down

sled-agent/src/params.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use internal_dns_client::names::{BackendName, ServiceName, AAAA, SRV};
6-
use omicron_common::address::{DENDRITE_PORT, OXIMETER_PORT};
6+
use omicron_common::address::{
7+
DENDRITE_PORT, NEXUS_INTERNAL_PORT, OXIMETER_PORT,
8+
};
79
use omicron_common::api::external;
810
use omicron_common::api::internal::nexus::{
911
DiskRuntimeState, InstanceRuntimeState,
@@ -342,7 +344,7 @@ impl From<DatasetEnsureBody> for sled_agent_client::types::DatasetEnsureBody {
342344
)]
343345
#[serde(tag = "type", rename_all = "snake_case")]
344346
pub enum ServiceType {
345-
Nexus { internal_address: SocketAddrV6, external_address: SocketAddr },
347+
Nexus { internal_ip: Ipv6Addr, external_ip: IpAddr },
346348
InternalDns { server_address: SocketAddrV6, dns_address: SocketAddrV6 },
347349
Oximeter,
348350
Dendrite { asic: DendriteAsic },
@@ -354,9 +356,9 @@ impl From<ServiceType> for sled_agent_client::types::ServiceType {
354356
use ServiceType as St;
355357

356358
match s {
357-
St::Nexus { internal_address, external_address } => AutoSt::Nexus {
358-
internal_address: internal_address.to_string(),
359-
external_address: external_address.to_string(),
359+
St::Nexus { internal_ip, external_ip } => AutoSt::Nexus {
360+
internal_address: internal_ip.to_string(),
361+
external_address: external_ip.to_string(),
360362
},
361363
St::InternalDns { server_address, dns_address } => {
362364
AutoSt::InternalDns {
@@ -370,7 +372,7 @@ impl From<ServiceType> for sled_agent_client::types::ServiceType {
370372
}
371373
}
372374

373-
/// Describes a request to create a service. This information
375+
/// Describes a request to create a service. This informatios tn
374376
/// should be sufficient for a Sled Agent to start a zone
375377
/// containing the requested service.
376378
#[derive(
@@ -415,7 +417,9 @@ impl ServiceRequest {
415417
pub fn address(&self) -> SocketAddrV6 {
416418
match self.service_type {
417419
ServiceType::InternalDns { server_address, .. } => server_address,
418-
ServiceType::Nexus { internal_address, .. } => internal_address,
420+
ServiceType::Nexus { internal_ip, .. } => {
421+
SocketAddrV6::new(internal_ip, NEXUS_INTERNAL_PORT, 0, 0)
422+
}
419423
ServiceType::Oximeter => {
420424
SocketAddrV6::new(self.addresses[0], OXIMETER_PORT, 0, 0)
421425
}

sled-agent/src/services.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::illumos::zfs::ZONE_ZFS_DATASET_MOUNTPOINT;
1313
use crate::illumos::zone::AddressRequest;
1414
use crate::params::{ServiceEnsureBody, ServiceRequest, ServiceType};
1515
use crate::zone::Zones;
16-
use dropshot::ConfigDropshot;
1716
use omicron_common::address::Ipv6Subnet;
1817
use omicron_common::address::OXIMETER_PORT;
1918
use omicron_common::address::RACK_PREFIX;
@@ -25,7 +24,7 @@ use omicron_common::postgres_config::PostgresConfigWithUrl;
2524
use slog::Logger;
2625
use std::collections::HashSet;
2726
use std::iter::FromIterator;
28-
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
27+
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
2928
use std::path::{Path, PathBuf};
3029
use std::str::FromStr;
3130
use tokio::io::AsyncWriteExt;
@@ -373,21 +372,21 @@ impl ServiceManager {
373372
let default_smf_name = format!("{}:default", smf_name);
374373

375374
match service.service_type {
376-
ServiceType::Nexus { internal_address, external_address } => {
375+
ServiceType::Nexus { internal_ip, external_ip } => {
377376
info!(self.log, "Setting up Nexus service");
378377

379378
// The address of Nexus' external interface is a special
380379
// case; it may be an IPv4 address.
381380
let addr_request =
382-
AddressRequest::new_static(external_address.ip(), None);
381+
AddressRequest::new_static(external_ip, None);
383382
running_zone
384383
.ensure_external_address_with_name(
385384
addr_request,
386385
"public",
387386
)
388387
.await?;
389388

390-
if let IpAddr::V4(_public_addr4) = external_address.ip() {
389+
if let IpAddr::V4(_public_addr4) = external_ip {
391390
// If requested, create a default route back through
392391
// the internet gateway.
393392
if let Some(ref gateway) = self.config.gateway_address {
@@ -406,21 +405,8 @@ impl ServiceManager {
406405
let deployment_config = NexusDeploymentConfig {
407406
id: service.id,
408407
rack_id: self.rack_id,
409-
dropshot_external: ConfigDropshot {
410-
bind_address: external_address,
411-
request_body_max_bytes: 1048576,
412-
tls: Some(
413-
dropshot::ConfigTls {
414-
cert_file: PathBuf::from("/var/nexus/certs/cert.pem"),
415-
key_file: PathBuf::from("/var/nexus/certs/key.pem"),
416-
}
417-
),
418-
},
419-
dropshot_internal: ConfigDropshot {
420-
bind_address: SocketAddr::V6(internal_address),
421-
request_body_max_bytes: 1048576,
422-
..Default::default()
423-
},
408+
external_ip,
409+
internal_ip: IpAddr::V6(internal_ip),
424410
subnet: Ipv6Subnet::<RACK_PREFIX>::new(
425411
self.underlay_address,
426412
),

smf/sled-agent/config-rss.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ addresses = [ "fd00:1122:3344:0101::3" ]
5555
gz_addresses = []
5656
[request.service.service_type]
5757
type = "nexus"
58-
internal_address = "[fd00:1122:3344:0101::3]:12221"
58+
internal_address = "fd00:1122:3344:0101::3"
5959
# NOTE: In the lab, use "172.20.15.226"
60-
external_address = "192.168.1.20:80"
60+
external_address = "192.168.1.20"
6161

6262
# TODO(https://github.com/oxidecomputer/omicron/issues/732): Nexus
6363
# should allocate Oximeter services.

0 commit comments

Comments
 (0)