@friggframework/devtools 2.0.0--canary.413.39a9576.0 → 2.0.0--canary.414.451bd3d.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,10 +14,10 @@ npx frigg generate-iam [options]
14
14
 
15
15
  ### Options
16
16
 
17
- - `-o, --output <path>` - Output directory (default: `backend/infrastructure`)
18
- - `-u, --user <name>` - Deployment user name (default: `frigg-deployment-user`)
19
- - `-s, --stack-name <name>` - CloudFormation stack name (default: `frigg-deployment-iam`)
20
- - `-v, --verbose` - Enable verbose output
17
+ - `-o, --output <path>` - Output directory (default: `backend/infrastructure`)
18
+ - `-u, --user <name>` - Deployment user name (default: `frigg-deployment-user`)
19
+ - `-s, --stack-name <name>` - CloudFormation stack name (default: `frigg-deployment-iam`)
20
+ - `-v, --verbose` - Enable verbose output
21
21
 
22
22
  ### Examples
23
23
 
@@ -40,38 +40,33 @@ npx frigg generate-iam --verbose
40
40
  The command analyzes your `backend/index.js` AppDefinition and generates IAM policies based on:
41
41
 
42
42
  ### Always Included (Core Features)
43
-
44
- - **CloudFormation** - Stack management permissions
45
- - **Lambda** - Function deployment and management
46
- - **IAM** - Role creation and management for Lambda functions
47
- - **S3** - Deployment bucket access
48
- - **SQS/SNS** - Messaging services
49
- - **CloudWatch/Logs** - Monitoring and logging
50
- - **API Gateway** - REST API management
43
+ - **CloudFormation** - Stack management permissions
44
+ - **Lambda** - Function deployment and management
45
+ - **IAM** - Role creation and management for Lambda functions
46
+ - **S3** - Deployment bucket access
47
+ - **SQS/SNS** - Messaging services
48
+ - **CloudWatch/Logs** - Monitoring and logging
49
+ - **API Gateway** - REST API management
51
50
 
52
51
  ### Conditionally Included (Based on AppDefinition)
53
52
 
54
53
  #### VPC Support (`vpc.enable: true`)
55
-
56
- - VPC endpoint creation and management
57
- - NAT Gateway creation and management
58
- - Route table and security group management
59
- - Elastic IP allocation
54
+ - VPC endpoint creation and management
55
+ - NAT Gateway creation and management
56
+ - Route table and security group management
57
+ - Elastic IP allocation
60
58
 
61
59
  #### KMS Encryption (`encryption.useDefaultKMSForFieldLevelEncryption: true`)
62
-
63
- - KMS key usage for Lambda and S3
64
- - Data encryption and decryption permissions
60
+ - KMS key usage for Lambda and S3
61
+ - Data encryption and decryption permissions
65
62
 
66
63
  #### SSM Parameter Store (`ssm.enable: true`)
67
-
68
- - Parameter retrieval permissions
69
- - Scoped to parameters containing "frigg" in the path
64
+ - Parameter retrieval permissions
65
+ - Scoped to parameters containing "frigg" in the path
70
66
 
71
67
  #### WebSocket Support (`websockets.enable: true`)
72
-
73
- - Currently included in core permissions
74
- - API Gateway WebSocket management
68
+ - Currently included in core permissions
69
+ - API Gateway WebSocket management
75
70
 
76
71
  ## Sample AppDefinition Analysis
77
72
 
@@ -82,27 +77,26 @@ const appDefinition = {
82
77
  name: 'my-integration-app',
83
78
  integrations: [AsanaIntegration, SlackIntegration],
84
79
  vpc: {
85
- enable: true,
80
+ enable: true
86
81
  },
87
82
  encryption: {
88
- useDefaultKMSForFieldLevelEncryption: true,
83
+ useDefaultKMSForFieldLevelEncryption: true
89
84
  },
90
85
  ssm: {
91
- enable: false,
86
+ enable: false
92
87
  },
93
88
  websockets: {
94
- enable: true,
95
- },
89
+ enable: true
90
+ }
96
91
  };
