Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl DbUrlOptions {
Fut: Future<Output = anyhow::Result<T>>,
{
let datastore = self.connect(omdb, log).await?;
let opctx = OpContext::for_tests(log.clone(), datastore.clone());
let opctx = OpContext::for_omdb(log.clone(), datastore.clone());
let result = f(opctx, datastore.clone()).await;
datastore.terminate().await;
result
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4401,7 +4401,7 @@ async fn cmd_nexus_sled_expunge_with_datastore(
// most recent inventory collection
use nexus_db_queries::context::OpContext;

let opctx = OpContext::for_tests(log.clone(), datastore.clone());
let opctx = OpContext::for_omdb(log.clone(), datastore.clone());
let opctx = &opctx;

// First, we need to look up the sled so we know its serial number.
Expand Down Expand Up @@ -4511,7 +4511,7 @@ async fn cmd_nexus_sled_expunge_disk_with_datastore(
) -> Result<(), anyhow::Error> {
use nexus_db_queries::context::OpContext;

let opctx = OpContext::for_tests(log.clone(), datastore.clone());
let opctx = OpContext::for_omdb(log.clone(), datastore.clone());
let opctx = &opctx;

// First, we need to look up the disk so we can lookup identity information.
Expand Down Expand Up @@ -4732,7 +4732,7 @@ async fn cmd_nexus_trust_quorum_remove_sled_with_datastore(
_destruction_token: DestructiveOperationToken,
) -> Result<(), anyhow::Error> {
use nexus_db_queries::context::OpContext;
let opctx = OpContext::for_tests(log.clone(), datastore.clone());
let opctx = OpContext::for_omdb(log.clone(), datastore.clone());
let opctx = &opctx;

// First, we need to look up the sled so we know its serial number.
Expand Down
11 changes: 11 additions & 0 deletions nexus/auth/src/authn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub use nexus_db_fixed_data::user_builtin::USER_DB_INIT;
pub use nexus_db_fixed_data::user_builtin::USER_EXTERNAL_AUTHN;
pub use nexus_db_fixed_data::user_builtin::USER_INTERNAL_API;
pub use nexus_db_fixed_data::user_builtin::USER_INTERNAL_READ;
pub use nexus_db_fixed_data::user_builtin::USER_OMDB;
pub use nexus_db_fixed_data::user_builtin::USER_SAGA_RECOVERY;
pub use nexus_db_fixed_data::user_builtin::USER_SERVICE_BALANCER;

Expand Down Expand Up @@ -242,6 +243,11 @@ impl Context {
Context::context_for_builtin_user(USER_SERVICE_BALANCER.id)
}

/// Returns an authenticated context for omdb
pub fn omdb() -> Context {
Context::context_for_builtin_user(USER_OMDB.id)
}

fn context_for_builtin_user(user_builtin_id: BuiltInUserUuid) -> Context {
Context {
kind: Kind::Authenticated(
Expand Down Expand Up @@ -366,6 +372,7 @@ mod test {
use super::USER_DB_INIT;
use super::USER_INTERNAL_API;
use super::USER_INTERNAL_READ;
use super::USER_OMDB;
use super::USER_SAGA_RECOVERY;
use super::USER_SERVICE_BALANCER;
use super::USER_TEST_PRIVILEGED;
Expand Down Expand Up @@ -413,6 +420,10 @@ mod test {
let authn = Context::internal_api();
let actor = authn.actor().unwrap();
assert_eq!(actor.built_in_user_id(), Some(USER_INTERNAL_API.id));

let authn = Context::omdb();
let actor = authn.actor().unwrap();
assert_eq!(actor.built_in_user_id(), Some(USER_OMDB.id));
}
}

Expand Down
24 changes: 24 additions & 0 deletions nexus/auth/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,30 @@ impl OpContext {
}
}

/// Returns a context for use by omdb (the debugging tool).
pub fn for_omdb(
log: slog::Logger,
datastore: Arc<dyn Storage>,
) -> OpContext {
let created_instant = Instant::now();
let created_walltime = SystemTime::now();
let authn = Arc::new(authn::Context::omdb());
let authz = authz::Context::new(
Arc::clone(&authn),
Arc::new(authz::Authz::new(&log)),
Arc::clone(&datastore),
);
OpContext {
log,
authz,
authn,
created_instant,
created_walltime,
metadata: BTreeMap::new(),
kind: OpKind::Test,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we want a different OpKind here. It's not a big deal.

}
}

/// Creates a new `OpContext` with extra metadata (including log metadata)
///
/// This is intended for cases where you want an OpContext that's
Expand Down
8 changes: 8 additions & 0 deletions nexus/db-fixed-data/src/role_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@ pub static BUILTIN_ROLE_ASSIGNMENTS: LazyLock<Vec<RoleAssignment>> =
*FLEET_ID,
"external-authenticator",
),
// The "omdb" user gets the "admin" role on the sole Fleet.
// It has all privileges for debugging purposes.
RoleAssignment::new_for_builtin_user(
user_builtin::USER_OMDB.id,
ResourceType::Fleet,
*FLEET_ID,
"admin",
),
]
});
12 changes: 12 additions & 0 deletions nexus/db-fixed-data/src/user_builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,24 @@ pub static USER_EXTERNAL_AUTHN: LazyLock<UserBuiltinConfig> =
)
});

/// Built-in user for omdb (the Omicron debugger)
pub static USER_OMDB: LazyLock<UserBuiltinConfig> = LazyLock::new(|| {
UserBuiltinConfig::new_static(
// "00db" for "omdb"
"001de000-05e4-4000-8000-0000000000db",
"omdb",
"used by the omdb debug tool",
)
});

#[cfg(test)]
mod test {
use super::super::assert_valid_typed_uuid;
use super::USER_DB_INIT;
use super::USER_EXTERNAL_AUTHN;
use super::USER_INTERNAL_API;
use super::USER_INTERNAL_READ;
use super::USER_OMDB;
use super::USER_SAGA_RECOVERY;
use super::USER_SERVICE_BALANCER;

Expand All @@ -112,5 +123,6 @@ mod test {
assert_valid_typed_uuid(&USER_EXTERNAL_AUTHN.id);
assert_valid_typed_uuid(&USER_INTERNAL_READ.id);
assert_valid_typed_uuid(&USER_SAGA_RECOVERY.id);
assert_valid_typed_uuid(&USER_OMDB.id);
}
}
1 change: 1 addition & 0 deletions nexus/db-queries/src/db/datastore/silo_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ impl DataStore {
&authn::USER_INTERNAL_READ,
&authn::USER_EXTERNAL_AUTHN,
&authn::USER_SAGA_RECOVERY,
&authn::USER_OMDB,
]
.iter()
.map(|u| {
Expand Down
3 changes: 3 additions & 0 deletions nexus/tests/integration_tests/users_builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ async fn test_users_builtin(cptestctx: &ControlPlaneTestContext) {
let u = users.remove(&authn::USER_SAGA_RECOVERY.name.to_string()).unwrap();
assert_eq!(u.identity.id, authn::USER_SAGA_RECOVERY.id.into_untyped_uuid());

let u = users.remove(&authn::USER_OMDB.name.to_string()).unwrap();
assert_eq!(u.identity.id, authn::USER_OMDB.id.into_untyped_uuid());

assert!(users.is_empty(), "found unexpected built-in users");

// TODO-coverage add test for fetching individual users, including invalid
Expand Down
Loading