Lab — Account, first VM, firewall and spend alert
Time: 120 minutes — 10 setup, 10 project and tags, 10 SSH key, 10 token, 15 firewall including the lockout drill, 15 Droplet and first login, 5 spend alert, 5 buffer, 20 evidence, 10 teardown.
Prerequisite: the pre-course checklist — a DigitalOcean account with two-factor authentication and a backup method, the instructor added as a Resource Viewer, doctl installed, and a payment method on the account. The card is required at signup; spend alerts are email thresholds, not caps.
You need to know: DigitalOcean separates the object that groups resources (a project) from the object that admits traffic (a cloud firewall) and the credential that authorises commands (an API token). A project is organisational only; it is not an access boundary. A firewall attached by tag protects every Droplet that later carries that tag. A token's custom scopes are fixed at creation, so choosing too few means creating a new token, not editing the old one. A Droplet bills while it exists, including while it is powered off; only destroying it stops the meter.
Safe-data acknowledgement: I have read the lab safe-data policy. I will use only the synthetic media supplied with the course, and I will not upload real personal media — or real account identifiers, emails or tokens in a screenshot — to any cloud service.
Task
Create a safe DigitalOcean identity, a project, an SSH key, a scoped API token, a default-deny firewall and one small Rocky Linux 10 Droplet in SGP1. Prove the first key-only login, break your own SSH access and recover it through the Control Panel, set a $10 spend alert, capture the evidence, and tear the Droplet and firewall down. The lab must stay under $0.10.
Steps
1. Pre-flight: account, two-factor and the scoped token
Panel path: Account → Settings, check that 2FA shows Enabled and a backup method is listed. Panel path for membership: Teams → Members, confirm the instructor appears as Resource Viewer.
Panel path: API → Tokens → Generate New Token. Choose Custom scopes, name it course-s1-<id>, set the expiry to 90 days (or the longest offered), and select exactly:
| Resource | Scopes |
|---|---|
| droplet | read, create, delete |
| ssh_key | read, create |
| firewall | read, create, update, delete |
| project | read, create, assign_resource |
| tag | read, create |
| account | read |
| region | read |
| size | read |
| image | read |
| billing | read |
The secret is shown once; copy it into doctl auth init immediately. Custom scopes are per resource type and action — a token cannot be limited to one Droplet — and they cannot be edited after creation. If the Droplet commands later fail with a 403, a scope is missing: create a new token, do not hunt for an edit button. There is no CLI path for this step.
doctl auth init
Asks for the token and saves it in the default context. Paste the secret you just copied; it is not echoed as you type.
chmod 600 "$HOME/Library/Application Support/doctl/config.yaml"
Restricts the saved token to your user account. On Linux the path is ~/.config/doctl/config.yaml. This file is a credential: never commit it, copy it into the repository, or paste its contents into a report.
สรุปภาษาไทย
สร้างโทเคนแบบกำหนดขอบเขตเอง ชื่อ course-s1-中文总结
创建一个自定义作用域的 token,命名为 course-s1-<id>,有效期 90 天,并按表格选择权限。token 只显示一次,要立即复制并用于 `doctl auth init`。作用域之后无法修改;如果命令返回 403,说明缺少权限,必须重新创建 token。这一步没有 CLI 路径。doctl version
Prints the doctl version and the API endpoint. The course was verified with doctl 2.4.0; an older release may not know doctl projects or doctl balance get.
doctl compute image list --public --format Slug --no-header | grep -x rockylinux-10-x64
Checks that the Rocky Linux 10 image slug exists in the public catalogue and prints it back. No output means the slug is unavailable in this account or region; stop and use the image ID the panel shows instead of guessing.
doctl account get
Calls the account endpoint and prints the account email, team and Droplet limit. Success proves the token is valid. Do not screenshot this output: it contains the account email. In the evidence, describe it as "account read confirmed".
doctl balance get
Records the starting month-to-date usage. Note the third column: the lab's cost is the difference between this value and the value at teardown, so a starting number is part of the evidence.
สรุปภาษาไทย
ขั้นเตรียมความพร้อมตรวจว่าเปิดใช้ 2FA และมีวิธีสำรองแล้ว อาจารย์ถูกเพิ่มเป็น Resource Viewer จากนั้นสร้างโทเคน API แบบกำหนดขอบเขตเอง อายุ 90 วัน ตามตาราง แล้วใช้ `doctl auth init` บันทึกโทเคนไว้ในเครื่อง ตั้งสิทธิ์ไฟล์ config เป็น 600 คำสั่ง `doctl version` และ `doctl compute image list` ตรวจเครื่องมือและอิมเมจ `doctl account get` ยืนยันโทเคน และ `doctl balance get` บันทึกยอดใช้จ่ายเริ่มต้น อย่าถ่ายภาพผลลัพธ์ account get เพราะมีอีเมลบัญชี中文总结
预检步骤确认已启用 2FA 并设置好备份方式,教师已被添加为 Resource Viewer。然后按表格创建一个自定义作用域、有效期 90 天的 API token,再用 `doctl auth init` 把 token 保存到本机,并把 config 文件的权限设为 600。命令 `doctl version` 和 `doctl compute image list` 检查工具和镜像,`doctl account get` 验证 token,`doctl balance get` 记录初始支出余额。不要对 account get 的结果截图,因为其中包含账号邮箱。2. Create the project and the tag
Panel path: Projects → Create project, name it course-<id>, choose the purpose Just experimenting.
doctl projects create --name "course-<id>" --purpose "Just experimenting" --format ID --no-header
Creates the project and prints its UUID. Record the UUID: the Droplet is assigned to the project at creation, and the project cannot be an access boundary, so its value is organisational.
doctl compute tag create "week:1"
Creates the tag that the firewall follows. Tags allow letters, numbers, colons, dashes and underscores; = is not allowed. If the tag already exists the call fails harmlessly — move on.
สรุปภาษาไทย
สร้างโปรเจกต์ชื่อ course-中文总结
创建一个名为 course-<id> 的项目来分组资源(它不是权限边界),并记录它的 UUID。然后创建标签 week:1,防火墙会用这个标签绑定到 Droplet。标签只允许字母、数字、冒号、连字符和下划线。3. Create the SSH key
Panel path: Settings → Security → SSH keys → Add SSH key; paste the public key printed by the first command.
ssh-keygen -t ed25519 -C "course-s1-<id>" -f ~/.ssh/do_s1
Generates an ed25519 keypair. The public half is ~/.ssh/do_s1.pub; the private half is ~/.ssh/do_s1 and never leaves the laptop. ed25519 is the current default and produces a short key that is hard to get wrong.
chmod 600 ~/.ssh/do_s1
Makes the private key readable only by you. SSH refuses to use a key with looser permissions, so this also prevents a frustrating "bad permissions" error later.
doctl compute ssh-key import course-s1-<id> --public-key-file ~/.ssh/do_s1.pub
Uploads only the public half to the account. The account stores it as a named key that a Droplet can reference at creation.
doctl compute ssh-key list --format ID,FingerPrint,Name --no-header
Lists the account's keys with their fingerprints. The Name column makes the row easy to find; record the ID and fingerprint for the Droplet step.
ssh-keygen -E md5 -lf ~/.ssh/do_s1.pub
Prints the MD5 fingerprint of your local public key, the same form doctl lists. The value must match the doctl row — that equality is the evidence that the key you hold is the key the account holds.
สรุปภาษาไทย
สร้างคู่กุญแจ ed25519 โดยเก็บกุญแจส่วนตัวไว้บนเครื่องและอัปโหลดเฉพาะกุญแจสาธารณะขึ้นบัญชี ตั้งสิทธิ์ไฟล์กุญแจส่วนตัวเป็น 600 มิฉะนั้น SSH จะปฏิเสธการใช้ จากนั้นตรวจว่า fingerprint จาก `doctl compute ssh-key list` ตรงกับ `ssh-keygen -lf` ซึ่งเป็นหลักฐานว่ากุญแจที่เราถือคือกุญแจที่บัญชีมี中文总结
创建一对 ed25519 密钥,把私钥保存在本机,只把公钥上传到账号。把私钥文件的权限设为 600,否则 SSH 会拒绝使用它。然后检查 `doctl compute ssh-key list` 输出的 fingerprint 与 `ssh-keygen -lf` 输出的一致,这就是你持有的密钥就是账号所持有的密钥的证据。4. Create the default-deny firewall
Panel path: Networking → Firewalls → Create Firewall, name it course-<id>-s1, add an inbound rule SSH / TCP 22 / your IP, keep all outbound TCP, UDP and ICMP allowed, and attach it to the tag week:1.
MYIP=$(curl -s https://api.ipify.org)
Asks a public service for the address your laptop appears to use, and stores it in MYIP. The firewall will allow SSH from that single address and nothing else, so a café network change later means updating the rule.
doctl compute firewall create --name "course-<id>-s1" --inbound-rules "protocol:tcp,ports:22,address:$MYIP/32" --outbound-rules "protocol:tcp,ports:0,address:0.0.0.0/0 protocol:udp,ports:0,address:0.0.0.0/0 protocol:icmp,ports:0,address:0.0.0.0/0" --tag-names "week:1" --format ID --no-header
Creates the firewall and prints its ID. /32 means one address, not a range. With no rule for any other inbound port, the default is deny. The three outbound rules let the Droplet fetch packages, resolve DNS and answer ping; a Droplet with no outbound rules is very hard to debug.
doctl compute firewall get <firewall-id>
Prints the firewall's name, status, inbound and outbound rules, and the tags it follows. Read the Inbound Rules block: it must contain exactly one TCP 22 rule whose address ends in /32. Anything else is a defect you fix before creating the Droplet.
สรุปภาษาไทย
สร้างไฟร์วอลล์แบบปฏิเสธเป็นค่าเริ่มต้น เปิดเฉพาะ SSH TCP 22 จาก IP ของเครื่องคุณ และเปิดขาออก TCP/UDP/ICMP ทั้งหมด ผูกกับแท็ก week:1 คำสั่ง `doctl compute firewall get` ใช้ตรวจว่ามีกฎขาเข้าเพียงข้อเดียวและลงท้ายด้วย /32 ก่อนสร้าง Droplet中文总结
创建一个默认拒绝的云防火墙,只开放来自你本机 IP 的 SSH TCP 22,并开放全部 TCP/UDP/ICMP 出站流量,然后绑定标签 week:1。命令 `doctl compute firewall get` 用于在创建 Droplet 之前检查入站规则只有一条,并且地址以 /32 结尾。5. Create the Droplet and prove the first login
Panel path: Droplets → Create Droplet; choose SGP1, Rocky Linux 10, the Basic plan $6/mo (s-1vcpu-1gb), the SSH key course-s1-<id>, the tags course:42-05-0112, student:<id> and week:1, and the project course-<id>.
doctl compute droplet create "course-<id>-s1" --region sgp1 --image rockylinux-10-x64 --size s-1vcpu-1gb --ssh-keys <key-id> --tag-names "course:42-05-0112,student:<id>,week:1" --project-id <project-uuid> --wait --format ID --no-header
Creates the Droplet and waits until it is active. --ssh-keys accepts the key ID from step 3, not a file path; --tag-names applies all three labels, one of which (week:1) attaches the firewall; --project-id files it under the course project at creation. --wait returns only when the Droplet is running, so the next command can use its address.
doctl compute droplet get <droplet-id> --format PublicIPv4 --no-header
Prints the IPv4 address assigned to the Droplet. That address is what SSH uses, and it changes if the Droplet is destroyed and rebuilt.
mkdir -p data
Creates the data/ folder the evidence files are saved into if it is not already present.
doctl compute droplet list -o json > data/droplet-before.json
Saves the account's Droplet list as JSON before teardown. The notebook reads the fields that prove the Droplet's name, region, size, image, tags and status. On a fresh student account this file contains exactly one Droplet.
ssh -i ~/.ssh/do_s1 root@<droplet-ip> 'hostname; id'
Opens the first key-only session and runs two short commands. hostname prints the Droplet's generated name and id prints uid=0(root); together they prove the key works and that you are root. DigitalOcean disables password authentication on key-created Droplets, so there is no password prompt to fall back on.
exit
Closes the SSH session and returns you to the laptop. Nothing on the Droplet depends on the session staying open.
สรุปภาษาไทย
สร้าง Droplet ขนาด s-1vcpu-1gb อิมเมจ Rocky Linux 10 ในภูมิภาค sgp1 พร้อมแท็กสามตัวและโปรเจกต์ จากนั้นอ่าน IP ด้วย `doctl compute droplet get` บันทึกรายการ Droplet เป็น JSON และเข้าสู่เครื่องด้วยกุญแจ SSH เพื่อยืนยันว่า `hostname` และ `id` ทำงาน (ได้ uid=0(root)) ระบบปิดการล็อกอินด้วยรหัสผ่านสำหรับ Droplet ที่สร้างด้วยกุญแจ中文总结
在区域 sgp1 创建一个规格为 s-1vcpu-1gb、镜像为 Rocky Linux 10 的 Droplet,带上三个标签并放入项目。然后用 `doctl compute droplet get` 读取 IP,把 Droplet 的清单保存为 JSON,并用 SSH 密钥登录机器,确认 `hostname` 和 `id` 能正常工作(得到 uid=0(root))。用密钥创建的 Droplet 会禁用密码登录。6. Failure drill: lock yourself out and recover from the panel
This is the session's deliberate failure. You will make the firewall reject your own address, watch SSH time out, then restore access from the Control Panel — which proves the management plane works even when the data plane does not.
Panel path: Networking → Firewalls → course-203.0.113.1/32 (the TEST-NET address that stands for "somewhere else"), and save.
ssh -o ConnectTimeout=5 -i ~/.ssh/do_s1 root@<droplet-ip> 'hostname'
Attempts the login under the broken rule. It must time out or be refused: the firewall drops packets from your address before they reach the Droplet. A timeout here is the expected result, not a bug.
Panel path: Networking → Firewalls → course-$MYIP/32 and save.
ssh -o ConnectTimeout=5 -i ~/.ssh/do_s1 root@<droplet-ip> 'hostname'
Attempts the same login after the panel change. It must succeed again within a few seconds. Record the elapsed time: DigitalOcean applies firewall rule changes quickly, and the number is part of your evidence.
doctl compute firewall get <firewall-id> -o json > data/firewall-before.json
Saves the restored firewall configuration as JSON before teardown. The notebook asserts one inbound TCP 22 rule from a single /32 address and the three outbound rules.
API extension. The panel is the required recovery path because it is out-of-band. The same change can be made through the API, and the reference run uses it to measure propagation:
doctl compute firewall update <firewall-id> --name "course-<id>-s1" --inbound-rules "protocol:tcp,ports:22,address:203.0.113.1/32" --outbound-rules "protocol:tcp,ports:0,address:0.0.0.0/0 protocol:udp,ports:0,address:0.0.0.0/0 protocol:icmp,ports:0,address:0.0.0.0/0" --tag-names "week:1"
Replaces the whole firewall representation with the broken rule. update resets anything you omit, which is why every rule and the tag are repeated.
doctl compute firewall update <firewall-id> --name "course-<id>-s1" --inbound-rules "protocol:tcp,ports:22,address:$MYIP/32" --outbound-rules "protocol:tcp,ports:0,address:0.0.0.0/0 protocol:udp,ports:0,address:0.0.0.0/0 protocol:icmp,ports:0,address:0.0.0.0/0" --tag-names "week:1"
Restores the rule from your address. Run it only after you have watched the timeout; this is the API path, and the panel path is what the brief requires you to demonstrate.
สรุปภาษาไทย
แบบฝึกความล้มเหลวโดยตั้งกฎขาเข้าชั่วคราวให้รับเฉพาะ 203.0.113.1/32 แล้วลอง SSH จะหมดเวลา จากนั้นแก้กฎกลับผ่าน Control Panel ซึ่งพิสูจน์ว่าระนาบจัดการยังใช้งานได้แม้ระนาบข้อมูลล้มเหลว บันทึกเวลาที่กฎมีผลและบันทึกไฟร์วอลล์เป็น JSON ภาคผนวกแสดงเส้นทาง API ที่ใช้ทดสอบเวลาการปรับใช้中文总结
演练一次故障:临时设置一条入站规则,只接受 203.0.113.1/32,然后尝试 SSH,连接会超时。接着通过 Control Panel 把规则改回来,这证明即使数据平面失效,管理平面仍然可用。记录规则生效的时间,并把防火墙保存为 JSON。附录展示用于测试生效时间的 API 路径。7. Set the spend alert and read the bill
Panel path: Billing → Spend alerts → Add alert, set a $10 monthly budget and percentage email thresholds, then Billing → Insights for the current usage view.
doctl balance get
Prints the month-to-date balance, the account balance and month-to-date usage. Record the usage before and after the lab; the difference is the lab's real cost. There is no CLI path for creating a spend alert — it is panel-only, and the email is a warning, not a cap.
สรุปภาษาไทย
ตั้งการแจ้งเตือนการใช้จ่าย 10 ดอลลาร์ต่อเดือนผ่านหน้า Billing (ไม่มีคำสั่ง CLI) และใช้ `doctl balance get` อ่านยอดใช้จ่ายก่อนและหลังแล็บ ผลต่างคือค่าใช้จ่ายจริง การแจ้งเตือนเป็นเพียงอีเมล ไม่ได้หยุดการใช้จ่าย中文总结
通过 Billing 页面设置每月 10 美元的支出提醒(没有 CLI 命令),并使用 `doctl balance get` 读取实验前后的支出余额。两者的差额就是真实成本。提醒只是一封邮件,并不会停止支出。8. Capture the evidence
Take the ten items in the evidence bundle below. Redact the account email, account UUID, project UUID and every token value; a token page is captured with the secret covered and the expiry date visible. Copy the four JSON files into data/ and run the notebook.
Your shell can produce item 8 for you:
history > data/commands-raw.log
Writes the commands you typed to a raw file. Open it, delete or replace the account email, UUIDs, tokens and IP addresses, save the result as data/commands-host.log, and delete the raw file. The published log is the sanitized one; a raw trace is never submitted.
9. Tear down and prove the account is clean
Panel path: Droplets → course-
doctl compute droplet delete <droplet-id> --force
Destroys the Droplet without a confirmation prompt. This is the command that stops the meter; powering off would not.
doctl compute firewall delete <firewall-id> --force
Deletes the firewall. It has no cost, but leaving it behind means later Droplets that carry week:1 are silently protected by a rule you have forgotten.
doctl compute droplet list -o json > data/droplet-after.json
Saves the post-teardown Droplet list. On a fresh account it is an empty array; the notebook also accepts an account with unrelated Droplets as long as no week:1 Droplet remains.
doctl compute firewall list -o json > data/firewall-after.json
Saves the post-teardown firewall list. The proof is the same: no firewall carrying week:1.
doctl balance get
Reads the bill after teardown. Month-to-date usage minus the starting value must be under the $0.10 ceiling; an idle Droplet left behind would keep the number growing.
If you ran on a shared instructor slot, also remove the objects the lab created so the next student starts clean:
doctl projects delete <project-uuid> --force
Deletes the project. On your own account, keep it for the course.
doctl compute ssh-key delete <key-id> --force
Deletes the imported public key. On your own account, keep it for the course.
สรุปภาษาไทย
ทำลาย Droplet และลบไฟร์วอลล์ แล้วบันทึกรายการหลังรื้อเป็น JSON สองไฟล์ หลักฐานคือไม่มีทรัพยากรที่ติดแท็ก week:1 เหลืออยู่ และอ่านยอดใช้จ่ายอีกครั้งเพื่อยืนยันว่าต่ำกว่า 0.10 ดอลลาร์ หากใช้บัญชีอาจารย์ที่แชร์กัน ให้ลบโปรเจกต์และคีย์ SSH ที่สร้างขึ้นด้วย中文总结
销毁 Droplet 并删除防火墙,然后把拆除后的清单保存为两个 JSON 文件。证据是不再有带 week:1 标签的资源残留,并且再次读取支出余额以确认低于 0.10 美元。如果使用共享的教师账号,还要删除创建的项目和 SSH 密钥。Evidence bundle
Submit ten items; the bundle is scored 3/2/1/0.
- The 2FA and backup-method page, captured pre-course.
- The project and the three Droplet tags.
- The SSH key fingerprint from
doctlandssh-keygenside by side. - The token page with the secret covered: scopes and expiry visible.
- The firewall rules: one inbound TCP 22
/32, three outbound rules, tagweek:1. - The running Droplet with its IP, and the first-login proof (
hostnameanduid=0(root)). - The $10 spend-alert screenshot.
- The sanitized command log — no token, account ID or email.
- The empty post-teardown lists,
doctl balance get, and the Insights view. - A 150–250 word what this proves note.
The notebook's inventory.json is the machine-checkable companion. The failure-drill log (the timeout, the panel change, the successful retry and the elapsed time) belongs inside item 5.
Cost ceiling
Under $0.10. The main spender is one s-1vcpu-1gb Droplet at $0.00893/hour, so the ceiling is about eleven Droplet-hours. The firewall, project, key, tag and spend alert are free. Read doctl balance get at the start and the end; record both numbers and the difference.
Teardown
Destroy the Droplet, delete the firewall, then prove both lists are empty of week:1 resources. Read the bill. Keep the project, SSH key, token and spend alert on your own account for the rest of the course; delete the project and key only if you used a shared instructor slot. The token expires after 90 days by design.
Failure and recovery chain
- No card or signup blocked: use an instructor-owned account slot; the evidence shape does not change. Item 1 becomes the instructor's 2FA page.
doctlblocked on the network: follow the panel checklist instead; capture each panel screen. The JSON evidence is replaced by screenshots and the instructor records the deviation.- Outbound SSH blocked: use the Droplet's browser console for the login proof now, and repeat the SSH login from another network before submission.
- Droplet creation fails with 403: the token is missing a scope. Create a new token with the full table in step 1; tokens cannot be edited.
- Private key lost: Rocky Linux's root password cannot be reset from outside. Destroy the Droplet and repeat steps 5–9 with a new key. This is why key custody is a warning, not a drill.
Self-study: the domain and Cloudflare zone (due before Session 2)
The CDN session assumes a domain you own and a Cloudflare zone that is already active. Do this outside the two-hour lab, before Session 2; the TA checks it at the start of S2.
- Register a cheap root domain (about $8–12/year, paid by you — it is your asset, not a course purchase). Do not register a subdomain: Cloudflare Free cannot host a subdomain as its own zone.
- Create a free Cloudflare account, choose Add a site, enter the root domain, and take the Free plan.
- At your registrar, replace the registrar's nameservers with the two Cloudflare nameservers shown in the dashboard. Propagation can take up to 24 hours.
- Prove it:
dig NS <root-domain> +short
Prints the nameservers that answer for your domain. The two names must end in .ns.cloudflare.com; an empty or registrar answer means the change has not propagated yet. Take a screenshot of the Cloudflare zone in the Active state as the second proof. The instructor's demo hostname is a fallback for Session 4, not a substitute for your own zone.
สรุปภาษาไทย
งานศึกษาด้วยตนเองก่อนเซสชัน 2: จดทะเบียนโดเมนระดับราก (ประมาณปีละ 8–12 ดอลลาร์ จ่ายเอง) สร้างบัญชี Cloudflare ฟรี เพิ่มโดเมน และเปลี่ยนเนมเซิร์ฟเวอร์ที่ผู้ให้บริการจดทะเบียนเป็นของ Cloudflare ซึ่งอาจใช้เวลาถึง 24 ชั่วโมง ตรวจสอบด้วย `dig NS中文总结
第 2 课之前的自学任务:注册一个根域名(每年约 8–12 美元,自费),创建一个免费的 Cloudflare 账号,添加域名,并把注册商处的名称服务器改为 Cloudflare 的名称服务器,这可能需要长达 24 小时。用 `dig NS <root-domain> +short` 检查,应答应是名称以 `.ns.cloudflare.com` 结尾,并截取处于 Active 状态的区域(zone)。Reference run
The published sequence above is the learner form. The reference run executes it end to end and records the differences below, so no executed command is unexplained. The ssh-keygen call omits the passphrase prompt and writes to a temporary path; the SSH poll repeats the login until the Droplet answers; the image check is the same one from step 1.
ssh-keygen -t ed25519 -N "" -C "course-s1-<id>" -f <temporary-key-path>
ssh -o BatchMode=yes -o ConnectTimeout=5 -i <private-key> root@<droplet-ip> true
doctl compute image list --public --format Slug --no-header | grep -x rockylinux-10-x64
COMMANDS.md records the executed order and the sanitized trace is data/commands-host.log.
Notebook
Open the lab notebook. Save the four JSON files into data/, set LAB_START and LAB_FINISH to your lab's ISO-8601 window (or edit the two values in the cost cell), and run the notebook top to bottom. It writes inventory.json; the final assertion is the completion gate.