Some Notes on Data source Info / Data source Ref:
-
Terms I'm using for these notes:
- DatasourceRef: is model that includes (uid+type), is saved by dashboards and alerting (note: alerting is current UID only)
- DatasourceInfo: is full information that a datasource neededs to execute a request, and can be looked up by the Ref
-
Contexts:
- Alerting: The Ref is saved. Alerts run as a service, so in this context there is no user (although perhaps there should be a service user or role). Therefore for saved alerts run by the service, authorization is done at creation time, not run time - (as users would not want alerts to stop working if a user is removed).
- Query API: Runtime, in this context there is a user
-
Main Question:
- What Services are responsbile for what for data source execution?
- Where trailing "What" is:
- Authorizing a User (or Service) to a data source (or data source ref?), and who caches this?
- Taking a data source ref and getting data source info
- Decryption of secrets within data source info?
-
Considerations:
- Security (e.g. Defense in depth, services not having secrets they don't need)
- Performance (e.g. not looking up things twice)
- Making things services - and the stateless aspect (TBH "stateless" in this context isn't entirely clear to me)
-
Misc Notes:
- SSE doesn't need data source info, only the ref, I think only data source plugins and editing of data sources needs the full info
-
A Possible Architecture
- Service to Authorize Datasource Ref to Users (To be called at borders (e.g. APIs or exported services))
- Another service to Translate Datasource Ref -> Datasource Info (to be called by internal services)
- With this, things like recorded queries would use the Data Source Ref Authorization service, SSE as well only sees the Datasoure Ref but isn't responsbile for authorization. Data sources get info (I imagine an execute queries call could use the ref to fetch data source info before sending the request to a data source).
ngalert evaluating query:
Recorded queries are doing something similar: https://github.com/grafana/grafana-enterprise/blob/45e59426ff5a670898d211ddda9ee450a3bff472/src/pkg/extensions/recordedqueries/metric/expressiongetter.go#L77