Skip to content

Commit c2862a0

Browse files
authored
Store the silo admin group name (#8850)
The silo admin group is a special group that is automatically created during silo creation where members are granted the silo admin role. This name however is not stored, but this is currently ok: any existing silo won't have the ability to delete groups, meaning that the automatically created admin group is there to stay and a group with a duplicate name cannot be created. Very soon there will be silos with provision types that _can_ delete groups, meaning this name has to be known in order for Nexus to create the appropriate policy when a group with a matching name is created again. It was a mistake not to store this parameter with the silo, so rectify that with this PR.
1 parent 7c98617 commit c2862a0

File tree

7 files changed

+38
-3
lines changed

7 files changed

+38
-3
lines changed

nexus/db-model/src/schema_versions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
1616
///
1717
/// This must be updated when you change the database schema. Refer to
1818
/// schema/crdb/README.adoc in the root of this repository for details.
19-
pub const SCHEMA_VERSION: Version = Version::new(183, 0, 0);
19+
pub const SCHEMA_VERSION: Version = Version::new(184, 0, 0);
2020

2121
/// List of all past database schema versions, in *reverse* order
2222
///
@@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
2828
// | leaving the first copy as an example for the next person.
2929
// v
3030
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
31+
KnownVersion::new(184, "store-silo-admin-group-name"),
3132
KnownVersion::new(183, "add-ip-version-to-pools"),
3233
KnownVersion::new(182, "add-tuf-artifact-board"),
3334
KnownVersion::new(181, "rename-nat-table"),

nexus/db-model/src/silo.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ pub struct Silo {
100100

101101
/// child resource generation number, per RFD 192
102102
pub rcgen: Generation,
103+
104+
/// Store a group name that will be
105+
///
106+
/// 1) automatically created (depending on the provision type of this silo)
107+
/// at silo create time.
108+
/// 2) assigned a policy granting members the silo admin role
109+
///
110+
/// Prior to this column existing, for api_only and jit provision types,
111+
/// Nexus would create this group, and create a policy where users of the
112+
/// group would have the silo admin role. It wouldn't store this information
113+
/// though as groups cannot be deleted with those provision types.
114+
///
115+
/// For provision types that can both create and delete groups, it's
116+
/// important to store this name so that when groups are created the same
117+
/// automatic policy can be created as well.
118+
pub admin_group_name: Option<String>,
103119
}
104120

105121
/// Form of mapped fleet roles used when serializing to the database
@@ -180,6 +196,7 @@ impl Silo {
180196
.into(),
181197
rcgen: Generation::new(),
182198
mapped_fleet_roles,
199+
admin_group_name: params.admin_group_name,
183200
})
184201
}
185202

@@ -225,6 +242,7 @@ impl TryFrom<Silo> for views::Silo {
225242
discoverable: silo.discoverable,
226243
identity_mode,
227244
mapped_fleet_roles,
245+
admin_group_name: silo.admin_group_name,
228246
})
229247
}
230248
}

nexus/db-schema/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ table! {
751751
mapped_fleet_roles -> Jsonb,
752752

753753
rcgen -> Int8,
754+
755+
admin_group_name -> Nullable<Text>,
754756
}
755757
}
756758

nexus/types/src/external_api/views.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ pub struct Silo {
5858
/// unless there's a corresponding entry in this map.
5959
pub mapped_fleet_roles:
6060
BTreeMap<shared::SiloRole, BTreeSet<shared::FleetRole>>,
61+
62+
/// Optionally, silos can have a group name that is automatically granted
63+
/// the silo admin role.
64+
pub admin_group_name: Option<String>,
6165
}
6266

6367
/// A collection of resource counts used to describe capacity and utilization

openapi/nexus.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23566,6 +23566,11 @@
2356623566
"description": "View of a Silo\n\nA Silo is the highest level unit of isolation.",
2356723567
"type": "object",
2356823568
"properties": {
23569+
"admin_group_name": {
23570+
"nullable": true,
23571+
"description": "Optionally, silos can have a group name that is automatically granted the silo admin role.",
23572+
"type": "string"
23573+
},
2356923574
"description": {
2357023575
"description": "human-readable free-form text about a resource",
2357123576
"type": "string"

schema/crdb/dbinit.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,9 @@ CREATE TABLE IF NOT EXISTS omicron.public.silo (
875875
mapped_fleet_roles JSONB NOT NULL,
876876

877877
/* child resource generation number, per RFD 192 */
878-
rcgen INT NOT NULL
878+
rcgen INT NOT NULL,
879+
880+
admin_group_name TEXT
879881
);
880882

881883
CREATE UNIQUE INDEX IF NOT EXISTS lookup_silo_by_name ON omicron.public.silo (
@@ -6562,7 +6564,7 @@ INSERT INTO omicron.public.db_metadata (
65626564
version,
65636565
target_version
65646566
) VALUES
6565-
(TRUE, NOW(), NOW(), '183.0.0', NULL)
6567+
(TRUE, NOW(), NOW(), '184.0.0', NULL)
65666568
ON CONFLICT DO NOTHING;
65676569

65686570
COMMIT;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE omicron.public.silo
2+
ADD COLUMN IF NOT EXISTS
3+
admin_group_name TEXT DEFAULT NULL

0 commit comments

Comments
 (0)