97
92
  ```
98
93
 
99
94
  The command will generate:
100
-
101
- - Core deployment permissions
102
- - VPC management permissions
103
- - KMS encryption permissions
104
- - SSM Parameter Store permissions (disabled)
105
- - ✅ WebSocket permissions (via core)
95
+ - ✅ Core deployment permissions
96
+ - VPC management permissions
97
+ - KMS encryption permissions
98
+ - SSM Parameter Store permissions (disabled)
99
+ - WebSocket permissions (via core)
106
100
 
107
101
  ## Generated File Structure
108
102
 
@@ -116,32 +110,26 @@ backend/infrastructure/
116
110
  ## Security Benefits
117
111
 
118
112
  ### Principle of Least Privilege
119
-
120
- - Only includes permissions your app actually uses
121
- - Scoped resource patterns (e.g., only resources containing "frigg")
122
- - No unnecessary cloud service permissions
113
+ - Only includes permissions your app actually uses
114
+ - Scoped resource patterns (e.g., only resources containing "frigg")
115
+ - No unnecessary cloud service permissions
123
116
 
124
117
  ### Resource Scoping
125
-
126
118
  All permissions are scoped to resources following naming patterns:
127
-
128
- - `*frigg*` - General Frigg resources
129
- - `*serverless*` - Deployment buckets
130
- - `internal-error-queue-*` - Error handling queues
119
+ - `*frigg*` - General Frigg resources
120
+ - `*serverless*` - Deployment buckets
121
+ - `internal-error-queue-*` - Error handling queues
131
122
 
132
123
  ### Conditional Policies
133
-
134
124
  Feature-specific policies are only created when:
135
-
136
- - The feature is enabled in your AppDefinition
137
- - CloudFormation conditions control policy attachment
125
+ - The feature is enabled in your AppDefinition
126
+ - CloudFormation conditions control policy attachment
138
127
 
139
128
  ## Deployment Workflow
140
129
 
141
130
  After generating the template:
142
131
 
143
132
  ### 1. Deploy the Stack
144
-
145
133
  ```bash
146
134
  aws cloudformation deploy \
147
135
  --template-file backend/infrastructure/frigg-deployment-iam.yaml \
@@ -151,7 +139,6 @@ aws cloudformation deploy \
151
139
  ```
152
140
 
153
141
  ### 2. Retrieve Access Key
154
-
155
142
  ```bash
156
143
  aws cloudformation describe-stacks \
157
144
  --stack-name frigg-deployment-iam \
@@ -160,7 +147,6 @@ aws cloudformation describe-stacks \
160
147
  ```
161
148
 
162
149
  ### 3. Get Secret Access Key
163
-
164
150
  ```bash
165
151
  aws secretsmanager get-secret-value \
166
152
  --secret-id frigg-deployment-credentials \
@@ -169,18 +155,15 @@ aws secretsmanager get-secret-value \
169
155
  ```
170
156
 
171
157
  ### 4. Configure CI/CD
172
-
173
158
  Add the credentials to your deployment environment:
174
-
175
- - GitHub Actions: Repository secrets
176
- - GitLab CI: Environment variables
177
- - Jenkins: Credentials manager
178
- - Local: AWS credentials file
159
+ - GitHub Actions: Repository secrets
160
+ - GitLab CI: Environment variables
161
+ - Jenkins: Credentials manager
162
+ - Local: AWS credentials file
179
163
 
180
164
  ## Troubleshooting
181
165
 
182
166
  ### Command Not Found
183
-
184
167
  ```bash
185
168
  # Install dependencies
186
169
  npm install
