Skip to content

Commit 63391ba

Browse files
committed
CP-52320 & CP-52743: Classify xapi threads.
Classifies the threads at the time of session creation and inside `do_dispatch`. This ensures that new threads created by current session/request inherit the propper classification. Note: threads created by xenopsd calling back into xapi are yet to be classified. Signed-off-by: Gabriel Buica <[email protected]>
1 parent 76c8556 commit 63391ba

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

ocaml/xapi/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
sexplib0
7979
sexplib
8080
sexpr
81+
tgroup
8182
forkexec
8283
xapi-idl
8384
xapi_aux

ocaml/xapi/server_helpers.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ let do_dispatch ?session_id ?forward_op ?self:_ supports_async called_fn_name
133133
Context.of_http_req ?session_id ~internal_async_subtask ~generate_task_for
134134
~supports_async ~label ~http_req ~fd ()
135135
in
136+
let identity =
137+
try
138+
Option.map
139+
(fun session_id ->
140+
let subject =
141+
Db.Session.get_auth_user_sid ~__context ~self:session_id
142+
in
143+
Tgroup.Group.Identity.make ?user_agent:http_req.user_agent subject
144+
)
145+
session_id
146+
with _ -> None
147+
in
148+
Tgroup.of_creator (Tgroup.Group.Creator.make ?identity ()) ;
136149
let sync () =
137150
let need_complete = not (Context.forwarded_task __context) in
138151
exec_with_context ~__context ~need_complete ~called_async

ocaml/xapi/xapi_session.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ let consider_touching_session rpc session_id =
686686
(* Make sure the pool secret matches *)
687687
let slave_login_common ~__context ~host_str ~psecret =
688688
Context.with_tracing ~__context __FUNCTION__ @@ fun __context ->
689+
Tgroup.of_creator (Tgroup.Group.Creator.make ~intrapool:true ()) ;
689690
if not (Helpers.PoolSecret.is_authorized psecret) then (
690691
let msg = "Pool credentials invalid" in
691692
debug "Failed to authenticate slave %s: %s" host_str msg ;
@@ -881,6 +882,8 @@ let login_with_password ~__context ~uname ~pwd ~version:_ ~originator =
881882
| Some `root ->
882883
(* in this case, the context origin of this login request is a unix socket bound locally to a filename *)
883884
(* we trust requests from local unix filename sockets, so no need to authenticate them before login *)
885+
Tgroup.of_creator
886+
Tgroup.Group.(Creator.make ~identity:Identity.root_identity ()) ;
884887
login_no_password_common ~__context ~uname:(Some uname) ~originator
885888
~host:(Helpers.get_localhost ~__context)
886889
~pool:false ~is_local_superuser:true ~subject:Ref.null ~auth_user_sid:""
@@ -929,6 +932,8 @@ let login_with_password ~__context ~uname ~pwd ~version:_ ~originator =
929932
do_local_auth uname pwd ;
930933
debug "Success: local auth, user %s from %s" uname
931934
(Context.get_origin __context) ;
935+
Tgroup.of_creator
936+
Tgroup.Group.(Creator.make ~identity:Identity.root_identity ()) ;
932937
login_no_password_common ~__context ~uname:(Some uname) ~originator
933938
~host:(Helpers.get_localhost ~__context)
934939
~pool:false ~is_local_superuser:true ~subject:Ref.null
@@ -1224,6 +1229,10 @@ let login_with_password ~__context ~uname ~pwd ~version:_ ~originator =
12241229
Caching.memoize ~__context uname pwd
12251230
~slow_path:query_external_auth
12261231
in
1232+
Tgroup.of_creator
1233+
Tgroup.Group.(
1234+
Creator.make ~identity:(Identity.make subject_identifier) ()
1235+
) ;
12271236
login_no_password_common ~__context ~uname:(Some uname)
12281237
~originator
12291238
~host:(Helpers.get_localhost ~__context)

ocaml/xe-cli/newcli.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ let main () =
816816
in
817817
let args = String.concat "\n" args in
818818
Printf.fprintf oc "User-agent: xe-cli/Unix/%d.%d\r\n" major minor ;
819+
Printf.fprintf oc "originator: cli\r\n" ;
819820
Option.iter (Printf.fprintf oc "traceparent: %s\r\n") traceparent ;
820821
Printf.fprintf oc "content-length: %d\r\n\r\n" (String.length args) ;
821822
Printf.fprintf oc "%s" args ;

0 commit comments

Comments
 (0)