File tree 5 files changed +40
-25
lines changed
5 files changed +40
-25
lines changed Original file line number Diff line number Diff line change @@ -728,8 +728,8 @@ impl<RT: Runtime> Application<RT> {
728
728
self . database . latest_snapshot ( )
729
729
}
730
730
731
- pub fn app_auth ( & self ) -> Arc < ApplicationAuth > {
732
- self . app_auth . clone ( )
731
+ pub fn app_auth ( & self ) -> & Arc < ApplicationAuth > {
732
+ & self . app_auth
733
733
}
734
734
735
735
pub async fn search_with_compiled_query (
@@ -2097,12 +2097,14 @@ impl<RT: Runtime> Application<RT> {
2097
2097
) -> anyhow:: Result < Identity > {
2098
2098
let identity = match token {
2099
2099
AuthenticationToken :: Admin ( token, acting_as) => {
2100
- let admin_identity = self . key_broker ( ) . check_admin_key ( & token) . context (
2101
- ErrorMetadata :: unauthenticated (
2100
+ let admin_identity = self
2101
+ . app_auth ( )
2102
+ . check_key ( token. to_string ( ) , self . instance_name ( ) )
2103
+ . await
2104
+ . context ( ErrorMetadata :: unauthenticated (
2102
2105
"BadAdminKey" ,
2103
2106
"The provided admin key was invalid for this instance" ,
2104
- ) ,
2105
- ) ?;
2107
+ ) ) ?;
2106
2108
2107
2109
match acting_as {
2108
2110
Some ( acting_user) => {
Original file line number Diff line number Diff line change @@ -27,20 +27,15 @@ impl ApplicationAuth {
27
27
admin_key_or_access_token : String ,
28
28
instance_name : String ,
29
29
) -> anyhow:: Result < Identity > {
30
- if admin_key_or_access_token. contains ( '|' )
31
- || self
32
- . key_broker
33
- . is_encrypted_admin_key ( & admin_key_or_access_token)
30
+ if self
31
+ . key_broker
32
+ . is_encrypted_admin_key ( & admin_key_or_access_token)
34
33
{
35
34
// assume this is a legacy Deploy Key
36
- // This is either a pipe-delimited deployment specific key
37
- // or an encrypted admin key.
38
- // The latter is used by smoke tests.
39
35
self . key_broker . check_admin_key ( & admin_key_or_access_token)
40
36
} else {
41
37
// assume this is an Access Token
42
- // Access Tokens are base64 encoded strings and do not have pipes
43
- // in them
38
+ // Access Tokens are base64 encoded strings
44
39
self . access_token_auth
45
40
. is_authorized ( & instance_name, & admin_key_or_access_token)
46
41
. await
Original file line number Diff line number Diff line change 1
1
use anyhow:: Context ;
2
+ use authentication:: application_auth:: ApplicationAuth ;
2
3
use common:: types:: MemberId ;
3
4
use errors:: ErrorMetadata ;
4
5
use keybroker:: {
@@ -17,6 +18,18 @@ pub fn must_be_admin_from_keybroker(
17
18
Ok ( identity)
18
19
}
19
20
21
+ pub async fn must_be_admin_from_key (
22
+ app_auth : & ApplicationAuth ,
23
+ instance_name : String ,
24
+ admin_key_or_access_token : String ,
25
+ ) -> anyhow:: Result < Identity > {
26
+ let identity = app_auth
27
+ . check_key ( admin_key_or_access_token, instance_name. clone ( ) )
28
+ . await
29
+ . context ( bad_admin_key_error ( Some ( instance_name) ) ) ?;
30
+ Ok ( identity)
31
+ }
32
+
20
33
pub fn must_be_admin ( identity : & Identity ) -> anyhow:: Result < MemberId > {
21
34
let member_id = identity
22
35
. member_id ( )
Original file line number Diff line number Diff line change @@ -73,7 +73,10 @@ use serde_json::Value as JsonValue;
73
73
use value:: ConvexObject ;
74
74
75
75
use crate :: {
76
- admin:: must_be_admin_from_keybroker,
76
+ admin:: {
77
+ must_be_admin_from_key,
78
+ must_be_admin_from_keybroker,
79
+ } ,
77
80
parse:: parse_module_path,
78
81
EmptyResponse ,
79
82
LocalAppState ,
@@ -350,11 +353,12 @@ pub async fn get_config_hashes(
350
353
State ( st) : State < LocalAppState > ,
351
354
Json ( req) : Json < GetConfigRequest > ,
352
355
) -> Result < impl IntoResponse , HttpResponseError > {
353
- let identity = must_be_admin_from_keybroker (
354
- st. application . key_broker ( ) ,
355
- Some ( st. instance_name . clone ( ) ) ,
356
+ let identity = must_be_admin_from_key (
357
+ st. application . app_auth ( ) ,
358
+ st. instance_name . clone ( ) ,
356
359
req. admin_key ,
357
- ) ?;
360
+ )
361
+ . await ?;
358
362
359
363
let mut tx = st. application . begin ( identity) . await ?;
360
364
let ( config, modules, udf_config) = ConfigModel :: new ( & mut tx)
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ use value::{
60
60
use crate :: {
61
61
admin:: {
62
62
must_be_admin,
63
- must_be_admin_from_keybroker ,
63
+ must_be_admin_from_key ,
64
64
} ,
65
65
authentication:: ExtractIdentity ,
66
66
deploy_config:: ModuleJson ,
@@ -255,11 +255,12 @@ pub async fn prepare_schema_handler(
255
255
req : PrepareSchemaArgs ,
256
256
) -> Result < ( Json < PrepareSchemaResponse > , bool ) , HttpResponseError > {
257
257
let bundle = req. bundle . try_into ( ) ?;
258
- let identity = must_be_admin_from_keybroker (
259
- st. application . key_broker ( ) ,
260
- Some ( st. instance_name . clone ( ) ) ,
258
+ let identity = must_be_admin_from_key (
259
+ st. application . app_auth ( ) ,
260
+ st. instance_name . clone ( ) ,
261
261
req. admin_key ,
262
- ) ?;
262
+ )
263
+ . await ?;
263
264
let schema = match st. application . evaluate_schema ( bundle) . await {
264
265
Ok ( m) => m,
265
266
Err ( e) => return Err ( e. into ( ) ) ,
You can’t perform that action at this time.
0 commit comments