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.

91 lines (90 loc) • 3.98 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.WebCertStack = void 0; const cdk = __importStar(require("aws-cdk-lib")); const acm = __importStar(require("aws-cdk-lib/aws-certificatemanager")); const route53 = __importStar(require("aws-cdk-lib/aws-route53")); const naming_1 = require("../lambdacode/network/naming"); const web_acl_1 = require("./constructs/web-acl"); /** us-east-1 companion: what CloudFront only accepts from there — the * issuer's certificate, the web + auth-domain certificate (Cognito's too) * and the WAF web ACL. Never deployed alone — it rides along as a * CredsStack + WebStack dependency. */ class WebCertStack extends cdk.Stack { issuerCertificate; certificate; webAclArn; /** Observe-only ACL for the issuer distribution — it never blocks STS. */ issuerWebAclArn; constructor(scope, id, props) { super(scope, id, props); const issuerZone = route53.HostedZone.fromHostedZoneAttributes(this, "IssuerZone", { hostedZoneId: props.issuer.hostedZoneId, zoneName: props.issuer.zoneName, }); this.issuerCertificate = new acm.Certificate(this, "IssuerCert", { domainName: props.issuer.domainName, validation: acm.CertificateValidation.fromDns(issuerZone), }); if (props.web) { const zone = route53.HostedZone.fromHostedZoneAttributes(this, "Zone", { hostedZoneId: props.web.hostedZoneId, zoneName: props.web.zoneName, }); this.certificate = new acm.Certificate(this, "WebCert", { domainName: props.web.domainName, subjectAlternativeNames: [props.web.authDomainName], validation: acm.CertificateValidation.fromDns(zone), }); } if (props.waf) { const prefix = props.resourcePrefix ?? naming_1.DEFAULT_RESOURCE_PREFIX; this.webAclArn = new web_acl_1.WebAcl(this, "WebAcl", { scope: "CLOUDFRONT", name: `${prefix}-web`, rateLimit: { limit: props.waf.rateLimit, pathPrefix: "/api/" }, }).arn; // Separate from the app's ACL so web-motivated tuning can never reach // STS's fetch of the discovery document + JWKS. this.issuerWebAclArn = new web_acl_1.WebAcl(this, "IssuerWebAcl", { scope: "CLOUDFRONT", name: `${prefix}-issuer`, observeOnly: true, }).arn; } } } exports.WebCertStack = WebCertStack;