Skip to content

Commit 95edfc0

Browse files
committed
remove too-strict auth check on getting default pool
1 parent 0798ab2 commit 95edfc0

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

nexus/db-queries/src/db/datastore/external_ip.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//! [`DataStore`] methods on [`ExternalIp`]s.
66
77
use super::DataStore;
8-
use crate::authz;
98
use crate::context::OpContext;
109
use crate::db;
1110
use crate::db::error::public_error_from_diesel_pool;
@@ -62,7 +61,6 @@ impl DataStore {
6261
Some(name) => {
6362
self.ip_pools_fetch_for(
6463
&opctx,
65-
authz::Action::CreateChild, // TODO: wtf
6664
&name,
6765
current_silo.id(),
6866
None, // TODO: include current project ID
@@ -73,7 +71,6 @@ impl DataStore {
7371
None => {
7472
self.ip_pools_fetch_default_for(
7573
&opctx,
76-
authz::Action::CreateChild, // TODO: wtf
7774
Some(current_silo.id()),
7875
None, // TODO: include current project ID
7976
)

nexus/db-queries/src/db/datastore/ip_pool.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,19 @@ impl DataStore {
7979
pub async fn ip_pools_fetch_default_for(
8080
&self,
8181
opctx: &OpContext,
82-
action: authz::Action,
8382
silo_id: Option<Uuid>,
8483
project_id: Option<Uuid>,
8584
) -> LookupResult<IpPool> {
8685
use db::schema::ip_pool::dsl;
87-
opctx.authorize(action, &authz::IP_POOL_LIST).await?;
86+
87+
// TODO: Need auth check here. Only fleet viewers can list children on
88+
// IP_POOL_LIST, so if we check that, nobody can make instances. This
89+
// used to check CreateChild on an individual IP pool, but now we're not
90+
// looking up by name so the check is more complicated
91+
//
92+
// opctx
93+
// .authorize(authz::Action::ListChildren, &authz::IP_POOL_LIST)
94+
// .await?;
8895

8996
dsl::ip_pool
9097
.filter(dsl::silo_id.eq(silo_id).or(dsl::silo_id.is_null()))
@@ -114,15 +121,16 @@ impl DataStore {
114121
pub(crate) async fn ip_pools_fetch_for(
115122
&self,
116123
opctx: &OpContext,
117-
action: authz::Action,
118124
name: &Name,
119125
silo_id: Uuid,
120126
// TODO: project_id should always be defined, this is temporary
121127
project_id: Option<Uuid>,
122128
) -> LookupResult<IpPool> {
123129
let (.., authz_pool, pool) = LookupPath::new(opctx, &self)
124130
.ip_pool_name(&name)
125-
.fetch_for(action)
131+
// any authenticated user can CreateChild on an IP pool. this is
132+
// meant to represent allocating an IP
133+
.fetch_for(authz::Action::CreateChild)
126134
.await?;
127135

128136
// You can't look up a pool by name if it conflicts with your current
@@ -472,7 +480,6 @@ impl DataStore {
472480

473481
#[cfg(test)]
474482
mod test {
475-
use crate::authz;
476483
use crate::db::datastore::datastore_test;
477484
use crate::db::model::IpPool;
478485
use assert_matches::assert_matches;
@@ -487,12 +494,10 @@ mod test {
487494
let mut db = test_setup_database(&logctx.log).await;
488495
let (opctx, datastore) = datastore_test(&logctx, &db).await;
489496

490-
let action = authz::Action::ListChildren;
491-
492497
// we start out with the default fleet-level pool already created,
493498
// so when we ask for the fleet default (no silo or project) we get it back
494499
let fleet_default_pool = datastore
495-
.ip_pools_fetch_default_for(&opctx, action, None, None)
500+
.ip_pools_fetch_default_for(&opctx, None, None)
496501
.await
497502
.unwrap();
498503

@@ -523,7 +528,7 @@ mod test {
523528
// has no default of its own
524529
let silo_id = opctx.authn.silo_required().unwrap().id();
525530
let ip_pool = datastore
526-
.ip_pools_fetch_default_for(&opctx, action, Some(silo_id), None)
531+
.ip_pools_fetch_default_for(&opctx, Some(silo_id), None)
527532
.await
528533
.expect("Failed to get silo's default IP pool");
529534
assert_eq!(ip_pool.id(), fleet_default_pool.id());
@@ -543,7 +548,7 @@ mod test {
543548
// because that one was not a default, when we ask for silo default
544549
// pool, we still get the fleet default
545550
let ip_pool = datastore
546-
.ip_pools_fetch_default_for(&opctx, action, Some(silo_id), None)
551+
.ip_pools_fetch_default_for(&opctx, Some(silo_id), None)
547552
.await
548553
.expect("Failed to get fleet default IP pool");
549554
assert_eq!(ip_pool.id(), fleet_default_pool.id());
@@ -559,14 +564,14 @@ mod test {
559564

560565
// now when we ask for the silo default pool, we get the one we just made
561566
let ip_pool = datastore
562-
.ip_pools_fetch_default_for(&opctx, action, Some(silo_id), None)
567+
.ip_pools_fetch_default_for(&opctx, Some(silo_id), None)
563568
.await
564569
.expect("Failed to get silo's default IP pool");
565570
assert_eq!(ip_pool.name().as_str(), "default-for-silo");
566571

567572
// and of course, if we ask for the fleet default again we still get that one
568573
let ip_pool = datastore
569-
.ip_pools_fetch_default_for(&opctx, action, None, None)
574+
.ip_pools_fetch_default_for(&opctx, None, None)
570575
.await
571576
.expect("Failed to get fleet default IP pool");
572577
assert_eq!(ip_pool.id(), fleet_default_pool.id());

nexus/db-queries/src/db/queries/external_ip.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,12 +924,7 @@ mod tests {
924924
async fn default_pool_id(&self) -> Uuid {
925925
let pool = self
926926
.db_datastore
927-
.ip_pools_fetch_default_for(
928-
&self.opctx,
929-
crate::authz::Action::ListChildren,
930-
None,
931-
None,
932-
)
927+
.ip_pools_fetch_default_for(&self.opctx, None, None)
933928
.await
934929
.expect("Failed to lookup default ip pool");
935930
pool.identity.id

nexus/src/app/sagas/instance_create.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -827,13 +827,8 @@ async fn sic_allocate_instance_snat_ip(
827827
let ip_id = sagactx.lookup::<Uuid>("snat_ip_id")?;
828828

829829
let pool = datastore
830-
.ip_pools_fetch_default_for(
831-
&opctx,
832-
authz::Action::CreateChild,
833-
// TODO: get these values right
834-
None,
835-
None,
836-
)
830+
// TODO: pass silo ID and project ID
831+
.ip_pools_fetch_default_for(&opctx, None, None)
837832
.await
838833
.map_err(ActionError::action_failed)?;
839834
let pool_id = pool.identity.id;

nexus/tests/integration_tests/endpoints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ lazy_static! {
455455
description: String::from("an IP pool"),
456456
},
457457
silo: None,
458-
// TODO: this might error due to the unique index
459458
is_default: true,
460459
};
461460
pub static ref DEMO_IP_POOL_PROJ_URL: String =

0 commit comments

Comments
 (0)