@friggframework/devtools 2.0.0--canary.398.e2147f7.0 → 2.0.0--canary.398.c9e5d61.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.
- package/frigg-cli/build-command/index.js +25 -2
- package/frigg-cli/deploy-command/index.js +26 -2
- package/frigg-cli/generate-iam-command.js +115 -0
- package/frigg-cli/index.js +11 -1
- package/infrastructure/AWS-DISCOVERY-TROUBLESHOOTING.md +245 -0
- package/infrastructure/AWS-IAM-CREDENTIAL-NEEDS.md +23 -3
- package/infrastructure/DEPLOYMENT-INSTRUCTIONS.md +268 -0
- package/infrastructure/GENERATE-IAM-DOCS.md +253 -0
- package/infrastructure/WEBSOCKET-CONFIGURATION.md +105 -0
- package/infrastructure/aws-discovery.js +24 -3
- package/infrastructure/build-time-discovery.js +10 -1
- package/infrastructure/frigg-deployment-iam-stack.yaml +370 -0
- package/infrastructure/iam-generator.js +644 -0
- package/infrastructure/iam-generator.test.js +169 -0
- package/infrastructure/run-discovery.js +108 -0
- package/infrastructure/serverless-template.js +47 -20
- package/package.json +6 -5
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# Frigg IAM Deployment Instructions
|
|
2
|
+
|
|
3
|
+
This guide explains how to deploy the IAM CloudFormation stack to create the necessary AWS credentials for your Frigg deployment pipeline.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- AWS CLI installed and configured with administrator privileges
|
|
8
|
+
- AWS account ID
|
|
9
|
+
- Appropriate permissions to create IAM resources
|
|
10
|
+
|
|
11
|
+
## Deployment Steps
|
|
12
|
+
|
|
13
|
+
You can deploy the stack using either the AWS Management Console (UI) or AWS CLI.
|
|
14
|
+
|
|
15
|
+
### Option A: Deploy via AWS Management Console (UI)
|
|
16
|
+
|
|
17
|
+
#### 1. Upload and Create Stack
|
|
18
|
+
|
|
19
|
+
1. Log in to the [AWS Management Console](https://console.aws.amazon.com/)
|
|
20
|
+
2. Navigate to **CloudFormation** service
|
|
21
|
+
3. Click **Create stack** → **With new resources (standard)**
|
|
22
|
+
4. In the **Specify template** section:
|
|
23
|
+
- Select **Upload a template file**
|
|
24
|
+
- Click **Choose file** and select `frigg-deployment-iam-stack.yaml`
|
|
25
|
+
- Click **Next**
|
|
26
|
+
|
|
27
|
+
#### 2. Configure Stack Details
|
|
28
|
+
|
|
29
|
+
1. **Stack name**: Enter `frigg-deployment-iam`
|
|
30
|
+
2. **Parameters**:
|
|
31
|
+
- **DeploymentUserName**: `frigg-deployment-user` (or customize)
|
|
32
|
+
- **EnableVPCSupport**: `true`
|
|
33
|
+
- **EnableKMSSupport**: `true`
|
|
34
|
+
- **EnableSSMSupport**: `true`
|
|
35
|
+
3. Click **Next**
|
|
36
|
+
|
|
37
|
+
#### 3. Configure Stack Options
|
|
38
|
+
|
|
39
|
+
1. Leave all options as default (or configure tags if needed)
|
|
40
|
+
2. Click **Next**
|
|
41
|
+
|
|
42
|
+
#### 4. Review and Create
|
|
43
|
+
|
|
44
|
+
1. Review all settings
|
|
45
|
+
2. **Important**: Check the box that says **"I acknowledge that AWS CloudFormation might create IAM resources with custom names"**
|
|
46
|
+
3. Click **Submit**
|
|
47
|
+
4. Wait for the stack to reach **CREATE_COMPLETE** status (usually 2-3 minutes)
|
|
48
|
+
|
|
49
|
+
#### 5. Retrieve Credentials from Console
|
|
50
|
+
|
|
51
|
+
1. Once the stack is created, click on the stack name
|
|
52
|
+
2. Go to the **Outputs** tab
|
|
53
|
+
3. Note the **AccessKeyId** value
|
|
54
|
+
4. To get the Secret Access Key:
|
|
55
|
+
- Click on the **Resources** tab
|
|
56
|
+
- Find **FriggDeploymentCredentials** and click on its Physical ID link
|
|
57
|
+
- This will take you to AWS Secrets Manager
|
|
58
|
+
- Click **Retrieve secret value**
|
|
59
|
+
- Copy the **SecretAccessKey** value
|
|
60
|
+
|
|
61
|
+
### Option B: Deploy via AWS CLI
|
|
62
|
+
|
|
63
|
+
#### 1. Deploy the CloudFormation Stack
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
aws cloudformation deploy \
|
|
67
|
+
--template-file frigg-deployment-iam-stack.yaml \
|
|
68
|
+
--stack-name frigg-deployment-iam \
|
|
69
|
+
--capabilities CAPABILITY_NAMED_IAM \
|
|
70
|
+
--parameter-overrides \
|
|
71
|
+
DeploymentUserName=frigg-deployment-user \
|
|
72
|
+
EnableVPCSupport=true \
|
|
73
|
+
EnableKMSSupport=true \
|
|
74
|
+
EnableSSMSupport=true
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### 2. Retrieve Deployment Credentials
|
|
78
|
+
|
|
79
|
+
After successful deployment, retrieve the credentials:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Get the Access Key ID
|
|
83
|
+
aws cloudformation describe-stacks \
|
|
84
|
+
--stack-name frigg-deployment-iam \
|
|
85
|
+
--query 'Stacks[0].Outputs[?OutputKey==`AccessKeyId`].OutputValue' \
|
|
86
|
+
--output text
|
|
87
|
+
|
|
88
|
+
# Get the Secret Access Key from Secrets Manager
|
|
89
|
+
aws secretsmanager get-secret-value \
|
|
90
|
+
--secret-id frigg-deployment-credentials \
|
|
91
|
+
--query SecretString \
|
|
92
|
+
--output text | jq -r .SecretAccessKey
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 3. Configure CI/CD Environment
|
|
96
|
+
|
|
97
|
+
#### GitHub Actions
|
|
98
|
+
|
|
99
|
+
Add these secrets to your GitHub repository:
|
|
100
|
+
|
|
101
|
+
1. Go to Settings → Secrets and variables → Actions
|
|
102
|
+
2. Add new repository secrets:
|
|
103
|
+
- `AWS_ACCESS_KEY_ID`: The Access Key ID from step 2
|
|
104
|
+
- `AWS_SECRET_ACCESS_KEY`: The Secret Access Key from step 2
|
|
105
|
+
|
|
106
|
+
Example GitHub Actions workflow:
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
name: Deploy Frigg Application
|
|
110
|
+
on:
|
|
111
|
+
push:
|
|
112
|
+
branches: [main]
|
|
113
|
+
|
|
114
|
+
jobs:
|
|
115
|
+
deploy:
|
|
116
|
+
runs-on: ubuntu-latest
|
|
117
|
+
steps:
|
|
118
|
+
- uses: actions/checkout@v3
|
|
119
|
+
|
|
120
|
+
- name: Configure AWS credentials
|
|
121
|
+
uses: aws-actions/configure-aws-credentials@v2
|
|
122
|
+
with:
|
|
123
|
+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
124
|
+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
125
|
+
aws-region: us-east-1
|
|
126
|
+
|
|
127
|
+
- name: Install dependencies
|
|
128
|
+
run: npm install
|
|
129
|
+
|
|
130
|
+
- name: Deploy Frigg application
|
|
131
|
+
run: npx frigg deploy
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### GitLab CI/CD
|
|
135
|
+
|
|
136
|
+
Add variables in Settings → CI/CD → Variables:
|
|
137
|
+
|
|
138
|
+
```yaml
|
|
139
|
+
deploy:
|
|
140
|
+
image: node:18
|
|
141
|
+
before_script:
|
|
142
|
+
- npm install
|
|
143
|
+
script:
|
|
144
|
+
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
|
|
145
|
+
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
|
|
146
|
+
- export AWS_REGION=us-east-1
|
|
147
|
+
- npx frigg deploy
|
|
148
|
+
only:
|
|
149
|
+
- main
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Jenkins
|
|
153
|
+
|
|
154
|
+
Store credentials in Jenkins Credentials Manager and use in pipeline:
|
|
155
|
+
|
|
156
|
+
```groovy
|
|
157
|
+
pipeline {
|
|
158
|
+
agent any
|
|
159
|
+
environment {
|
|
160
|
+
AWS_ACCESS_KEY_ID = credentials('frigg-aws-access-key-id')
|
|
161
|
+
AWS_SECRET_ACCESS_KEY = credentials('frigg-aws-secret-access-key')
|
|
162
|
+
AWS_REGION = 'us-east-1'
|
|
163
|
+
}
|
|
164
|
+
stages {
|
|
165
|
+
stage('Deploy') {
|
|
166
|
+
steps {
|
|
167
|
+
sh 'npm install'
|
|
168
|
+
sh 'npx frigg deploy'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 4. Local Development Setup
|
|
176
|
+
|
|
177
|
+
For local development, configure AWS CLI profile:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# Option 1: Use AWS CLI configure
|
|
181
|
+
aws configure --profile frigg-deployment
|
|
182
|
+
# Enter the Access Key ID and Secret Access Key when prompted
|
|
183
|
+
|
|
184
|
+
# Option 2: Add to ~/.aws/credentials manually
|
|
185
|
+
[frigg-deployment]
|
|
186
|
+
aws_access_key_id = YOUR_ACCESS_KEY_ID
|
|
187
|
+
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Use the profile in your deployment:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
export AWS_PROFILE=frigg-deployment
|
|
194
|
+
npx frigg deploy
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Stack Parameters
|
|
198
|
+
|
|
199
|
+
- **DeploymentUserName**: Name of the IAM user (default: `frigg-deployment-user`)
|
|
200
|
+
- **EnableVPCSupport**: Enable VPC-related permissions (default: `true`)
|
|
201
|
+
- **EnableKMSSupport**: Enable KMS encryption permissions (default: `true`)
|
|
202
|
+
- **EnableSSMSupport**: Enable SSM Parameter Store permissions (default: `true`)
|
|
203
|
+
|
|
204
|
+
## Security Best Practices
|
|
205
|
+
|
|
206
|
+
1. **Rotate Credentials Regularly**: Create a new access key periodically and update your CI/CD systems
|
|
207
|
+
2. **Use Separate Stacks**: Deploy separate stacks for dev, staging, and production environments
|
|
208
|
+
3. **Enable MFA**: For production deployments, consider using IAM roles with MFA requirements
|
|
209
|
+
4. **Audit Access**: Regularly review CloudTrail logs for deployment activities
|
|
210
|
+
|
|
211
|
+
## Updating the Stack
|
|
212
|
+
|
|
213
|
+
To update permissions or parameters:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
aws cloudformation update-stack \
|
|
217
|
+
--stack-name frigg-deployment-iam \
|
|
218
|
+
--template-body file://frigg-deployment-iam-stack.yaml \
|
|
219
|
+
--capabilities CAPABILITY_NAMED_IAM \
|
|
220
|
+
--parameter-overrides \
|
|
221
|
+
EnableVPCSupport=false # Example: disable VPC support
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Deleting the Stack
|
|
225
|
+
|
|
226
|
+
⚠️ **Warning**: This will delete the IAM user and all associated access keys!
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# First, delete any access keys manually
|
|
230
|
+
aws iam delete-access-key \
|
|
231
|
+
--user-name frigg-deployment-user \
|
|
232
|
+
--access-key-id YOUR_ACCESS_KEY_ID
|
|
233
|
+
|
|
234
|
+
# Then delete the stack
|
|
235
|
+
aws cloudformation delete-stack --stack-name frigg-deployment-iam
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Troubleshooting
|
|
239
|
+
|
|
240
|
+
### Permission Denied Errors
|
|
241
|
+
|
|
242
|
+
If you encounter permission errors during deployment:
|
|
243
|
+
|
|
244
|
+
1. Check that the IAM user name follows the pattern `*frigg*`
|
|
245
|
+
2. Ensure your resources (Lambda functions, stacks) include "frigg" in their names
|
|
246
|
+
3. Verify the correct AWS region is configured
|
|
247
|
+
|
|
248
|
+
### Discovery Failures
|
|
249
|
+
|
|
250
|
+
If AWS resource discovery fails during build:
|
|
251
|
+
|
|
252
|
+
1. Verify the deployment user has the discovery permissions
|
|
253
|
+
2. Check that default VPC and subnets exist in your region
|
|
254
|
+
3. Review build logs for specific error messages
|
|
255
|
+
|
|
256
|
+
### Stack Creation Failures
|
|
257
|
+
|
|
258
|
+
Common issues:
|
|
259
|
+
|
|
260
|
+
- **CAPABILITY_NAMED_IAM required**: Add `--capabilities CAPABILITY_NAMED_IAM` to deploy command
|
|
261
|
+
- **User already exists**: Choose a different `DeploymentUserName` parameter
|
|
262
|
+
- **Policy limit exceeded**: AWS accounts have limits on managed policies; consider consolidating
|
|
263
|
+
|
|
264
|
+
## Additional Resources
|
|
265
|
+
|
|
266
|
+
- [AWS IAM Best Practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
|
|
267
|
+
- [Frigg Documentation](https://github.com/friggframework/frigg)
|
|
268
|
+
- [AWS CloudFormation Documentation](https://docs.aws.amazon.com/cloudformation/)
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Generate IAM Command
|
|
2
|
+
|
|
3
|
+
The `frigg generate-iam` command creates a customized IAM CloudFormation template based on your specific Frigg application configuration.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Instead of using a generic IAM policy that includes all possible permissions, this command analyzes your AppDefinition and generates an IAM stack that only includes the permissions your application actually needs.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx frigg generate-iam [options]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Options
|
|
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
|
|
21
|
+
|
|
22
|
+
### Examples
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Generate with defaults
|
|
26
|
+
npx frigg generate-iam
|
|
27
|
+
|
|
28
|
+
# Specify custom output directory
|
|
29
|
+
npx frigg generate-iam --output ./aws-infrastructure
|
|
30
|
+
|
|
31
|
+
# Custom user name and stack name
|
|
32
|
+
npx frigg generate-iam --user my-app-deployer --stack-name my-app-iam
|
|
33
|
+
|
|
34
|
+
# Verbose output
|
|
35
|
+
npx frigg generate-iam --verbose
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## What Gets Generated
|
|
39
|
+
|
|
40
|
+
The command analyzes your `backend/index.js` AppDefinition and generates IAM policies based on:
|
|
41
|
+
|
|
42
|
+
### Always Included (Core Features)
|
|
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
|
|
50
|
+
|
|
51
|
+
### Conditionally Included (Based on AppDefinition)
|
|
52
|
+
|
|
53
|
+
#### VPC Support (`vpc.enable: true`)
|
|
54
|
+
- VPC endpoint creation and management
|
|
55
|
+
- NAT Gateway creation and management
|
|
56
|
+
- Route table and security group management
|
|
57
|
+
- Elastic IP allocation
|
|
58
|
+
|
|
59
|
+
#### KMS Encryption (`encryption.useDefaultKMSForFieldLevelEncryption: true`)
|
|
60
|
+
- KMS key usage for Lambda and S3
|
|
61
|
+
- Data encryption and decryption permissions
|
|
62
|
+
|
|
63
|
+
#### SSM Parameter Store (`ssm.enable: true`)
|
|
64
|
+
- Parameter retrieval permissions
|
|
65
|
+
- Scoped to parameters containing "frigg" in the path
|
|
66
|
+
|
|
67
|
+
#### WebSocket Support (`websockets.enable: true`)
|
|
68
|
+
- Currently included in core permissions
|
|
69
|
+
- API Gateway WebSocket management
|
|
70
|
+
|
|
71
|
+
## Sample AppDefinition Analysis
|
|
72
|
+
|
|
73
|
+
Given this AppDefinition:
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
const appDefinition = {
|
|
77
|
+
name: 'my-integration-app',
|
|
78
|
+
integrations: [AsanaIntegration, SlackIntegration],
|
|
79
|
+
vpc: {
|
|
80
|
+
enable: true
|
|
81
|
+
},
|
|
82
|
+
encryption: {
|
|
83
|
+
useDefaultKMSForFieldLevelEncryption: true
|
|
84
|
+
},
|
|
85
|
+
ssm: {
|
|
86
|
+
enable: false
|
|
87
|
+
},
|
|
88
|
+
websockets: {
|
|
89
|
+
enable: true
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The command will generate:
|
|
95
|
+
- ✅ Core deployment permissions
|
|
96
|
+
- ✅ VPC management permissions
|
|
97
|
+
- ✅ KMS encryption permissions
|
|
98
|
+
- ❌ SSM Parameter Store permissions (disabled)
|
|
99
|
+
- ✅ WebSocket permissions (via core)
|
|
100
|
+
|
|
101
|
+
## Generated File Structure
|
|
102
|
+
|
|
103
|
+
The command creates:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
backend/infrastructure/
|
|
107
|
+
├── frigg-deployment-iam.yaml # Main CloudFormation template
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Security Benefits
|
|
111
|
+
|
|
112
|
+
### Principle of Least Privilege
|
|
113
|
+
- Only includes permissions your app actually uses
|
|
114
|
+
- Scoped resource patterns (e.g., only resources containing "frigg")
|
|
115
|
+
- No unnecessary cloud service permissions
|
|
116
|
+
|
|
117
|
+
### Resource Scoping
|
|
118
|
+
All permissions are scoped to resources following naming patterns:
|
|
119
|
+
- `*frigg*` - General Frigg resources
|
|
120
|
+
- `*serverless*` - Deployment buckets
|
|
121
|
+
- `internal-error-queue-*` - Error handling queues
|
|
122
|
+
|
|
123
|
+
### Conditional Policies
|
|
124
|
+
Feature-specific policies are only created when:
|
|
125
|
+
- The feature is enabled in your AppDefinition
|
|
126
|
+
- CloudFormation conditions control policy attachment
|
|
127
|
+
|
|
128
|
+
## Deployment Workflow
|
|
129
|
+
|
|
130
|
+
After generating the template:
|
|
131
|
+
|
|
132
|
+
### 1. Deploy the Stack
|
|
133
|
+
```bash
|
|
134
|
+
aws cloudformation deploy \
|
|
135
|
+
--template-file backend/infrastructure/frigg-deployment-iam.yaml \
|
|
136
|
+
--stack-name frigg-deployment-iam \
|
|
137
|
+
--capabilities CAPABILITY_NAMED_IAM \
|
|
138
|
+
--parameter-overrides DeploymentUserName=frigg-deployment-user
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 2. Retrieve Access Key
|
|
142
|
+
```bash
|
|
143
|
+
aws cloudformation describe-stacks \
|
|
144
|
+
--stack-name frigg-deployment-iam \
|
|
145
|
+
--query 'Stacks[0].Outputs[?OutputKey==`AccessKeyId`].OutputValue' \
|
|
146
|
+
--output text
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 3. Get Secret Access Key
|
|
150
|
+
```bash
|
|
151
|
+
aws secretsmanager get-secret-value \
|
|
152
|
+
--secret-id frigg-deployment-credentials \
|
|
153
|
+
--query SecretString \
|
|
154
|
+
--output text | jq -r .SecretAccessKey
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 4. Configure CI/CD
|
|
158
|
+
Add the credentials to your deployment environment:
|
|
159
|
+
- GitHub Actions: Repository secrets
|
|
160
|
+
- GitLab CI: Environment variables
|
|
161
|
+
- Jenkins: Credentials manager
|
|
162
|
+
- Local: AWS credentials file
|
|
163
|
+
|
|
164
|
+
## Troubleshooting
|
|
165
|
+
|
|
166
|
+
### Command Not Found
|
|
167
|
+
```bash
|
|
168
|
+
# Install dependencies
|
|
169
|
+
npm install
|
|
170
|
+
|
|
171
|
+
# Ensure you're in a Frigg project
|
|
172
|
+
ls backend/index.js
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### No AppDefinition Found
|
|
176
|
+
- Ensure `backend/index.js` exports a `Definition` object
|
|
177
|
+
- Check that the Definition follows the correct structure
|
|
178
|
+
|
|
179
|
+
### Permission Errors During Deployment
|
|
180
|
+
- Ensure your AWS CLI is configured with admin permissions
|
|
181
|
+
- Add `--capabilities CAPABILITY_NAMED_IAM` to deployment commands
|
|
182
|
+
|
|
183
|
+
### Generated Policy Too Restrictive
|
|
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
|
|
187
|
+
|
|
188
|
+
## Comparison with Generic Template
|
|
189
|
+
|
|
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 |
|
|
197
|
+
|
|
198
|
+
## Integration with Development Workflow
|
|
199
|
+
|
|
200
|
+
### Local Development
|
|
201
|
+
1. Update AppDefinition
|
|
202
|
+
2. Run `npx frigg generate-iam`
|
|
203
|
+
3. Deploy updated IAM stack
|
|
204
|
+
4. Test deployment with new permissions
|
|
205
|
+
|
|
206
|
+
### CI/CD Pipeline
|
|
207
|
+
```yaml
|
|
208
|
+
# GitHub Actions example
|
|
209
|
+
- name: Generate IAM Template
|
|
210
|
+
run: npx frigg generate-iam
|
|
211
|
+
|
|
212
|
+
- name: Deploy IAM Stack
|
|
213
|
+
run: |
|
|
214
|
+
aws cloudformation deploy \
|
|
215
|
+
--template-file backend/infrastructure/frigg-deployment-iam.yaml \
|
|
216
|
+
--stack-name ${{ env.STACK_NAME }} \
|
|
217
|
+
--capabilities CAPABILITY_NAMED_IAM
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Version Control
|
|
221
|
+
- Commit generated templates to version control
|
|
222
|
+
- Review changes in pull requests
|
|
223
|
+
- Track permission changes over time
|
|
224
|
+
|
|
225
|
+
## Best Practices
|
|
226
|
+
|
|
227
|
+
1. **Regenerate After Changes** - Run the command whenever you modify your AppDefinition
|
|
228
|
+
2. **Review Generated Templates** - Check the generated YAML before deployment
|
|
229
|
+
3. **Test Deployments** - Verify your app can deploy with the generated permissions
|
|
230
|
+
4. **Environment Separation** - Use different stack names for dev/staging/prod
|
|
231
|
+
5. **Regular Audits** - Periodically review and minimize permissions
|
|
232
|
+
|
|
233
|
+
## Advanced Usage
|
|
234
|
+
|
|
235
|
+
### Custom Parameter Values
|
|
236
|
+
```bash
|
|
237
|
+
# Enable all features regardless of AppDefinition
|
|
238
|
+
npx frigg generate-iam --verbose
|
|
239
|
+
|
|
240
|
+
# Then manually edit the generated template to set:
|
|
241
|
+
# EnableVPCSupport: true
|
|
242
|
+
# EnableKMSSupport: true
|
|
243
|
+
# EnableSSMSupport: true
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Multiple Environments
|
|
247
|
+
```bash
|
|
248
|
+
# Generate for different environments
|
|
249
|
+
npx frigg generate-iam --stack-name my-app-dev-iam --output ./aws/dev
|
|
250
|
+
npx frigg generate-iam --stack-name my-app-prod-iam --output ./aws/prod
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
This command helps you maintain secure, minimal IAM policies that evolve with your application requirements.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# WebSocket Configuration for Frigg Applications
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
WebSockets in Frigg applications are now **disabled by default** and can be enabled through the AppDefinition configuration. This allows applications that don't need real-time communication to avoid deploying unnecessary WebSocket infrastructure.
|
|
6
|
+
|
|
7
|
+
## Enabling WebSockets
|
|
8
|
+
|
|
9
|
+
To enable WebSocket support in your Frigg application, add the `websockets` configuration to your AppDefinition:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// backend/index.js
|
|
13
|
+
const appDefinition = {
|
|
14
|
+
integrations: [YourIntegration],
|
|
15
|
+
websockets: {
|
|
16
|
+
enable: true // Enable WebSocket support
|
|
17
|
+
},
|
|
18
|
+
// ... other configuration
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
Definition: appDefinition,
|
|
23
|
+
};
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## What Happens When WebSockets Are Enabled
|
|
27
|
+
|
|
28
|
+
When you set `websockets.enable: true`, the following resources are deployed:
|
|
29
|
+
|
|
30
|
+
1. **WebSocket API Gateway** - AWS API Gateway WebSocket endpoint
|
|
31
|
+
2. **Lambda Functions** - Handlers for `$connect`, `$disconnect`, and `$default` routes
|
|
32
|
+
3. **Database Collection** - MongoDB collection to store active WebSocket connections
|
|
33
|
+
4. **Environment Variable** - `WEBSOCKET_API_ENDPOINT` is automatically configured
|
|
34
|
+
|
|
35
|
+
## Using WebSockets in Your Application
|
|
36
|
+
|
|
37
|
+
Once enabled, you can use the `WebsocketConnection` model to send messages to connected clients:
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
const { WebsocketConnection } = require('@friggframework/core');
|
|
41
|
+
|
|
42
|
+
// Get all active connections and send a message
|
|
43
|
+
const connections = await WebsocketConnection.getActiveConnections();
|
|
44
|
+
for (const connection of connections) {
|
|
45
|
+
await connection.send({
|
|
46
|
+
type: 'update',
|
|
47
|
+
data: { message: 'Hello from server!' }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Default Behavior (WebSockets Disabled)
|
|
53
|
+
|
|
54
|
+
When websockets are disabled (the default):
|
|
55
|
+
- No WebSocket infrastructure is deployed
|
|
56
|
+
- `WebsocketConnection.getActiveConnections()` returns an empty array
|
|
57
|
+
- No `WEBSOCKET_API_ENDPOINT` environment variable is set
|
|
58
|
+
- No additional Lambda functions or API Gateway resources are created
|
|
59
|
+
|
|
60
|
+
## Use Cases for WebSockets
|
|
61
|
+
|
|
62
|
+
Enable WebSockets when you need:
|
|
63
|
+
- Real-time updates for integration sync status
|
|
64
|
+
- Live streaming of data processing progress
|
|
65
|
+
- Push notifications to connected clients
|
|
66
|
+
- Real-time collaboration features
|
|
67
|
+
|
|
68
|
+
## Cost Considerations
|
|
69
|
+
|
|
70
|
+
Disabling WebSockets by default helps reduce costs by:
|
|
71
|
+
- Avoiding API Gateway WebSocket charges when not needed
|
|
72
|
+
- Reducing Lambda function invocations
|
|
73
|
+
- Eliminating unnecessary database operations for connection management
|
|
74
|
+
|
|
75
|
+
## Migration Guide
|
|
76
|
+
|
|
77
|
+
If you have an existing Frigg application that uses WebSockets:
|
|
78
|
+
|
|
79
|
+
1. Add the websockets configuration to your AppDefinition:
|
|
80
|
+
```javascript
|
|
81
|
+
websockets: {
|
|
82
|
+
enable: true
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2. Redeploy your application:
|
|
87
|
+
```bash
|
|
88
|
+
npx frigg deploy
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Your WebSocket functionality will continue to work as before.
|
|
92
|
+
|
|
93
|
+
## Troubleshooting
|
|
94
|
+
|
|
95
|
+
### WebSocket Connection Errors
|
|
96
|
+
If you see errors related to WebSocket connections, ensure:
|
|
97
|
+
1. WebSockets are enabled in your AppDefinition
|
|
98
|
+
2. The application has been redeployed after enabling WebSockets
|
|
99
|
+
3. The `WEBSOCKET_API_ENDPOINT` environment variable is set (automatically done during deployment)
|
|
100
|
+
|
|
101
|
+
### WebsocketConnection.getActiveConnections() Returns Empty Array
|
|
102
|
+
This is expected behavior when:
|
|
103
|
+
- WebSockets are disabled (default)
|
|
104
|
+
- No clients are currently connected
|
|
105
|
+
- The `WEBSOCKET_API_ENDPOINT` environment variable is not set
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
let EC2Client, DescribeVpcsCommand, DescribeSubnetsCommand, DescribeSecurityGroupsCommand, DescribeRouteTablesCommand;
|
|
2
|
+
let KMSClient, ListKeysCommand, DescribeKeyCommand;
|
|
3
|
+
let STSClient, GetCallerIdentityCommand;
|
|
4
|
+
|
|
5
|
+
function loadEC2() {
|
|
6
|
+
if (!EC2Client) {
|
|
7
|
+
({ EC2Client, DescribeVpcsCommand, DescribeSubnetsCommand, DescribeSecurityGroupsCommand, DescribeRouteTablesCommand } = require('@aws-sdk/client-ec2'));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function loadKMS() {
|
|
12
|
+
if (!KMSClient) {
|
|
13
|
+
({ KMSClient, ListKeysCommand, DescribeKeyCommand } = require('@aws-sdk/client-kms'));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function loadSTS() {
|
|
18
|
+
if (!STSClient) {
|
|
19
|
+
({ STSClient, GetCallerIdentityCommand } = require('@aws-sdk/client-sts'));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
4
22
|
|
|
5
23
|
/**
|
|
6
24
|
* AWS Resource Discovery utilities for Frigg applications
|
|
@@ -13,6 +31,9 @@ class AWSDiscovery {
|
|
|
13
31
|
*/
|
|
14
32
|
constructor(region = 'us-east-1') {
|
|
15
33
|
this.region = region;
|
|
34
|
+
loadEC2();
|
|
35
|
+
loadKMS();
|
|
36
|
+
loadSTS();
|
|
16
37
|
this.ec2Client = new EC2Client({ region });
|
|
17
38
|
this.kmsClient = new KMSClient({ region });
|
|
18
39
|
this.stsClient = new STSClient({ region });
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
|
|
3
|
+
let AWSDiscovery;
|
|
4
|
+
|
|
5
|
+
function loadAWSDiscovery() {
|
|
6
|
+
if (!AWSDiscovery) {
|
|
7
|
+
({ AWSDiscovery } = require('./aws-discovery'));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
12
|
* Build-time AWS resource discovery and configuration injection
|
|
@@ -13,6 +19,7 @@ class BuildTimeDiscovery {
|
|
|
13
19
|
* @param {string} [region=process.env.AWS_REGION || 'us-east-1'] - AWS region for discovery
|
|
14
20
|
*/
|
|
15
21
|
constructor(region = process.env.AWS_REGION || 'us-east-1') {
|
|
22
|
+
loadAWSDiscovery();
|
|
16
23
|
this.region = region;
|
|
17
24
|
this.discovery = new AWSDiscovery(region);
|
|
18
25
|
}
|
|
@@ -140,6 +147,7 @@ class BuildTimeDiscovery {
|
|
|
140
147
|
}
|
|
141
148
|
|
|
142
149
|
// Create discovery instance with specified region
|
|
150
|
+
loadAWSDiscovery();
|
|
143
151
|
const discovery = new AWSDiscovery(region);
|
|
144
152
|
const resources = await discovery.discoverResources();
|
|
145
153
|
|
|
@@ -149,6 +157,7 @@ class BuildTimeDiscovery {
|
|
|
149
157
|
AWS_DISCOVERY_SECURITY_GROUP_ID: resources.defaultSecurityGroupId,
|
|
150
158
|
AWS_DISCOVERY_SUBNET_ID_1: resources.privateSubnetId1,
|
|
151
159
|
AWS_DISCOVERY_SUBNET_ID_2: resources.privateSubnetId2,
|
|
160
|
+
AWS_DISCOVERY_PUBLIC_SUBNET_ID: resources.publicSubnetId,
|
|
152
161
|
AWS_DISCOVERY_ROUTE_TABLE_ID: resources.privateRouteTableId,
|
|
153
162
|
AWS_DISCOVERY_KMS_KEY_ID: resources.defaultKmsKeyId
|
|
154
163
|
};
|