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

Initial integration of TUF client into Nexus #469

Closed
wants to merge 14 commits into from
Closed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ tools/clickhouse*
tools/cockroach*
clickhouse/
cockroachdb/
smf/nexus/root.json
126 changes: 126 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ pub enum ResourceType {
Oximeter,
MetricProducer,
Zpool,
UpdateAvailableArtifact,
}

impl Display for ResourceType {
Expand All @@ -509,6 +510,8 @@ impl Display for ResourceType {
ResourceType::Oximeter => "oximeter",
ResourceType::MetricProducer => "metric producer",
ResourceType::Zpool => "zpool",
ResourceType::UpdateAvailableArtifact =>
"available update artifact",
}
)
}
Expand Down
31 changes: 30 additions & 1 deletion common/src/sql/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ CREATE TABLE omicron.public.rack (
/* Identity metadata (asset) */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL
time_modified TIMESTAMPTZ NOT NULL,

/* Used to configure the updates service URLs */
tuf_metadata_base_url STRING(512) NOT NULL,
tuf_targets_base_url STRING(512) NOT NULL
);

/*
Expand Down Expand Up @@ -644,6 +648,31 @@ CREATE INDEX ON omicron.public.console_session (

/*******************************************************************/

CREATE TYPE omicron.public.update_artifact_kind AS ENUM (
'zone'
);

CREATE TABLE omicron.public.update_available_artifact (
name STRING(40) NOT NULL,
version INT NOT NULL,
kind omicron.public.update_artifact_kind NOT NULL,

/* the version of the targets.json role this came from */
targets_role_version INT NOT NULL,

/* when the metadata this artifact was cached from expires */
valid_until TIMESTAMPTZ NOT NULL,

/* data about the target from the targets.json role */
target_name STRING(512) NOT NULL,
target_sha256 STRING(64) NOT NULL,
target_length INT NOT NULL,

PRIMARY KEY (name, version, kind)
);

/*******************************************************************/

/*
* Metadata for the schema itself. This version number isn't great, as there's
* nothing to ensure it gets bumped when it should be, but it's a start.
Expand Down
1 change: 1 addition & 0 deletions nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sled-agent-client = { path = "../sled-agent-client" }
structopt = "0.3"
thiserror = "1.0"
toml = "0.5.6"
tough = { version = "0.12", features = [ "http" ] }

[dependencies.api_identity]
path = "../api_identity"
Expand Down
4 changes: 4 additions & 0 deletions nexus/examples/config-file.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ level = "info"
mode = "file"
path = "logs/server.log"
if_exists = "append"

[updates]
# If not present, accessing the TUF updates repository will fail
#tuf_trusted_root = ""
4 changes: 4 additions & 0 deletions nexus/examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ mode = "stderr-terminal"
#mode = "file"
#path = "logs/server.log"
#if_exists = "append"

[updates]
# If not present, accessing the TUF updates repository will fail
#tuf_trusted_root = ""
17 changes: 16 additions & 1 deletion nexus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ pub struct ConsoleConfig {
pub session_absolute_timeout_minutes: u32,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct UpdatesConfig {
/** Trusted root.json role for the TUF updates repository. If `None`, accessing the TUF
* repository will fail. */
pub tuf_trusted_root: Option<PathBuf>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any deployment where we might want to leave this out? (i.e., why not require this? is it a pain for development?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine this could be temporary, but given all the work going on right now I didn't want to break folks' testing workflows. There should not be production deployments where this is somehow left unconfigured.

}

/**
* Configuration for a nexus server
*/
Expand All @@ -59,6 +66,9 @@ pub struct Config {
pub database: db::Config,
/** Authentication-related configuration */
pub authn: AuthnConfig,
/** Updates-related configuration */
#[serde(default)]
pub updates: UpdatesConfig,
}

#[derive(Debug)]
Expand Down Expand Up @@ -164,7 +174,7 @@ impl Config {
mod test {
use super::{
AuthnConfig, Config, ConsoleConfig, LoadError, LoadErrorKind,
SchemeName,
SchemeName, UpdatesConfig,
};
use crate::db;
use dropshot::ConfigDropshot;
Expand Down Expand Up @@ -293,6 +303,8 @@ mod test {
level = "debug"
path = "/nonexistent/path"
if_exists = "fail"
[updates]
tuf_trusted_root = "/path/to/root.json"
"##,
)
.unwrap();
Expand Down Expand Up @@ -330,6 +342,9 @@ mod test {
.parse()
.unwrap()
},
updates: UpdatesConfig {
tuf_trusted_root: Some(PathBuf::from("/path/to/root.json"))
},
}
);

Expand Down
7 changes: 4 additions & 3 deletions nexus/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ impl ServerContext {
* Create a new context with the given rack id and log. This creates the
* underlying nexus as well.
*/
pub fn new(
rack_id: &Uuid,
pub async fn new(
rack_id: Uuid,
log: Logger,
pool: db::Pool,
config: &config::Config,
Expand Down Expand Up @@ -140,7 +140,8 @@ impl ServerContext {
pool,
config,
Arc::clone(&authz),
),
)
.await,
log,
external_authn,
authz,
Expand Down
Loading