Skip to content

Commit 51e8bef

Browse files
authored
Consolidate strict mode validation into strict_mode_validation.go (#3492)
1 parent 3fb8d73 commit 51e8bef

5 files changed

Lines changed: 65 additions & 92 deletions

File tree

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ When adding validation logic, follow the established architecture:
148148
- Repository-level feature detection
149149

150150
**Domain-specific validation** (dedicated files):
151-
- `strict_mode.go` - Security and strict mode enforcement
152-
- `pip.go` - Python package validation
153-
- `npm.go` - NPM package validation
151+
- `strict_mode_validation.go` - Security and strict mode enforcement
152+
- `pip_validation.go` - Python package validation
153+
- `npm_validation.go` - NPM package validation
154+
- `docker_validation.go` - Docker image validation
154155
- `expression_safety.go` - GitHub Actions expression security
155156
- `engine.go` - AI engine configuration
156157
- `mcp-config.go` - MCP server configuration
157-
- `docker.go` - Docker image validation
158158
- `template.go` - Template structure validation
159159

160160
**When to create a new validation file**:

pkg/workflow/strict_mode.go

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
// Package workflow provides strict mode security validation for agentic workflows.
22
//
3-
// # Strict Mode Validation Functions
3+
// # Strict Mode Validation
44
//
5-
// This file contains the individual validation functions that enforce security
5+
// This file contains strict mode validation functions that enforce security
66
// and safety constraints when workflows are compiled with the --strict flag.
7-
// These functions are called by validateStrictMode() in strict_mode.go.
7+
//
8+
// Strict mode is designed for production workflows that require enhanced security
9+
// guarantees. It enforces constraints on:
10+
// - Write permissions on sensitive scopes
11+
// - Network access configuration
12+
// - Custom MCP server network settings
13+
// - Bash wildcard tool usage
814
//
915
// # Validation Functions
1016
//
1117
// The strict mode validator performs progressive validation:
12-
// 1. validateStrictPermissions() - Refuses write permissions on sensitive scopes
13-
// 2. validateStrictNetwork() - Requires explicit network configuration
14-
// 3. validateStrictMCPNetwork() - Requires network config on custom MCP servers
18+
// 1. validateStrictMode() - Main orchestrator that coordinates all strict mode checks
19+
// 2. validateStrictPermissions() - Refuses write permissions on sensitive scopes
20+
// 3. validateStrictNetwork() - Requires explicit network configuration
21+
// 4. validateStrictMCPNetwork() - Requires network config on custom MCP servers
1522
//
1623
// # Integration with Security Scanners
1724
//
@@ -28,7 +35,6 @@
2835
// - It enforces tool usage restrictions for security
2936
//
3037
// For general validation, see validation.go.
31-
// For the main strict mode orchestrator, see strict_mode.go.
3238
// For detailed documentation, see specs/validation-architecture.md
3339
package workflow
3440

@@ -118,3 +124,37 @@ func (c *Compiler) validateStrictMCPNetwork(frontmatter map[string]any) error {
118124

119125
return nil
120126
}
127+
128+
// validateStrictMode performs strict mode validations on the workflow
129+
//
130+
// This is the main orchestrator that calls individual validation functions.
131+
// It performs progressive validation:
132+
// 1. validateStrictPermissions() - Refuses write permissions on sensitive scopes
133+
// 2. validateStrictNetwork() - Requires explicit network configuration
134+
// 3. validateStrictMCPNetwork() - Requires network config on custom MCP servers
135+
//
136+
// Note: Strict mode also affects zizmor security scanner behavior (see pkg/cli/zizmor.go)
137+
// When zizmor is enabled with --zizmor flag, strict mode will treat any security
138+
// findings as compilation errors rather than warnings.
139+
func (c *Compiler) validateStrictMode(frontmatter map[string]any, networkPermissions *NetworkPermissions) error {
140+
if !c.strictMode {
141+
return nil
142+
}
143+
144+
// 1. Refuse write permissions
145+
if err := c.validateStrictPermissions(frontmatter); err != nil {
146+
return err
147+
}
148+
149+
// 2. Require network configuration and refuse "*" wildcard
150+
if err := c.validateStrictNetwork(networkPermissions); err != nil {
151+
return err
152+
}
153+
154+
// 3. Require network configuration on custom MCP servers
155+
if err := c.validateStrictMCPNetwork(frontmatter); err != nil {
156+
return err
157+
}
158+
159+
return nil
160+
}

pkg/workflow/validation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// This file contains general-purpose validation functions that apply across the entire
66
// workflow system. For domain-specific validation (e.g., strict mode, package validation,
77
// expression safety), see the corresponding domain files:
8-
// - strict_mode.go: Security and strict mode validation
9-
// - pip.go: Python package validation
10-
// - npm.go: NPM package validation
8+
// - strict_mode_validation.go: Security and strict mode validation
9+
// - pip_validation.go: Python package validation
10+
// - npm_validation.go: NPM package validation
11+
// - docker_validation.go: Docker image validation
1112
// - expression_safety.go: GitHub Actions expression security
1213
// - engine.go: AI engine configuration validation
1314
// - mcp-config.go: MCP server configuration validation
14-
// - docker_validation.go: Docker image validation
1515
// - template.go: Template structure validation
1616
//
1717
// # When to Add Validation Here

specs/validation-architecture.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,22 @@ This architecture balances maintainability with domain expertise, allowing valid
4242

4343
Domain-specific validation is organized into separate files based on functional area:
4444

45-
#### 1. **Strict Mode Validation**: `strict_mode.go` and `validation_strict_mode.go`
45+
#### 1. **Strict Mode Validation**: `strict_mode_validation.go`
4646

47-
**Location**:
48-
- `pkg/workflow/strict_mode.go` (70 lines) - Main orchestrator
49-
- `pkg/workflow/validation_strict_mode.go` (170 lines) - Individual validation functions
47+
**Location**: `pkg/workflow/strict_mode_validation.go` (190 lines)
5048

5149
**Purpose**: Enforces security and safety constraints in strict mode
5250

5351
**Validation Functions**:
54-
- `validateStrictMode()` - Main strict mode orchestrator (in `strict_mode.go`)
55-
- `validateStrictPermissions()` - Refuses write permissions (in `validation_strict_mode.go`)
56-
- `validateStrictNetwork()` - Requires explicit network configuration (in `validation_strict_mode.go`)
57-
- `validateStrictMCPNetwork()` - Requires network config on custom MCP servers (in `validation_strict_mode.go`)
58-
- `validateStrictBashTools()` - Refuses bash wildcard tools (in `validation_strict_mode.go`)
52+
- `validateStrictMode()` - Main strict mode orchestrator
53+
- `validateStrictPermissions()` - Refuses write permissions
54+
- `validateStrictNetwork()` - Requires explicit network configuration
55+
- `validateStrictMCPNetwork()` - Requires network config on custom MCP servers
56+
- `validateStrictBashTools()` - Refuses bash wildcard tools
5957

6058
**Pattern**: Security policy enforcement with progressive validation
6159

62-
**Architecture**: The strict mode validation is split across two files for better organization:
63-
- `strict_mode.go` contains the main orchestrator that coordinates validation
64-
- `validation_strict_mode.go` contains the individual validation function implementations
60+
**Architecture**: All strict mode validation logic is consolidated in a single file following the `*_validation.go` naming pattern used throughout the codebase
6561

6662
**When to add validation here**:
6763
- ✅ Strict mode security policies
@@ -200,7 +196,7 @@ Use this decision tree to determine where to place new validation logic:
200196
┌───────────────┐
201197
│ Is it about │
202198
│ security or │ YES
203-
│ strict mode? ├──────────► strict_mode.go
199+
│ strict mode? ├──────────► strict_mode_validation.go
204200
└───────┬───────┘
205201
│ NO
206202
@@ -332,7 +328,7 @@ func (c *Compiler) validateGitHubActionsSchema(yamlContent string) error {
332328

333329
### Pattern 4: Progressive Validation
334330

335-
**Used in**: `strict_mode.go`
331+
**Used in**: `strict_mode_validation.go`
336332

337333
**Purpose**: Apply multiple validation checks in sequence
338334

0 commit comments

Comments
 (0)