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

[nexus] Add a new user for service balancing #1234

Merged
merged 58 commits into from Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b78ff98
[nexus] Split Nexus configuration (package vs runtime)
smklein Jun 8, 2022
cca5795
Merge branch 'main' into nexus-argsplit
smklein Jun 8, 2022
fccc15c
Ensure postgres config was just a rename
smklein Jun 8, 2022
2443215
Merge branch 'main' into nexus-argsplit
smklein Jun 8, 2022
a077bd4
review feedback
smklein Jun 8, 2022
f91cea1
Merge branch 'main' into nexus-argsplit
smklein Jun 8, 2022
d16eda2
DNS client
smklein Jun 8, 2022
8db30b7
Add concurrency
smklein Jun 8, 2022
3a0c6ba
comment
smklein Jun 8, 2022
33b3e02
fmt
smklein Jun 8, 2022
3eb57dc
lockfile
smklein Jun 8, 2022
39aa9ff
Merge branch 'main' into nexus-argsplit
smklein Jun 15, 2022
dd04a67
s/runtime/deployment
smklein Jun 15, 2022
63b6379
Merge branch 'nexus-argsplit' into dns-client
smklein Jun 15, 2022
e1dc941
[nexus][sled-agent] Generate rack ID in RSS, plumb it through Nexus
smklein Jun 15, 2022
a4309ac
need rack_id in the test config too
smklein Jun 15, 2022
02f592d
Merge branch 'main' into nexus-argsplit
smklein Jun 20, 2022
ff2d7b9
[internal-dns] Avoid 'picking ports'
smklein Jun 20, 2022
a261155
Merge branch 'nexus-argsplit' into dns-client
smklein Jun 20, 2022
6cc7864
Merge branch 'fix-internal-dns-api' into dns-client
smklein Jun 20, 2022
2a035a5
Changes from rss-handoff
smklein Jun 20, 2022
e84faaf
Merge branch 'dns-client' into rack-id
smklein Jun 20, 2022
c3a49bb
[nexus] Add a new user for background tasks
smklein Jun 20, 2022
1e0b8fe
Merge branch 'main' into nexus-argsplit
smklein Jun 21, 2022
da4a2b8
Merge branch 'nexus-argsplit' into fix-internal-dns-api
smklein Jun 21, 2022
d7b10cf
Merge branch 'fix-internal-dns-api' into dns-client
smklein Jun 21, 2022
bb9a3af
Merge branch 'dns-client' into rack-id
smklein Jun 21, 2022
fed4a3d
Merge branch 'rack-id' into background-work-user
smklein Jun 21, 2022
4df23c2
jgallagher feedback
smklein Jun 21, 2022
71f3aac
Merge branch 'fix-internal-dns-api' into dns-client
smklein Jun 21, 2022
5556d5f
Patch tests
smklein Jun 21, 2022
226fd94
Merge branch 'fix-internal-dns-api' into dns-client
smklein Jun 21, 2022
6126e41
merge
smklein Jun 21, 2022
b01bffd
Merge branch 'dns-client' into rack-id
smklein Jun 21, 2022
d09c8d5
Merge branch 'rack-id' into background-work-user
smklein Jun 21, 2022
e4f434f
Merge branch 'main' into nexus-argsplit
smklein Jun 21, 2022
62fccb2
Merge branch 'nexus-argsplit' into fix-internal-dns-api
smklein Jun 21, 2022
1905985
Merge branch 'fix-internal-dns-api' into dns-client
smklein Jun 21, 2022
1a0b61b
Merge branch 'dns-client' into rack-id
smklein Jun 21, 2022
f5ee394
Merge branch 'rack-id' into background-work-user
smklein Jun 21, 2022
d6e3c9d
background-work -> service-balancer
smklein Jun 22, 2022
fd8286a
Merge branch 'main' into dns-client
smklein Jun 22, 2022
bed0269
Merge branch 'dns-client' into rack-id
smklein Jun 22, 2022
ef6072d
Merge branch 'rack-id' into background-work-user
smklein Jun 22, 2022
b959c39
Merge branch 'main' into dns-client
smklein Jun 23, 2022
470da8b
review feedback
smklein Jun 24, 2022
a23a036
Merge branch 'dns-client' into rack-id
smklein Jun 24, 2022
56d2e1c
Merge branch 'rack-id' into background-work-user
smklein Jun 24, 2022
13b9825
Merge branch 'main' into dns-client
smklein Jun 24, 2022
e1a912f
Merge branch 'dns-client' into rack-id
smklein Jun 24, 2022
28d87f5
Merge branch 'rack-id' into background-work-user
smklein Jun 24, 2022
5fa89fe
Merge branch 'main' into dns-client
smklein Jun 24, 2022
a5fb65a
Merge branch 'dns-client' into rack-id
smklein Jun 24, 2022
a5784c1
Merge branch 'rack-id' into background-work-user
smklein Jun 24, 2022
f7d7796
Merge branch 'main' into dns-client
smklein Jun 24, 2022
01a5fa5
Merge branch 'dns-client' into rack-id
smklein Jun 24, 2022
52357a6
Merge branch 'rack-id' into background-work-user
smklein Jun 24, 2022
71b40e7
Merge branch 'main' into background-work-user
smklein Jun 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions nexus/src/app/mod.rs
Expand Up @@ -223,6 +223,16 @@ impl Nexus {
&self.opctx_external_authn
}

