Skip to content

Commit 4a82007

Browse files
committed
addressing review comments
1 parent d2ca987 commit 4a82007

File tree

3 files changed

+19
-174
lines changed

3 files changed

+19
-174
lines changed

docs/guide/ci-cd.md

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -440,40 +440,3 @@ All actions automatically configure:
440440
- **`NO_COLOR=1`** — clean log output without ANSI colors
441441

442442
## Best Practices
443-
444-
### Use Safety Mode
445-
446-
Enable [Safety Mode](/guide/security#operational-security-safety-mode) in CI/CD to prevent accidental destructive operations:
447-
448-
```yaml
449-
jobs:
450-
deploy:
451-
runs-on: ubuntu-latest
452-
env:
453-
# Prevent accidental deletions
454-
SFCC_SAFETY_LEVEL:NO_DELETE
455-
steps:
456-
- uses: SalesforceCommerceCloud/b2c-developer-tooling/actions/setup@v1
457-
- name: Deploy code
458-
run: b2c code deploy
459-
```
460-
461-
**Safety Levels for CI/CD:**
462-
463-
- **`NO_DELETE`** (Recommended for most CI/CD) - Prevents deletions but allows deployments and updates
464-
- **`NO_UPDATE`** (Strict) - Only allows read and create operations, blocks updates and deletions
465-
- **`READ_ONLY`** (Monitoring/Reporting) - Only allows read operations
466-
467-
**Example: Production deployment with safety:**
468-
```yaml
469-
deploy-production:
470-
environment: production
471-
env:
472-
SFCC_SAFETY_LEVEL: NO_DELETE
473-
steps:
474-
- name: Deploy
475-
run: |
476-
b2c code deploy # ✅ Allowed
477-
b2c sandbox start prod # ✅ Allowed
478-
b2c sandbox delete test # ❌ Blocked by safety mode
479-
```

docs/guide/security.md

Lines changed: 7 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,13 @@ This project uses [NPM trusted publishers](https://docs.npmjs.com/trusted-publis
6666

6767
## Operational Security: Safety Mode
6868

69-
The CLI includes a **Safety Mode** feature that prevents accidental or unwanted destructive operations. This is particularly important when:
69+
The CLI includes a **Safety Mode** feature via CLI checks and HTTP middleware that prevents accidental or unwanted destructive operations. This is particularly important when:
7070

71-
- Using the CLI in automated environments (CI/CD pipelines)
7271
- Providing the CLI as a tool to AI agents/LLMs
7372
- Working in production environments
7473
- Training new team members
7574
- Running commands from untrusted scripts
7675

77-
### How It Works
78-
79-
Safety Mode uses a **hybrid protection approach**:
80-
81-
1. **HTTP Middleware Layer** (Primary Protection)
82-
- Intercepts ALL HTTP requests before they're sent
83-
- Cannot be bypassed by command-line flags
84-
- Works automatically for all commands
85-
- LLM-proof: controlled via environment variable
86-
87-
2. **Command-Level Checks** (Better UX)
88-
- Provides early, user-friendly error messages
89-
- Catches operations before HTTP requests
90-
9176
### Safety Levels
9277

9378
Configure via the `SFCC_SAFETY_LEVEL` environment variable:
@@ -99,131 +84,23 @@ Configure via the `SFCC_SAFETY_LEVEL` environment variable:
9984
| `NO_UPDATE` | Prevent deletions and destructive updates | DELETE + reset/stop/restart |
10085
| `READ_ONLY` | Read-only mode | All writes (POST/PUT/PATCH/DELETE) |
10186

102-
### Usage Examples
87+
### Usage
10388

104-
#### Development (Allow Everything)
10589
```bash
106-
# No restrictions (default)
107-
unset SFCC_SAFETY_LEVEL
108-
# OR
90+
# Default - no restrictions
10991
export SFCC_SAFETY_LEVEL=NONE
11092
111-
b2c sandbox delete test-id # ✅ Allowed
112-
```
113-
114-
#### CI/CD (Prevent Deletions)
115-
```bash
116-
# Prevent accidental deletions in automated environments
93+
# Prevent deletions
11794
export SFCC_SAFETY_LEVEL=NO_DELETE
11895
119-
b2c sandbox create --realm test # ✅ Allowed
120-
b2c sandbox delete test-id # ❌ Blocked
121-
```
122-
123-
#### LLM/Agent Tools (Maximum Protection)
124-
```bash
125-
# Prevent AI agents from performing destructive operations
96+
# Prevent deletions and destructive updates
12697
export SFCC_SAFETY_LEVEL=NO_UPDATE
12798
128-
b2c sandbox list # ✅ Allowed
129-
b2c sandbox create --realm test # ✅ Allowed
130-
b2c sandbox delete test-id # ❌ Blocked
131-
b2c sandbox reset test-id # ❌ Blocked
132-
```
133-
134-
#### Monitoring/Reporting (Read-Only)
135-
```bash
136-
# Absolute read-only mode
99+
# Read-only mode
137100
export SFCC_SAFETY_LEVEL=READ_ONLY
138-
139-
b2c sandbox list # ✅ Allowed
140-
b2c sandbox get test-id # ✅ Allowed
141-
b2c sandbox create test # ❌ Blocked
142-
```
143-
144-
### What Gets Blocked
145-
146-
| Safety Level | DELETE | POST (create) | POST (reset) | PUT/PATCH | GET |
147-
|--------------|--------|---------------|--------------|-----------|-----|
148-
| **NONE** | ✅ | ✅ | ✅ | ✅ | ✅ |
149-
| **NO_DELETE** | ❌ | ✅ | ✅ | ✅ | ✅ |
150-
| **NO_UPDATE** | ❌ | ✅ | ❌ | ✅ | ✅ |
151-
| **READ_ONLY** | ❌ | ❌ | ❌ | ❌ | ✅ |
152-
153-
### Protected Commands
154-
155-
Safety Mode automatically protects ALL destructive commands across all topics:
156-
157-
- **Sandbox**: `delete`, `reset`, `alias delete`
158-
- **Account Manager**: `users delete`, `users reset`, `clients delete`
159-
- **Code**: `delete`
160-
- **MRT**: `project delete`, `env delete`, `env var delete`, `env redirect delete`, `project notification delete`
161-
- **SLAS**: `client delete`
162-
- **eCDN**: All delete operations (certificates, zones, rules, etc.)
163-
164-
### Why Environment Variable?
165-
166-
Environment variables are more secure than command-line flags because:
167-
168-
1. **LLMs Don't Control Them**: When an LLM uses the CLI as a tool, it controls commands and flags but NOT the environment
169-
2. **Session-Level**: Set once for the entire session/container
170-
3. **Audit Trail**: Can be logged and monitored in CI/CD
171-
4. **Cannot Be Bypassed**: Even `--force` flags don't override safety mode
172-
173-
### Error Messages
174-
175-
When an operation is blocked, you'll see clear error messages:
176-
177-
```bash
178-
export SFCC_SAFETY_LEVEL=NO_DELETE
179-
b2c sandbox delete test-id
180-
181-
# Error: Cannot delete sandbox: blocked by safety level NO_DELETE.
182-
#
183-
# Delete operations are blocked in NO_DELETE mode
184-
#
185-
# To allow this operation, unset or change the SFCC_SAFETY_LEVEL environment variable.
186-
```
187-
188-
### Best Practices
189-
190-
#### For CI/CD Pipelines
191-
```yaml
192-
# GitHub Actions example
193-
- name: Deploy to Production
194-
env:
195-
SFCC_SAFETY_LEVEL: NO_DELETE # Prevent accidental deletions
196-
run: |
197-
b2c code deploy
198-
b2c sandbox start production
199-
```
200-
201-
#### For AI Agent Tools
202-
```bash
203-
# Provide CLI to LLMs with safety enabled
204-
export SFCC_SAFETY_LEVEL=NO_UPDATE
205-
# LLMs can now read and create, but cannot delete or reset
206-
```
207-
208-
#### For Production Environments
209-
```bash
210-
# Set in shell profile for production access
211-
echo 'export SFCC_SAFETY_LEVEL=NO_UPDATE' >> ~/.bashrc
212-
```
213-
214-
### Testing Safety Mode
215-
216-
Verify safety mode is working:
217-
218-
```bash
219-
export SFCC_SAFETY_LEVEL=NO_DELETE
220-
b2c sandbox delete fake-id
221-
222-
# Expected: "blocked by safety level NO_DELETE"
223-
# NOT expected: Authentication error or API call
224101
```
225102

226-
For comprehensive testing, see [GitHub Issue #67](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/issues/67).
103+
Environment variables are used instead of command-line flags because LLMs control commands and flags, but not the environment.
227104

228105
## Best Practices
229106

packages/b2c-tooling-sdk/src/cli/base-command.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
AuthMiddlewareHookOptions,
1717
AuthMiddlewareHookResult,
1818
} from './hooks.js';
19-
import {setLanguage} from '../i18n/index.js';
19+
import {setLanguage, t} from '../i18n/index.js';
2020
import {configureLogger, getLogger, type LogLevel, type Logger} from '../logging/index.js';
2121
import {createExtraParamsMiddleware, createSafetyMiddleware, type ExtraParamsConfig} from '../clients/middleware.js';
2222
import {getSafetyLevel, describeSafetyLevel} from '../safety/index.js';
@@ -621,7 +621,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
621621
return; // No restrictions
622622
}
623623

624-
const operation = operationDescription || 'this destructive operation';
624+
const operation = operationDescription || t('base.destructiveOperation', 'this destructive operation');
625625

626626
// Determine if this operation should be blocked
627627
// We assume all calls to this method are for destructive operations
@@ -632,11 +632,16 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
632632
const shouldBlock = safetyLevel === 'READ_ONLY' || safetyLevel === 'NO_DELETE' || safetyLevel === 'NO_UPDATE';
633633

634634
if (shouldBlock) {
635-
this.error(
636-
`Cannot ${operation}: blocked by safety level ${safetyLevel}.\n\n` +
637-
`${describeSafetyLevel(safetyLevel)}\n\n` +
638-
`To allow this operation, unset or change the SFCC_SAFETY_LEVEL environment variable.\n` +
639-
`See: https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/issues/67`,
635+
return this.error(
636+
t(
637+
'base.safetyModeBlocked',
638+
'Cannot {{operation}}: blocked by safety level {{safetyLevel}}.\n\n{{description}}\n\nTo allow this operation, unset or change the SFCC_SAFETY_LEVEL environment variable.\nSee: https://salesforcecommercecloud.github.io/b2c-developer-tooling/guide/security#operational-security-safety-mode',
639+
{
640+
operation,
641+
safetyLevel,
642+
description: describeSafetyLevel(safetyLevel),
643+
},
644+
),
640645
{exit: 1},
641646
);
642647
}

0 commit comments

Comments
 (0)