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.

65 lines (64 loc) • 3.23 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.synthTargetAccountTemplate = synthTargetAccountTemplate; const fs = __importStar(require("node:fs")); const os = __importStar(require("node:os")); const path = __importStar(require("node:path")); const cdk = __importStar(require("aws-cdk-lib")); const target_account_trust_1 = require("./constructs/target-account-trust"); /** The target-account trust as a plain CloudFormation template that deploys into any account with nothing * prepared there: no account id baked in (the role-scoped sub pin resolves through `AWS::AccountId`), a native * `AWS::IAM::OIDCProvider` instead of CDK's asset-backed custom resource, no bootstrap bucket, no parameters. * For accounts the hub has never seen — a StackSet over an OU, or the account-creation pipeline's * CloudFormation step; an account that already runs `Roles-<acct>` keeps that stack. The hub registers the * account afterwards with the role names used here. */ function synthTargetAccountTemplate(props) { // The cloud assembly is a by-product: synthesize into a scratch dir and remove it. const outdir = fs.mkdtempSync(path.join(os.tmpdir(), "target-account-template-")); try { const app = new cdk.App({ analyticsReporting: false, outdir }); const stack = new cdk.Stack(app, "TargetAccountTemplate", { stackName: "RolesStack", analyticsReporting: false, synthesizer: new cdk.DefaultStackSynthesizer({ generateBootstrapVersionRule: false }), }); (0, target_account_trust_1.addTargetAccountTrust)(stack, { issuerUrl: props.issuerUrl, roles: props.roles, nativeProvider: true }); return app.synth().getStackArtifact(stack.artifactId).template; } finally { fs.rmSync(outdir, { recursive: true, force: true }); } }