serverless-plugin-module-registry 1.0.8 → 1.0.9

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/README.md CHANGED
@@ -540,6 +540,74 @@ Look for `[module-registry]` prefixed logs for plugin-specific information.
540
540
  - Policy ARNs resolved at deployment time
541
541
  - No runtime AWS API calls for policy management
542
542
 
543
+ ## 🔐 Tenant Role Creation
544
+
545
+ The module registry provides a utility function to create IAM roles for tenant onboarding with ABAC (Attribute-Based Access Control) tags.
546
+
547
+ ### Usage
548
+
549
+ ```typescript
550
+ import { createTenantRoles } from 'serverless-plugin-module-registry/tenant'
551
+
552
+ // During tenant onboarding
553
+ const roleArns = await createTenantRoles({
554
+ tenantId: 'acme',
555
+ identityPoolId: 'us-east-1:12345678-1234-1234-1234-123456789012',
556
+ modules: ['sign', 'workforce'], // Optional: filter to specific modules
557
+ config: {
558
+ tableName: 'ModuleRegistry',
559
+ region: 'us-east-1',
560
+ policyPrefix: 'api'
561
+ },
562
+ logger: {
563
+ info: (msg, data) => console.log(msg, data),
564
+ warning: (msg, data) => console.warn(msg, data),
565
+ error: (msg, err) => console.error(msg, err)
566
+ }
567
+ })
568
+
569
+ console.log(roleArns)
570
+ // {
571
+ // authenticated: "arn:aws:iam::123456789012:role/api-acme-authenticated",
572
+ // unauthenticated: "arn:aws:iam::123456789012:role/api-acme-unauthenticated"
573
+ // }
574
+ ```
575
+
576
+ ### What It Does
577
+
578
+ 1. **Discovers Roles**: Queries DynamoDB to find all role types (authenticated, unauthenticated, admin, etc.)
579
+ 2. **Collects Features**: For each role, gathers all module features and builds ABAC tags
580
+ 3. **Creates IAM Roles**: Creates roles with proper Cognito trust policies and ABAC tags
581
+ 4. **Attaches Policies**: Attaches module ManagedPolicies to roles
582
+ 5. **Registers with Cognito**: Attaches roles to the Cognito Identity Pool
583
+
584
+ ### Role Naming Convention
585
+
586
+ Roles follow the pattern: `{policyPrefix}-{tenantId}-{roleType}`
587
+
588
+ Examples:
589
+ - `api-acme-authenticated`
590
+ - `api-acme-unauthenticated`
591
+ - `api-acme-admin`
592
+
593
+ ### ABAC Tags
594
+
595
+ Each role is tagged with module features in the format:
596
+ ```
597
+ {moduleName}Features: "feature1:feature2:feature3"
598
+ ```
599
+
600
+ Example tags:
601
+ - `signFeatures`: `"7tmARMbS:BRUBT2SN:F8d3wY_v"`
602
+ - `workforceFeatures`: `"abc123:def456:ghi789"`
603
+
604
+ ### Idempotency
605
+
606
+ The function is idempotent - it can be called multiple times safely:
607
+ - Existing roles are updated with new tags and policies
608
+ - No duplicate roles are created
609
+ - Cognito attachment is updated if needed
610
+
543
611
  ## 🔒 Security Considerations
544
612
 
545
613
  ### IAM Policies
@@ -547,6 +615,7 @@ Look for `[module-registry]` prefixed logs for plugin-specific information.
547
615
  - Generated policies follow **least privilege** principle
548
616
  - Endpoint-specific resource ARNs (not wildcards)
549
617
  - Custom policies allow fine-grained permission control
618
+ - Tenant roles use Cognito Identity Pool trust policies
550
619
 
551
620
  ### Access Control
552
621
 
package/dist/index.d.ts CHANGED
@@ -252,6 +252,43 @@ declare class AIRegistryGenerator {
252
252
  private cleanFeatureKey;
253
253
  }
254
254
 
255
+ /**
256
+ * Type definitions for Tenant Role Creation
257
+ */
258
+ interface RoleSpec {
259
+ roleName: string;
260
+ tags: Record<string, string>;
261
+ policyArns: string[];
262
+ }
263
+ interface CreateTenantRolesParams {
264
+ tenantId: string;
265
+ identityPoolId: string;
266
+ modules?: string[];
267
+ config: {
268
+ tableName: string;
269
+ region: string;
270
+ policyPrefix: string;
271
+ };
272
+ logger: {
273
+ info: (message: string, data?: any) => void;
274
+ warning: (message: string, data?: any) => void;
275
+ error: (message: string, error?: any) => void;
276
+ };
277
+ }
278
+ interface TenantRoleArns {
279
+ [roleName: string]: string;
280
+ }
281
+
282
+ /**
283
+ * Tenant Role Creator
284
+ * Creates IAM roles with ABAC tags and Cognito Identity Pool registration
285
+ */
286
+
287
+ /**
288
+ * Main function to create tenant IAM roles with ABAC tags
289
+ */
290
+ declare function createTenantRoles(params: CreateTenantRolesParams): Promise<TenantRoleArns>;
291
+
255
292
  /**
256
293
  * Serverless Module Registry Plugin
257
294
  * -------------------------------------------
@@ -413,6 +450,11 @@ declare class ServerlessModuleRegistryPlugin {
413
450
  * Ensure DynamoDB table exists using AWS SDK v3, then update registry data
414
451
  */
415
452
  private ensureTableAndUpdateData;
453
+ /**
454
+ * Deploy internal infrastructure (DynamoDB table, Streams, SQS, Lambda processors)
455
+ * Runs BEFORE main deployment to ensure table exists
456
+ */
457
+ private deployInternalInfrastructure;
416
458
  /**
417
459
  * Handler for the registryGenerate command
418
460
  */
@@ -423,4 +465,4 @@ declare class ServerlessModuleRegistryPlugin {
423
465
  private generateServicePackageCommand;
424
466
  }
425
467
 
426
- export { AIRegistryGenerator, ServerlessModuleRegistryPlugin, createCustomFeature, createModuleRegistryLogger, ServerlessModuleRegistryPlugin as default, generateAbacTags, generateAllModuleAbacPolicies, generateModuleAbacPolicy, getAllEndpoints, getFeatureById, getFeatureDetails, getModuleFeatures, getModuleMetadata, getNonCustomEndpoints, getRequiredModulePolicyArns, listAllModules };
468
+ export { AIRegistryGenerator, type CreateTenantRolesParams, type RoleSpec, ServerlessModuleRegistryPlugin, type TenantRoleArns, createCustomFeature, createModuleRegistryLogger, createTenantRoles, ServerlessModuleRegistryPlugin as default, generateAbacTags, generateAllModuleAbacPolicies, generateModuleAbacPolicy, getAllEndpoints, getFeatureById, getFeatureDetails, getModuleFeatures, getModuleMetadata, getNonCustomEndpoints, getRequiredModulePolicyArns, listAllModules };