@@ -190,42 +173,37 @@ ls backend/index.js
190
173
  ```
191
174
 
192
175
  ### No AppDefinition Found
193
-
194
- - Ensure `backend/index.js` exports a `Definition` object
195
- - Check that the Definition follows the correct structure
176
+ - Ensure `backend/index.js` exports a `Definition` object
177
+ - Check that the Definition follows the correct structure
196
178
 
197
179
  ### Permission Errors During Deployment
198
-
199
- - Ensure your AWS CLI is configured with admin permissions
200
- - Add `--capabilities CAPABILITY_NAMED_IAM` to deployment commands
180
+ - Ensure your AWS CLI is configured with admin permissions
181
+ - Add `--capabilities CAPABILITY_NAMED_IAM` to deployment commands
201
182
 
202
183
  ### Generated Policy Too Restrictive
203
-
204
- - Check that your resources follow naming conventions (contain "frigg")
205
- - Enable additional features in your AppDefinition if needed
206
- - Review the generated template for resource patterns
184
+ - Check that your resources follow naming conventions (contain "frigg")
185
+ - Enable additional features in your AppDefinition if needed
186
+ - Review the generated template for resource patterns
207
187
 
208
188
  ## Comparison with Generic Template
209
189
 
210
- | Aspect | Generic Template | Generated Template |
211
- | --------------- | ---------------- | --------------------- |
212
- | Size | ~15KB | ~8-12KB (varies) |
213
- | Permissions | All features | Only enabled features |
214
- | Security | Broad access | Scoped access |
215
- | Maintenance | Manual updates | Auto-generated |
216
- | Deployment Risk | Over-privileged | Least privilege |
190
+ | Aspect | Generic Template | Generated Template |
191
+ |--------|-----------------|-------------------|
192
+ | Size | ~15KB | ~8-12KB (varies) |
193
+ | Permissions | All features | Only enabled features |
194
+ | Security | Broad access | Scoped access |
195
+ | Maintenance | Manual updates | Auto-generated |
196
+ | Deployment Risk | Over-privileged | Least privilege |
217
197
 
218
198
  ## Integration with Development Workflow
219
199
 
220
200
  ### Local Development
221
-
222
201
  1. Update AppDefinition
223
202
  2. Run `npx frigg generate-iam`
224
203
  3. Deploy updated IAM stack
225
204
  4. Test deployment with new permissions
226
205
 
227
206
  ### CI/CD Pipeline
228
-
229
207
  ```yaml
230
208
  # GitHub Actions example
231
209
  - name: Generate IAM Template
@@ -233,17 +211,16 @@ ls backend/index.js
233
211
 
234
212
  - name: Deploy IAM Stack
235
213
  run: |
236
- aws cloudformation deploy \
237
- --template-file backend/infrastructure/frigg-deployment-iam.yaml \
238
- --stack-name ${{ env.STACK_NAME }} \
239
- --capabilities CAPABILITY_NAMED_IAM
214
+ aws cloudformation deploy \
215
+ --template-file backend/infrastructure/frigg-deployment-iam.yaml \
216
+ --stack-name ${{ env.STACK_NAME }} \
217
+ --capabilities CAPABILITY_NAMED_IAM
240
218
  ```
241
219
 
242
220
  ### Version Control
243
-
244
- - Commit generated templates to version control
245
- - Review changes in pull requests
246
- - Track permission changes over time
221
+ - Commit generated templates to version control
222
+ - Review changes in pull requests
223
+ - Track permission changes over time
247
224
 
248
225
  ## Best Practices
249
226
 
@@ -256,23 +233,21 @@ ls backend/index.js
256
233
  ## Advanced Usage
257
234
 
258
235
  ### Custom Parameter Values
259
-
260
236
  ```bash
261
237
  # Enable all features regardless of AppDefinition
262
238
  npx frigg generate-iam --verbose
263
239
 
264
240
  # Then manually edit the generated template to set:
265
241
  # EnableVPCSupport: true
266
- # EnableKMSSupport: true
242
+ # EnableKMSSupport: true
267
243
  # EnableSSMSupport: true
268
244
  ```
269
245
 
270
246
  ### Multiple Environments
271
-
272
247
  ```bash
273
248
  # Generate for different environments
274
249
  npx frigg generate-iam --stack-name my-app-dev-iam --output ./aws/dev
275
250
  npx frigg generate-iam --stack-name my-app-prod-iam --output ./aws/prod
