blob: c77fac44d7c4b0f742040cdbb9b66a1816a537f9 [file] [log] [blame] [view]
Bastian Kersting18c9e722022-08-17 09:11:111# Telemetry Extension API
2
3This document describes the Architecture for the third-party Telemetry
4Extensions Platform.
5
6[TOC]
7
8# Overview
9
10The Telemetry Extension Platform provides means for accessing Telemetry and
11Diagnostics data of a ChromeOS device. The Telemetry Extension Platform
12consists of 2 parts:
13
141. A Chrome headless extension for API access, background data gathering and
15processing (Telemetry Extension)
16
172. A companion [Progressive Web App (PWA)](https://web.dev/progressive-web-apps/)
18to show UI to a user.
19
20The Telemetry Extension uses
21[Manifest V3](https://developer.chrome.com/docs/extensions/mv3/intro/) to
22benefit from using
23[Service Workers](https://developer.chrome.com/docs/workbox/service-worker-overview/)
24instead of a background script. Only when the PWA is open, the Telemetry
25Extension periodically receives user driven requests from the PWA to fetch
26telemetry and run diagnostics routines. The PWA also has its own launch icon
27and it doesn’t have direct access to the telemetry and diagnostics API, but it
28communicates with the Telemetry Extension using message passing.
29
30This image shows an overview of the architecture.
31<br>
32<br>
Bastian Kersting43c4f5252022-08-18 12:47:0633![](images/TelemetryExtensionArchitecture.png)
Bastian Kersting18c9e722022-08-17 09:11:1134
35# Components
36
37## Telemetry Extension
38
39The Telemetry Extension's role is to handle requests from the UI and gather
40telemetry and diagnostics data. The Telemetry Extension has a service worker
41and does not have a launch icon. For this specific situation a new Chrome
42extension type was declared, the ChromeOS System extension. In a ChromeOS
43System extension, the service worker has direct access to normal
44[web APIs](https://developer.mozilla.org/en-US/docs/Web/API). Most of the
45[common Chrome Extension APIs](https://developer.chrome.com/docs/extensions/reference/)
46are disabled (besides `chrome.runtime` to communicate with the PWA) and access
47to the Telemetry API is granted either directly through `os.` or via DPSL.js
48the recommended way of using the API). Please note that each extension ID needs
49to be allowlisted by Google in the Chrome codebase to have access to APIs.
50
51## PWA
52
53It is the role of the PWA to show UI to the user and communicate with the
54Telemetry Extension to get telemetry and diagnostics data. The PWA has a
55launch icon, UI, and access to web APIs.
56
57## DPSL.js
58
59DPSL.js stands for Diagnostic Processor Support Library for Javascript, it’s a
60JS wrapper around the underlying Telemetry Extensions APIs. It offers an
61abstracted way for querying the API and is supported and updated by Google to
62always support the latest APIs. DPSL.js is Google’s recommended way to interact
63with the telemetry extension APIs. The library is hosted on
64[Github](https://github.com/GoogleChromeLabs/telemetry-support-extension-for-chromeos)
65and published to [npm](https://www.npmjs.com/package/cros-dpsl-js), please refer
66to the documentation.
67[These tables](https://github.com/GoogleChromeLabs/telemetry-support-extension-for-chromeos/tree/main/src#functions)
68show an overview of all available API functions.
69
70## Communication
71
72A Chrome extension and a PWA can communicate with each other using message
73passing. Only PWAs can initiate communication because a PWA is running only
74when the user launches it.
75The following example shows how the communication between the two components
76could look like. The PWA uses `chrome.runtime.sendMessage` to communicate with
77the Chrome extension:
78
79```javascript
80// PWA code
81
82// The ID of the extension we want to talk to.
83var editorExtensionId = "abcdefghijklmnoabcdefhijklmnoabc";
84
85// Make a simple request:
86chrome.runtime.sendMessage(
87 /* extensionId */ editorExtensionId,
88 /* message in JSON */ {openUrlInEditor: url},
89 /* callback */ function(response) {
90 if (!response.success)
91 handleError(url);
92 });
93```
94
95The extension side can handle incoming requests as follows:
96
97```javascript
98// Extension code
99
100chrome.runtime.onMessageExternal.addListener(
101 function(request, sender, sendResponse) {
102 if (sender.url == blocklistedWebsite)
103 return; // don't allow this web page access
104 if (request.openUrlInEditor)
105 openUrl(request.openUrlInEditor);
106 });
107```
108
Bastian Kerstingdb7db9f2022-11-30 17:29:00109[//]: <> (This section is part of the API terms of use, internal version is)
110[//]: <> (here go/telemetry-extension-tos. DO NOT EDIT unless changes in source)
111## Permission to API Functionality Mapping
112
113For an overview of all exposed function under `chrome.os.telemetry` and
114`chrome.os.diagnostics`, please visit
115[this page](https://github.com/GoogleChromeLabs/telemetry-support-extension-for-chromeos/blob/main/src/README.md#functions).
116Some telemetry data requires special permissions to be accessed:
117
1181. `VpdInfo.serialNumber` requires additional permission:
119"os.telemetry.serial_number" with string
120"Read Chrome OS device and component serial numbers"
121
1222. `OemData.oemData` requires additional permission:
123"os.telemetry.serial_number" with string
124"Read Chrome OS device and component serial numbers"
125
1263. `Batteryinfo.serialNumber` requires additional permission:
127"os.telemetry.serial_number" with string
128"Read Chrome OS device and component serial numbers"
129
1304. MAC Address in `InternetConnectivity` requires additional permission:
131“os.telemetry.network_info” with string “Read ChromeOS network information”
132
Bastian Kersting18c9e722022-08-17 09:11:11133# The Chrome extension
134
135In order for a Chrome extension to have access to telemetry and diagnostics
136APIs, the following requirements need to be satisfied:
137
1381. The user must be either:
139
140 a. managed and the Telemetry extension was force-installed via policy, or
141
142 b. The user is the device owner (the first user of the device).
143
Chung-Sheng Wub713ab02023-07-21 15:56:20144 c. The user is in Shimless RMA flow.
145
Bastian Kersting18c9e722022-08-17 09:11:111462. The PWA UI associated with the Telemetry extension must be opened for the
147extension to have access to APIs.
148
1493. The device hardware must belong to the OEM associated with the Telemetry
150extension (e.g. HP Support Assist only runs on HP devices).
151
1524. Only an allowlisted extension ID can access Telemetry Extension APIs. Each
153allowlisted extension ID can be connected to one PWA origin. It is mandatory
154to declare one entry in `externally_connectable.matches` list.
155An example can be found here:
156```json
157"externally_connectable": {
158 "matches": ["https://third-party.com/*"]
159}
160```
161
162The `externally_connectable` key determines whether or not a website (or other
163Chrome extension) can initiate communication with a Telemetry Extension. A
164Telemetry Extension can always choose to communicate with sites indirectly via
165content scripts injected into a tab. Please note that no matter what,
166extensions should always validate and sanitize messages. An extension should
167never have a listener that evals random code sent in a message. This helps
168mitigate the damage a sender (whether untrusted or compromised) may be able to
169perform. This is also critical because other Chrome extensions may be running
170on the site that tries to connect to the Telemetry Extension and can initiate
171that connection.
172
173# Development / Testing support
174
175## Overriding PWA origin (Since M98) / Manufacturer (Since M105)
176
177Support for overriding the PWA origin and manufacturer to use while development
178and testing was added in version M98 and M105. The PWA origin option overrides
179the allowlisted PWA origin while the manufacturer overrides the actual device
180manufacturer fetched from cros_config. Here is what you need to do in order to
181access the flags (you can skip to step 3 if you already have read/write access
182to rootfs):
183
1841. On your testing device, make sure you enable developer mode.
185
1862. Make sure you have write access to rootfs, if not run `/usr/share/vboot/bin/make_dev_ssd.sh --remove_rootfs_verification`
187
1883. Open `/etc/chrome_dev.conf` and add these lines to the end:
189```
190--telemetry-extension-pwa-origin-override-for-testing=<new-pwa-origin>
191--telemetry-extension-manufacturer-override-for-testing=<new-manufacturer>
192```
193
194<ol start="4">
195<li>In your Telemetry Extension's manifest.json, set the
196externally_connectable.matches entry to match <new-pwa-origin>.</li>
197</ol>
198
199After following those steps, the new PWA and the Telemetry Extension should be
200able to communicate via message passing.
201
202## A Note on Serial Number
203
204The device serial number can be accessed using `dpsl.telemetry.getVpdInfo()`
205and the battery serial number is accessed using `dpsl.telemetry.getOemDataInfo()`.
206Because of the sensitive nature of serial numbers, this information is guarded
207using a runtime permission: `os.telemetry.serial_number`.
208For technical limitation, this is now a mandatory permission, meaning the
209chrome extension’s manifest.json needs to include it in the permissions list in
210order to have access to serial numbers.
211
Bastian Kersting7280fe842022-08-29 12:46:31212## Setup a secure connection on localhost
213
214The Telemetry Extension enforces `https` as the protocol for communicating with
215the PWA. During development, this leads to a rejection of a PWA hosted under
216`http://localhost/` or another origin that does not have a valid certificate
217that is trusted by Chrome. The following steps describe how to set up a secure
218development PWA under crostini (Linux on ChromeOS). For this guide we assume
219`localhost` as the host. Please note that the `openssl` commands for this
220guide were taken from
221[this](https://www.section.io/engineering-education/how-to-get-ssl-https-for-localhost/)
222blog post.
223
224* Setup crostini (`Settings>Developers>Linux development environment`) and make
225sure that "My Files" are shared with Linux (right click on the "My Files" folder
226and then select "Share with Linux").
227* Navigate to a shared folder under `mnt/chromeos/..` and run the following
228command to create a root certificate:
229```
230openssl genrsa -out CA.key -des3 2048
231```
232* Using this key, generate a root certificate:
233```
234openssl req -x509 -sha256 -new -nodes -days 3650 -key CA.key -out CA.pem
235```
236* Next up, create a file named `localhost.ext` with the following content:
237```
238authorityKeyIdentifier = keyid,issuer
239basicConstraints = CA:FALSE
240keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
241subjectAltName = @alt_names
242
243[alt_names]
244DNS.1 = localhost
245IP.1 = 127.0.0.1
246```
247* Now create a key and a Certificate Signing Request (CSR) for localhost using
248the following commands:
249```
250openssl genrsa -out localhost.key -des3 2048
251openssl req -new -key localhost.key -out localhost.csr
252```
253* Finally generate a Certificate for localhost with the following command:
254```
255openssl x509 -req -in localhost.csr -CA ../CA.pem -CAkey ../CA.key -CAcreateserial -days 3650 -sha256 -extfile localhost.ext -out localhost.crt
256```
257* For your convenience create a decrypted version of your key for localhost.
258This can be used by your development instance.
259````
260openssl rsa -in localhost.key -out localhost.decrypted.key
261````
262
263You can now use the generated key and certificate for localhost in your
264development environment. In order for Chrome to trust the key used by your
265application, you need to add the CA root certificate to Chrome.
266Under `Settings>Privacy and security>Security>Manage certificates` you are
267able to set the root CA. Just select the `Authorities` tab and click `Import`.
268Select the generated `CA.pem` file and click open. Now your Chrome instance
269and testing environment trust each other.
270
Bastian Kerstingdb7db9f2022-11-30 17:29:00271[//]: <> (This section is part of the API terms of use, internal version is)
272[//]: <> (here go/telemetry-extension-tos. DO NOT EDIT unless changes in source)
273# Restrictions on Data Use
274
275Due to the powerful nature of this API there are limits on how the data can be
276utilized:
277
2781. This API can only be used to receive telemetry data and diagnostic
279information from ChromeOS-based devices to provide Customer Support Services.
280
2812. This API will only be used, access or otherwise process personal data or
282device identifiers at the Customer’s express direction in each instance.
283
2843. Company will not access the ChromeOS API on an ongoing basis, or at recurring
285intervals, without express direction by the Customer.
286
2874. Company will not store (on device or server), or use for geolocation
288purposes, the device SSID or BSSID.
289
2905. Company will not use data obtained through the API for marketing purposes.
291
2926. Company will provide and adhere to a privacy policy that clearly and
293accurately describes to Customers what data is collected and how the data is
294used and shared.
295
Bastian Kerstinge8aea8a2022-11-25 13:46:18296# Further reads
297
298For information around configuration of certain cros-config values please visit:
299
3001. [Customization Guide - OEM Name](add_oem_name.md)
301
3022. [Customization Guide - Fingerprint Diagnostics](fingerprint_diag.md)
303
Bastian Kersting137a8a1c2023-04-26 15:04:073043. [Telemetry Extension API overview](api_overview.md)
305
Bastian Kersting18c9e722022-08-17 09:11:11306# FAQs
307
308Q: I found a bug, how do I report it?<br>
309A: Thank you for your contribution. Please create a new bug with the description
310and logs (if possible) on our
Bastian Kersting6b8b21b2022-09-01 09:33:00311[bugtracker](https://partnerissuetracker.corp.google.com/issues/new?component=1225577&template=1725782).
312You need a partner account to do that.
Bastian Kersting18c9e722022-08-17 09:11:11313
314Q: Have a question?<br>
Bastian Kerstinge8aea8a2022-11-25 13:46:18315A: Please reach out to [email protected].