Tutorial Tutorial Developer Platform Developer Platform ~32 phút ~32 min Đồng bộ 2026-06-10 Synced 2026-06-10

Manage secrets với Pulumi ESC Manage secrets with Pulumi ESC

Hướng dẫn chi tiết đồng bộ từ docs Cloudflare — mỗi section có backlink tới đúng vị trí trên trang gốc. Detailed guide synced from Cloudflare docs — each section links to the matching anchor on the official page.

← Danh mục ← Catalog

Giải thích nhanh Quick context

Thuộc Developer Platform — thực hành triển khai code, API và dữ liệu trên edge/serverless. Tutorial «Manage secrets với Pulumi ESC» giúp bạn làm quen luồng triển khai thật — phù hợp đọc trước khi mở tài liệu gốc tiếng Anh. Docs gốc chia khoảng 4 bước chính; bản tóm tắt dưới đây giúp bạn nắm khung trước khi làm theo từng lệnh.

Pulumi ESC (Environments, Secrets, and Configuration) is a secure and robust secrets management solution. The tutorial will walk you through how to develop with Wrangler while following security best practices.

Lưu ý trước khi làm Notes before you start

  • Đây là bản tóm tắt trên Orange Cloud Learning Hub — không thay thế tài liệu chính thức. This is a summary on Orange Cloud Learning Hub — it does not replace the official documentation.
  • Luôn mở liên kết «Tài liệu gốc» bên dưới khi cần lệnh CLI, snippet code và ảnh minh họa đầy đủ. Open the Official docs link below for CLI commands, code snippets, and full screenshots.
  • Kiểm tra token/API và state backend trước khi chạy trên môi trường production. Verify API tokens and the state backend before running against production.
  • Docs Cloudflare cập nhật thường xuyên — đối chiếu ngày «Rà soát lần cuối» trên trang gốc khi triển khai production. Cloudflare docs change frequently — verify the Last reviewed date on the official page before production use.

Tài liệu gốc — rà soát lần cuối: almost 2 years ago Official docs — last reviewed: almost 2 years ago

Tổng quan Overview

Phần «Tổng quan» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Overview" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

In this tutorial, you will receive step-by-step instructions on using Pulumi ESC (Environments, Secrets, and Configuration), which is a secure and robust secrets management solution.

The tutorial will walk you through how to develop with Wrangler while following security best practices.

Specifically, you will learn how to manage your CLOUDFLAREAPITOKEN for logging in to your Cloudflare account, pass ESC-stored secrets to Workers, and programmatically load your .dev.vars file.

You will provision resources that qualify under free tier offerings for both Pulumi Cloud and Cloudflare.

Before you begin Before you begin

Phần «Before you begin» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Before you begin" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Ensure you have:

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

1. Thiết lập mới Environment 1. Set up a new Environment

Phần «Thiết lập mới Environment» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "1. Set up a new Environment" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

A Pulumi ESC Environment ↗, or Environment, is a YAML file containing configurations and secrets for your application and infrastructure. These can be accessed in several ways, including shell commands. All ESC Environments reside in your Pulumi Cloud account.

. Log in to Pulumi Cloud a. Log in to Pulumi Cloud

Phần «. Log in to Pulumi Cloud» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "a. Log in to Pulumi Cloud" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Use the Pulumi ESC CLI to log into your Pulumi Cloud account.

Terminal window

text
esc login
text
Logged in to pulumi.com as  ....

B. Create mới Environment b. Create a new Environment

Phần «B. Create mới Environment» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "b. Create a new Environment" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Environment names must be unique within a Pulumi organization and may only contain alphanumeric characters, hyphens, underscores, and periods.

Terminal window

text
ESC_ENV=wrangler/my-dev-environment

esc env init $ESC_ENV
text
Environment created.

2. Log into Cloudflare 2. Log into Cloudflare

Phần «Log into Cloudflare» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "2. Log into Cloudflare" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Now that the Pulumi ESC Environment has been created, it can be consumed in various ways. For instance, to log into your Cloudflare account without needing to predefine credentials in your shell.

. Add your credentials a. Add your credentials

Phần «. Add your credentials» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "a. Add your credentials" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

By externally and securely storing your CLOUDFLAREAPITOKEN, you can control access and rotate the token value. We will run wrangler in non-interactive mode, which requires:

