UNPKG

@fntio/infra-client

Version:

Self-hosted AWS access portal: credential vending, target-account trust, and grant-driven private networking as CDK stacks and constructs.

190 lines (189 loc) • 9.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addAccessPortal = addAccessPortal; const registration_1 = require("./plugins/registration"); const audit_log_1 = require("./audit-log"); const data_stack_1 = require("./data-stack"); const creds_stack_1 = require("./creds-stack"); const web_stack_1 = require("./web-stack"); const web_cert_stack_1 = require("./web-cert-stack"); const network_stack_1 = require("./network-stack"); const network_validation_1 = require("./network-validation"); const dimensions_validation_1 = require("./dimensions-validation"); const personal_access_tokens_1 = require("./personal-access-tokens"); const dashboard_layout_1 = require("./dashboard-layout"); const web_acl_1 = require("./constructs/web-acl"); const api_throttle_1 = require("./api-throttle"); const role_session_name_1 = require("./role-session-name"); const federation_1 = require("./federation"); /** Every hub stack as one unit — NOT a `cdk.Stage`: a Stage prefixes every * construct path, renaming physical names and replacing live resources. */ function addAccessPortal(scope, props) { const { project, resourcePrefix, sites } = props; const env = { account: project.env.account, region: project.env.region }; (0, network_validation_1.assertValidResourcePrefix)(resourcePrefix); // Without this the VPN feature deploys silently absent (/network → 501). if (project.network && !sites) { throw new Error("project.network is set but no `sites` were passed — resolve them with " + "resolveSites(project.network) and pass them in."); } // Zone names here are compared with endsWith() and joined into record // names — a trailing dot never matches and builds off-by-one FQDNs. for (const [label, zoneName] of Object.entries({ "issuer.zoneName": project.issuer.zoneName, "email.zoneName": project.email?.zoneName, "web.zoneName": project.web?.zoneName, "network.zoneName": project.network?.zoneName, })) { if (zoneName?.endsWith(".")) { throw new Error(`${label} ("${zoneName}") must not end with a dot.`); } } const waf = (0, web_acl_1.resolveWaf)(project.waf); const apiThrottle = (0, api_throttle_1.resolveApiThrottle)(project.apiThrottle); const roleSessionName = (0, role_session_name_1.resolveRoleSessionName)(project.roleSessionName); const plugins = (0, registration_1.resolvePlugins)(project.plugins, props.plugins); const auditRetentionDays = (0, audit_log_1.resolveAuditRetentionDays)(project.audit); // Validated once, consumed by both stacks (pool attributes + trigger; provider + client). const federation = (0, federation_1.resolveFederation)(project.loginMethods.federation, project.env.region); // Security Hub CloudFormation.3 for prod; a prod teardown lifts it first // (runbook "Tear down"). const hubStack = { env, terminationProtection: project.prod }; const dataStack = new data_stack_1.DataStack(scope, "DataStack", { ...hubStack, prod: project.prod, email: project.email ? { dmarcReportEmail: (0, creds_stack_1.resolveAlertEmails)(project.alertEmail)[0], ...project.email } : undefined, }); // CloudFront only takes certs and WAF web ACLs from us-east-1, wherever // the app deploys — hence the companion stack + cross-region references. // Always present: the issuer's certificate is minted there. const webCertStack = new web_cert_stack_1.WebCertStack(scope, "WebCertStack", { ...hubStack, env: { account: project.env.account, region: "us-east-1" }, crossRegionReferences: true, resourcePrefix, issuer: project.issuer, web: project.web, waf, }); // Dev shares ride the network block: no sites, no shares (validated even when disabled). const devShares = project.network && sites ? (0, network_validation_1.resolveDevShares)(project.network.devShares) : undefined; // Validated even when disabled; only an ENABLED block reaches the API env and config.json. const dimensions = (0, dimensions_validation_1.resolveAccountDimensions)(project.accountDimensions); const accountDimensions = dimensions?.enabled ? dimensions : undefined; const tokens = (0, personal_access_tokens_1.resolvePersonalAccessTokens)(project.personalAccessTokens); const personalAccessTokens = tokens?.enabled ? tokens : undefined; const dashboardLayout = (0, dashboard_layout_1.resolveDashboardLayout)(project.dashboard); const credsStack = new creds_stack_1.CredsStack(scope, "CredsStack", { ...hubStack, crossRegionReferences: true, resourcePrefix, prod: project.prod, passkeyDomain: project.web?.domainName, appUrl: project.web ? `https://${project.web.domainName}` : undefined, accountsTable: dataStack.accountsTable, rolesTable: dataStack.rolesTable, requestsTable: dataStack.requestsTable, auditTable: dataStack.auditTable, auditRetentionDays, groupsTable: dataStack.groupsTable, resourcesTable: dataStack.resourcesTable, accessTable: dataStack.accessTable, revocationsTable: dataStack.revocationsTable, serviceUsersTable: dataStack.serviceUsersTable, tokensTable: dataStack.tokensTable, personalAccessTokens, roleSessionName, plugins: plugins && { ...plugins, catalogTable: dataStack.pluginCatalogTable, assetsBucket: dataStack.pluginAssetsBucket }, loginMethods: project.loginMethods, federation, firstAdmin: project.firstAdmin, projectName: project.projectName, issuer: { keyVersions: [1], signerVersion: 1, ...project.issuer, certificate: webCertStack.issuerCertificate, webAclArn: webCertStack.issuerWebAclArn, }, alertEmail: project.alertEmail, email: project.email, waf, apiThrottle, accessLogsBucket: dataStack.accessLogsBucket, configAccounts: Object.entries(project.rolesByAccount).map(([accountNumber, roles]) => ({ accountNumber, roles: roles.map((r) => r.roleName), })), networkSites: sites?.map((s) => ({ id: s.id, displayName: s.displayName, controlUrl: s.controlUrl, accounts: s.accounts, splitDns: s.splitDns, connectorVpcs: s.connectorVpcs, })), // Only an ENABLED block reaches the API env — absent = the routes answer 501. devShares: devShares?.enabled ? devShares : undefined, accountDimensions, dashboardLayout, }); const webStack = new web_stack_1.WebStack(scope, "WebStack", { ...hubStack, crossRegionReferences: true, resourcePrefix, api: credsStack.api, userPool: credsStack.userPool, branding: { projectName: project.projectName, ...project.branding }, mfa: project.loginMethods.mfa, passkey: project.loginMethods.passkey, federation, web: project.web, certificate: webCertStack.certificate, webAclArn: webCertStack.webAclArn, // VPN is opt-in: without sites the web app hides its Network pages. network: !!(project.network && sites), // Only an ENABLED block reaches config.json — absent = the UI hides the feature. devShares: devShares?.enabled ? devShares : undefined, accountDimensions, personalAccessTokens, webAssetPath: props.webAssetPath, plugins: plugins && { discoveryRefreshSeconds: plugins.discoveryRefreshSeconds, assetsBucketName: dataStack.pluginAssetsBucket.bucketName, }, accessLogsBucket: dataStack.accessLogsBucket, }); // Site ids and control-plane URLs are permanent once anything enrolls (same class of invariant // as the issuer). let networkStack; if (project.network && sites) { networkStack = new network_stack_1.NetworkStack(scope, "NetworkStack", { ...hubStack, resourcePrefix, hostedZoneId: project.network.hostedZoneId, zoneName: project.network.zoneName, subdomain: project.network.subdomain, sites, prod: project.prod, containerInsights: project.network.containerInsights, mirrorImages: project.network.mirrorImages, resourcesTable: dataStack.resourcesTable, accessTable: dataStack.accessTable, groupsTable: dataStack.groupsTable, accessLogsBucket: dataStack.accessLogsBucket, alertTopic: credsStack.alertTopic, auditLog: { table: dataStack.auditTable, retentionDays: auditRetentionDays }, }); // Which site a connector joins is decided by which minter its account // may invoke; redeploy NetworkStack after editing the lists. for (const site of sites) { for (const principal of site.connectorAccounts) { networkStack.grantConnectorAccount(site.id, principal); } } } return { dataStack, credsStack, webCertStack, webStack, networkStack }; }