通过玩这个游戏来提升你的 S3 技能!
学习技能的最佳方法是刻意练习!
S3 游戏是一款由Vasily Pantyukhin制作的精彩游戏,它将引导您从入门到高级地了解 S3 的各种功能。
您需要:
- 浏览器(呃!)
- AWS CLI
点击此处开始游戏!
每个级别都包括找到一个“宝藏”物体,然后使用“宝藏”中的密码进入下一个级别。
来玩这个游戏吧!每个级别都包含多个提示,并附有 S3 API 文档链接。
如果你在任何关卡卡住,可以参考下面的攻略。在看这里之前,请务必先尝试一下 :)
演练(剧透)
1级
解决方案:
# List the objects in bucket
aws s3 ls s3://s3game-level1
参观宝藏对象
2级
解决方案:
只需使用浏览器或 aws s3 获取 treasure2 对象:https://s3game-level2.s3.us-east-2.amazonaws.com/treasure2
确保将访问密钥和密钥保存在某处
3级
使用上一关获得的访问密钥和密钥创建一个 AWS 配置文件“tmp”。从现在开始,几乎每个关卡都需要用到它。
aws configure --profile tmp
> AWS Access Key ID
> AWS Secret Access Key
> Default region name - us-east-2
解决方案:
aws s3 ls s3://s3game-level3 --profile tmp
aws s3 cp s3://s3game-level3/treasure3_has_no_secret_code . --profile tmp
cat treasure3_has_no_secret_code
# The object data itself does not have the secret code. It is present in the metadata
aws s3api head-object --bucket s3game-level3 --key treasure3_has_no_secret_code --profile tmp
4级
解决方案:
# List the bucket ..
# get the file
aws s3 cp s3://s3game-level4-k73045aztqln/treasure4_also_has_no_secret_code . --profile tmp
# looks like the data is empty
aws s3api head-object --bucket s3game-level4-k73045aztqln --profile tmp --key treasure4_also_has_no_secret_code
# ... so is the metadata. Let's try object tags as mentioned in hint
aws s3api get-object-tagging --bucket s3game-level4-k73045aztqln --profile tmp --key treasure4_also_has_no_secret_code
要点:
S3 中的对象(包括其元数据)是不可变的。当您编辑对象的元数据时,实际上是用其自身的副本覆盖该对象,并修改其元数据。
相比之下,标签是子资源。它们是单独管理的,可以在不修改对象本身的情况下进行修改。
5级
解决方案
# We are listing all versions of objects as the hint says that the object is not present in its current version
aws s3api list-object-versions --bucket s3game-level5-8v95e5rv7z4i --profile tmp
# Get the specific version of treasure5_is_deleted using version-id from previous call
aws s3api get-object --bucket 's3game-level5-8v95e5rv7z4i' --key treasure5_is_deleted --version-id '344PQOyFqocF0TI66MbLynNNdQqHfBz3' --profile tmp treasure5_is_deleted
外卖
S3 版本控制功能会将一个对象的多个变体保存在同一个存储桶中。
如果您为存储桶启用版本控制,S3 会自动为存储的对象生成一个唯一的版本 ID。
一个存储桶中可以有两个具有相同键但不同版本 ID 的对象。
使用以下命令检查版本控制功能是否已启用:aws s3api get-bucket-versioning --bucket my-bucket
6级
解决方案
# We need to get a gzipped object using S3 select
aws s3api list-objects --bucket s3game-level6-vjv45x1gux81 --profile tmp
# Now, do the select on s3select.csv.gz
aws s3api select-object-content --bucket s3game-level6-vjv45x1gux81 --key s3select.csv.gz --expression "SELECT s.Answer FROM s3object s WHERE Category = 'TREASURE'" --expression-type sql --input-serialization '{"CSV": {"FileHeaderInfo": "USE", "FieldDelimiter": ";"}, "CompressionType": "GZIP"}' --output-serialization '{"CSV": {}}' --profile tmp treasure6
7级
解决方案
# Get 'somethingstrange' from the bucket
aws s3api get-object --bucket s3game-level7-zhovpo4j8588 --key somethingstrange --profile tmp t7
cat t7
# Visit the pre-signed URL in the file to get URL for next level
外卖
预签名 URL 是 S3 的一项强大功能。文档中写道:
预签名 URL 由有权访问对象的 AWS 用户生成。生成的 URL 随后会提供给未经授权的用户。预签名 URL 可以在浏览器中输入,也可以由程序或 HTML 网页使用。预签名 URL 使用的凭证是生成该 URL 的 AWS 用户的凭证。
预签名的 URL在生成 URL 时指定的有限时间内有效。
8级
解决方案
# List objects
aws s3api list-objects --bucket s3game-level8-v6g8tp7ra2ld --profile tmp
# Visit the treasure file using the cloudfront URL
curl 'https://d2suiw06vujwz3.cloudfront.net/treasure8_CDN'
外卖
- 您可以轻松创建由 S3 bucket 支持的 Cloudfront 发行版
- 在这种情况下,您可以限制存储桶中对象的公共访问,因为可以使用 Cloudfront 访问它们
- 确保您的存储桶不允许无特权的用户列出存储桶中的所有对象
9级
该存储桶具有一项策略,用于检查对“arn:aws:s3 :: s3game-level9-781xtls2quvy / treasure9_referer”的任何请求是否具有引用字符串“ http://s3game.treasure ”
解决方案
我们需要做的就是使用策略
curl 中的 --refer 命令来执行 curl ' https://s3game-level9-781xtls2quvy.s3.us-east-2.amazonaws.com/treasure9_referer ' --refer ' http://s3game.treasure '
10级
在这里,我们需要获取不频繁访问存储中的对象。
解决方案
# We can use the powerful query param of aws cli to just fetch those objects which are in infrequent access storgae
aws s3api list-objects --bucket s3game-level10-gac6tf83erp6 --query 'Contents[?StorageClass == `STANDARD_IA`]' --profile tmp
外卖
Amazon S3 提供了一系列针对不同用例设计的存储类:
- 频繁访问数据的通用存储标准
- 针对访问模式未知或变化的数据进行智能分层
- 标准-不频繁访问(标准-IA)和单区-不频繁访问(单区-IA),适用于长期存在但访问频率较低的数据
- Glacier 和 Glacier Deep Archive 用于长期存档
11级
这里我们需要获取一个已使用客户端加密并上传到 S3 的对象。这意味着,除非我们拥有加密密钥,否则无法获取该对象。
解决方案
# The encryption key is given in the hint
aws s3 cp --sse-c 'AES256' --sse-c-key 'UkXp2s5v8y/B?E(H+MbPeShVmYq3t6w9' 's3://s3game-level11-djq30a807iyq/treasure11_encryption' --profile tmp .
# Alternate way using aws s3api. Here we also need to give md5 of encryption key as additional integrity check
aws s3api get-object --bucket s3game-level11-djq30a807iyq --key treasure11_encryption --sse-customer-key 'UkXp2s5v8y/B?E(H+MbPeShVmYq3t6w9' --sse-customer-algorithm AES256 --profile tmp treasure11_encryption
外卖
胜利!-第 12 关
恭喜!你已通关!
文章来源:https://dev.to/rrampage/level-up-your-s3-skills-by-playing-this-game-23a8