When one codebase serves multiple customers, configuration and secrets must be stored separately, and secrets must be revocable the same day a contract ends or a leak is suspected.

Key Takeaways

  • All customers run exactly the same code; only configuration differs. If an if branch keyed on customer names appears, the two have already been mixed together.
  • ConfigMaps cannot hold secrets; by default, Kubernetes Secrets are also stored unencrypted in etcd.
  • Secrets need lifetimes and must be revocable: once a lease is revoked, the secret becomes invalid immediately, whether you are ending a customer engagement or responding to a suspected leak.

Your solution runs smoothly at the first customer. Then the second customer signs, and to hit the deadline you add one line

if customer == "B":

to switch the CRM address. By the third customer, the repo has gained two files,

config_a.yaml

and

config_b.yaml

, plus a token committed by someone at 11 p.m.

Nobody sets out to wreck the codebase. It degrades gradually through one rushed delivery after another. For Forward Deployed Engineers (FDEs), this is the daily routine, not an edge case: the same product must be deployed across different infrastructure, different data, and different security requirements.

The skill needed here is separating code, configuration, and secrets, then putting each where it belongs. Done right, the tenth customer requires only a new set of values, not another code branch.

Code doesn't change per customer; configuration does

The Twelve-Factor App configuration principle rests on one observation: configuration varies greatly between deployments, while code stays the same. For an FDE, "one deployment" is one customer. Every customer is a deployment, with its own API endpoints, model names, batch sizes, and access tokens.

To test whether the separation is thorough, 12-factor offers a test: could this codebase be open-sourced at any moment without exposing a single credential? For an FDE, the test needs one more clause: the repo must also not reveal customer names, internal URLs, or how the customer's systems are organized.

12-factor chooses environment variables for configuration. For an FDE, the practical reason is simple: when you're standing in a customer's machine room, allowed to change parameters but not rebuild the image, environment variables can be modified on the spot without touching a line of code.

Don't let the number of "environments" double with the customer count

Many people habitually name config sets by environment:

dev

、

staging

、

prod

. With three customers, the list becomes

prod-a

、

staging-a

、

prod-b

, and before long, nobody remembers what distinguishes these files.

A clearer approach is to describe each customer as a flat list of variables, with types marked and explanations written. Imagine an agent that reads tickets from a customer's CRM, deployed in two places:

VariableCustomer A (hypothetical)Customer B (hypothetical)Type
TENANT_IDacmebetaConfig
CRM_BASE_URLhttps://crm.a.examplehttps://crm.b.exampleConfig
BATCH_SIZEUnset, uses shared default in code20Config
CRM_API_TOKENStored in secret storeStored in secret storeSecret

The last column matters most. The customer-specific values in the first three rows must not live in the repo; the code should only keep shared, harmless defaults, such as batch size.

If the first three values leak, the damage is mainly information about the customer's systems. If the fourth leaks, it's a security incident involving the customer, and possibly a contract breach.

Example: a loader that stops immediately when a variable is missing

The most dangerous configuration mistakes often come from a default value nobody noticed. The app starts fine, then three days later calls another customer's CRM. The loader below does the opposite: it stops immediately when a required variable is missing, and never prints secrets.

# config.py:从环境变量读取配置,缺少任何一项就立即停止
import os
from dataclasses import dataclass, field

class ConfigError(RuntimeError):
    pass

def _required(name: str) -> str:
    value = os.environ.get(name)
    if not value:
        raise ConfigError(f"缺少必需的环境变量:{name}")
    return value

@dataclass(frozen=True)
class Settings:
    tenant_id: str
    crm_base_url: str
    batch_size: int
    crm_api_token: str = field(repr=False)  # 密钥:绝不出现在日志中

def load() -> Settings:
    return Settings(
        tenant_id=_required("TENANT_ID"),
        crm_base_url=_required("CRM_BASE_URL"),
        batch_size=int(os.environ.get("BATCH_SIZE", "100")),  # 共享默认值,不属于任何客户
        crm_api_token=_required("CRM_API_TOKEN"),
    )

Three things are worth noting. No customer names appear in the code. Defaults in code are only allowed for harmless parameters like

BATCH_SIZE

: 100 is a safe shared value, not a customer-specific number; customers needing other values set the variable themselves, as Customer B does with 20.

Any variable that determines where data flows must be declared explicitly, with no default. And

repr=False

ensures that even a casual

print(settings)

during debugging won't leak tokens into the customer's logs.

On Kubernetes: ConfigMaps for configuration, Secrets for secrets

If the customer uses Kubernetes, the ConfigMap is the natural home for the first three variables—it's designed for non-sensitive settings that vary by environment. One image, multiple customer clusters.

envFrom:
  - configMapRef:
      name: app-config-customer-b
  - secretRef:
      name: app-secrets-customer-b

The trap is the second item. The Kubernetes documentation states explicitly that ConfigMaps provide no confidentiality or encryption, and sensitive data must go into Secrets so passwords and tokens don't appear in application code. But even Secrets are stored unencrypted in etcd by default, readable by anyone with access to the API or etcd.

Therefore, Secrets are only safe after additional hardening. In the kickoff meeting with the customer's infrastructure team, ask directly: is Secret encryption enabled on this cluster? Who currently has read access to Secrets in this namespace?

Secrets need lifetimes

A token that never expires is a landmine waiting to detonate on the day it leaks. OWASP recommends rotating secrets regularly so stolen credentials are usable only for a very short window, and centralizing secret storage, distribution, auditing, and rotation in one place.

Vault takes this idea further with leases. Once a lease is revoked, the secret becomes invalid immediately and cannot be renewed.

This fundamentally changes the two trickiest situations an FDE faces: when a customer contract ends, revoke that customer's lease instead of auditing machine by machine; when a leak is suspected, revoke first, investigate after.

Boundaries between customers must be equally clear. In multi-tenant systems, each tenant's secrets need strict isolation—for example, separate storage per tenant and no shared encryption key across customers—so that an incident at one customer doesn't spread to others.

In CI/CD pipelines, this means a separate service account per customer: a pipeline deploying for Customer B has no reason whatsoever to read Customer A's tokens.

Four mistakes that break configuration in the field

The most common is letting customer names creep into the code, even as a single "temporary"

if

branch. Next is setting defaults for variables that determine where data flows. Then comes putting tokens in ConfigMaps on the grounds that "it's all inside the customer's cluster anyway."

The last one is more subtle: your dev machine runs SQLite while the customer runs Postgres, and the configuration only breaks once you're on site. 12-factor recommends keeping development and production environments as similar as possible, with differences confined to configuration. On your own machine, use the same kind of database and the same kind of queue as the customer.

Customer B is leaving, and a token may have leaked—what now?

This question is worth rehearsing before the customer ever asks it, and it's an excellent practice scenario before an FDE interview. OWASP lists rapid response to exposed secrets as a key focus area.

A good answer works layer by layer: revoke B's lease, confirm that B's CI service account cannot touch any other customer's secrets, issue new secrets for whatever is still running, log every action in the audit trail, and change no code at all.

If you've done this in a real project, put it on your resume with one concrete sentence: number of customers, how keys were isolated, and how long revocation took.

By the time you deliver to your tenth customer, your work is just filling in a variable list and creating a new tenant. The codebase stays clean enough to be open-sourced at any moment.

Was this article helpful?

Thanks for your feedback!

Next on the roadmap · Phase 1: Foundational Understanding Three invisible bytes quietly corrupt a customer's CSV file Excel adds a BOM to display Vietnamese correctly; a small Python parser plus golden tests can expose it and two other silent bugs.