/// Returns an [`OpContext`] used for balancing services.
pub fn opctx_for_service_balancer(&self) -> OpContext {
OpContext::for_background(
self.log.new(o!("component" => "ServiceBalancer")),
Arc::clone(&self.authz),
authn::Context::internal_service_balancer(),
Arc::clone(&self.db_datastore),
)
}

/// Used as the body of a "stub" endpoint -- one that's currently
/// unimplemented but that we eventually intend to implement
///
Expand Down
11 changes: 11 additions & 0 deletions nexus/src/authn/mod.rs
Expand Up @@ -35,6 +35,7 @@ pub use crate::db::fixed_data::user_builtin::USER_EXTERNAL_AUTHN;
pub use crate::db::fixed_data::user_builtin::USER_INTERNAL_API;
pub use crate::db::fixed_data::user_builtin::USER_INTERNAL_READ;
pub use crate::db::fixed_data::user_builtin::USER_SAGA_RECOVERY;
pub use crate::db::fixed_data::user_builtin::USER_SERVICE_BALANCER;
use crate::db::model::ConsoleSession;

use crate::authz;
Expand Down Expand Up @@ -170,6 +171,11 @@ impl Context {
Context::context_for_builtin_user(USER_DB_INIT.id)
}

/// Returns an authenticated context for Nexus-driven service balancing.
pub fn internal_service_balancer() -> Context {
Context::context_for_builtin_user(USER_SERVICE_BALANCER.id)
}

