@@ -158,30 +158,34 @@ impl DataStore {
158158
159159 pub async fn sled_list (
160160 & self ,
161+ opctx : & OpContext ,
161162 pagparams : & DataPageParams < ' _ , Uuid > ,
162163 ) -> ListResultVec < Sled > {
164+ opctx. authorize ( authz:: Action :: Read , & authz:: FLEET ) . await ?;
163165 use db:: schema:: sled:: dsl;
164166 paginated ( dsl:: sled, dsl:: id, pagparams)
165167 . select ( Sled :: as_select ( ) )
166- . load_async ( self . pool ( ) )
168+ . load_async ( self . pool_authorized ( opctx ) . await ? )
167169 . await
168170 . map_err ( |e| public_error_from_diesel_pool ( e, ErrorHandler :: Server ) )
169171 }
170172
171- pub async fn sled_fetch ( & self , id : Uuid ) -> LookupResult < Sled > {
173+ pub async fn sled_fetch (
174+ & self ,
175+ opctx : & OpContext ,
176+ authz_sled : & authz:: Sled ,
177+ ) -> LookupResult < Sled > {
178+ opctx. authorize ( authz:: Action :: Read , authz_sled) . await ?;
172179 use db:: schema:: sled:: dsl;
173180 dsl:: sled
174- . filter ( dsl:: id. eq ( id ) )
181+ . filter ( dsl:: id. eq ( authz_sled . id ( ) ) )
175182 . select ( Sled :: as_select ( ) )
176- . first_async ( self . pool ( ) )
183+ . first_async ( self . pool_authorized ( opctx ) . await ? )
177184 . await
178185 . map_err ( |e| {
179186 public_error_from_diesel_pool (
180187 e,
181- ErrorHandler :: NotFoundByLookup (
182- ResourceType :: Sled ,
183- LookupType :: ById ( id) ,
184- ) ,
188+ ErrorHandler :: NotFoundByResource ( authz_sled) ,
185189 )
186190 } )
187191 }
@@ -3153,6 +3157,7 @@ impl DataStore {
31533157 // Note: "db_init" is also a builtin user, but that one by necessity
31543158 // is created with the database.
31553159 & * authn:: USER_INTERNAL_API ,
3160+ & * authn:: USER_INTERNAL_READ ,
31563161 & * authn:: USER_SAGA_RECOVERY ,
31573162 & * authn:: USER_TEST_PRIVILEGED ,
31583163 & * authn:: USER_TEST_UNPRIVILEGED ,
@@ -3338,30 +3343,37 @@ impl DataStore {
33383343
33393344 pub async fn update_available_artifact_upsert (
33403345 & self ,
3346+ opctx : & OpContext ,
33413347 artifact : UpdateAvailableArtifact ,
33423348 ) -> CreateResult < UpdateAvailableArtifact > {
3349+ opctx. authorize ( authz:: Action :: Modify , & authz:: FLEET ) . await ?;
3350+
33433351 use db:: schema:: update_available_artifact:: dsl;
33443352 diesel:: insert_into ( dsl:: update_available_artifact)
33453353 . values ( artifact. clone ( ) )
33463354 . on_conflict ( ( dsl:: name, dsl:: version, dsl:: kind) )
33473355 . do_update ( )
33483356 . set ( artifact. clone ( ) )
33493357 . returning ( UpdateAvailableArtifact :: as_returning ( ) )
3350- . get_result_async ( self . pool ( ) )
3358+ . get_result_async ( self . pool_authorized ( opctx ) . await ? )
33513359 . await
33523360 . map_err ( |e| public_error_from_diesel_pool ( e, ErrorHandler :: Server ) )
33533361 }
33543362
33553363 pub async fn update_available_artifact_hard_delete_outdated (
33563364 & self ,
3365+ opctx : & OpContext ,
33573366 current_targets_role_version : i64 ,
33583367 ) -> DeleteResult {
3359- // We use the `targets_role_version` column in the table to delete any old rows, keeping
3360- // the table in sync with the current copy of artifacts.json.
3368+ opctx. authorize ( authz:: Action :: Modify , & authz:: FLEET ) . await ?;
3369+
3370+ // We use the `targets_role_version` column in the table to delete any
3371+ // old rows, keeping the table in sync with the current copy of
3372+ // artifacts.json.
33613373 use db:: schema:: update_available_artifact:: dsl;
33623374 diesel:: delete ( dsl:: update_available_artifact)
33633375 . filter ( dsl:: targets_role_version. lt ( current_targets_role_version) )
3364- . execute_async ( self . pool ( ) )
3376+ . execute_async ( self . pool_authorized ( opctx ) . await ? )
33653377 . await
33663378 . map ( |_rows_deleted| ( ) )
33673379 . map_err ( |e| {
@@ -3374,8 +3386,11 @@ impl DataStore {
33743386
33753387 pub async fn update_available_artifact_fetch (
33763388 & self ,
3389+ opctx : & OpContext ,
33773390 artifact : & UpdateArtifact ,
33783391 ) -> LookupResult < UpdateAvailableArtifact > {
3392+ opctx. authorize ( authz:: Action :: Read , & authz:: FLEET ) . await ?;
3393+
33793394 use db:: schema:: update_available_artifact:: dsl;
33803395 dsl:: update_available_artifact
33813396 . filter (
@@ -3385,7 +3400,7 @@ impl DataStore {
33853400 . and ( dsl:: kind. eq ( UpdateArtifactKind ( artifact. kind ) ) ) ,
33863401 )
33873402 . select ( UpdateAvailableArtifact :: as_select ( ) )
3388- . first_async ( self . pool ( ) )
3403+ . first_async ( self . pool_authorized ( opctx ) . await ? )
33893404 . await
33903405 . map_err ( |e| {
33913406 Error :: internal_error ( & format ! (
0 commit comments