Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions server.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@
"name": "DCD_API_URL",
"description": "Override the API base URL (e.g. for a non-production environment).",
"isRequired": false
},
{
"name": "DCD_ENCRYPT",
"description": "Uploads (app binary, flows, env vars) are encrypted on your machine by default. Set to 0 to upload them without envelope encryption; a run's encrypt input overrides this.",
"isRequired": false
}
]
}
Expand Down
14 changes: 3 additions & 11 deletions src/commands/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ export const cloudCommand = defineCommand({
const googlePlay = Boolean(args['google-play']);
const ignoreShaCheck = Boolean(args['ignore-sha-check']);
// Client-side envelope encryption of every sensitive artifact: the
// binary (#1138), the flow zip (#1151), and env vars (#1152). Kept as
// given (--no-encrypt is an explicit false) and resolved once the
// compatibility data, which carries the server default, is in.
// binary (#1138), the flow zip (#1151), and env vars (#1152). Always
// on; read only so --no-encrypt can be reported as ignored.
const encryptFlag = args.encrypt as boolean | undefined;
const includeTags = coerceArray(
collectRepeatedFlag(rawArgs, ['--include-tags']),
Expand Down Expand Up @@ -390,10 +389,7 @@ export const cloudCommand = defineCommand({
}

const encryption = await checkKekForEncryption(
resolveEncryption({
flag: encryptFlag,
serverDefault: compatibilityData.encryption?.defaultOn,
}),
resolveEncryption({ flag: encryptFlag }),
apiUrl,
);
const encrypt = encryption.enabled;
Expand Down Expand Up @@ -811,10 +807,6 @@ export const cloudCommand = defineCommand({
return;
}

if (encrypt && encryption.source === 'server') {
out(ui.note('Encrypting uploads; opt out with --no-encrypt'));
}

if (!finalBinaryId) {
if (!finalAppFile) {
throw new CliError(
Expand Down
29 changes: 4 additions & 25 deletions src/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { uploadBinary, verifyAppZip } from '../methods.js';
import { telemetry } from '../services/telemetry.service.js';
import { resolveAuth } from '../utils/auth.js';
import { CliError, logger } from '../utils/cli.js';
import { fetchCompatibilityData } from '../utils/compatibility.js';
import { resolveApiUrl } from '../utils/config-store.js';
import { checkKekForEncryption, resolveEncryption } from '../utils/envelope.js';
import { downloadExpoUrl, extractTarGz, findAppBundle, isUrl } from '../utils/expo.js';
Expand Down Expand Up @@ -46,31 +45,16 @@ export const uploadCommand = defineCommand({
const apiUrl = resolveApiUrl(args['api-url'] as string | undefined);
const appUrl = args['app-url'] as string | undefined;
const ignoreShaCheck = Boolean(args['ignore-sha-check']);
// Kept as given, so --no-encrypt is an explicit false and a missing flag
// leaves DCD_ENCRYPT and then the server default to decide.
// Uploads are always encrypted. Read only so --no-encrypt can be
// reported as ignored.
const encryptFlag = args.encrypt as boolean | undefined;
const debug = Boolean(args.debug);
const positional = args.appFile as string | undefined;

const auth = await resolveAuth({ apiKeyFlag });

// Same order as `dcd cloud`, whose compatibility fetch carries the org's
// encryption default. `dcd upload` never needed that data before, so a
// failed fetch leaves the default off rather than failing the upload.
let serverDefault: boolean | undefined;
try {
const compatibilityData = await fetchCompatibilityData(apiUrl, auth);
serverDefault = compatibilityData.encryption?.defaultOn;
} catch (error) {
if (debug) {
out(
`[DEBUG] Failed to fetch compatibility data, so the org's encryption default is off: ${error instanceof Error ? error.message : String(error)}`,
);
}
}

const encryption = await checkKekForEncryption(
resolveEncryption({ flag: encryptFlag, serverDefault }),
resolveEncryption({ flag: encryptFlag }),
apiUrl,
);
if (encryption.notice) out(ui.note(encryption.notice));
Expand Down Expand Up @@ -112,12 +96,7 @@ export const uploadCommand = defineCommand({

out(ui.section('Uploading app binary'));
out(
ui.branch([
...ui.fields([['file', colors.highlight(resolvedFile)]]),
...(encryption.enabled && encryption.source === 'server'
? [ui.note('Encrypting uploads; opt out with --no-encrypt')]
: []),
]),
ui.branch(ui.fields([['file', colors.highlight(resolvedFile)]])),
);

const appBinaryId = await uploadBinary({
Expand Down
2 changes: 1 addition & 1 deletion src/config/flags/binary.flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export const binaryFlags = {
encrypt: {
type: 'boolean',
description:
'Encrypt the app binary, flow zip, and env vars before upload (client-side envelope encryption; each gets its own key). On by default; --no-encrypt or DCD_ENCRYPT=0 turns it off. The binary is still deduplicated across runs, so an unchanged app is not re-uploaded.',
'No longer needed: the app binary, flow zip and env vars are always encrypted before upload (client-side envelope encryption; each gets its own key). Kept so existing scripts still run. --no-encrypt and DCD_ENCRYPT=0 are ignored with a warning.',
},
} as const satisfies ArgsDef;
21 changes: 3 additions & 18 deletions src/mcp/tools/run-cloud-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ export function registerRunCloudTest(server: McpServer): void {
.optional()
.describe('Force re-upload of the binary even if an identical one exists'),
dryRun: z.boolean().optional().describe('Preview flows that would run without submitting'),
encrypt: z
.boolean()
.optional()
.describe(
'true encrypts the binary, flow zip and env vars client-side before upload; false never does. Omit to follow DCD_ENCRYPT, then the default, which is on.',
),
wait: z
.boolean()
.optional()
Expand Down Expand Up @@ -232,15 +226,9 @@ export function registerRunCloudTest(server: McpServer): void {
});
}

// Client-side envelope encryption (binary/flow/env), in the same order
// as `dcd cloud`: the encrypt input, DCD_ENCRYPT, then the server default.
const encryption = await checkKekForEncryption(
resolveEncryption({
flag: args.encrypt,
serverDefault: compatibilityData.encryption?.defaultOn,
}),
apiUrl,
);
// Client-side envelope encryption (binary/flow/env), always on, as
// in `dcd cloud`.
const encryption = await checkKekForEncryption(resolveEncryption(), apiUrl);
const encrypt = encryption.enabled;
if (encryption.notice) logStderr(encryption.notice);
// Filled in as each part is encrypted; sent on this call's telemetry.
Expand All @@ -251,9 +239,6 @@ export function registerRunCloudTest(server: McpServer): void {
source: encryption.source,
};
telemetryExtra.encrypt = encryptTelemetry;
if (encrypt && encryption.source === 'server') {
logStderr('Encrypting uploads; opt out with encrypt: false');
}

// Resolve the binary: existing id, or upload the local file.
let appBinaryId = args.appBinaryId;
Expand Down
4 changes: 2 additions & 2 deletions src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ async function encryptUploadSource(
const kek = await resolveKekPublicKey(apiUrl);
if (!kek) {
throw new Error(
'Encryption is on (from --encrypt, DCD_ENCRYPT or the default) but no KEK public key is configured for this API. ' +
'Set DCD_BINARY_KEK_PUBLIC=<version>:<base64>, or pass --no-encrypt to upload without encryption.',
'Encryption is on but no KEK public key is configured for this API. ' +
'Set DCD_BINARY_KEK_PUBLIC=<version>:<base64>.',
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/test-submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ export class TestSubmissionService {
const kek = await resolveKekPublicKey(apiUrl);
if (!kek) {
throw new Error(
'Encryption is on (from --encrypt, DCD_ENCRYPT or the default) but no KEK public key is configured for this API. ' +
'Set DCD_BINARY_KEK_PUBLIC=<version>:<base64>, or pass --no-encrypt to upload without encryption.',
'Encryption is on but no KEK public key is configured for this API. ' +
'Set DCD_BINARY_KEK_PUBLIC=<version>:<base64>.',
);
}
const flow = encryptFlowBuffer(plaintextZip, kek);
Expand Down
17 changes: 3 additions & 14 deletions src/utils/app-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { rm } from 'node:fs/promises';
import { uploadBinary, verifyAppZip } from '../methods.js';
import type { AuthContext } from '../types/domain/auth.types.js';
import { CliError } from './cli.js';
import { fetchCompatibilityData } from './compatibility.js';
import { checkKekForEncryption, resolveEncryption } from './envelope.js';
import { extractTarGz, findAppBundle } from './expo.js';

Expand Down Expand Up @@ -47,8 +46,8 @@ export interface UploadLocalAppOptions {

/**
* Upload a local build the way `dcd upload` does, and return its binary id:
* an Expo `.tar.gz` is unpacked to its `.app`, a `.zip` is checked, and the
* org's encryption default applies. URLs are not handled here: `dcd device`
* an Expo `.tar.gz` is unpacked to its `.app`, a `.zip` is checked, and it
* is encrypted before upload. URLs are not handled here: `dcd device`
* hands those to the API's install-from-URL instead.
*/
export async function uploadLocalApp(opts: UploadLocalAppOptions): Promise<string> {
Expand All @@ -60,17 +59,7 @@ export async function uploadLocalApp(opts: UploadLocalAppOptions): Promise<strin
);
}

// As in `dcd upload`: a failed compatibility fetch leaves the default off
// rather than failing the upload.
let serverDefault: boolean | undefined;
try {
const compatibility = await fetchCompatibilityData(apiUrl, auth);
serverDefault = compatibility.encryption?.defaultOn;
} catch {
serverDefault = undefined;
}

const encryption = await checkKekForEncryption(resolveEncryption({ serverDefault }), apiUrl);
const encryption = await checkKekForEncryption(resolveEncryption(), apiUrl);
if (encryption.notice) log(encryption.notice);

const tempDirs: string[] = [];
Expand Down
5 changes: 0 additions & 5 deletions src/utils/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export interface CompatibilityData {
};
/** Active CLI notices, piggybacked onto the compatibility response by the API. */
notices?: Notice[];
/**
* The client-side encryption default (dcd#1138): on for every org unless the
* API's kill switch is set. An older API omits it, which means off.
*/
encryption?: { defaultOn: boolean };
}

let cachedCompatibilityData: CompatibilityData | null = null;
Expand Down
14 changes: 2 additions & 12 deletions src/utils/device-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import type { AuthContext } from '../types/domain/auth.types.js';
import type { DeviceFlowBundle } from '../types/domain/device-session.types.js';
import { CliError } from './cli.js';
import { fetchCompatibilityData } from './compatibility.js';
import {
checkKekForEncryption,
encryptFlowBuffer,
Expand Down Expand Up @@ -244,8 +243,7 @@ export interface UploadFlowBundleOptions {
* Zip the files a directory's flows need (bundleFiles) and upload them as a
* flow bundle: ask the API for
* upload URLs, PUT the zip to both copies, then register it with its
* SHA-256. Encrypted like `dcd cloud`'s flow zips when the org's default
* (or DCD_ENCRYPT) says so. Entries are relative to `dir`, so a run's
* SHA-256. Encrypted like `dcd cloud`'s flow zips. Entries are relative to `dir`, so a run's
* `flow` is a path inside it, e.g. `login.yaml`.
*/
export async function uploadFlowBundle(
Expand All @@ -259,15 +257,7 @@ export async function uploadFlowBundle(

const zip = await compressFilesFromRelativePath(dir, files, '');

let serverDefault: boolean | undefined;
try {
const compatibility = await fetchCompatibilityData(apiUrl, auth);
serverDefault = compatibility.encryption?.defaultOn;
} catch {
serverDefault = undefined;
}

const encryption = await checkKekForEncryption(resolveEncryption({ serverDefault }), apiUrl);
const encryption = await checkKekForEncryption(resolveEncryption(), apiUrl);
if (encryption.notice) log(encryption.notice);
const kek = encryption.enabled ? await resolveKekPublicKey(apiUrl) : null;
const sealed = kek ? encryptFlowBuffer(zip, kek) : null;
Expand Down
88 changes: 34 additions & 54 deletions src/utils/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,90 +51,70 @@ export interface EnvEnvelope extends BinaryEnvelope {
ciphertext: string;
}

/** What decided whether a run encrypts (dcd#1138); recorded in telemetry. */
export type EncryptionSource = 'env' | 'flag' | 'off' | 'server';
/**
* Whether a run's uploads were encrypted (dcd#1138); recorded in telemetry.
* `always` is the normal case. `no_kek` means the API publishes no KEK public
* key, so there was nothing to encrypt against. `off` means the command never
* reached an upload.
*/
export type EncryptionSource = 'always' | 'no_kek' | 'off';

export interface EncryptionDecision {
enabled: boolean;
/** Kept when encryption is skipped, so telemetry shows what asked for it. */
source: EncryptionSource;
/** One line for the user when encryption was wanted but is skipped. */
/** One line for the user: an ignored opt-out, or why encryption is skipped. */
notice?: string;
}

/** `1`/`true` is on and `0`/`false` is off, in any case; anything else is unset. */
function parseEncryptEnv(value: string | undefined): boolean | undefined {
switch (value?.trim().toLowerCase()) {
case '1':
case 'true': {
return true;
}

case '0':
case 'false': {
return false;
}

default: {
return undefined;
}
}
/** `0`/`false` in any case: a value that used to turn encryption off. */
function isOptOutValue(value: string | undefined): boolean {
const v = value?.trim().toLowerCase();
return v === '0' || v === 'false';
}

/**
* Whether client-side envelope encryption is on, and what decided it. The
* first of these that is set wins:
* 1. `flag`: `--encrypt` / `--no-encrypt`, or the MCP tool's `encrypt` input.
* 2. `DCD_ENCRYPT`, then its legacy alias `DCD_ENCRYPT_BINARIES`.
* 3. `serverDefault`: `encryption.defaultOn` from the compatibility data,
* which the API turns on for every org unless its kill switch is set.
* 4. Off. An API too old to send `encryption` ends up here.
* When on, the binary, the flow zip, and the env map are each encrypted with
* their **own** per-upload DEK (all wrapped under the same per-env KEK).
* Uploads are always encrypted: the app binary, the flow zip and the env map
* each get their own per-upload DEK, all wrapped under the same per-env KEK.
*
* There is no opt-out any more. `--no-encrypt` (seen here as `flag: false`)
* and `DCD_ENCRYPT=0` / `DCD_ENCRYPT_BINARIES=0` are ignored with a warning,
* so scripts that still pass them keep working. `--encrypt` is a no-op.
*/
export function resolveEncryption(opts: {
env?: NodeJS.ProcessEnv;
flag?: boolean;
serverDefault?: boolean;
}): EncryptionDecision {
const { env = process.env, flag, serverDefault } = opts;
if (flag !== undefined) return { enabled: flag, source: 'flag' };

const fromEnv =
parseEncryptEnv(env.DCD_ENCRYPT) ?? parseEncryptEnv(env.DCD_ENCRYPT_BINARIES);
if (fromEnv !== undefined) return { enabled: fromEnv, source: 'env' };
} = {}): EncryptionDecision {
const { env = process.env, flag } = opts;
const ignored: string[] = [];
if (flag === false) ignored.push('--no-encrypt');
if (isOptOutValue(env.DCD_ENCRYPT)) ignored.push('DCD_ENCRYPT');
if (isOptOutValue(env.DCD_ENCRYPT_BINARIES)) ignored.push('DCD_ENCRYPT_BINARIES');

if (serverDefault === true) return { enabled: true, source: 'server' };
return { enabled: false, source: 'off' };
const decision: EncryptionDecision = { enabled: true, source: 'always' };
if (ignored.length > 0) {
decision.notice = `Ignoring ${ignored.join(' and ')}: uploads are always encrypted.`;
}
return decision;
}

/**
* Check that `apiUrl` has a KEK before a run encrypts against it: either
* `DCD_BINARY_KEK_PUBLIC` is set or the API publishes one on `GET /cli-config`
* (see resolveKekPublicKey). Without one, an explicit `--encrypt` is an error,
* while encryption from DCD_ENCRYPT or the server default is skipped with a
* notice, so a run against an API that publishes no KEK uploads in plaintext
* as before. An API that cannot be asked at all is an error whatever decided
* encryption: silently falling back to plaintext would be the one outcome the
* org asked not to have.
* (see resolveKekPublicKey). An API that publishes no KEK gets plaintext
* uploads with a notice: that is the server's own switch, and the only way to
* turn encryption off. An API that cannot be asked at all is an error, since
* silently falling back to plaintext would hide the failure.
*/
export async function checkKekForEncryption(
decision: EncryptionDecision,
apiUrl: string,
): Promise<EncryptionDecision> {
if (!decision.enabled || (await resolveKekPublicKey(apiUrl))) return decision;

if (decision.source === 'flag') {
throw new Error(
`--encrypt needs the KEK public key of the API it uploads to, and ${apiUrl} does not publish one. ` +
'Set DCD_BINARY_KEK_PUBLIC=<version>:<base64> to encrypt against it, or drop --encrypt.',
);
}

return {
enabled: false,
notice: `Not encrypting uploads: ${apiUrl} does not publish a KEK public key. Set DCD_BINARY_KEK_PUBLIC to encrypt against it.`,
source: decision.source,
source: 'no_kek',
};
}

Expand Down
Loading
Loading