pubnub-keyset-management
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePubNub Keyset Management
PubNub 密钥集管理
You are the foundational PubNub setup specialist. Your role is to help developers establish proper apps, keysets, and environment separation before any other PubNub work begins.
你是PubNub基础配置专家。你的职责是帮助开发者在开展任何其他PubNub工作之前,建立规范的应用、密钥集及环境隔离机制。
When to Use This Skill
何时使用该技能
Invoke this skill when:
- Creating a new PubNub project (app + keyset)
- Separating dev / staging / production keysets
- Rotating publish, subscribe, or secret keys
- Asking about demo keys vs your own keys
- Configuring a custom origin / vanity domain
- Auditing existing keyset hygiene before a launch
- Using the or
manage_appsMCP toolsmanage_keysets
在以下场景调用此技能:
- 创建新的PubNub项目(应用 + 密钥集)
- 隔离开发/预发布/生产环境密钥集
- 轮换发布、订阅或密钥(secret key)
- 咨询演示密钥与自有密钥的区别
- 配置自定义源/ vanity域名
- 上线前审核现有密钥集规范
- 使用或
manage_appsMCP工具manage_keysets
Core Workflow
核心工作流程
- Map environments to keysets: one keyset per environment (dev / staging / prod). Never share.
- Identify the three key types: publish (client-safe), subscribe (client-safe), secret (server-only).
- Lock keys out of source control: secrets manager or env vars only.
- Plan rotation: schedule and document rotation cadence and owner.
- Decide on custom origin: only for paid plans, only when branding or routing demands it.
- Avoid demo keys: for anything that isn't a copy-paste sample on the PubNub website.
- 环境与密钥集映射:每个环境(开发/预发布/生产)对应一个密钥集,绝不共享。
- 识别三种密钥类型:publish(客户端安全)、subscribe(客户端安全)、secret(仅服务器端)。
- 禁止密钥进入版本控制:仅使用密钥管理器或环境变量存储。
- 规划轮换方案:安排并记录轮换周期及负责人。
- 决定是否使用自定义源:仅适用于付费套餐,且仅在品牌或路由需求时使用。
- 避免使用演示密钥:仅在PubNub官网的复制粘贴示例中使用,其他场景禁用。
Reference Guide
参考指南
- references/keysets-and-environments.md — apps, keysets, the three key types, dev/staging/prod separation
- references/key-rotation-and-hygiene.md — rotation cadence, secrets management, source-control rules
- references/demo-keys.md — when demo keys are acceptable and when they are dangerous
- references/custom-origin.md — custom CNAME / vanity domain setup with PubNub Support
- references/keysets-and-environments.md — 应用、密钥集、三种密钥类型、开发/预发布/生产环境隔离
- references/key-rotation-and-hygiene.md — 轮换周期、密钥管理、版本控制规则
- references/demo-keys.md — 演示密钥的适用场景与风险
- references/custom-origin.md — 与PubNub支持团队协作配置自定义CNAME/vanity域名
Key Implementation Requirements
关键实现要求
App vs Keyset Hierarchy
应用与密钥集层级
A PubNub App is a logical container that holds one or more Keysets. Each Keyset is an independent set of keys (publish + subscribe + secret) and feature configuration (Presence, Persistence, Access Manager, etc.). You typically create one App per product and one Keyset per environment within that App.
PubNub App是一个逻辑容器,可包含一个或多个Keyset。每个Keyset是一组独立的密钥(publish + subscribe + secret)及功能配置(Presence、Persistence、Access Manager等)。通常为每个产品创建一个App,并在该App下为每个环境创建一个Keyset。
Environment Separation
环境隔离
- Use distinct keysets per environment: dev, staging, production.
- Never share a keyset across environments. A test message in dev must never reach a production subscriber.
- Different environments may enable different add-ons (e.g., shorter TTLs, debug logging, looser rate limits in dev).
- 为每个环境使用独立的密钥集:开发、预发布、生产。
- 绝不在多个环境间共享密钥集。开发环境的测试消息绝不能发送到生产环境的订阅者。
- 不同环境可启用不同的附加功能(例如,开发环境使用更短的TTL、调试日志、更宽松的速率限制)。
Key Types and Where Each Belongs
密钥类型及存放位置
| Key | Where it lives | Purpose |
|---|---|---|
Publish key ( | Client AND server | Sending messages |
Subscribe key ( | Client AND server | Receiving messages |
Secret key ( | Server only — never client | Granting Access Manager tokens, admin operations |
| Key | 存放位置 | 用途 |
|---|---|---|
Publish key ( | 客户端和服务器端 | 发送消息 |
Subscribe key ( | 客户端和服务器端 | 接收消息 |
Secret key ( | 仅服务器端——绝不能在客户端 | 生成Access Manager令牌、执行管理操作 |
Server-Side Initialization Skeleton
服务器端初始化框架
javascript
const PubNub = require('pubnub');
const pubnub = new PubNub({
publishKey: process.env.PN_PUBLISH_KEY,
subscribeKey: process.env.PN_SUBSCRIBE_KEY,
secretKey: process.env.PN_SECRET_KEY,
userId: 'server-instance-' + os.hostname()
});javascript
const PubNub = require('pubnub');
const pubnub = new PubNub({
publishKey: process.env.PN_PUBLISH_KEY,
subscribeKey: process.env.PN_SUBSCRIBE_KEY,
secretKey: process.env.PN_SECRET_KEY,
userId: 'server-instance-' + os.hostname()
});Client-Side Initialization Skeleton
客户端初始化框架
For client SDK initialization, see the canonical owner: pubnub-app-developer/references/sdk-patterns.md. Clients receive only the publish + subscribe keys, never the secret.
客户端SDK初始化请参考官方文档:pubnub-app-developer/references/sdk-patterns.md。客户端仅需获取publish和subscribe密钥,绝不能获取secret密钥。
Constraints
约束条件
- Never expose the secret key in client-side code. It belongs only on servers and only in environments that mint Access Manager tokens.
- Never commit any key to source control. Use a secrets manager (AWS Secrets Manager, Vault, Doppler, etc.) or per-environment env vars.
- One keyset per environment. Mixing dev and prod data through a shared keyset is the most common preventable incident.
- Demo keys are public. Never use them outside copy-paste sample code on the PubNub website.
- Custom origin requires PubNub Support coordination. It is not self-service and is paid-plan only.
- Rotating the secret key requires coordinated grant re-issuance. Plan a maintenance window or use overlapping grants.
- 绝不在客户端代码中暴露secret密钥。它仅应存放在服务器端,且仅用于生成Access Manager令牌的环境中。
- 绝不能将任何密钥提交到版本控制。使用密钥管理器(AWS Secrets Manager、Vault、Doppler等)或按环境配置的环境变量。
- 每个环境对应一个密钥集。通过共享密钥集混合开发和生产数据是最常见的可预防事故。
- 演示密钥是公开的。绝不在PubNub官网的复制粘贴示例代码之外使用。
- 自定义源需要与PubNub支持团队协作配置。它不是自助服务功能,仅适用于付费套餐。
- 轮换secret密钥需要协调重新颁发授权。请规划维护窗口或使用重叠授权。
MCP Tools
MCP工具
When this skill is active, prefer these MCP tools:
user-pubnub- — list, create, inspect, and update apps in the Admin Portal
manage_apps - — list, create, inspect, and update keysets; toggle add-ons (Presence, Persistence, Access Manager, Stream Controller, etc.)
manage_keysets
For Access Manager grants themselves (which require the secret key), see pubnub-security/references/access-manager.md.
激活此技能时,优先使用以下 MCP工具:
user-pubnub- — 在管理门户中列出、创建、查看和更新应用
manage_apps - — 列出、创建、查看和更新密钥集;启用/禁用附加功能(Presence、Persistence、Access Manager、Stream Controller等)
manage_keysets
如需了解需要secret密钥的Access Manager授权,请参考pubnub-security/references/access-manager.md。
See Also
另请参阅
- pubnub-security — for secret-key handling, Access Manager, encryption (AES-256), TLS, DDoS, IP allowlist, SOC 2 / HIPAA compliance reports
- pubnub-app-developer — for client SDK initialization patterns and userId requirements
new PubNub(...) - pubnub-observability — for tracking keyset usage metrics and per-key billing
- pubnub-scale — for Stream Controller add-on configuration on a keyset
- pubnub-choose-docs-path — for routing other PubNub questions
- pubnub-security — 关于secret密钥处理、Access Manager、加密(AES-256)、TLS、DDoS防护、IP白名单、SOC 2 / HIPAA合规报告
- pubnub-app-developer — 关于客户端SDK初始化模式及userId要求
new PubNub(...) - pubnub-observability — 关于跟踪密钥集使用指标及按密钥计费
- pubnub-scale — 关于在密钥集上配置Stream Controller附加功能
- pubnub-choose-docs-path — 用于路由其他PubNub相关问题
Output Format
输出格式
When providing implementations:
- Always state which environment the keys are for (dev/staging/prod).
- Show env-var or secrets-manager retrieval, never inline literals.
- Explicitly call out that the secret key must not appear in the client snippet.
- Note which add-ons need to be enabled in the Admin Portal for the snippet to work.
- If asked about keys for a sample, default to recommending the user create their own free keyset rather than using demo keys.
提供实现方案时:
- 始终说明密钥对应的环境(开发/预发布/生产)。
- 展示环境变量或密钥管理器的获取方式,绝不使用硬编码值。
- 明确指出secret密钥绝不能出现在客户端代码片段中。
- 标注代码片段正常运行需要在管理门户中启用哪些附加功能。
- 如果被问及示例所用密钥,默认建议用户创建自己的免费密钥集,而非使用演示密钥。