Chromebook 上的 Linux(Crostini):安全开发 — Google I/O 2019
本页标题、字幕、摘要和阅读笔记为已保存的 AI 译文,可能有误。时间戳与来源一致,可展开查看原始字幕,并对照原视频核对。
Google 工程师解释 Chromebook 上的 Linux(Crostini)如何在虚拟机内隔离开发者工作负载,同时保障 Chrome OS 用户数据安全。
文字稿来源:创作者上传至 YouTube 的字幕。AI 标点由 Vidleaf 添加;原始措辞和时间戳锚点均保留。原始文字稿见下方。
AI 生成的摘要
Sudha Broslawsky、Dylan Reid 和 Tom Buckley 介绍 Chromebook 上的 Linux(Crostini),让开发者通过平衡简洁性与安全性而非采用新框架来获得安心。自 I/O 大会宣布以来,Chromebook 上的 Linux 可运行常用编辑器、IDE 和工具,并已在超过 50% 的 Chromebook 上获得支持;设置只需点击几下,后台会下载虚拟机并配置容器,留下一个终端和标准 Debian 环境,支持 Git、Vim、APT 和 .deb,图形应用则出现在启动器中。安全性依赖于 Chrome OS 的分层方案:一个虚拟化层,其跨虚拟机程序用 Rust 编写,仅暴露少量 API,并拆分为受隔离的支柱(随机数、显示、USB),Canonical 的 LXD 提供 Debian 系统容器。文件共享使用一个名为 9S 的 Rust 9P 服务器,运行在严密隔离环境中,因此容器、虚拟机和服务器各自只能看到共享文件,而 Linux Files 目录充当 Linux 主目录。在用户授予权限之前,Linux 无法访问设备其余部分,可通过右键“与 Linux 共享”共享文件夹,包括 Google Drive 文件夹,并可在设置中取消共享。Web 服务器运行在虚拟机内的容器中,位于虚拟机监控程序之下,基于 VSOCK 的端口转发让 Chrome 能以受信任域访问 localhost 8080。USB 设备必须显式授权,保护措施包括跨虚拟机隔离、最小攻击面、Rust 的内存安全和模糊测试,部分原因是 USB 设备列表可用于对用户进行指纹识别。高级工具可从 Chrome OS shell(Control-Alt-T)使用,包括用于 Termina 虚拟机和 Penguin 容器的 VMC 命令、通过 LXD 使用的 LXC 命令,以及 btrfs 写时复制快照。LXC Restore 可将容器恢复到已保存的快照,多个容器可实现独立设置,通过 LXC Copy 创建;选择 Debian 是因为它是最简单的选项,但用户并不受其束缚,Canonical 的镜像服务器提供许多发行版,例如使用 PacMan 的 Arch 容器。结束语指出,许多 Web 和 Android 开发者流程已获支持,未来将面向其他开发者、多容器以及备份和恢复开展工作,同时应用简洁性与安全性。
根据文字稿生成。请对照原始视频核查所链接的段落。
带时间戳的章节摘要
I/O 大会上的 Chromebook Linux(Crostini)
讲者介绍与演讲框架
- [0:04] Chromebook 上 Crostini 的设计师 Sudha Broslawsky 与 Chrome OS 虚拟化负责人 Dylan Reid、Chromebook 上 Linux 的产品经理 Tom Buckley 一同开场。
- [0:31] 演讲并未推销新框架或平台,而是聚焦开发者如何通过使用 Chromebook 上的 Linux 获得安心,这通过平衡简洁性与安全性来实现。
关于开发与安全的观众投票
- [1:07] 一项观众投票显示,现场满是开发者,他们也会用电脑处理报税和电子邮件等非开发任务,其中许多人都担心安全问题。
- [1:34] Dylan Reid 表示,观众确实应该关注安全问题,他很高兴看到这么多人举手。
Dylan 的难题:不受信任的代码与两台笔记本电脑
- [1:40] 在启动新项目时,Dylan 会卡住并求助于 Google,但有时答案来自不受信任网站的脚本,而由于截止日期,他还是会运行它。
- [2:17] 反复运行这类脚本让他对自己的系统越来越不信任,因为他不再清楚自己运行过什么代码,而且他没有时间阅读所有脚本。
- [2:29] 他的解决方案是携带两台笔记本电脑——一台用于开发,另一台安全笔记本电脑用于其他所有事情——但他最近改用单台笔记本电脑,Tom 对此进行了解释。
Linux 支持状态与入门
- [2:46] Chrome OS 从一开始就追求简单安全的体验,但以前无法运行开发者需要的所有工具;去年 I/O 大会上宣布 Chromebook 支持 Linux 后,情况发生了变化。
- [3:11] Chromebook 上的 Linux 可运行常用编辑器、IDE 和工具,目前已在超过 50% 款 Chromebook 上获得支持,包括搭载第八代 Intel CPU 的设备,如 Lenovo Yoga Book C630 和 Acer Chromebook Spin 13。
- [3:36] 入门只需点击几下;后台会下载虚拟机、设置容器并完成所有配置,而开发者只需在启动器中获得一个终端。
Debian 环境、应用与安全保证
演讲结构概览
计划议程与交接
Chrome OS Linux 开发环境安全
渲染器隔离与虚拟机层的必要性
- [5:34] Chrome OS 一直采用分层安全策略,浏览器和渲染器将所有不受信任的代码运行在隔离的渲染器中,以将核心系统的攻击面降至最低。
- [5:51] 渲染器代码不允许进行许多系统调用,也无法随意访问内核的各个部分,这对网页和 Web 应用来说效果很好。
- [6:00] 开发者工具需要安装许多程序,其权限等同于任何 Linux 应用,这在 Chrome OS 核心上不可接受,因此添加了虚拟化层。
- [6:15] 虚拟化层位于 Chrome OS 主层中,启动一个接口极为有限的虚拟机,同时仍向虚拟机内的程序暴露完整的 Linux 内核。
签名的只读客户机虚拟机及其灵活性限制
- [6:30] 虚拟机只能通过跨虚拟机程序向客户机暴露的小型 API 与 Chrome OS 本体通信,从而大幅减少攻击面。
- [6:52] 客户机虚拟机由 Google 签名并具有一定可信度,因此可以信任其部分操作;同时它是只读的,用户最多只能造成有限破坏,并且始终可以启动虚拟机。
- [7:10] 以这种方式解决安全问题后,灵活性却不足:应用做不了太多事,环境是只读的,什么也无法安装。
为开发者灵活性而设的 LXD 容器层
作为最后防线的 Rust 跨虚拟机层
- [7:47] 跨虚拟机层被描述为安全故事中最重要的部分,也是某些东西进入 Chrome OS 之前的最后一道防线,因此长期聚焦于此。
- [8:06] 跨虚拟机层用 Rust 编写,这是一种内存安全语言,消除了缓冲区溢出、整数溢出以及攻击者利用的许多常见内存安全漏洞。
虚拟化接口的支柱隔离
Chromebook 上的 Linux:三个设计目标
符合开发者习惯的直观体验
- [9:56] 第一个设计目标是保持体验直观。
- [10:09] 团队希望契合用户既有的工作流程和习惯,为他们提供自然的体验。
- [10:19] 目标是让各地的开发者使用 Chromebook 时感到宾至如归。
原生集成而非完整的 Linux 虚拟机桌面
- [10:26] 第二个目标是让体验原生。
- [10:30] 在虚拟机中为用户提供完整的 Linux 桌面是简单的路径,但被认为不够好。
- [10:39] 目标是将开发者依赖的 Linux 应用带入原生的 Chrome OS 体验中。
简洁性以及安全与设计模式的平衡
Crostini 文件共享与安全
促使限制文件访问的威胁
- [11:53] 开发者的文件系统不仅包含代码,还包含个人照片、纳税申报表和其他敏感文件,因此可能出很多问题。
- [12:08] 勒索软件可能劫持数据,恶意软件可能将文件上传到随机服务器,或者某些东西可能直接删除一切。
- [12:21] Crostini 在构建时考虑了这些威胁,以限制可能出错的范围。
分层式 9P 共享架构
- [12:31] 目标是在需要的地方提供所需的开发文件,同时不将文件暴露给不受信任的代码,因为虚拟机内运行的代码最终是不受信任的。
- [12:48] 文件位于 Chrome OS 底部的“文件”应用中,并通过一个名为 9S 的 9P 服务器共享给虚拟机,该服务器用 Rust 编写,经过模糊测试,并被置于严密的沙盒中,因此只能访问共享文件。
- [13:20] 虚拟机会挂载内置的 Linux 9P 支持,LXD 会将该挂载暴露到运行开发工具的容器中。
- [13:29] 容器、虚拟机以及 Chrome OS 上的 9S 服务器各自只能看到用户选择共享的文件,因此即使整个技术栈被完全攻破,也无法触及未共享的文件。
通过界面简化共享
在 Crostini 中安全地运行 Web 服务器
Web 服务器在 Chrome OS 上的重要性
- [15:54] Chrome OS 关心打造优秀 Web 应用的人,并希望确保他们能在 Chromebook 上创建这些应用。
- [16:01] 能够运行 Web 服务器对于构建任何 Web 应用来说都相当核心。
底层 Web 服务器访问的安全风险
- [16:08] Web 服务器需要相当低级别的访问权限,这可能会引发问题。
- [16:16] 能够运行 Web 服务器的代码同样能够窥探互联网流量,知晓访问了哪些网站,在某些情况下甚至能看到页面内容。
- [16:26] 恶意 Web 服务器可能会跟踪用户所做的一切。
- [16:30] Crostini 在设计时就考虑到了这一点,旨在防止此类攻击。
底层网络隔离层
- [16:45] 从 Crostini 启动 Web 服务器很简单:输入命令并像在任何 Linux 发行版上一样启动它。
- [16:59] 在底层,用户处于容器中,并在虚拟机内部的网络命名空间中打开一个端口。
- [17:10] 该虚拟机运行在特殊的虚拟机监控程序下,其网络栈位于主机上的另一个命名空间中,之后流量才会发往 Chrome。
- [17:20] Chrome 无法反向进入,这对安全性非常有利,并提供了出色的隔离。
实现 Chrome 与虚拟机通信的守护进程
Chrome OS Linux 容器端口转发
端口检测与 VSOCK 转发守护进程
- [17:43] 虚拟机中的一个守护进程会等待检测任何正在运行的容器何时打开端口,并识别是哪个容器打开的。
- [17:57] 该虚拟机守护进程会打包这些信息并发送给 Chrome OS,表明容器中有端口正在监听,用户可能想使用它。
- [18:08] Chrome OS 上的第二个守护进程会响应,设置一条通过 VSOCK(一种用于与本地虚拟机通信的协议)转发流量的路由。
- [18:22] 两端都通过 HTTP 与守护进程通信,守护进程之间通过 VSOCK 通信,因此 Web 服务器和 Chrome 都使用普通的 HTTP。
受信任域与 PWA 功能
- [18:45] 该设置被设为受信任,因此用户可以获得所有 PWA 功能,并能将应用安装到桌面。
- [18:53] 尽管从技术上讲并非同一台机器,但系统知道它是,因为系统设置了该虚拟机,所以允许使用受信任域。
- [19:02] 演讲者称这是他们最好的演示之一,展示了隐藏于底层之下的复杂性与实际使用中的简洁性。
在端口 8080 上测试 PWA 且无需权限提示
在 Chromebook 上测试 Android 应用
Chrome OS 上的 Android Studio 支持
- [20:39] Android Studio 现已在 Chromebook 上获得官方支持,并专门为 Chrome OS 创建了安装程序,让入门变得简单。
- [20:49] 构建出色的 Android 应用还需要一台设备来测试,通常是一部手机。
USB 设备测试与 Crostini 安全
Chrome OS Linux(Crostini)中的 USB 支持
将 USB 协议栈与主机隔离
- [21:55] 实现 USB 支持很有趣,但可能是团队最痛苦的协议栈,同样采用了分层原则。
- [22:06] 主机受到保护,因为主机 USB 协议栈攻击面很大,它是一份被许多人松散实现的精确规范。
- [22:24] USB 驱动运行在跨虚拟机 jail 中且隔离良好,因此无法访问用户文件、网络或任何 USB 设备。
通过模拟总线显式共享设备
- [22:44] 用户必须显式授权将 USB 设备授予其开发环境,团队尽力使这一过程尽可能简单。
- [22:52] 模拟 USB 总线始终运行,因此客户机看到的是空总线,直到用户指示应将某个设备交给虚拟机,随后该设备会被添加到总线上。
- [23:09] 客户机必须依次将设备转发到容器中,容器才能看到它。
安全与隐私目标
- [23:16] 安全性通过 jail、最小攻击面、Rust 的内存安全以及模糊测试来解决。
- [23:29] 隐私是一个关注点,因为已连接 USB 设备列表被用于对用户进行指纹识别和跟踪,因此不受信任的容器代码不应成为另一种实现该目的的方式。
- [23:46] 该流程涉及许多步骤——创建设备、将其导出到虚拟机、将其导出到容器,以及决定导出哪个设备——演示展示了它有多么简单。
演示:将手机连接到 Chromebook 上的 Linux
- [24:06] 在支持 Linux 的 Chromebook 上,插入手机会显示通知,提示用户将其连接到 Linux;此时只有 Chrome OS 知道该手机。
- [24:28] 在用户通过通知连接之前,手机不会列在 USB 列表中;连接后它会出现,Linux 便可访问它。
- [24:49] 在 Android Studio 中,用户点击运行、选择手机,即可在手机上测试和调试应用。
- [25:12] 设置让用户可以随时管理 Linux 可以访问的内容,使用户保持完全控制。
用于用户控制的原生用户体验模式
Chrome OS 高级虚拟机和容器工具
超出标准工作流程的不受支持的高级折腾
- [26:19] 精心打磨的常见工作流程背后的技术细节仍然可用,并且为用户保留了可供实验的钩子。
- [26:33] 这些高级功能未经测试或支持,因为标准流程旨在对每个人都足够。
- [26:41] 有时可能有理由做一些更高级的事情,或者用户可能只是想作为折腾者深入底层玩玩。
访问 Chrome OS shell 和 VMC 命令
- [26:58] 所有示例都从 Chrome OS shell 运行,该 shell 在 Chrome OS 中存在的时间比演讲者在那里工作的时间还长。
- [27:04] Control-Alt-T 会打开一个带有调试命令集的 shell。
- [27:09] 重点是 VMC 命令,它被添加用于控制虚拟机和容器。
列出虚拟机并进入 Termina 和 Penguin
- [27:18] VMC list 显示系统上安装的虚拟机,默认虚拟机名为 Termina。
- [27:34] Termina 是用于之前所有幻灯片演示的虚拟机,并且正在运行。
- [27:41] 一个快捷方式可进入虚拟机内的容器;默认容器名为 Penguin,演示就是在其中运行的。
- [27:51] VMC container 命令进入默认容器,而 VMC Start 进入虚拟机但不进入容器。
在虚拟机中使用 LXC 命令和快照
- [28:21] 由于 Chrome OS 使用 LXD,许多 LXC 命令在 Chrome OS 中的工作方式与默认 Ubuntu 安装中非常相似。
- [28:37] LXC list 显示单个 Penguin 容器正在运行并带有 IP 地址。
- [28:53] LXC Snapshot 命令接受容器名称和快照名称,以保存一个镜像,以便在出现问题时可以回退到该镜像。
- [29:20] 快照在虚拟机中使用 btrfs 的写时复制,因此不会占用大量磁盘空间。
- [29:27] 容器信息会在底部显示刚刚创建的快照,并且可以存在多个快照,每个快照都带有日期。
使用 LXC Copy 创建多个容器
Chromebook 上的 Linux:容器与发行版
在新容器中安装工具
- [30:58] 新容器中的 shell 允许安装默认容器中不需要的任意工具链。
Debian 默认与替代发行版
- [31:07] 选择 Debian 是因为它是最简单的选项,但用户并不受限于它。
- [31:17] 支持 Debian 工作流以及 Debian 中默认安装的一些客户机软件包。
- [31:29] Canonical 运营的镜像服务器上提供了许多发行版。
Arch 容器与 PacMan
- [31:36] 一个名为 ArchTest 的 Arch 容器与 Debian 容器 Penguin 和 Kingfisher 一起安装。
- [31:53] 通过让 Arch 容器运行 Bash 来进入该容器,并使用 PacMan 而不是 Act 来安装软件包。
更多文档与 GUI 集成
- [32:11] 在线 LXD 文档提供了更多思路,包括有关安装其他发行版以及将它们更好地与 GUI 集成(而不仅仅是命令行)的帮助。
Crostini 子版块推荐
- [32:29] Tom Buckley 推荐 Crostini 子版块,人们会在功能发布后(有时甚至更早)就发现它们,并且该版块对 Chromebook 上的 Linux 新用户很友好。
关于开发者支持和未来能力的总结发言
扩展开发者流程与新能力
原则与加入邀请
前 3 段双语对照预览 · 免消耗额度
以下展示前 3 段已保存中文译文与英文原版字幕的逐段对照(零额度消耗):
[音乐播放] SUDHA BROSLAWSKY:大家下午好。希望你们在 I/O 上玩得开心。我们在这里和大家聊聊 Chromebook 上的 Linux,也就是 Crostini。我们先做个自我介绍。我叫 Sudha,是 Chromebook 上 Crostini 的设计师。DYLAN REID:大家好,我是 Dylan,是 Chrome OS 虚拟化负责人。TOM BUCKLEY:我是 Tom,是 Chromebook 上 Linux 的产品经理。
[MUSIC PLAYING] SUDHA BROSLAWSKY: Good afternoon, everyone. I hope you are having a great time at the I/O. We are here to talk to you about Linux for Chromebooks, also known as Crostini. We'll start by introducing ourselves. My name is Sudha. I'm a designer on Crostini for Chromebooks. DYLAN REID: Hi, I'm Dylan. I'm the Chrome OS Virtualization Lead. TOM BUCKLEY: And I'm Tom, Product Manager for Linux on Chromebooks.
现在是 I/O 第二天的尾声,你们可能已经参加了很多场不同的会议,听到了各种关于你需要使用的新框架、或者你需要为其构建的平台的内容,大家说得都对,你确实应该这么做,但我们今天并不是要聊这些。相反,我们想聊的是作为开发者的你,以及如何通过使用 Chromebook 上的 Linux 获得更多安心。我们通过平衡简洁与安全来为你带来这份安心。
Now it's the end of day two at I/O and you've probably already been to a bunch of different sessions that have talked about all the new frameworks that you need to be using or the platforms that you need to be building for, and everyone's right, you absolutely should be, but we're not really here to talk about that. Instead what we want to talk about is you as developers and how you can get more peace of mind by using Linux on Chromebooks. We give you that peace of mind by balancing simplicity and security.
SUDHA BROSLAWSKY:说到这个,我们来做个小调查。在座有多少人是开发者?哇,果然座无虚席。请继续举手。有多少人除了开发之外还会用电脑做别的事,比如报税、查邮件——同样,100% 的人。好,最后一个问题。有多少人担心安全问题?DYLAN REID:很好,这挺——我是说,你们都该担心,所以我很高兴看到这么多人举手。
SUDHA BROSLAWSKY: On that note, let's do a quick user study. How many of you are developers in the audience? Wow, that's a full room, as expected. Keep your hands raised. How many of you use your computers for anything else other than development, like doing your taxes, checking email-- again, 100% of you. OK, one last question. How many of you are worried about security? DYLAN REID: Good, that's pretty-- I mean, you all should be, so I'm glad to see many hands up anyway.
[0:00] [音乐播放] SUDHA BROSLAWSKY:大家下午好。希望你们在 I/O 上玩得开心。我们在这里和大家聊聊 Chromebook 上的 Linux,也就是 Crostini。我们先做个自我介绍。我叫 Sudha,是 Chromebook 上 Crostini 的设计师。DYLAN REID:大家好,我是 Dylan,是 Chrome OS 虚拟化负责人。TOM BUCKLEY:我是 Tom,是 Chromebook 上 Linux 的产品经理。
[0:31] 现在是 I/O 第二天的尾声,你们可能已经参加了很多场不同的会议,听到了各种关于你需要使用的新框架、或者你需要为其构建的平台的内容,大家说得都对,你确实应该这么做,但我们今天并不是要聊这些。相反,我们想聊的是作为开发者的你,以及如何通过使用 Chromebook 上的 Linux 获得更多安心。我们通过平衡简洁与安全来为你带来这份安心。
[1:03] SUDHA BROSLAWSKY:说到这个,我们来做个小调查。在座有多少人是开发者?哇,果然座无虚席。请继续举手。有多少人除了开发之外还会用电脑做别的事,比如报税、查邮件——同样,100% 的人。好,最后一个问题。有多少人担心安全问题?DYLAN REID:很好,这挺——我是说,你们都该担心,所以我很高兴看到这么多人举手。
[1:40] 我不知道你们怎么样,但当我开始一个新项目时,我经常卡住。我会撞上很多墙、遇到很多障碍,然后去找问题、找解决方案,就求助于 Google。幸运的是,Google 几乎总能给我一个很好的答案。不幸的是,有时候答案看起来是这样的。我知道我不该从 evilsite.com 运行这个脚本,然后把它管道传给 Sudu,但截止日期快到了,而且这个网站看起来还挺正规的,所以在这种情况下,我就破个例,这么做了。
[2:17] 然后这种情况一再发生,最终,我得到一个系统。我对它的信任程度没有应有的那么高,因为我已经不太清楚自己在上面运行过什么代码了。我没有时间阅读所有这些脚本。我对这个问题的解决方案一直是携带两台笔记本电脑——一台用于我的开发者世界,另一台用于我希望保持安全的其他一切世界。但最近,我改用一台笔记本电脑,Tom 将谈谈我是如何做到这一点的。TOM BUCKLEY:所以我们在 Chrome OS 上的目标一直是为你提供简单而安全的体验。从一开始就是这样,但如果你以前尝试过,你可能会发现它还没有完全为开发者准备好。
[2:57] 为了简单和安全,我们无法运行开发者完成工作所需的所有工具。但这一切在去年的 I/O 上发生了变化。当时我们宣布将开始在 Chromebook 上支持 Linux。Chromebook 上的 Linux 让你可以运行所有你喜欢的编辑器、IDE 和工具,而且现在已支持超过 50% 款 Chromebook,包括搭载第八代 Intel CPU 的优秀设备,比如 Lenovo Yoga Book C630 和 Acer Chromebook Spin 13。
[3:31] 如果你还没看过,我们将快速演示几个示例。首先,如何获取它?非常简单。只需点击几下。现在在后台,这会下载一个虚拟机、设置容器、配置所有内容——Dylan 将在几分钟后更详细地介绍这一点,但对你作为开发者来说,只需点击几下即可开始。这会在你的启动器中添加一个终端。现在如果你打开那个终端,你会看到你有一个相当标准的 Debian 环境,而且我们已经预装了许多开发者期望的工具,比如 Git 和 Vim,如果你还需要其他东西,你有 APT 包管理器,可以安装任何你需要的软件包。
[4:11] 如果你希望通过 .dev 文件安装程序,也可以这样做。这让你可以使用成千上万个世界级的开发者工具。现在,一旦你安装了任何图形应用,你会发现它们都会像其他 Chrome OS 应用一样出现在你的启动器中,如果你打开它们,它们会出现在你的窗口管理器中——同样,就像其他 Chrome OS 应用一样。这就是人们期望从 Chrome OS 获得的简单体验,我们不想因为 Linux 而改变这一点。
[4:45] 但重要的是,这同样是安全的。你不必担心恶意软件访问你的文件、窥探你的流量或感染你的外设。我本想请你们在这方面信任我们,但这件事太重要了,不能只靠信任,所以在本场演讲中,Dylan 和 Sudha 将带你了解 Crostini 架构与设计背后的原则。然后我们会剖析一些常见的开发者流程,向你展示这些原则如何应用。
[5:16] 最后,我们会为高级用户分享一些进阶使用的技巧和窍门。现在我把时间交给 Dylan,由他来讲架构。[掌声] DYLAN REID:讲得好。好。Chrome OS 一直采用分层的方式来保障安全。而我们最大的一层一直是浏览器和渲染器,把所有不受信任的代码运行在一个隔离良好的渲染器中,这让你核心系统的攻击面保持在绝对最低水平。
[5:51] 它们不被允许进行大量系统调用。它们不能随意触碰你内核的任意部分。这对网页和 Web 应用非常有效。然而,对于开发者工具,我需要安装许多不同的程序。它们需要许多不同的权限。它们能做 Linux 上任何应用能做的事。这对我们 Chrome OS 的核心来说是不可接受的,所以我们需要增加一层。于是我们增加了一个虚拟化层,它位于 Chrome OS 主层中,并启动一个虚拟机。
[6:23] 现在这个虚拟机的接口要受限得多,同时仍向虚拟机内运行的程序暴露完整的 Linux 内核。虚拟机与 Chrome OS 本体通信的唯一方式,是通过左上方那个跨虚拟机程序向客户机暴露的一个小型 API。这相当不错。现在我们大大减少了攻击面。我们对此相当满意。我们还想再进一步。所以我们确保客户机虚拟机也由 Google 签名,并在一定程度上受信任。
[6:58] 这让我们能够信任客户机虚拟机采取的某些操作,而且它是只读的,所以用户最多也只能破坏到一定程度。而且,无论你做什么,你都能够启动一个虚拟机。然而,在解决了所有这些安全问题之后,我们又回到了灵活性不足的处境。你的应用什么都做不了。它是只读的。你无法在其中安装任何东西。于是我们又增加了一层,为此我们借鉴了——使用了——Canonical 的 LXD。
[7:32] 那个团队在帮我们启动这个项目方面非常给力。它是一个相当标准的容器运行时,专为运行系统容器而构建。在我们的场景中,我们启动了一个 Debian 系统容器并将其暴露给用户。所以我之前提到的那个跨虚拟机层,可以说是这里安全故事中最重要的部分。它是阻止某些东西进入 Chrome OS 之前的最后一道防线。因此我们花了很长时间专注于这一点,确保它尽可能安全。
[8:06] 我们用内存安全的编程语言编写了它。我们选择了 Rust。这消除了缓冲区溢出、整数溢出以及许多与内存安全相关的、常被攻击者利用的常见漏洞。我们对此相当满意,但我们又在这里增加了一层安全防护,将虚拟化程序拆分成多个支柱,并确保每个与客户机交互的支柱只能访问你主机 Chrome OS 系统的一小部分。
[8:38] 在你的主机 Chrome OS 系统中,你打开了银行的网页,打开了在线报税的东西,到处都是各种个人可识别信息。我们真的很想保护这些。但我们需要给客户机访问一些东西的权限,比如随机数、显示器、USB 设备。所以每一个都获得了自己的隔离环境,它们只能看到自己需要的东西。因此我们的随机数生成器可以生成随机数,它不能访问任何文件。从它的视角来看,它处在一个空文件系统中。
[9:09] 它没有任何网络访问权限。显示驱动可以访问显示器,同样,它不能碰网络。它不能去抓取你的文件并上传,即使有人入侵了它并试图让它做我们没打算让它做的事。这一切有点复杂,但我们添加了大量系统 UI 来让你轻松使用,所以当你只是做开发者的本职工作时,不必担心我为你画的这些漂亮图。Sudha 会向你展示我们做了什么。
[9:40] SUDHA BROSLAWSKY:谢谢你,Dylan。安全绝对是我们的首要考虑。在 Chromebook 上打造 Linux 体验时,我们提出了三个高层次的设计目标。第一个目标是保持你的体验直观。这个房间里的每个人使用电脑都很久了,你们已经建立了自己的工作流程和习惯。所以基本上我们想做的就是匹配这些期望。
[10:14] 我们希望为你提供一种自然的体验。我们希望各地的开发者都能使用 Chromebook,并且在使用时感到得心应手。第二个目标是让你的体验原生。我们本可以走捷径,在虚拟机中提供完整的 Linux 桌面,但这还不够好。我们的目标是将你开发所依赖的 Linux 应用融入原生的 Chrome OS 体验中。
[10:47] 第三个目标是让你的体验简单,我认为这一点非常重要。底层存在大量复杂性,我们希望将其留在那里。我们的指导原则是复杂性不应干扰用户体验。我们在这里试图平衡几件事:在 Chromebook 上安装 Linux 应用带来的安全顾虑,以及遵循 Chrome OS 既定设计模式所带来的简洁性。
[11:26] 我们的使命就是找到那个最佳平衡点。TOM BUCKLEY:好的。那么现在我们要讨论三个常见的开发者流程,看看它们如何与 Crostini 配合工作。第一个是访问文件。作为开发者,我们必须一直这样做。我们的编辑器需要访问文件,编译器、源代码控制以及更多工具也是如此。但问题在于,我们的文件系统里远不止代码。
[11:58] 里面还有我们的个人照片、纳税申报表,也许还有你一直在写的那部小说。很多事情都可能出错。勒索软件可以把所有这些数据扣为人质。恶意软件可以把你的文件上传到某个随机服务器。或者你只是遇到了一个为了好玩而删除一切的东西。我们在构建 Crostini 时就考虑到了这些威胁,以限制可能出错的范围,Dylan 会告诉你具体怎么做。DYLAN REID:因此,我们与虚拟机和容器共享文件的目标是,让你能轻松获取开发任务所需的文件,同时不暴露你不想暴露给不可信代码的内容。
[12:44] 因为归根结底,我们不信任在这个虚拟机内运行的代码。为此,我们采取了分层方法。你的文件全部位于最底层的 Chrome OS 中,我们通过 9P 服务器将它们共享给虚拟机。我们将其命名为 9S。同样,我们用 Rust 编写它,因此内存安全;我们对其进行了模糊测试,以确保意外输入不会导致意外行为;我们还把它关在严密的牢笼中,使其只能访问你与它共享的文件。
[13:16] 然后它接收这些文件并将它们导出到虚拟机。虚拟机会挂载 Linux 内置的 9P 功能,接着 LXD 会将该挂载点暴露到运行开发工具的容器中。这里的关键在于,你的容器只能看到你明确表示“我想与开发环境共享”的文件。你的虚拟机也只能看到这些相同的文件。甚至我们编写的、运行在 Chrome OS 上的服务器也只能看到这些文件,而无法看到全部内容。因此,即使有人利用了这个技术栈,一路攻击回 Chrome OS,
[13:49] 他们仍然无法访问你未与容器共享的文件。要设置的东西很多。设置 9P 挂载点、将内容绑定挂载到容器中。在开发过程中,我们曾不得不手动完成这些操作,非常痛苦。所以,接下来让 Sudha 向你展示我们为你简化到了何种程度。SUDHA BROSLAWSKY:这里涉及很多层,但让我们看看在 UI 中这有多简单。开箱即用,你会看到一个名为 Linux Files 的目录,它就是 Linux 中的主目录。
[14:24] 此目录中的任何内容都会自动与 Linux 共享。在此目录之外,设备上的任何其他位置,在你授予权限之前,Linux 都无法访问。我在这里举几个例子。假设你正在处理一个项目,发现自己需要某个名为 Illustrations 的文件夹中的文件。要共享它,你只需访问右键菜单并点击“与 Linux 共享”。
[14:58] 只需两步,你就已经将这个文件夹与 Linux 共享了。如果你注意到,这个文件夹位于 Google Drive 中,这很棒。当你不再想共享时,可以前往“设置”并取消共享。再举一个例子,我们让快速编辑变得非常简单。你的“下载”文件夹中有一个数据文件,双击它就会自动在 VS Code 中打开。
[15:31] 发生这种情况时,后台会隐式共享该文件。共享会持续到你重新启动。这就是我们想要为你带来的安全性与简便性之间的平衡。TOM BUCKLEY:谢谢。那么,我们要讨论的第二个开发者流程是运行 Web 服务器。作为 Chrome OS,我们非常关心人们制作出色的 Web 应用,我们希望确保他们能在 Chromebook 上创建这些应用。而能够运行 Web 服务器对于构建任何 Web 应用来说都相当核心。
[16:08] 遗憾的是,Web 服务器也需要相当低级别的访问权限,这可能会引发一些问题。能够运行 Web 服务器的代码同样也能窥探你的互联网流量。它可以知道你正在访问哪些网站,在某些情况下,甚至能看到那些页面的内容。这意味着恶意的 Web 服务器有可能追踪你所做的一切。当然,我们在设计 Crostini 时已经考虑到了这一点,并确保阻止了这类攻击。
[16:39] Dylan 会告诉你具体怎么做。DYLAN REID:叫我 Linux 也行,没关系。这就是我的工作。好,那么从 Crostini 启动 Web 服务器,很简单。我们在 Web 开发沙箱里已经有一个不错的演示了。输入一条命令。你就像在任何 Linux 发行版上一样启动你的 Web 服务器。不过,底层实际发生的是:你身处一个容器中,并打开了一个端口。该端口位于虚拟机内的网络命名空间中,虚拟机运行在我们特殊的 hypervisor 之下,它把网络栈放在宿主机上的另一个命名空间里,最后再通向 Chrome。
[17:20] 所以 Chrome 无法反向进入,这对安全性来说非常好。你获得了出色的隔离性。但如果我想测试我在虚拟机里运行的这个新 PWA 或网页,我该如何让 Chrome 与它通信呢?这并不简单。为此,我们不得不沿途添加一些守护进程——实际上,每一层都会为此配一个守护进程。第一个运行在虚拟机中,它在那里等待,检查是否有正在运行的容器恰好打开了端口。
[17:53] 然后它得弄清楚是哪个容器打开了那个端口。它把这些信息打包,发送给 Chrome OS。意思是:嘿,这个容器里的这个端口正在监听。用户可能想使用那个端口。而在 Chrome OS 上,我们说:好的。另一个守护进程回应道:我会设置一条路由来做转发。我要把这一切都通过 VSOCK 转发出去,VSOCK 是一种用于与本机上的本地虚拟机通信的协议。这些都隐藏在底层。所以两端都是通过 HTTP 与守护进程通信,而守护进程之间通过 VSOCK 通信。
[18:28] 所以关键在于,Web 服务器可以正常使用 HTTP,Chrome 也可以正常使用 HTTP。一切都很正常。一切都像你预期的那样工作。当然,底层有所有这些额外的守护进程和 VSOCK 转发在运行,但我们已经把它隐藏起来了。另一个重要的事情是,我们让它变得可信。这样你就能获得所有 PWA 功能。你可以把它安装到桌面上。尽管从技术上讲它不是同一台机器,但我们知道它是,因为我们掌握着信息。是我们设置了这台虚拟机。
[18:58] 因此我们允许它成为受信任的域。我认为所有这些复杂性使它成为我们今天最好的演示之一,展示了我们在底层做得多么复杂,而你在实际使用中看到的又是多么简单。SUDHA BROSLAWSKY:我完全同意。这在底层非常复杂,但在 UI 中,它完全符合你的预期。假设你正在尝试构建这个很酷的 PWA。在终端里,你位于自己的文件夹中,PWA Starter Kit。
[19:31] 你正在运行命令来启动你的 Web 服务器。如果你看屏幕底部,它正在端口 8080 上监听。此时,你可以启动浏览器,访问 localhost 8080,并测试你的 Web 应用。在屏幕上,左侧是你的 Web 应用在 Chrome 中运行,而右侧,如果你注意到了,它也在 Chrome 中。是的,你也可以在 Chromebook 上的 Firefox 中测试你的 Web 应用。
[20:07] 如果你注意到了,在这个流程中我们没有提示你授予任何权限。这是因为是主机在访问虚拟机,而不是反过来。这同样是我们平衡所谈论的安全性和简单性的一种方式。TOM BUCKLEY:好的。最后,对于我们的第三个演示,我们将讨论测试 Android 应用。这真的很令人兴奋,因为就在昨天,我们宣布 Android Studio 已在 Chromebook 上获得官方支持,我们甚至专门为 Chrome OS 创建了一个安装程序,让入门变得非常容易。
[20:49] 当然,Android Studio 并不是构建出色 Android 应用所需的唯一东西。你还需要一个设备来测试该应用——通常是手机——虽然你可以通过 Wi-Fi 使用 ADB 远程等方式来做,但我们想让它变得简单——就像你在任何其他设备上期望的体验一样。我可以通过 USB 插入我的手机,用这种方式测试我的应用。现在,如果我是一名 Android 开发者,当然,我会插入手机来测试我的应用,但在一天中我还会通过 USB 插入许多其他设备。
[21:21] 我可能会插入一个存有很多家庭照片的 USB 驱动器。我可能会插入一个包含一些健康信息的可穿戴设备。我甚至可能会插入我的工作安全密钥,它给了我所有的访问权限。恶意软件可以利用这些设备在你跨机器移动时唯一识别你、自我传播,甚至对它们进行更改。同样,我们在设计 Crostini 时考虑到了这些威胁,并确保我们阻止了它们。DYLAN REID:是的,实现 USB 对我们来说很有趣。
[21:57] 这可能是我们最痛苦的技术栈。同样的原则依然适用。我们有分层结构。我们保护主机。主机 USB 栈中存在大量攻击面。它是一种非常复杂的、规范松散定义的协议。嗯,它其实有精确的规范,只是被很多人松散地实现。所以我们把这一层隐藏了起来。把它留在主机侧。我们编写了一个设备,运行在跨虚拟机的隔离环境中。
[22:27] 同样,我们有一个 USB 驱动。它相当复杂。里面有很多代码,我确信也有一两个 bug。所以我们确保它被很好地隔离。它无法访问你的文件。它无法访问网络。它也无法访问任何 USB 设备。你必须明确表示,嘿,我想把这个 USB 设备交给我的开发环境。我们尽量让这件事变得尽可能简单。而底层实际发生的是,我们始终运行着一个模拟的 USB 总线,所以客户机始终能看到,嘿,我有一条 USB 总线,只是没有插任何东西。
[23:02] 一旦你表示我想把这个交给我的虚拟机,它就会说,好的,我要把这个设备添加到这条总线上,然后我们把它呈现给客户机。接着客户机又必须把它转发到容器中,容器才能看到它。我们在这里真正关注两件事。一是安全性。同样,我们通过隔离环境解决了这个问题,并确保攻击面尽可能小。它也是用 Rust 编写的,内存安全且经过了模糊测试。但另一个问题是隐私,因为人们会以某种方式利用连接到机器的 USB 设备列表来对用户进行指纹识别和跟踪,我们希望确保容器内运行的不受信任代码不能成为另一种实现该目的的方式。
[23:46] 同样,这涉及很多步骤。我们必须创建一个设备。我们必须把它导出到虚拟机。我们必须把它导出到容器。我们必须决定导出哪个设备或不导出。同样,我们会有一个演示来展示这有多简单。SUDHA BROSLAWSKY:好的。这是最后一个演示。假设我在我的 Linux 版 Chromebook 上,你插入了你的手机。你会看到一条通知,提示你连接到 Linux。
[24:17] 此时,只有 Chrome OS 知道你的手机。Linux 甚至不知道你的手机存在,这是件好事。如果你看这里,你的手机没有列在 USB 列表中,但当你重新运行命令时,一旦你在通知上点击连接,你的手机就会出现在列表中。此时,你就建立了 Linux 对你手机的访问权限。
[24:49] 假设你正在做一个项目。你又在 Android Studio 里开发一个很酷的应用,准备测试一下。你点击运行并选择手机,然后砰的一下。就这样,你就能在手机上测试你的应用了。此时,你可以调试和测试你的应用。最后,你可以进入设置,随时管理 Linux 能访问什么。所以你能看到,安全性是 Chromebook 上 Linux 体验的核心。
[25:27] 你,也就是用户,始终完全掌控 Linux 能访问什么。我们利用各种用户体验模式,让它既简单易用,又原生融入 Chrome OS。Chrome OS 与 Crostini 的原则相结合,让这一体验相当独特。DYLAN REID:谢谢。轮到我了。
[25:57] 好,很好。我们时间还很充裕。我们一直在讨论很多细节,我也一直在讲分层和 jail 之类的东西,这些都很重要,也是你信任我们常规流程的好理由。而且当我在用我的 Chromebook 时,几乎总是待在这些我们已经打磨过、确保可用的常见工作流里。不过,我讲到的很多技术细节其实仍然可用,我们留了一些钩子让你去折腾。
[26:27] 所以我很高兴还有时间,可以过几个这样的例子,稍微吊一下你的胃口,看看你还能做什么。这些东西我们不测试,也不支持。我们真心希望标准流程对所有人都够用。但偶尔,你可能会有理由想做点更高级的事,或者你只是想找点乐子,在底层折腾折腾。我们都是爱鼓捣的人,对吧?本来就该是。所以我们会过一遍,展示其中一些东西是怎么运作的。
[26:58] 这些都将从 Chrome OS shell 里进行。这个功能在 Chrome OS 里已经存在——嗯,比我在这里的时间还长。所以按 Control-Alt-T 就能打开一个 shell。你可以运行一组调试命令。我们将重点讲一个命令,就是我们添加的用来控制虚拟机和容器的 VMC 命令。基本命令,你可以执行 VMC list。它会显示你系统上安装了哪些虚拟机。默认虚拟机叫 Termina。
[27:29] 希望字体够大,你能看清它的大小。Termina 虚拟机就是之前幻灯片里所有演示所用的那个,所以它已经启动并运行着。我们做了一个快捷方式,用来进入虚拟机里的容器。所以如果你想进入默认容器,这个容器叫 Penguin。再说一次,那就是我们做所有这些演示的地方。有一个 VMC container 命令可以让你进去。我们会从那里退出,然后再回到虚拟机本身。
[27:59] 因此,VMC Start 会进入你的虚拟机,而不会进入你的容器。所以如果你回到我的层级结构,它就是中间那一层——LXD 运行所在的地方。你之所以想进入这里,是因为你想操作或更改容器。我提到过我们使用 LXD。会有很多 LXC 命令。那是 LXD 控制程序。这在网上有详细文档,而且大部分命令在 Chrome OS 里都能用,就像在默认的 Ubuntu 安装里一样。
[28:37] 你可以做的第一件事是列出列表。你可以看到 Penguin 正在运行。我们有一个容器。它已启动并运行。它有一个 IP 地址。所以我们有了一个容器。我们可能想稍微玩一玩它。在这么做之前,也许我想确保能回到一个我知道它状态良好的状态,对吧?因为我以前把它们弄坏过。能直接回到原来的状态随便折腾而不用担心,这很不错。所以是标准的 LXE 命令。
[29:08] 它叫 Snapshot。你给它你的容器名,还可以给它你的快照名,现在你就有了一个保存下来的镜像,如果弄坏了可以回到这个镜像。还有写时复制。我们在虚拟机里用了 btrfs,所以不会占用大量磁盘空间。我们可以获取容器的信息。这会给出很多信息。再说一次,如果你想的话,可以在 Chromebook 上自己试试。这里重要的一点是,底部有一个快照,就是我们刚创建的 IO1 快照。
[29:41] 你可以有多个快照。上面有日期,帮你记住它,以防你没用很有创意的名字。然后当你想恢复它时,用 LXE Restore。这些命令命名得很好。他们在这方面做得比我好。如果你真的想尝试不同的东西,有时你会想要不止一个容器。所以我有我的 Penguin 容器,我要去,比如说,在这个容器里安装一些不同的库。也许我想要一个装有 Python 2.7 的容器,另一个装有 Python 3 的容器。
[30:15] 或者也许我想要一个与写 Rust 的容器不同的容器来写 Go。所以我们让你可以这样做。你可以创建任意数量的容器,受磁盘空间限制。这些确实会占用磁盘空间。启动新容器最基本的方式是复制一个现有容器。有一个 LXE Copy 命令。上面的示例把默认的 Penguin 容器复制到一个名为 Kingfisher 的新容器。你可以列出容器。
[30:46] 你已经有两个了。默认情况下,容器是停止的,所以我们必须启动它们。现在我们可以列出——它正在运行。你可以进去。你说,我想在 Kingfisher 里运行 Bash。现在我在新容器里有了一个 shell,我可以去安装任何我不想要在默认容器里的随机工具链。再进一步,我们选择 Debian 是因为它对我们来说是最容易的。但我们不想把你限制在它上面。
[31:17] 我们支持 Debian 工作流。我们支持一些默认安装在 Debian 中的客户机软件包。但有些人想用他们最喜欢的发行版。Canonical 运行的镜像服务器上有大量可用的发行版。我们在这里安装一个 Arch 的。我不是 Arch 用户,我对 Arch 了解不多,但我的一些同事说服我这么做并玩玩它。所以现在你可以看到我们有三个容器。
[31:48] 我有两个 Debian 容器,我的 Penguin 和我的 Kingfisher,现在我有了一些叫做 ArchTest 的东西。同样,我可以通过告诉它运行 Bash 来进入它。如果我想在这个容器里安装软件包,我会用 PacMan 而不是 Act。看,它确实是 Arch,我保证。这只是你从这里能做的事情的一点体验。如果你去在线查看 LXD 和 LXD 文档,你可以获得更多想法。甚至有一些在线帮助关于安装其他容器并让它们更好地与 GUI 集成,如果你想要的不只是命令行。
[32:28] TOM BUCKLEY:好的。所以 Dylan 刚刚向你展示了一堆你在深入 Crostini 时能做的非常酷的技巧,如果你对这种东西感兴趣,我们真的建议你去看看 Crostini 子版块。那里的人在我们发布功能时就会找到它们,有时甚至更早,而且他们对 Chromebook 上 Linux 的新用户也非常欢迎。所以如果你有任何问题,请去看看,并非常感谢那里的人们。
[33:00] 这就是 Chromebook 上的 Linux。如你所见,我们已经支持了很多 Web 和 Android 开发者流程。还有更多即将到来,既包括支持其他开发者,也包括扩展我们可以用新功能做的事情,比如多容器和备份与恢复。我们将继续应用简单和安全的原则,为你提供尽可能最好的开发者体验。当你准备好时,我们希望你能加入我们。谢谢。
[33:31] [掌声] [音乐播放]
查看英文原始字幕
[0:00] [MUSIC PLAYING] SUDHA BROSLAWSKY: Good afternoon, everyone. I hope you are having a great time at the I/O. We are here to talk to you about Linux for Chromebooks, also known as Crostini. We'll start by introducing ourselves. My name is Sudha. I'm a designer on Crostini for Chromebooks. DYLAN REID: Hi, I'm Dylan. I'm the Chrome OS Virtualization Lead. TOM BUCKLEY: And I'm Tom, Product Manager for Linux on Chromebooks.
[0:31] Now it's the end of day two at I/O and you've probably already been to a bunch of different sessions that have talked about all the new frameworks that you need to be using or the platforms that you need to be building for, and everyone's right, you absolutely should be, but we're not really here to talk about that. Instead what we want to talk about is you as developers and how you can get more peace of mind by using Linux on Chromebooks. We give you that peace of mind by balancing simplicity and security.
[1:03] SUDHA BROSLAWSKY: On that note, let's do a quick user study. How many of you are developers in the audience? Wow, that's a full room, as expected. Keep your hands raised. How many of you use your computers for anything else other than development, like doing your taxes, checking email-- again, 100% of you. OK, one last question. How many of you are worried about security? DYLAN REID: Good, that's pretty-- I mean, you all should be, so I'm glad to see many hands up anyway.
[1:40] So I don't know about you, but when I start a new project, I get stuck a lot. I hit a lot of walls and I hit a lot of barriers and I go to look for a problem, go to look for a solution, and I turn to Google. And luckily, Google's almost always got a great answer for me. Unluckily, sometimes the answer looks like this. And I know I shouldn't run this script from evilsite.com and pipe it to Sudu, but that deadline's coming up and maybe this site looks kind of legit, so in this case, I'll make an exception and I'll do this.
[2:17] And then it happens again and again, and eventually, I end up with a system that I don't trust as much as I should, because I don't really know what code I've run on it anymore. I don't have time to read all these scripts. My solution to this has been to carry two laptops-- one for my developer world and one for my everything else world that I want to be secure in. But recently, I've switched to using one laptop, and Tom's going to talk about how I do that. TOM BUCKLEY: So our goal with Chrome OS has been to give you a simple and secure experience from the start, but if you tried it previously, you might have seen that it wasn't quite ready for developers.
[2:57] In order to be simple and secure, we couldn't run all of the tools that developers need to get their job done. But that all changed at I/O last year when we announced that we were going to start supporting Linux on Chromebooks. Linux on Chromebooks lets you run all of your favorite editors, IDEs, and tools, and it's now supported on over 50% of Chromebooks, including great devices with eighth generation Intel CPUs like the Lenovo Yoga Book C630 and the Acer Chromebook Spin 13.
[3:31] If you haven't seen it, we're going to run through a few examples. First off, how do you get it? It's really easy. It's just a couple clicks. Now in the background, this is downloading a virtual machine, setting up containers, configuring it all-- Dylan's going to go more into that in a few minutes, but for you as a developer, it's just a couple clicks to get started. And this adds a terminal to your launcher. Now if you open that terminal, you'll see that you have a pretty standard Debian environment and we've already loaded in a bunch of the tools that developers expect, like Git and Vim, and if you need anything else, you have the APT Package Manager and you can install whatever packages you need.
[4:11] And if you want to instead install programs via .dev files, you can do that, too. This gives you access to thousands of world-class developer tools. Now once you've installed any graphical apps, you'll find that they all show up in your launcher, just like the rest of your Chrome OS apps, and if you open them, they show up in your Window Manager-- again, just like the rest of your Chrome OS apps. This is the simple experience that people have come to expect from Chrome OS and we didn't want to change that with Linux.
[4:45] But importantly, this is also secure. You don't have to worry about malware accessing your files, snooping on your traffic, or infecting your peripherals. I'd ask you to trust us on that but this is way too important for you to take on trust alone, so over the course of this talk, Dylan and Sudha are going to walk you through the principles behind the architecture and design of Crostini. We're then going to dissect some common developer flows to show you how these principles apply.
[5:16] And finally, we're going to share some tips and tricks for advanced usage for the power users out there. So now I'm going to hand it over to Dylan to talk about the architecture. [APPLAUSE] DYLAN REID: Good job. OK. So Chrome OS has always had a layered approach to security and our big layer has always been the browser and the renderer and running all untrusted code in a nice isolated renderer, and that keeps the attack surface of your core system to an absolute minimum.
[5:51] They're not allowed to make a lot of system calls. They can't poke at random bits of your kernel. And that worked really well for web pages, web apps. However, for developer tools, I need to install a lot of different programs. They need a lot of different privileges. They can do anything any app on Linux can do. And that wasn't acceptable for us on the core of Chrome OS, so we needed to add a layer. So we added a virtualization layer, and that lives in the main Chrome OS layer, and that spins up a VM.
[6:23] And now this VM has a much more limited interface while still exposing a full Linux kernel to the programs that run inside the VM. The only way the VM can talk to Chrome OS proper is through a small API that that cross-VM program on the left up there exposes to the guest. This is pretty good. Now we've greatly reduced attack surface. We were pretty happy with this. We wanted to go a little further. So we made sure that the guest VM was also signed by Google and somewhat trusted.
[6:58] This lets us trust some of the actions the guest VM takes, and it's also read-only, so users can only break things so much. And that, no matter what you do, you're going to be able to boot a VM. However, with all that security solved, we're back in a situation where you don't have enough flexibility. Your apps can't do anything. It's a read-only thing. You can't install anything in it. So we added another layer, and for this, we stole-- used-- LXD from Canonical.
[7:32] That team's been very helpful in getting this spun up with us. It's a pretty standard container runtime. It's built for running system containers. And in our case, we started a system container of Debian and exposed that to the user. So that cross-VM layer I was talking about, that's kind of the most important part of the security story here. It's the last line of defense before something gets into Chrome OS. So we went and we focused on this for a long time and made sure we got that as secure as possible.
[8:06] We wrote it in a memory-safe programming language. We chose Rust. This eliminates buffer overflows and integer overflows and a lot of common bugs related to memory safety that are exploited by attackers. We were pretty happy with that, but we again added another layer of security here in that we broke up the virtualization program into pillars and made sure that each pillar that interfaces with the guest only has access to small parts of your host Chrome OS system.
[8:38] So your host Chrome OS system, you've got your bank's web page open, you've got your online tax filing thing open, you've got all kinds of personal identifiable information everywhere. We really wanted to protect that. But we needed to give the guest access to things, like a random number, a display, a USB device. So each of those got their own jail and they can only see the thing they need. So our random number generator can generate random numbers. It can't access any files. It's in an empty file system from its perspective.
[9:09] It doesn't have any network access. The display driver, it can access the display. Again, it can't touch the network. It can't go grab your files and upload them, even if somebody gets into it and tries to make it do things we didn't intend it to. This is all a little complicated, but we've added a great amount of system UI to make this easy for you to use, so when you're just doing your job as a developer, you don't have to worry about these pretty pictures I've drawn for you. And Sudha will show you what we did.
[9:40] SUDHA BROSLAWSKY: Thank you, Dylan. Security is absolutely top of mind for us. While crafting the Linux experience on Chromebooks, we came up with three high-level design goals. The first goal was to keep your experience intuitive. Everyone here in this room has been using computers for a long time and you have established your workflows and habits. So basically what we wanted to do is to match to those expectations.
[10:14] We wanted to provide an experience that's natural to you. We want developers everywhere to be using Chromebooks and feel right at home doing it. The second goal was to make your experience native. We could have taken the easy path by giving you a full Linux desktop in a VM but that wasn't good enough. Our goal was to bring the Linux apps you depend on for development into your native Chrome OS experience.
[10:47] The third goal was to make your experience simple, and I think this is very important. There's a lot of complexity that's going on under the hood and we want to leave it there. Our guiding principle is that complexity shouldn't interfere with the user experience. There's a couple of things we are trying to balance here. The security concerns that come with installing Linux apps on Chromebooks and the simplicity that comes with sticking to design patterns established by Chrome OS.
[11:26] And our mission was to find that sweet spot. TOM BUCKLEY: All right. So now we're going to talk about three common developer flows and see how they work with Crostini. And the first of these is accessing files. As developers, we have to do this all the time. Our editors need to access files, as do our compilers, our source control, and a whole lot more. But the problem is that our file systems have a lot more than just code.
[11:58] They have our personal photos, our tax returns, maybe that novel that you've been working on. A lot can go wrong. Ransomware can hold all of that data hostage. Malware can upload your files to some random server. Or maybe you just get something that goes and deletes everything for the fun of it. We built Crostini with those threats in mind to limit what can go wrong, and Dylan will tell you how. DYLAN REID: So our goal sharing files with your VM and with your container was to make it easy for you to get the files you needed for your development tasks where you need them but not expose things you don't want exposed to untrusted code.
[12:44] Because ultimately, we don't trust the code that's running inside this VM. To do this, we took a layered approach. Your files all live in Chrome OS at the very bottom, and we share them out to the VM with a 9P server. We named it 9S. Again, we wrote it in Rust so it's memory safe, we fuzzed it to make sure unexpected inputs don't cause unexpected behavior, and we put it in a tight jail so it can access only the files you share with it.
[13:16] And it takes those files and exports them to the VM. The VM mounts the 9P thing that's built into Linux, and then LXD takes that mount and exposes it into your container where your development tools are running. The important thing here is that your container can only see files that you say, I want to share with my development environment. Your VM can only see those same files. And even the server that we wrote, running on Chrome OS, can only see those files. It doesn't get to see everything. So somebody exploits this stack all the way back into Chrome OS.
[13:49] They still don't have access to the files you haven't shared with the container. That's a lot of stuff to set up. Setting up 9P amounts, bind-mounting things into containers. We had to do this manually for a while when we were developing it. It was painful. So I'll let Sudha show you how easy we made it for you. SUDHA BROSLAWSKY: There are a lot of layers going on, but let's see how simple this is in the UI. Right out of the box, you have a directory called Linux Files, which is your home directory within Linux.
[14:24] Anything in this directory is automatically shared with Linux. Outside of this directory, anywhere else on the device, Linux doesn't have access to anything until you grant permissions. I'll walk you through a couple of examples here. Let's say you're working on a project and you see yourself needing files from this one folder called Illustrations. To share this, all you have to do is access the right-click menu and click on Share with Linux.
[14:58] And as simple as two steps, you've now shared this folder with Linux. If you notice, this is in Google Drive, and that's a cool thing. When you don't want to share this anymore, you can do that by going to Settings and Unsharing. Here's another example where we made quick edits really simple for you. You have a data file in your Downloads folder, and when you double-click, it automatically opens in VS code.
[15:31] When this happens, in the background, it's implicitly shared. And the sharing lasts until you restart. This is the balance of security and simplicity we wanted to bring you. TOM BUCKLEY: Thank you. So, for our second developer flow that we're going to talk about, we're going to look at running a web server. Now being Chrome OS, we care a lot about people making great web apps, and we want to make sure that they can create those on a Chromebook. And being able to run a web server is pretty central to being able to build any web app.
[16:08] Unfortunately, web servers also need a pretty low level of access and that can cause some problems. The code that can run a web server is also capable of snooping on your internet traffic. It can know what sites you're accessing, and in some cases, even see the contents of those pages. This means that a malicious web server could potentially track everything that you're doing. Now again, we thought of this as we designed Crostini and we made sure that we prevented this kind of attack.
[16:39] Dylan will tell you how. DYLAN REID: I can be called Linux, that's OK. That's my job. All right, so starting a web server from Crostini, simple. We've got a good demo over in the web dev sandbox already. Type a command. You fire up your web server, just like you would on any Linux distribution out there. What's actually happening under the hood, though, is you're in a container and you open up a port. That port's in a network namespace inside a VM, running under our special hypervisor which puts its network stack in another namespace on the host, and then finally out to Chrome.
[17:20] So Chrome can't get back in, which is great for security. You've got wonderful isolation. But if I want to test this new PWA or web page I'm running in my VM, how do I get Chrome to talk to it? This was not simple. So for that, we had to add some daemons along the way-- actually, every layer gets a daemon for this. The first one's running in the VM and it's sitting there waiting to check if any container that's running happens to open a port.
[17:53] And then it's got to figure out which container opened that port. And bundles that information up, sends it to Chrome OS. Says, hey, this port in this container is listening. The user might want to use that port. And on the Chrome OS, we say, OK. The other daemon responds. Says, I will set up a route to do some forwarding. I'm going to forward all of this over VSOCK, which is a protocol used to talk to local VMs on machines. That's kept under the hood. So either end, it talks HTTP into the daemons, and the daemons talk VSOCK to each other.
[18:28] So the key here is that the web server gets to talk HTTP. Chrome gets to talk HTTP. Everything's normal. Everything works just like you would. Well, under the hood, we've got all these extra daemons and VSOCK forwarding going, but we've hidden that. One other important thing, we've made it trusted. So you can get all your PWA features. You can install it to your desktop. Even though it's not technically the same machine, we know it is because we've got the information. We set up the VM.
[18:58] So we allow it to be trusted domain. And all this complexity I think makes one of our best demos today of how complicated we made it under the hood and how simple you're going to see it as actual use. SUDHA BROSLAWSKY: I totally agree that this is very complicated under the hood, but in the UI, it's exactly like you would expect it to be. Let's say you're experimenting with building this cool PWA. Here in terminal, you're in your folder, PWA Starter Kit.
[19:31] You're running the commands to start your web server. And if you see at the bottom of the screen, it's listening at port 8080. At this point, you can launch your browser, go to local host 8080, and test your web app. On the screen here, on the left, you have your web app in Chrome, and on the right, if you're noticing it, it's in Chrome. Yes, you can test your web app on a Chromebook in Firefox, too.
[20:07] If you notice, we did not prompt you to give any permissions while we were in this flow. This is because the host is accessing the VM and not the other way around. Again, this is another way we kind of balanced the security and simplicity factor we were talking about. TOM BUCKLEY: All right. Finally, for our third demo, we're going to talk about testing an Android app. Now this is really exciting because just yesterday, we announced that Android Studio is officially supported on Chromebooks, and we even created an installer just for Chrome OS to make it really easy to get started with.
[20:49] Now of course, Android Studio isn't the only thing that you need in order to build a great Android app. You also need something to test that app on-- usually a phone-- and while you could do that over Wi-Fi with ADB remote and all this sort of stuff, we wanted to make it easy-- just the experience that you'd expect on any other device. I can plug my phone in over USB and test my app that way. Now, if I'm an Android developer, sure, I'll plug my phone in to test my app, but I'm also going to plug in a lot of other devices over USB over the course of my day.
[21:21] I may plug in a USB drive that has a lot of family photos on it. I may plug in a wearable that has some health information. I may even plug in my security key for work that gives me all of my access. Malware can take advantage of these devices to uniquely identify you as you move between machines, to spread itself, or even to make changes to them. Again, we thought of these threats when designing Crostini and made sure that we were preventing them. DYLAN REID: Yeah, implementing USB was a lot of fun for us.
[21:57] It might have been our most painful stack. Same principles apply. We've got our layers. We protect the host. There's a lot of attack surface in a host USB stack. It's a very complicated kind of loosely-specced protocol. Well it's an exact spec that's loosely implemented by a lot of people. So we've hidden that. Kept that on the host side. Wrote a device that we live in cross-VM jail.
[22:27] Again, we've got a USB driver. It's pretty complicated. It's got a lot of code in it and I'm sure there's a bug or two. So we made sure it was very well isolated. It can't get to your files. It can't get to the network. It also can't get to any USB device. You have to explicitly say, hey, I want to give this USB device to my development environment. And we've tried to make that as easy as possible. And what actually happens under the hood, we've always got an emulated USB bus running, so the guest always sees, hey, I've got a USB bus, there's just nothing plugged in.
[23:02] And once you indicate that I want to give this to my VM, it says, OK, I'm going to add this device to this bus and then we show it to the guest. And then the guest again in turn has to forward that into the container and the container can see it. There's two things we really focused on here. One was security. Again, we addressed that with the jail and we made sure that the attack surface was as minimal as possible. It's also written in Rust and it's nice and memory-safe and it's fuzzed. But the other issue here is privacy because people somehow use lists of USB devices attached to machines to fingerprint and track users, and we wanted to make sure the untrusted code running inside the container couldn't be another way to do that.
[23:46] Again, this is a lot of steps. We have to create a device. We have to export it to a VM. We have to export it to a container. We have to decide which device to export or not. And again, we'll have a demo that shows how easy it is. SUDHA BROSLAWSKY: OK. This is the last demo. Let's say I'm on my Linux-enabled Chromebook and you're plugging in your phone. You'll see a notification that prompts you to connect to Linux.
[24:17] At this point, only Chrome OS has knowledge of your phone. Linux doesn't even know that your phone exists and that's a good thing. If you see here, your phone is not listed in the USB list, but when you rerun the command, once you connect on the notification, your phone shows up in the list. At this point, you established access to Linux to your phone.
[24:49] Let's say you're working on a project. You're developing a cool app again in Android Studio, and you're ready to test it out. You hit Run and select the phone, and boom. Just like that, you're able to test your app on your phone. At this point, you can debug and test out your app. Finally, you can go to Settings and manage what Linux access to at any point of time. So you can see how security is at the core of your Linux experience on Chromebooks.
[25:27] You, the user, are in full control at all times of what Linux has access to. We take advantage of a variety of UX patterns to make it simple to use and also native to Chrome OS. The combination of principles of Chrome OS and Crostini make this experience pretty unique. DYLAN REID: Thanks. My turn.
[25:57] All right, good. We've got plenty of time. So we've been talking about a lot of details and I've been talking a lot about layers and jails, and all that's important and it's a good reason for you to trust our normal flows, and when I'm using my Chromebook, I almost always stay within these common workflows that we've polished and made sure work. However, a lot of that technical detail. I was talking about is still usable, and we've left hooks in for you to play with it.
[26:27] So I'm glad I've got time left so I can go through a few of these examples and kind of just whet your appetite for what else you can do. We don't test this stuff. We don't support this stuff. We really want the standard flow to be enough for everybody. But every once in a while, there might be a reason you want to do something a little more advanced, or you might just want to go have fun and play with things under the hood. We're tinkerers, right? We're supposed to be. So we'll go through and show how some of this stuff works.
[26:58] All this is going to be from the Chrome OS shell. This has been in Chrome OS since-- well, longer than I have. And so Control-Alt-T gets you a shell. There's a set of debug commands you can run. We're going to focus on one command, which is the VMC command that we added to control virtual machines and containers. The basic command, you can do a VMC list. It'll show you what VMs you have installed on your system. The default VM is called Termina.
[27:29] So hopefully the font's big enough and you can see what size it is. The Termina VM is the one that all the demos were done for the slides before, so it's up and running. We've made a shortcut to enter a container inside a VM. So if you want to go into the default container, the container's named Penguin. Again, that's where we were doing all these demos from. So there's a VMC container command that gets you into there. We'll pop out of there and then we'll pop back into just the VM.
[27:59] So VMC Start enters your virtual machine without entering your container. So if you go back to my layers, it's the one in the middle-- the thing that LXD runs in. And the reason you'd want to be in here is if you want to manipulate or change containers. So I mentioned we use LXD. There's going to be a lot of LXC commands. That's the LXD control program. This is well-documented online and most of it will work inside Chrome OS, just like it does on a default Ubuntu install.
[28:37] The first one you can do is a list. You can see we've got Penguin running. We have one container. It's up and running. It's got an IP address. So we've got our one container. We might want to play with it a little bit. And before we do, maybe I want to make sure I can get back to a state where I know it's good, right? Because I've broken them before. It's nice to be able to just go back to where I was and play around without worrying. So standard LXE command.
[29:08] It's called Snapshot. And you give it your container name and you can give it the name of your snapshot, and now you've got an image saved that you can go back to if you break things. There's a copy on write, too. We used btrfs in the VM so you're not eating up a ton of disk space. We can get info on our container. This gives a bunch of information. Again, you can go poke around with this on a Chromebook if you want to. The important bit here is that we've got one snapshot at the bottom, the IO1 snapshot we just created.
[29:41] You can have multiple snapshots. It's got a date on it to help you remember if you didn't use a very creative name. And then when you want to restore it back, LXE Restore. These are well-named commands. They did a better job with this than I did. If you really want to go and play with different things, sometimes you want more than one container. So I've got my Penguin container and I'm going to go, say, install some different libraries in this one. Maybe I want to have a container that's got Python 2.7 and a different one that's got Python 3.
[30:15] Or maybe I want a different container for writing Go than the container I have for writing Rust. So we let you do that. You can create as many containers as you want, disk space-limited. These do cost disk space. The most basic way to start off a new container is to copy an existing one. There's an LXE Copy command. The example up here copies the default Penguin container over to a new container named Kingfisher. You can list the containers.
[30:46] You've got two. By default, containers are stopped, so we have to start them. Now we can list-- there it's running. And you can jump in. You say, I want to run Bash in Kingfisher. And now I've got a shell in my new container and I can go off and install whatever random tool chain I didn't want in my default container. Taking that one step further, we chose Debian because it was kind of the easiest thing for us to do. We don't want to tie you down to that, though.
[31:17] We support the Debian workflow. We support some guest packages that are installed in Debian by default. But some people want to use their favorite distro. And there is a huge amount of distros available from the image server that Canonical runs. We'll install an Arch one here. I'm not an Arch guy, I don't really know much about Arch, but some of my coworkers talked me into doing this and playing with it. So now you can see we've got three containers.
[31:48] And I've got two Debian containers, my Penguin and my Kingfisher, and now I've got something called ArchTest. And again, I can enter it by telling it to run Bash. And if I want to install packages in this one, I'll use PacMan instead of Act. Look, it's actually Arch, I promise. That's just a taste of what you can do from here. If you go and look at the LXD and LXD documentation online, you can get some more ideas. There's even some help online about installing other ones and getting them to integrate better with the GUI if you want more than just a command line.
[32:28] TOM BUCKLEY: All right. So Dylan just showed you a bunch of the really cool tricks you can do with Crostini when you go under the hood, and if you're interested in this kind of thing, we really recommend checking out the Crostini subreddit. The folks there find features as soon as we release them, sometimes even sooner, and they're also really welcoming to new users of Linux on Chromebooks. So if you have any questions, please check it out, and a big thanks to the folks there.
[33:00] So that's Linux on Chromebooks. As you can see, we already support a lot of web and Android developer flows. And there's a lot more to come, both in supporting other developers and in expanding what we can do with new capabilities, like multiple containers and backup and restore. We're going to keep applying these principles of simplicity and security to give you the best developer experience possible. Whenever you're ready, we hope you'll join us. Thank you.
[33:31] [APPLAUSE] [MUSIC PLAYING]
在 Vidleaf 工作台中打开
搜索转录文本、选择行、复制带时间戳的引文、翻译。
署名
《Chromebook 上的 Linux:安全开发(Google I/O '19)》由 Chrome for Developers(https://www.youtube.com/@chromedevs)创作,依据 CC BY 4.0(https://creativecommons.org/licenses/by/4.0/)许可授权。源视频:https://www.youtube.com/watch?v=pRlh8LX4kQI。本页为该视频的文本转录稿,添加了段落分隔和时间戳;创作者与 Vidleaf 无关联,也不为其背书。Vidleaf 添加了 AI 标点和 AI 生成的摘要;原始措辞仍可在本页查看。
您是创作者或权利持有人吗?请求更正或移除:copyright@vidleaf.app(参见关于这些页面)。
最后更新于