fn context_for_builtin_user(user_builtin_id: Uuid) -> Context {
Context {
kind: Kind::Authenticated(Details {
Expand Down Expand Up @@ -217,6 +223,7 @@ mod test {
use super::USER_INTERNAL_API;
use super::USER_INTERNAL_READ;
use super::USER_SAGA_RECOVERY;
use super::USER_SERVICE_BALANCER;
use super::USER_TEST_PRIVILEGED;
use super::USER_TEST_UNPRIVILEGED;
use crate::db::fixed_data::user_builtin::USER_EXTERNAL_AUTHN;
Expand Down Expand Up @@ -251,6 +258,10 @@ mod test {
let actor = authn.actor().unwrap();
assert_eq!(actor.actor_id(), USER_DB_INIT.id);

let authn = Context::internal_service_balancer();
let actor = authn.actor().unwrap();
assert_eq!(actor.actor_id(), USER_SERVICE_BALANCER.id);

let authn = Context::internal_saga_recovery();
let actor = authn.actor().unwrap();
assert_eq!(actor.actor_id(), USER_SAGA_RECOVERY.id);
Expand Down
1 change: 1 addition & 0 deletions nexus/src/db/datastore.rs
Expand Up @@ -3250,6 +3250,7 @@ impl DataStore {
let builtin_users = [
// Note: "db_init" is also a builtin user, but that one by necessity
// is created with the database.
&*authn::USER_SERVICE_BALANCER,
&*authn::USER_INTERNAL_API,
&*authn::USER_INTERNAL_READ,
&*authn::USER_EXTERNAL_AUTHN,
Expand Down
7 changes: 7 additions & 0 deletions nexus/src/db/fixed_data/role_assignment.rs
Expand Up @@ -24,6 +24,13 @@ lazy_static! {
*FLEET_ID,
role_builtin::FLEET_ADMIN.role_name,
),
RoleAssignment::new(
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 can limit privileges more than this...but I imagine it's not worth much of our time right now to pick this apart. Up to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I'm gonna defer this while we're still sorting out the fundamental operations Nexus needs to take. Right now, everything seems to be lumped into the FLEET_ADMIN role, but I'm not really sure how to split that up without a clearer idea of the other "fleet-wide" ops.

IdentityType::UserBuiltin,
user_builtin::USER_SERVICE_BALANCER.id,
role_builtin::FLEET_ADMIN.resource_type,
*FLEET_ID,
role_builtin::FLEET_ADMIN.role_name,
),

// The "internal-read" user gets the "viewer" role on the sole
// Fleet. This will grant them the ability to read various control
Expand Down
11 changes: 11 additions & 0 deletions nexus/src/db/fixed_data/user_builtin.rs
Expand Up @@ -39,6 +39,15 @@ lazy_static! {
"used for seeding initial database data",
);

/// Internal user for performing operations to manage the
/// provisioning of services across the fleet.
pub static ref USER_SERVICE_BALANCER: UserBuiltinConfig =
UserBuiltinConfig::new_static(
"001de000-05e4-4000-8000-00000000bac3",
"service-balancer",
"used for Nexus-driven service balancing",
);

/// Internal user used by Nexus when handling internal API requests
pub static ref USER_INTERNAL_API: UserBuiltinConfig =
UserBuiltinConfig::new_static(
Expand Down Expand Up @@ -82,9 +91,11 @@ mod test {
use super::USER_INTERNAL_API;
use super::USER_INTERNAL_READ;
use super::USER_SAGA_RECOVERY;
use super::USER_SERVICE_BALANCER;

#[test]
fn test_builtin_user_ids_are_valid() {
assert_valid_uuid(&USER_SERVICE_BALANCER.id);
assert_valid_uuid(&USER_DB_INIT.id);
assert_valid_uuid(&USER_INTERNAL_API.id);
assert_valid_uuid(&USER_EXTERNAL_AUTHN.id);
Expand Down
3 changes: 3 additions & 0 deletions nexus/tests/integration_tests/users_builtin.rs
Expand Up @@ -27,6 +27,9 @@ async fn test_users_builtin(cptestctx: &ControlPlaneTestContext) {

let u = users.remove(&authn::USER_DB_INIT.name.to_string()).unwrap();
assert_eq!(u.identity.id, authn::USER_DB_INIT.id);
let u =
users.remove(&authn::USER_SERVICE_BALANCER.name.to_string()).unwrap();
assert_eq!(u.identity.id, authn::USER_SERVICE_BALANCER.id);
let u = users.remove(&authn::USER_INTERNAL_API.name.to_string()).unwrap();
assert_eq!(u.identity.id, authn::USER_INTERNAL_API.id);
let u = users.remove(&authn::USER_INTERNAL_READ.name.to_string()).unwrap();
Expand Down