---
title: "MSP 工具"
description: "PowerShell、Datto RMM、N-able、ConnectWise Automate。为您的客户群颁发凭据。"
lang: zh
url: https://clavitor.ai/zh/developers/msp
markdown: https://clavitor.ai/zh/developers/msp.md
translation_of: https://clavitor.ai/en/developers/msp.md
authoritative: false
publisher: Clavitor LLC
---

> This is the Chinese translation of [MSP Tools](https://clavitor.ai/en/developers/msp.md). The original English text is authoritative; where the two differ, the English version prevails.

# MSP 工具: 您的 RMM 已经在进行 API 调用。 Clavitor 让这些调用更安全。

您的技术人员每天都在使用 Datto、N-able 和 ConnectWise。每个脚本、每项自动化、每个计划任务都需要凭据。目前，这些凭据存放在脚本变量、自定义字段或所有人都能读取的共享保管库中。Clavitor 代理和 CLI 改变了这一现状，且无需更改您的工作流。

## 适用于 RMM 的代理模式

在端点上设置 `HTTPS_PROXY`，您现有的脚本即可照常运行。代理会拦截出站 HTTPS 请求，解析标头中的 `clavitor://` 引用，并注入真实凭据。您的脚本永远不会接触到机密。您的 RMM 控制台也永远不会记录该机密。

```
# On the managed endpoint — one-time setup

$env:HTTPS_PROXY = "http://localhost:1983"

# Your existing automation scripts work unchanged

# The proxy resolves clavitor:// references in request headers

Invoke-RestMethod -Uri "https://api.openai.com/v1/models" `
  -Headers @{ Authorization = "Bearer clavitor://OpenAI/key" }
```

## PowerShell

PowerShell 是 MSP 的日常工作语言。CLI 和代理均提供原生支持。

### CLI — 单一值

```
# Resolve, use, scrub — the credential lives for one statement

$cred = clavitor-cli get "Client-Acme/VPN" --field password
Add-VpnConnection -Name "Acme" -ServerAddress "vpn.acme.com" -AuthenticationMethod MSChapv2
$secure = ConvertTo-SecureString $cred -AsPlainText -Force
Set-VpnConnectionUsernamePassword -ConnectionName "Acme" -Password $secure
Remove-Variable cred, secure
```

### Render — 配置模板

```
# Template with clavitor:// references (safe to store in your RMM)

clavitor-cli render monitoring-config.json | `
  Set-Content -Path "C:\ProgramData\Monitor\config.json"
```

### 代理——透明注入

```
$env:HTTPS_PROXY = "http://localhost:1983"

# Every Invoke-RestMethod and Invoke-WebRequest now resolves clavitor://

Invoke-RestMethod -Uri "https://api.datto.com/v1/devices" `
  -Headers @{ Authorization = "Bearer clavitor://Datto API/key" }
```

## Atera

Atera 在运行时使用 `{[Atera.<level>.CustomField.<name>]}` 语法将自定义字段占位符替换到脚本参数中。将 Clavitor 令牌作为参数传递给一次性安装脚本；后续脚本则在端点上调用 CLI。

### 通过 IT Automation 配置文件安装

在 Atera 脚本库中，创建一个带有一个参数的 **Install Clavitor** PowerShell 脚本。在运行该脚本的 IT Automation 配置文件中，使用客户级字段占位符进行调用：

```
Install-Clavitor.ps1 -Token "{[Atera.Customer.CustomField.ClavitorToken]}"
```

Atera 在智能体读取其参数列表之前替换该值。脚本如下：

```
param([Parameter(Mandatory)][string]$Token)
$Token | clavitor-cli init
Remove-Variable Token
```

### 在运行时解析凭据

端点注册后，每个后续的 Atera 脚本都会从保管库读取凭据——Atera 仅保留令牌槽位：

```
$pass = clavitor-cli get "Client-Acme/SQL Server" --field password
$secure = ConvertTo-SecureString $pass -AsPlainText -Force
Invoke-Sqlcmd -ServerInstance "sql.acme.local" `
  -Credential (New-Object PSCredential("sa", $secure)) -Query "SELECT 1"
Remove-Variable pass, secure
```

## ConnectWise Automate

Automate 使用 `{%^el:FieldName^%}` 语法（计算机级 EDF）将额外数据字段 (EDF) 宏替换到脚本步骤参数中。CLI 通过 Automate 脚本安装，该脚本下载二进制文件并调用 PowerShell 步骤，同时将令牌作为参数传递——EDF 值在脚本步骤执行前被替换。

### Automate 脚本：安装

在 Automate 脚本编辑器中，创建包含两个步骤的脚本：

```
Step 1  File Download from LTShare       clavitor-cli.exe → %windir%\Temp\
Step 2  Shell Execute (PowerShell)       Install-Clavitor.ps1 -Token "{%^el:ClavitorToken^%}"
```

`{%^el:ClavitorToken^%}` 宏在 PowerShell 步骤运行前被替换为计算机级 EDF 值。将令牌保持在 255 个字符以内，以符合 LabReplace 的替换限制。脚本本身如下：

```
# Install-Clavitor.ps1

param([Parameter(Mandatory)][string]$Token)
$Token | clavitor-cli init
Remove-Variable Token
```

### Automate 脚本：轮换域凭据

后续脚本从保管库读取数据，并将状态写回 EDF 以供仪表板显示：

```
$cred = clavitor-cli get "Client-Delta/Domain Admin" --field password
$secure = ConvertTo-SecureString $cred -AsPlainText -Force
Reset-ComputerMachinePassword `
  -Credential (New-Object PSCredential("administrator", $secure))
# Push timestamp back to EDF "LastRotation" via Automate's ExtraData Set Value step

Write-Output (Get-Date -Format o)
Remove-Variable cred, secure
```

## Datto RMM

Datto RMM 将站点和全局变量作为带有 `$env:` 前缀的环境变量公开给 PowerShell 组件；用户定义字段 (UDF) 作为 `$env:UDF_1` 到 `$env:UDF_30` 公开。一个组件用于安装 CLI；之后的所有操作均从保管库读取。

### 组件：安装并初始化

在 Datto 控制台中定义站点变量 `ClavitorToken`——它在组件内部显示为 `$env:ClavitorToken`：

```
# Datto RMM component: bootstrap Clavitor CLI

# Site variable "ClavitorToken" → $env:ClavitorToken at runtime

$env:ClavitorToken | clavitor-cli init
```

### 组件：通过代理进行 API 监控

后续组件在请求标头中写入 `clavitor://` 引用——代理在主机上对其进行解析。凭据永远不会进入脚本内存或 Datto 日志：

```
# Scheduled monitor — runs every 15 minutes

$env:HTTPS_PROXY = "http://localhost:1983"
$response = Invoke-RestMethod -Uri "https://api.client.com/v1/status" `
  -Headers @{ Authorization = "Bearer clavitor://Client-Bravo/Monitoring API" }

# Push a status code back into UDF_5 for the Datto dashboard

New-ItemProperty -Path "HKLM:\SOFTWARE\CentraStage" `
  -Name "Custom5" -Value $response.status -Force | Out-Null
```

## Kaseya VSA

VSA 智能体过程在运行时将 `#variable#` 宏替换到 PowerShell 参数中，然后通过 `executePowershell` 步骤系列（如 `executePowerShell64BitSystem`）执行脚本。智能体记录上的自定义字段保存 Clavitor 令牌；该过程通过 stdin 将其传递给 init。

### 智能体过程：安装

添加智能体自定义字段 `ClavitorToken`（Audit → Edit Profile → Custom Fields），然后构建一个包含两个步骤的过程：

```
Step 1  Get File from VSA Server     clavitor-cli.exe → C:\Program Files\Clavitor\
Step 2  Execute PowerShell (64 Sys)  "C:\Program Files\Clavitor\clavitor-cli.exe init" \
                                     stdin = "#vAgentConfiguration.ClavitorToken#"
```

`#vAgentConfiguration.ClavitorToken#` 宏在 VSA 执行命令前被替换为自定义字段值——令牌不会出现在 VSA 的过程历史记录中。

### 智能体过程：轮换特权凭据

初始化后，任何后续过程都会从保管库读取：

```
# Executed via executePowerShell64BitSystem

$cred = clavitor-cli get "Client-Hotel/Local Admin" --field password
$secure = ConvertTo-SecureString $cred -AsPlainText -Force
Set-LocalUser -Name "Administrator" -Password $secure
Remove-Variable cred, secure
```

## N-able N-central

自动化的基本单位是 **AMP**（Automation Manager Policy）——在 Automation Manager 中构建的基于 PowerShell 的策略。组织、客户或站点级别的自定义属性可以作为输入参数传递给 `Run PowerShell Script` 对象。

### AMP：使用自定义属性作为输入进行安装

在客户级别添加自定义属性 `ClavitorToken`（Administration → Custom Properties）。在 Automation Manager 中，创建一个 AMP，其 `Run PowerShell Script` 对象将输入参数 `Token` 绑定到该自定义属性。脚本如下：

```
param([Parameter(Mandatory)][string]$Token)
$Token | clavitor-cli init
Remove-Variable Token
```

自定义属性值作为 `$Token` 流入。它永远不会出现在 AMP 导出的 XML 或 N-central 的审计日志中。

### 脚本存储库：在运行时获取凭据

对于通过脚本存储库（Configuration → Repository → Scripts/Software）推送的临时脚本，端点已经初始化——脚本只需调用 CLI：

```
$dbPass = clavitor-cli get "Client-Bcme/SQL Server" --field password
$secure = ConvertTo-SecureString $dbPass -AsPlainText -Force
Invoke-Sqlcmd -ServerInstance "sql.bcme.com" `
  -Credential (New-Object PSCredential("sa", $secure)) -Query "SELECT 1"
Remove-Variable dbPass, secure
```

## N-able N-sight

N-sight（前身为 SolarWinds RMM）运行与 N-central 相同的 Automation Manager 引擎，并增加了用于 `.ps1`、AMP、批处理和其他脚本类型的 Script Manager。该模式与 N-central 相同：AMP 带有一个用于令牌的输入参数，然后其他所有内容都在运行时解析。

### Script Manager：通过 Automated Task 安装

将带有令牌参数的 `Install-Clavitor.ps1` 上传到 Settings → Script Manager。将其作为 Automated Task 附加到端点上；从设备级设置中将令牌作为脚本参数传递：

```
param([Parameter(Mandatory)][string]$Token)
$Token | clavitor-cli init
Remove-Variable Token
```

### Automated Task：使用保管库凭据进行计划备份

初始化后，计划任务会从保管库中提取凭据。任何不超过 255 个字符的标准输出都会返回到 N-sight 仪表板：

```
$pass = clavitor-cli get "Client-India/SQL Backup" --field password
$secure = ConvertTo-SecureString $pass -AsPlainText -Force
Backup-SqlDatabase -ServerInstance "sql.india.com" -Database "AppDB" `
  -Credential (New-Object PSCredential("backup-svc", $secure))
Write-Output "backup OK $(Get-Date -Format o)"
Remove-Variable pass, secure
```

## NinjaOne

在端点上运行的 NinjaOne 脚本可以通过内置 cmdlet 读写自定义字段：`Ninja-Property-Get <name>` 返回值，`Ninja-Property-Set <name> <value>` 将其写回。将 Clavitor 令牌存储在组织自定义字段中（类型设为 **Secure**，使其在控制台中仅可写）；安装脚本只读取一次。

### 安装脚本：从自定义字段读取令牌

在 Administration → Library → Custom Fields 中，添加一个类型为 Secure 的组织字段 `clavitorToken`。然后运行安装脚本：

```
$token = Ninja-Property-Get clavitorToken
$token | clavitor-cli init
Remove-Variable token
```

### 自定义操作：通过代理进行 API 调用

安装后，自动化任务通过代理调用外部 API——凭据永远不会被复制到脚本变量中：

```
$env:HTTPS_PROXY = "http://localhost:1983"
$response = Invoke-RestMethod -Uri "https://api.client-echo.com/v1/status" `
  -Headers @{ Authorization = "Bearer clavitor://Client-Echo/Monitoring API" }

# Push the result back to a device custom field for dashboarding

Ninja-Property-Set lastApiStatus $response.status
```

## Syncro

Syncro 使用 `{{asset_custom_field_<name>}}` 双大括号语法将资产自定义字段和标签公开为 **Platform** 脚本变量。定义一个 Platform 类型的脚本变量并将其绑定到该字段——Syncro 在脚本运行时将该值替换到 PowerShell 参数中。

### Syncro 脚本：安装

创建资产自定义字段 `clavitor_token`。在脚本编辑器中，声明一个类型为 **Platform** 的变量 `Token`，并绑定到 `{{asset_custom_field_clavitor_token}}`；将其传递给脚本主体中的 PowerShell 参数：

```
param([Parameter(Mandatory)][string]$Token)
$Token | clavitor-cli init
Remove-Variable Token
```

每个 Syncro 脚本编辑器底部的快速帮助面板列出了资产、客户和工单上下文中所有可用的平台变量。

### Syncro 脚本：使用保管库凭据连接 VPN

安装后，脚本和 Automated Remediations 从保管库解析凭据并直接使用它们：

```
$pass = clavitor-cli get "Client-Golf/VPN" --field password
$secure = ConvertTo-SecureString $pass -AsPlainText -Force
Add-VpnConnection -Name "Golf" -ServerAddress "vpn.golf.com" `
  -AuthenticationMethod MSChapv2 -Force
Set-VpnConnectionUsernamePassword -ConnectionName "Golf" -Password $secure
# Write status back to asset for Syncro dashboard

Rmm-Alert -Category "vpn-status" -Body "Golf connected $(Get-Date -Format o)"
Remove-Variable pass, secure
```

## 为什么这对 MSP 很重要

每个 RMM 平台都将凭据存储在某个地方——自定义属性、站点变量、额外数据字段、脚本参数。每个拥有控制台访问权限的技术人员都能看到它们。您的 RMM 控制台每次遭到入侵，都会暴露所有客户的凭据。

Clavitor 将凭据从 RMM 中移出。RMM 仅存储智能体令牌（每个客户一个）。该令牌授予对该客户保管库的受限访问权限。您的 RMM 控制台遭到入侵时暴露的是令牌，而不是凭据——并且每个令牌都对其部署的端点进行了 IP 白名单限制。

### 按客户限制范围

每个客户保管库都有自己的智能体令牌。技术人员的访问权限由范围控制，而不是由“谁能登录 RMM 控制台”控制。

### 按脚本审计

每次凭据访问都会被记录——哪个脚本、哪个端点、哪个凭据、何时。您的客户可以看到审计跟踪。您可以证明谁访问了什么。

### 一键吊销

客户离开？吊销他们的智能体令牌。每个端点会立即停止解析凭据。无需轮换密码，无需在 200 台机器上清除自定义属性。

## 停止在您的 RMM 中存储凭据。

一个 CLI。所有客户。每个凭据都受限、受审计且可吊销。
[免费开始](https://clavitor.ai/zh/checkout)
[开发者概览 →](https://clavitor.ai/zh/developers)