Replace the placeholder 123abc with your corresponding values:

Terminal window

text
esc env set $ESC_ENV environmentVariables.CLOUDFLARE_ACCOUNT_ID 123abc

esc env set $ESC_ENV environmentVariables.CLOUDFLARE_API_TOKEN  123abc --secret

The API token is declared as a secret. Once the Environment is saved, Pulumi will encrypt its value and replace it with ciphertext.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

b. Log out b. Log out

Phần «b. Log out» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "b. Log out" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Ensure you're not currently logged in to your Cloudflare account.

Terminal window

text
npx wrangler logout
text
Not logged in, exiting...

c. Log in c. Log in

Phần «c. Log in» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "c. Log in" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Pass ESC-stored Cloudflare credentials to Wrangler.

Terminal window

text
esc run ${ESC_ENV} npx wrangler whoami
text
Getting User settings...

👋 You are logged in with an API Token.

When you use the esc run command, it opens the Environment and sets the specified Environment variables into a temporary environment. After that, it uses those variables in the context of the wrangler command. This is especially helpful when running wrangler commands in a CI/CD environment but wanting to avoid storing credentials directly in your pipeline.

3. Thêm Worker secrets 3. Add Worker secrets

Phần «Thêm Worker secrets» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "3. Add Worker secrets" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Pulumi ESC centralizes secrets, and Wrangler can be used to pass them on to Workers and other Cloudflare resources. You will use the wrangler secret put command for this purpose.

. Add secret a. Add a secret

Phần «. Add secret» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "a. Add a secret" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Terminal window

text
esc env set ${ESC_ENV} environmentVariables.TOP_SECRET "aliens are real" --secret

B. Pass secret vào Worker b. Pass the secret to your Worker

Phần «B. Pass secret vào Worker» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "b. Pass the secret to your Worker" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Terminal window

text
esc run -i ${ESC_ENV} -- sh -c 'echo "$TOP_SECRET" | npx wrangler secret put TOP_SECRET'

By using an external secrets management solution, commonly used Worker secrets can be stored in a single shared Environment that is accessed by the relevant Workers. You can use shell commands with esc to incorporate scripting and integrate them into deployment pipelines or make commands. Use esc [command] --help for more information about the various commands available in the CLI.

4. Load .dev.vars 4. Load .dev.vars

Phần «Load .dev.vars» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "4. Load .dev.vars" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

In this step, you will configure an Environment to load your .dev.vars file programmatically.

The .dev.vars file is located in the root of your Wrangler project to define secrets used when running wrangler dev. For more information, refer to Local Development with Secrets.

With a dedicated ESC Environment to store all the .dev.vars secrets, you can use a dotenv export flag.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

. Create Environment a. Create an Environment

Phần «. Create Environment» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "a. Create an Environment" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Terminal window

text
E=wrangler/my-devvars

esc env init $E
text
Environment created.

B. Add secret b. Add a secret

Phần «B. Add secret» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "b. Add a secret" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Terminal window

text
esc env set $E environmentVariables.TOP_SECRET  "the moon is made of cheese" --secret

C. Generate .dev.vars file c. Generate the .dev.vars file

Phần «C. Generate .dev.vars file» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "c. Generate the .dev.vars file" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Terminal window

text
esc env open ${E} --format dotenv > .dev.vars

As .dev.vars files may often contain secrets, they should not be committed to source control. Keeping these secrets externally ensures you can load them to a new development environment without any loss.

Bước tiếp theo Next steps

Phần «Bước tiếp theo» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Next steps" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

You have configured Pulumi ESC Environments to load secrets for Wrangler commands, enhancing security during development with Wrangler. The externalized secrets are now reusable across Workers. Learn more about Pulumi ESC features and integrations ↗ or follow the Deploy a Worker with Pulumi tutorial.

json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/pulumi/","name":"Pulumi"}},{"@type":"ListItem","position":3,"item":{"@id":"/pulumi/tutorial/","name":"Tutorials"}},{"@type":"ListItem","position":4,"item":{"@id":"/pulumi/tutorial/manage-secrets/","name":"Manage secrets with Pulumi ESC"}}]}

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Xem bản đầy đủ trên developers.cloudflare.com (ảnh, tab cấu hình). View the full guide on developers.cloudflare.com (images, config tabs).

Tài liệu gốc ↗ Official docs ↗