DO - Functions

支持 HackTricks

基本信息

DigitalOcean Functions,也称为 "DO Functions",是一个无服务器计算平台,让您运行代码而无需担心底层基础设施。使用 DO Functions,您可以将代码编写并部署为可以通过APIHTTP 请求(如果启用)或cron触发的“函数”。这些函数在完全托管的环境中执行,因此您不需要担心扩展、安全或维护。

在 DO 中,首先需要创建一个命名空间,该命名空间将分组函数。 在命名空间内,您可以创建一个函数。

触发器

通过 REST API 触发函数(始终启用,这是 cli 使用的方法)的方法是通过触发带有身份验证令牌的请求,例如:

curl -X POST "https://faas-lon1-129376a7.doserverless.co/api/v1/namespaces/fn-c100c012-65bf-4040-1230-2183764b7c23/actions/functionname?blocking=true&result=true" \
-H "Content-Type: application/json" \
-H "Authorization: Basic MGU0NTczZGQtNjNiYS00MjZlLWI2YjctODk0N2MyYTA2NGQ4OkhwVEllQ2t4djNZN2x6YjJiRmFGc1FERXBySVlWa1lEbUxtRE1aRTludXA1UUNlU2VpV0ZGNjNqWnVhYVdrTFg="

要查看 doctl cli 工具是如何获取此令牌的(以便您可以复制它),以下命令显示完整的网络跟踪:

doctl serverless connect --trace

当 HTTP 触发器启用时,可以通过这些 HTTP 方法 GET、POST、PUT、PATCH、DELETE、HEAD 和 OPTIONS 调用 web 函数。

在 DO 函数中,环境变量无法加密(在撰写本文时)。 我找不到从 CLI 读取它们的方法,但从控制台读取非常简单。

函数 URL 看起来像这样: https://<random>.doserverless.co/api/v1/web/<namespace-id>/default/<function-name>

枚举

# Namespace
doctl serverless namespaces list

# Functions (need to connect to a namespace)
doctl serverless connect
doctl serverless functions list
doctl serverless functions invoke <func-name>
doctl serverless functions get <func-name>

# Logs of executions
doctl serverless activations list
doctl serverless activations get <activation-id> # Get all the info about execution
doctl serverless activations logs <activation-id> # get only the logs of execution
doctl serverless activations result <activation-id> # get only the response result of execution

# I couldn't find any way to get the env variables form the CLI

Functions sandbox 没有元数据端点

支持 HackTricks

Last updated