안전한 비밀 정보 관리
엣지 환경에서 API 키, 토큰 및 기타 민감한 정보를 안전하게 처리하는 모범 사례를 배웁니다.
안전한 비밀 정보 관리은(는) CoddyKit의 무료 Edge Computing with Cloudflare Workers & Deno 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Edge Computing with Cloudflare Workers & Deno 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Edge Computing with Cloudflare Workers & Deno 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
What Are Edge Secrets?
When building applications, especially at the edge, you often need to handle sensitive information. These are called secrets.
Secrets include things like API keys, database credentials, authentication tokens, and private encryption keys. They are critical for your application's security and functionality.
Dangers of Hardcoding Secrets
A common mistake, especially for beginners, is to hardcode secrets directly into your application's source code.
- Exposure: Anyone with access to your code (e.g., in a public Git repository) can see your secrets.
- Rotation Issues: Changing a secret means changing and redeploying your code everywhere it's used.
- Security Breach: A single leak can compromise your entire system.
Cloudflare Worker Environment Variables
Cloudflare Workers provide a secure way to manage secrets using environment variables. These variables are:
- Injected securely at runtime, not stored in your code.
- Encrypted at rest by Cloudflare.
- Specific to each Worker, allowing fine-grained control.
They are accessed via the env object in your Worker's fetch handler.
Accessing Worker Secrets Demo
This Worker accesses an environment variable named MY_API_KEY. Notice how the secret itself is never hardcoded in the script.
Try running it! (The actual key won't be shown for security).
export default {
async fetch(request, env, ctx) {
const apiKey = env.MY_API_KEY; // Access the secret
if (apiKey) {
return new Response(`Secret accessed! Length: ${apiKey.length}`);
} else {
return new Response(
"MY_API_KEY environment variable not set.",
{ status: 400 }
);
}
},
};Deno Environment Variables
Similar to Workers, Deno applications also use environment variables for secrets. You can access them using Deno.env.
For local development, you might use .env files (though not directly supported by Deno, tools like deno task or third-party modules can help). For Deno Deploy, secrets are configured securely through their platform UI or CLI.
Using Deno Secrets Demo
Here's a simple Deno script that retrieves a secret named DB_PASSWORD from its environment variables. Run this example to see it in action.
const dbPassword = Deno.env.get("DB_PASSWORD");
if (dbPassword) {
console.log(`Database password accessed. Length: ${dbPassword.length}`);
} else {
console.log("DB_PASSWORD environment variable not set.");
console.log("To set: env DB_PASSWORD='mysecret' deno run --allow-env main.ts");
}Managing Secrets with Wrangler CLI
For Cloudflare Workers, the Wrangler CLI is your go-to tool for managing secrets. It encrypts and securely uploads them to Cloudflare's infrastructure.
wrangler secret put <NAME>: Prompts for a secret value and uploads it.wrangler secret delete <NAME>: Removes a secret.wrangler secret list: Lists all secrets for your Worker.
This keeps secrets out of your wrangler.toml file and source code.
Principle of Least Privilege
A crucial security principle is the Principle of Least Privilege. This means:
- Granting only the minimum necessary permissions to access resources.
- Only giving access to secrets to the specific services or users that absolutely need them.
Avoid giving a Worker access to a secret it doesn't actually use, even if it seems convenient.
Secret Rotation and Auditing
Even with secure storage, secrets can be compromised. Implement these practices:
- Secret Rotation: Regularly change your API keys and tokens (e.g., every 90 days). This limits the window of opportunity for attackers if a secret is leaked.
- Auditing: Monitor and log access to your secrets. This helps detect unusual activity and potential breaches.
Automate these processes where possible to reduce manual overhead.
Secrets Management Check
Test your understanding of secure secrets management.
Recap: Secure Secrets
In this lesson, we learned about the importance of securely managing sensitive information in edge applications.
- Never hardcode secrets.
- Utilize platform-provided environment variables (Cloudflare Workers
env, DenoDeno.env). - Use tools like Wrangler CLI for secure secret deployment.
- Follow the Principle of Least Privilege.
- Implement regular secret rotation and auditing.
These practices are fundamental to building robust and secure edge applications.
자주 묻는 질문
“안전한 비밀 정보 관리” 강의는 무료인가요?
네 — “안전한 비밀 정보 관리” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Edge Computing with Cloudflare Workers & Deno 강의 전체를 잠금 해제할 수 있습니다. Edge Computing with Cloudflare Workers & Deno 강의에는 총 4개의 강의가 포함되어 있습니다.
“안전한 비밀 정보 관리”에서 뭘 배우나요?
엣지 환경에서 API 키, 토큰 및 기타 민감한 정보를 안전하게 처리하는 모범 사례를 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Edge Computing with Cloudflare Workers & Deno을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Edge Computing with Cloudflare Workers & Deno을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Edge Computing with Cloudflare Workers & Deno은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“안전한 비밀 정보 관리” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Edge Computing with Cloudflare Workers & Deno 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Edge Computing with Cloudflare Workers & Deno 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 인증 및 권한 부여
- 요청 빈도 제한 및 DDoS 보호
- 안전한 비밀 정보 관리
- 입력 정제 및 인젝션 방지