276
251
  ```
277
252
 
278
- This command helps you maintain secure, minimal IAM policies that evolve with your application requirements.
253
+ This command helps you maintain secure, minimal IAM policies that evolve with your application requirements.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Environment variable validator for Frigg applications
3
+ * Validates that required environment variables are present based on appDefinition
4
+ */
5
+
6
+ /**
7
+ * Validate environment variables against appDefinition
8
+ * @param {Object} AppDefinition - Application definition with environment config
9
+ * @returns {Object} Validation results with valid, missing, and warnings arrays
10
+ */
11
+ const validateEnvironmentVariables = (AppDefinition) => {
12
+ const results = {
13
+ valid: [],
14
+ missing: [],
15
+ warnings: []
16
+ };
17
+
18
+ if (!AppDefinition.environment) {
19
+ return results;
20
+ }
21
+
22
+ console.log('🔍 Validating environment variables...');
23
+
24
+ for (const [key, value] of Object.entries(AppDefinition.environment)) {
25
+ if (value === true) {
26
+ if (process.env[key]) {
27
+ results.valid.push(key);
28
+ } else {
29
+ results.missing.push(key);
30
+ }
31
+ }
32
+ }
33
+
34
+ // Special handling for certain variables
35
+ if (results.missing.includes('NODE_ENV')) {
36
+ results.warnings.push('NODE_ENV not set, defaulting to "production"');
37
+ // Remove from missing since it has a default
38
+ results.missing = results.missing.filter(v => v !== 'NODE_ENV');
39
+ }
40
+
41
+ // Report results
42
+ if (results.valid.length > 0) {
43
+ console.log(` ✅ Valid: ${results.valid.length} environment variables found`);
44
+ }
45
+
46
+ if (results.missing.length > 0) {
47
+ console.log(` ⚠️ Missing: ${results.missing.join(', ')}`);
48
+ results.warnings.push(`Missing ${results.missing.length} environment variables. These should be set in your CI/CD environment or .env file`);
49
+ }
50
+
51
+ if (results.warnings.length > 0) {
52
+ results.warnings.forEach(warning => {
53
+ console.log(` ⚠️ ${warning}`);
54
+ });
55
+ }
56
+
57
+ return results;
58
+ };
59
+
60
+ /**
61
+ * Check if all required environment variables are present
62
+ * @param {Object} AppDefinition - Application definition
63
+ * @returns {boolean} True if all required variables are present
64
+ */
65
+ const hasAllRequiredEnvVars = (AppDefinition) => {
66
+ const results = validateEnvironmentVariables(AppDefinition);
67
+ return results.missing.length === 0;
68
+ };
69
+
70
+ module.exports = {
71
+ validateEnvironmentVariables,
72
+ hasAllRequiredEnvVars
73
+ };
@@ -257,26 +257,6 @@ Resources:
257
257
  - 'arn:aws:apigateway:*::/restapis/*'
258
258
  - 'arn:aws:apigateway:*::/domainnames'
259
259
  - 'arn:aws:apigateway:*::/domainnames/*'
260
-
261
- # API Gateway v2 permissions
262
- - Sid: 'FriggAPIGatewayV2'
263
- Effect: Allow
264
- Action:
265
- - 'apigateway:GET'
266
- - 'apigateway:DELETE'
267
- - 'apigateway:PATCH'
268
- - 'apigateway:POST'
269
- - 'apigateway:PUT'
270
- Resource:
271
- - 'arn:aws:apigateway:*::/apis'
272
- - 'arn:aws:apigateway:*::/apis/*'
273
- - 'arn:aws:apigateway:*::/apis/*/stages'
274
- - 'arn:aws:apigateway:*::/apis/*/stages/*'
275
- - 'arn:aws:apigateway:*::/apis/*/mappings'
276
- - 'arn:aws:apigateway:*::/apis/*/mappings/*'
277
- - 'arn:aws:apigateway:*::/domainnames'
278
- - 'arn:aws:apigateway:*::/domainnames/*'
279
- - 'arn:aws:apigateway:*::/domainnames/*/apimappings'
280
260
 
281
261
  # VPC-specific permissions
282
262
  FriggVPCPolicy:
@@ -317,8 +297,6 @@ Resources:
317
297
  - 'ec2:CreateTags'
318
298
  - 'ec2:DeleteTags'
319
299
  - 'ec2:DescribeTags'
320
- - 'ec2:DetachInternetGateway'
321
- - 'ec2:DeleteSubnet'
322
300
  Resource: '*'
323
301
 
324
302
  # KMS permissions