@geekmidas/cli 10.0.0-alpha.18 → 10.0.0-alpha.181
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 +323 -380
- package/bin/adjacent-tsconfig.mjs +46 -8
- package/bin/gkm.mjs +11 -3
- package/bin/owning-tsconfig-jsx-register.mjs +18 -0
- package/bin/owning-tsconfig-jsx.mjs +108 -0
- package/dist/EndpointGenerator-CBKH87_b.mjs +1043 -0
- package/dist/EndpointGenerator-CBKH87_b.mjs.map +1 -0
- package/dist/EndpointGenerator-iyA3HkOH.cjs +1102 -0
- package/dist/EndpointGenerator-iyA3HkOH.cjs.map +1 -0
- package/dist/LegacyStateStore-DvufVJjQ.cjs +124 -0
- package/dist/LegacyStateStore-DvufVJjQ.cjs.map +1 -0
- package/dist/LegacyStateStore-p-_Z8ucw.mjs +124 -0
- package/dist/LegacyStateStore-p-_Z8ucw.mjs.map +1 -0
- package/dist/LocalStateStore-BKAi5XsN.mjs +167 -0
- package/dist/LocalStateStore-BKAi5XsN.mjs.map +1 -0
- package/dist/LocalStateStore-DLDD6udB.cjs +178 -0
- package/dist/LocalStateStore-DLDD6udB.cjs.map +1 -0
- package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs +534 -0
- package/dist/OpenApiTsGenerator-CoVA3Ykv.mjs.map +1 -0
- package/dist/OpenApiTsGenerator-vy-fOJgs.cjs +539 -0
- package/dist/OpenApiTsGenerator-vy-fOJgs.cjs.map +1 -0
- package/dist/S3StateStore-C8thID2w.mjs +223 -0
- package/dist/S3StateStore-C8thID2w.mjs.map +1 -0
- package/dist/S3StateStore-J3FztlVC.cjs +222 -0
- package/dist/S3StateStore-J3FztlVC.cjs.map +1 -0
- package/dist/SSMStateStore-0TQsme40.mjs +205 -0
- package/dist/SSMStateStore-0TQsme40.mjs.map +1 -0
- package/dist/SSMStateStore-DhkkSF1D.cjs +204 -0
- package/dist/SSMStateStore-DhkkSF1D.cjs.map +1 -0
- package/dist/SubscriberGenerator-B3jHf26s.mjs +787 -0
- package/dist/SubscriberGenerator-B3jHf26s.mjs.map +1 -0
- package/dist/SubscriberGenerator-JhwVlWBS.cjs +852 -0
- package/dist/SubscriberGenerator-JhwVlWBS.cjs.map +1 -0
- package/dist/add-DWCzdPLz.mjs +711 -0
- package/dist/add-DWCzdPLz.mjs.map +1 -0
- package/dist/add-gs34ewLG.cjs +713 -0
- package/dist/add-gs34ewLG.cjs.map +1 -0
- package/dist/appPorts-BoXMwolc.mjs +249 -0
- package/dist/appPorts-BoXMwolc.mjs.map +1 -0
- package/dist/appPorts-IW-OZmRi.cjs +296 -0
- package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
- package/dist/apps-C27qrbEe.cjs +5174 -0
- package/dist/apps-C27qrbEe.cjs.map +1 -0
- package/dist/apps-D2oTQasd.mjs +4650 -0
- package/dist/apps-D2oTQasd.mjs.map +1 -0
- package/dist/aws-BXfiWNbi.cjs +108 -0
- package/dist/aws-BXfiWNbi.cjs.map +1 -0
- package/dist/aws-BjvSTTcE.mjs +97 -0
- package/dist/aws-BjvSTTcE.mjs.map +1 -0
- package/dist/awsStore-BYYCmXiq.mjs +121 -0
- package/dist/awsStore-BYYCmXiq.mjs.map +1 -0
- package/dist/awsStore-DKQUElJL.cjs +138 -0
- package/dist/awsStore-DKQUElJL.cjs.map +1 -0
- package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
- package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
- package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
- package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
- package/dist/backups/runner.cjs +519 -0
- package/dist/backups/runner.cjs.map +1 -0
- package/dist/backups/runner.d.cts +102 -0
- package/dist/backups/runner.d.cts.map +1 -0
- package/dist/backups/runner.d.mts +102 -0
- package/dist/backups/runner.d.mts.map +1 -0
- package/dist/backups/runner.mjs +506 -0
- package/dist/backups/runner.mjs.map +1 -0
- package/dist/{bundler-mwH7WOb1.mjs → bundler-CbT4y4H_.mjs} +68 -15
- package/dist/bundler-CbT4y4H_.mjs.map +1 -0
- package/dist/{bundler-mjqGAvu1.cjs → bundler-DGeOugof.cjs} +67 -14
- package/dist/bundler-DGeOugof.cjs.map +1 -0
- package/dist/cli-C-jUNT69.cjs +80 -0
- package/dist/cli-C-jUNT69.cjs.map +1 -0
- package/dist/cli-DKEJryS7.mjs +80 -0
- package/dist/cli-DKEJryS7.mjs.map +1 -0
- package/dist/clientTelemetry-BAwj6MOf.d.cts +10 -0
- package/dist/clientTelemetry-BAwj6MOf.d.cts.map +1 -0
- package/dist/clientTelemetry-CvamPJj_.d.mts +10 -0
- package/dist/clientTelemetry-CvamPJj_.d.mts.map +1 -0
- package/dist/compose-BpnSP2x7.mjs +2434 -0
- package/dist/compose-BpnSP2x7.mjs.map +1 -0
- package/dist/compose-DJAaJEqL.cjs +2925 -0
- package/dist/compose-DJAaJEqL.cjs.map +1 -0
- package/dist/compose-DmtR2f0l.cjs +3564 -0
- package/dist/compose-DmtR2f0l.cjs.map +1 -0
- package/dist/compose-Glqs13is.mjs +3451 -0
- package/dist/compose-Glqs13is.mjs.map +1 -0
- package/dist/config-BODxZemw.d.mts +291 -0
- package/dist/config-BODxZemw.d.mts.map +1 -0
- package/dist/config-C3U5HulX.d.cts +291 -0
- package/dist/config-C3U5HulX.d.cts.map +1 -0
- package/dist/config.cjs +457 -9
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +4 -117
- package/dist/config.d.mts +4 -117
- package/dist/config.mjs +441 -3
- package/dist/config.mjs.map +1 -0
- package/dist/credentialSchemas-D_85KW2k.mjs +236 -0
- package/dist/credentialSchemas-D_85KW2k.mjs.map +1 -0
- package/dist/credentialSchemas-DjK6xKMk.cjs +271 -0
- package/dist/credentialSchemas-DjK6xKMk.cjs.map +1 -0
- package/dist/databases-CV22HzrI.mjs +588 -0
- package/dist/databases-CV22HzrI.mjs.map +1 -0
- package/dist/databases-DwYYH2mX.cjs +703 -0
- package/dist/databases-DwYYH2mX.cjs.map +1 -0
- package/dist/dbTunnel-DUudiQWj.cjs +154 -0
- package/dist/dbTunnel-DUudiQWj.cjs.map +1 -0
- package/dist/dbTunnel-KgbAh2v1.mjs +154 -0
- package/dist/dbTunnel-KgbAh2v1.mjs.map +1 -0
- package/dist/define-BfrNaY82.mjs +106 -0
- package/dist/define-BfrNaY82.mjs.map +1 -0
- package/dist/define-zKgLY65H.cjs +153 -0
- package/dist/define-zKgLY65H.cjs.map +1 -0
- package/dist/deploy/public.cjs +211 -0
- package/dist/deploy/public.cjs.map +1 -0
- package/dist/deploy/public.d.cts +659 -0
- package/dist/deploy/public.d.cts.map +1 -0
- package/dist/deploy/public.d.mts +659 -0
- package/dist/deploy/public.d.mts.map +1 -0
- package/dist/deploy/public.mjs +144 -0
- package/dist/deploy/public.mjs.map +1 -0
- package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
- package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
- package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
- package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
- package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
- package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
- package/dist/deploy/sniffer-hooks.cjs +1 -1
- package/dist/deploy/sniffer-hooks.mjs +1 -1
- package/dist/deploy/sniffer-loader.cjs +2 -2
- package/dist/deploy/sniffer-loader.mjs +1 -1
- package/dist/deploy/sniffer-routes-worker.cjs +2 -2
- package/dist/deploy/sniffer-routes-worker.mjs +1 -1
- package/dist/deploy-UkAiPzTp.mjs +3838 -0
- package/dist/deploy-UkAiPzTp.mjs.map +1 -0
- package/dist/deploy-ycRCutW9.cjs +3894 -0
- package/dist/deploy-ycRCutW9.cjs.map +1 -0
- package/dist/destroy-Cq5Un0kf.mjs +789 -0
- package/dist/destroy-Cq5Un0kf.mjs.map +1 -0
- package/dist/destroy-DzRzQcAR.cjs +790 -0
- package/dist/destroy-DzRzQcAR.cjs.map +1 -0
- package/dist/discover-Dfmn6HQ7.mjs +940 -0
- package/dist/discover-Dfmn6HQ7.mjs.map +1 -0
- package/dist/discover-OXczlq08.cjs +1085 -0
- package/dist/discover-OXczlq08.cjs.map +1 -0
- package/dist/dns-7zc-Mc9k.cjs +2257 -0
- package/dist/dns-7zc-Mc9k.cjs.map +1 -0
- package/dist/dns-dl7WUWmB.mjs +1820 -0
- package/dist/dns-dl7WUWmB.mjs.map +1 -0
- package/dist/docker-BDqp9Pfn.cjs +1798 -0
- package/dist/docker-BDqp9Pfn.cjs.map +1 -0
- package/dist/docker-MjMWQSEN.mjs +1649 -0
- package/dist/docker-MjMWQSEN.mjs.map +1 -0
- package/dist/dokploy-B0xtYCzY.mjs +38 -0
- package/dist/dokploy-B0xtYCzY.mjs.map +1 -0
- package/dist/dokploy-D-pBRnSV.cjs +38 -0
- package/dist/dokploy-D-pBRnSV.cjs.map +1 -0
- package/dist/drivers-BQRb3KsL.mjs +294 -0
- package/dist/drivers-BQRb3KsL.mjs.map +1 -0
- package/dist/drivers-DP7__dJX.cjs +377 -0
- package/dist/drivers-DP7__dJX.cjs.map +1 -0
- package/dist/eas-9danFNrJ.mjs +334 -0
- package/dist/eas-9danFNrJ.mjs.map +1 -0
- package/dist/eas-BJRA27vb.cjs +337 -0
- package/dist/eas-BJRA27vb.cjs.map +1 -0
- package/dist/emit-C4KSXOeS.mjs +153 -0
- package/dist/emit-C4KSXOeS.mjs.map +1 -0
- package/dist/emit-DiW0kbue.cjs +164 -0
- package/dist/emit-DiW0kbue.cjs.map +1 -0
- package/dist/encryption-0IiNCA3O.cjs +90 -0
- package/dist/encryption-0IiNCA3O.cjs.map +1 -0
- package/dist/encryption-ZDhvgGvu.mjs +89 -0
- package/dist/encryption-ZDhvgGvu.mjs.map +1 -0
- package/dist/engine-Csnr6XDu.mjs +3217 -0
- package/dist/engine-Csnr6XDu.mjs.map +1 -0
- package/dist/engine-DpjIgsGn.cjs +3330 -0
- package/dist/engine-DpjIgsGn.cjs.map +1 -0
- package/dist/errors-C9uIyIDt.mjs +27 -0
- package/dist/errors-C9uIyIDt.mjs.map +1 -0
- package/dist/errors-D1x8duqI.cjs +38 -0
- package/dist/errors-D1x8duqI.cjs.map +1 -0
- package/dist/github-Dej8EWxH.mjs +986 -0
- package/dist/github-Dej8EWxH.mjs.map +1 -0
- package/dist/github-HHxVur1m.cjs +987 -0
- package/dist/github-HHxVur1m.cjs.map +1 -0
- package/dist/googlePlay-DNrD-67X.mjs +931 -0
- package/dist/googlePlay-DNrD-67X.mjs.map +1 -0
- package/dist/googlePlay-NK1zgJJm.cjs +931 -0
- package/dist/googlePlay-NK1zgJJm.cjs.map +1 -0
- package/dist/iam-BzFyFf7T.mjs +442 -0
- package/dist/iam-BzFyFf7T.mjs.map +1 -0
- package/dist/iam-WIoKnLBp.cjs +521 -0
- package/dist/iam-WIoKnLBp.cjs.map +1 -0
- package/dist/{index-RCUizGxL.d.cts → index-BKgOlfK2.d.mts} +38 -14
- package/dist/index-BKgOlfK2.d.mts.map +1 -0
- package/dist/{index-B4H4XF7A.d.mts → index-zPzigXh-.d.cts} +38 -14
- package/dist/index-zPzigXh-.d.cts.map +1 -0
- package/dist/index.cjs +14502 -12767
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +15137 -13400
- package/dist/index.mjs.map +1 -1
- package/dist/local-BW_VIsx0.cjs +241 -0
- package/dist/local-BW_VIsx0.cjs.map +1 -0
- package/dist/local-CVp-4wDb.mjs +224 -0
- package/dist/local-CVp-4wDb.mjs.map +1 -0
- package/dist/migrate-B8fq5egU.cjs +272 -0
- package/dist/migrate-B8fq5egU.cjs.map +1 -0
- package/dist/migrate-C8yCZ5P3.mjs +181 -0
- package/dist/migrate-C8yCZ5P3.mjs.map +1 -0
- package/dist/migrate-CkSq2f7k.mjs +267 -0
- package/dist/migrate-CkSq2f7k.mjs.map +1 -0
- package/dist/migrate-FOc2erAl.cjs +181 -0
- package/dist/migrate-FOc2erAl.cjs.map +1 -0
- package/dist/next.cjs +59 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +44 -0
- package/dist/next.d.cts.map +1 -0
- package/dist/next.d.mts +44 -0
- package/dist/next.d.mts.map +1 -0
- package/dist/next.mjs +58 -0
- package/dist/next.mjs.map +1 -0
- package/dist/notes--JQyDHim.cjs +510 -0
- package/dist/notes--JQyDHim.cjs.map +1 -0
- package/dist/notes-DXl9qERh.mjs +409 -0
- package/dist/notes-DXl9qERh.mjs.map +1 -0
- package/dist/openapi.cjs +213 -7
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +27 -8
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.mts +27 -8
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +208 -2
- package/dist/openapi.mjs.map +1 -0
- package/dist/projectBucket-CGpcWqyY.cjs +263 -0
- package/dist/projectBucket-CGpcWqyY.cjs.map +1 -0
- package/dist/projectBucket-TigJy25c.mjs +222 -0
- package/dist/projectBucket-TigJy25c.mjs.map +1 -0
- package/dist/provider-BvjDbsTR.mjs +46 -0
- package/dist/provider-BvjDbsTR.mjs.map +1 -0
- package/dist/provider-DLhgo-mB.cjs +57 -0
- package/dist/provider-DLhgo-mB.cjs.map +1 -0
- package/dist/publish-BPfW3DWi.mjs +123 -0
- package/dist/publish-BPfW3DWi.mjs.map +1 -0
- package/dist/publish-D4pC6_G0.cjs +124 -0
- package/dist/publish-D4pC6_G0.cjs.map +1 -0
- package/dist/ready-BcV28QoW.mjs +375 -0
- package/dist/ready-BcV28QoW.mjs.map +1 -0
- package/dist/ready-ByQvw4-W.cjs +404 -0
- package/dist/ready-ByQvw4-W.cjs.map +1 -0
- package/dist/reconcile/public.cjs +3 -5
- package/dist/reconcile/public.d.cts +33 -89
- package/dist/reconcile/public.d.cts.map +1 -1
- package/dist/reconcile/public.d.mts +33 -89
- package/dist/reconcile/public.d.mts.map +1 -1
- package/dist/reconcile/public.mjs +3 -3
- package/dist/reconcile--I7V4Klj.mjs +34 -0
- package/dist/reconcile--I7V4Klj.mjs.map +1 -0
- package/dist/reconcile-CuCQBa5-.cjs +34 -0
- package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
- package/dist/resolve-BmBR1vBr.cjs +316 -0
- package/dist/resolve-BmBR1vBr.cjs.map +1 -0
- package/dist/resolve-DA1kORng.mjs +263 -0
- package/dist/resolve-DA1kORng.mjs.map +1 -0
- package/dist/rollback-DlgQDX8m.mjs +136 -0
- package/dist/rollback-DlgQDX8m.mjs.map +1 -0
- package/dist/rollback-tsy4pyEp.cjs +165 -0
- package/dist/rollback-tsy4pyEp.cjs.map +1 -0
- package/dist/runtime-CaejlcZt.d.mts +82 -0
- package/dist/runtime-CaejlcZt.d.mts.map +1 -0
- package/dist/runtime-D3jD4Dvn.d.cts +82 -0
- package/dist/runtime-D3jD4Dvn.d.cts.map +1 -0
- package/dist/s3-BLEF-PQU.cjs +240 -0
- package/dist/s3-BLEF-PQU.cjs.map +1 -0
- package/dist/s3-DVYiOqWs.mjs +240 -0
- package/dist/s3-DVYiOqWs.mjs.map +1 -0
- package/dist/sandbox/config-worker.cjs +43 -0
- package/dist/sandbox/config-worker.cjs.map +1 -0
- package/dist/sandbox/config-worker.d.cts +1 -0
- package/dist/sandbox/config-worker.d.mts +1 -0
- package/dist/sandbox/config-worker.mjs +44 -0
- package/dist/sandbox/config-worker.mjs.map +1 -0
- package/dist/sandbox/credentials-worker.cjs +53 -0
- package/dist/sandbox/credentials-worker.cjs.map +1 -0
- package/dist/sandbox/credentials-worker.d.cts +1 -0
- package/dist/sandbox/credentials-worker.d.mts +1 -0
- package/dist/sandbox/credentials-worker.mjs +54 -0
- package/dist/sandbox/credentials-worker.mjs.map +1 -0
- package/dist/sandbox/discover-worker.cjs +47 -0
- package/dist/sandbox/discover-worker.cjs.map +1 -0
- package/dist/sandbox/discover-worker.d.cts +1 -0
- package/dist/sandbox/discover-worker.d.mts +1 -0
- package/dist/sandbox/discover-worker.mjs +48 -0
- package/dist/sandbox/discover-worker.mjs.map +1 -0
- package/dist/sandbox/migrate-worker.cjs +75 -0
- package/dist/sandbox/migrate-worker.cjs.map +1 -0
- package/dist/sandbox/migrate-worker.d.cts +1 -0
- package/dist/sandbox/migrate-worker.d.mts +1 -0
- package/dist/sandbox/migrate-worker.mjs +76 -0
- package/dist/sandbox/migrate-worker.mjs.map +1 -0
- package/dist/{workspace-CRD9YinV.cjs → schemas-BCwKKA42.mjs} +399 -1179
- package/dist/schemas-BCwKKA42.mjs.map +1 -0
- package/dist/{workspace-Bu3xNCej.mjs → schemas-BQ_v0lEX.cjs} +487 -982
- package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
- package/dist/secretsManager-CjTo6CRq.mjs +113 -0
- package/dist/secretsManager-CjTo6CRq.mjs.map +1 -0
- package/dist/secretsManager-CvmBGjdM.cjs +124 -0
- package/dist/secretsManager-CvmBGjdM.cjs.map +1 -0
- package/dist/seeds-Bc3niNVb.cjs +382 -0
- package/dist/seeds-Bc3niNVb.cjs.map +1 -0
- package/dist/seeds-Ccn0Ru2T.mjs +299 -0
- package/dist/seeds-Ccn0Ru2T.mjs.map +1 -0
- package/dist/serverSetup-B_O65wLb.cjs +685 -0
- package/dist/serverSetup-B_O65wLb.cjs.map +1 -0
- package/dist/serverSetup-Dsy8drIb.mjs +685 -0
- package/dist/serverSetup-Dsy8drIb.mjs.map +1 -0
- package/dist/sniffer-Ckx4cr-o.cjs +1997 -0
- package/dist/sniffer-Ckx4cr-o.cjs.map +1 -0
- package/dist/sniffer-fBefNUuJ.mjs +1824 -0
- package/dist/sniffer-fBefNUuJ.mjs.map +1 -0
- package/dist/snsSubscriptions-BJ0LErGk.mjs +1010 -0
- package/dist/snsSubscriptions-BJ0LErGk.mjs.map +1 -0
- package/dist/snsSubscriptions-ChbFp-QP.cjs +1135 -0
- package/dist/snsSubscriptions-ChbFp-QP.cjs.map +1 -0
- package/dist/sst-BnuPeGyy.cjs +501 -0
- package/dist/sst-BnuPeGyy.cjs.map +1 -0
- package/dist/sst-Y7H_zaEZ.mjs +478 -0
- package/dist/sst-Y7H_zaEZ.mjs.map +1 -0
- package/dist/stack-BAipv5Js.cjs +1887 -0
- package/dist/stack-BAipv5Js.cjs.map +1 -0
- package/dist/stack-BHrGbsGA.mjs +1777 -0
- package/dist/stack-BHrGbsGA.mjs.map +1 -0
- package/dist/stage-BSZ9890H.mjs +303 -0
- package/dist/stage-BSZ9890H.mjs.map +1 -0
- package/dist/stage-D7vBtLXL.cjs +332 -0
- package/dist/stage-D7vBtLXL.cjs.map +1 -0
- package/dist/stages-BeSQQQ4z.cjs +190 -0
- package/dist/stages-BeSQQQ4z.cjs.map +1 -0
- package/dist/stages-DjFKQv08.mjs +190 -0
- package/dist/stages-DjFKQv08.mjs.map +1 -0
- package/dist/target/public.cjs +15 -0
- package/dist/target/public.d.cts +28 -0
- package/dist/target/public.d.cts.map +1 -0
- package/dist/target/public.d.mts +28 -0
- package/dist/target/public.d.mts.map +1 -0
- package/dist/target/public.mjs +4 -0
- package/dist/terminal-B7G-FtkD.cjs +85 -0
- package/dist/terminal-B7G-FtkD.cjs.map +1 -0
- package/dist/terminal-lp8RwHdX.mjs +85 -0
- package/dist/terminal-lp8RwHdX.mjs.map +1 -0
- package/dist/{types-7R81hu0i.d.mts → types-CLxsw-QY.d.cts} +2135 -428
- package/dist/types-CLxsw-QY.d.cts.map +1 -0
- package/dist/{types-N7c2O2m7.d.cts → types-wLlwkSib.d.mts} +2133 -428
- package/dist/types-wLlwkSib.d.mts.map +1 -0
- package/dist/utils-D2Nk1Nv2.cjs +205 -0
- package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
- package/dist/utils-D_fxUqvU.mjs +156 -0
- package/dist/utils-D_fxUqvU.mjs.map +1 -0
- package/dist/vitest.cjs +65 -0
- package/dist/vitest.cjs.map +1 -0
- package/dist/vitest.d.cts +29 -0
- package/dist/vitest.d.cts.map +1 -0
- package/dist/vitest.d.mts +29 -0
- package/dist/vitest.d.mts.map +1 -0
- package/dist/vitest.mjs +65 -0
- package/dist/vitest.mjs.map +1 -0
- package/dist/workerRuntime-BXfhbe13.cjs +108 -0
- package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
- package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
- package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
- package/dist/workspace/index.cjs +6 -2
- package/dist/workspace/index.d.cts +3 -3
- package/dist/workspace/index.d.mts +3 -3
- package/dist/workspace/index.mjs +2 -2
- package/dist/workspace-DJjhfAGf.mjs +3027 -0
- package/dist/workspace-DJjhfAGf.mjs.map +1 -0
- package/dist/workspace-wTLnc1Ef.cjs +3577 -0
- package/dist/workspace-wTLnc1Ef.cjs.map +1 -0
- package/package.json +76 -13
- package/dist/HostingerProvider-BY26bWwB.mjs +0 -243
- package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
- package/dist/HostingerProvider-BZFGYYVA.cjs +0 -243
- package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
- package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
- package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
- package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
- package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
- package/dist/Route53Provider-Cvj40A8I.mjs +0 -209
- package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
- package/dist/Route53Provider-DVILBsvV.cjs +0 -209
- package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
- package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
- package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
- package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
- package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
- package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
- package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
- package/dist/bundler-mjqGAvu1.cjs.map +0 -1
- package/dist/bundler-mwH7WOb1.mjs.map +0 -1
- package/dist/config-DSXI480r.cjs +0 -467
- package/dist/config-DSXI480r.cjs.map +0 -1
- package/dist/config-DdKkoUE1.mjs +0 -414
- package/dist/config-DdKkoUE1.mjs.map +0 -1
- package/dist/config.d.cts.map +0 -1
- package/dist/config.d.mts.map +0 -1
- package/dist/credentials-C6Pfn6GY.cjs +0 -2939
- package/dist/credentials-C6Pfn6GY.cjs.map +0 -1
- package/dist/credentials-lbv-j0Be.mjs +0 -2802
- package/dist/credentials-lbv-j0Be.mjs.map +0 -1
- package/dist/discover-BERGFg8v.cjs +0 -288
- package/dist/discover-BERGFg8v.cjs.map +0 -1
- package/dist/discover-CK-n3w6b.mjs +0 -244
- package/dist/discover-CK-n3w6b.mjs.map +0 -1
- package/dist/emit-BdoPFjZf.cjs +0 -253
- package/dist/emit-BdoPFjZf.cjs.map +0 -1
- package/dist/emit-Bzq7JsMP.mjs +0 -224
- package/dist/emit-Bzq7JsMP.mjs.map +0 -1
- package/dist/generator-LfZU7NlU.mjs +0 -247
- package/dist/generator-LfZU7NlU.mjs.map +0 -1
- package/dist/generator-Wdfp0jCS.cjs +0 -282
- package/dist/generator-Wdfp0jCS.cjs.map +0 -1
- package/dist/github-DlIrXPee.mjs +0 -216
- package/dist/github-DlIrXPee.mjs.map +0 -1
- package/dist/github-n7N9yOff.cjs +0 -216
- package/dist/github-n7N9yOff.cjs.map +0 -1
- package/dist/index-B4H4XF7A.d.mts.map +0 -1
- package/dist/index-RCUizGxL.d.cts.map +0 -1
- package/dist/openapi-B8bu_OXN.cjs +0 -2038
- package/dist/openapi-B8bu_OXN.cjs.map +0 -1
- package/dist/openapi-DfjbhrsM.mjs +0 -1991
- package/dist/openapi-DfjbhrsM.mjs.map +0 -1
- package/dist/reconcile-Cq4cO83R.cjs +0 -136
- package/dist/reconcile-Cq4cO83R.cjs.map +0 -1
- package/dist/reconcile-fmoluZmZ.mjs +0 -113
- package/dist/reconcile-fmoluZmZ.mjs.map +0 -1
- package/dist/ssm-BKN1Cg4z.mjs +0 -60
- package/dist/ssm-BKN1Cg4z.mjs.map +0 -1
- package/dist/ssm-FxeSAt35.cjs +0 -60
- package/dist/ssm-FxeSAt35.cjs.map +0 -1
- package/dist/storage-DgypfSD6.cjs +0 -351
- package/dist/storage-DgypfSD6.cjs.map +0 -1
- package/dist/storage-TP0x118M.mjs +0 -304
- package/dist/storage-TP0x118M.mjs.map +0 -1
- package/dist/transfer-2aRVVJ6I.mjs +0 -122
- package/dist/transfer-2aRVVJ6I.mjs.map +0 -1
- package/dist/transfer-C3WZVmj_.cjs +0 -151
- package/dist/transfer-C3WZVmj_.cjs.map +0 -1
- package/dist/types-7R81hu0i.d.mts.map +0 -1
- package/dist/types-N7c2O2m7.d.cts.map +0 -1
- package/dist/workspace-Bu3xNCej.mjs.map +0 -1
- package/dist/workspace-CRD9YinV.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-BzFyFf7T.mjs","names":[],"sources":["../src/providers/s3/policy.ts","../src/providers/iam.ts"],"sourcesContent":["/**\n * The documents the `s3` provider writes: the user's inline policy, the\n * bucket's policy, its CORS rule and its public access block.\n *\n * Pure, so each is tested as JSON and compared with what AWS holds on every\n * run — a document that differs is drift, and is put back.\n */\n\n/** One IAM or bucket policy statement. */\nexport interface PolicyStatement {\n\tSid: string;\n\tEffect: 'Allow' | 'Deny';\n\tPrincipal?: '*' | { AWS: string | string[] } | { Service: string };\n\tAction: string | string[];\n\tResource: string | string[];\n\tCondition?: Record<string, Record<string, string | string[]>>;\n}\n\nexport interface PolicyDocument {\n\tVersion: '2012-10-17';\n\tStatement: PolicyStatement[];\n}\n\nconst bucketArn = (bucket: string) => `arn:aws:s3:::${bucket}`;\n\n/**\n * What the app's key may do: objects in this bucket, and listing it — and\n * nothing else in the account.\n *\n * Multipart uploads are in it because a presigned upload of a large file is\n * one, and an abandoned one is cleaned up by the app. Reading old versions is\n * added only when the bucket keeps them.\n */\nexport function userPolicy(\n\tbucket: string,\n\toptions: {\n\t\tversioning?: boolean;\n\t\t/**\n\t\t * The bucket's events topic, when a subscriber watches it: the worker\n\t\t * confirms the subscriptions the deploy made with this key, and does\n\t\t * nothing else to the topic.\n\t\t */\n\t\teventsTopicArn?: string;\n\t} = {},\n): PolicyDocument {\n\treturn {\n\t\tVersion: '2012-10-17',\n\t\tStatement: [\n\t\t\t{\n\t\t\t\tSid: 'GkmObjects',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t's3:GetObject',\n\t\t\t\t\t's3:PutObject',\n\t\t\t\t\t's3:DeleteObject',\n\t\t\t\t\t's3:AbortMultipartUpload',\n\t\t\t\t\t's3:ListMultipartUploadParts',\n\t\t\t\t\t...(options.versioning ? ['s3:GetObjectVersion'] : []),\n\t\t\t\t],\n\t\t\t\tResource: `${bucketArn(bucket)}/*`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'GkmBucket',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t's3:ListBucket',\n\t\t\t\t\t's3:GetBucketLocation',\n\t\t\t\t\t's3:ListBucketMultipartUploads',\n\t\t\t\t],\n\t\t\t\tResource: bucketArn(bucket),\n\t\t\t},\n\t\t\t...(options.eventsTopicArn\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSid: 'GkmEvents',\n\t\t\t\t\t\t\tEffect: 'Allow' as const,\n\t\t\t\t\t\t\tAction: 'sns:ConfirmSubscription',\n\t\t\t\t\t\t\tResource: options.eventsTopicArn,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t],\n\t};\n}\n\n/**\n * One open pattern as the resource it is public on. A `**` is S3's `*`; a\n * single `*` is too, which crosses `/` where the construct's own check does\n * not — the construct is the stricter of the two (see `bucketPolicy` in\n * reconcile, which the local MinIO is given the same way).\n */\nexport function openResource(bucket: string, pattern: string): string {\n\tconst path = pattern.replace(/^\\/+/, '').replace(/\\*\\*/g, '*');\n\treturn `${bucketArn(bucket)}/${path}`;\n}\n\n/**\n * The bucket's own policy: every request refused unless it came over TLS,\n * and — only when a file server opens paths on it — `s3:GetObject` on\n * exactly those prefixes: to anyone, or, when a CDN serves them, to\n * CloudFront alone, for exactly the stage's distributions. Behind a CDN the\n * bucket is never public: a key outside the open prefixes is refused to\n * CloudFront too, so the edge answers it 403.\n */\nexport function bucketPolicy(\n\tbucket: string,\n\topen: readonly string[] = [],\n\toptions: {\n\t\tcdn?: { distributionArns: readonly string[] };\n\t\t/**\n\t\t * SES may write received mail under this prefix — the bucket an inbox\n\t\t * owns — and only for this account's receipt rules.\n\t\t */\n\t\tsesWrite?: { prefix: string; account: string };\n\t} = {},\n): PolicyDocument {\n\tconst statements: PolicyStatement[] = [\n\t\t{\n\t\t\tSid: 'GkmDenyInsecureTransport',\n\t\t\tEffect: 'Deny',\n\t\t\tPrincipal: '*',\n\t\t\tAction: 's3:*',\n\t\t\tResource: [bucketArn(bucket), `${bucketArn(bucket)}/*`],\n\t\t\tCondition: { Bool: { 'aws:SecureTransport': 'false' } },\n\t\t},\n\t];\n\tconst resources = [\n\t\t...new Set(open.map((p) => openResource(bucket, p))),\n\t].sort();\n\tif (open.length > 0 && options.cdn) {\n\t\tstatements.push({\n\t\t\tSid: 'GkmCdnRead',\n\t\t\tEffect: 'Allow',\n\t\t\tPrincipal: { Service: 'cloudfront.amazonaws.com' },\n\t\t\tAction: 's3:GetObject',\n\t\t\tResource: resources,\n\t\t\tCondition: {\n\t\t\t\tStringEquals: {\n\t\t\t\t\t'AWS:SourceArn': [...new Set(options.cdn.distributionArns)].sort(),\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t} else if (open.length > 0) {\n\t\tstatements.push({\n\t\t\tSid: 'GkmOpenPaths',\n\t\t\tEffect: 'Allow',\n\t\t\tPrincipal: '*',\n\t\t\tAction: 's3:GetObject',\n\t\t\tResource: resources,\n\t\t});\n\t}\n\tif (options.sesWrite) {\n\t\tstatements.push({\n\t\t\tSid: 'GkmSesWritesMail',\n\t\t\tEffect: 'Allow',\n\t\t\tPrincipal: { Service: 'ses.amazonaws.com' },\n\t\t\tAction: 's3:PutObject',\n\t\t\tResource: `${bucketArn(bucket)}/${options.sesWrite.prefix}*`,\n\t\t\tCondition: {\n\t\t\t\tStringEquals: { 'aws:SourceAccount': options.sesWrite.account },\n\t\t\t},\n\t\t});\n\t}\n\treturn { Version: '2012-10-17', Statement: statements };\n}\n\n/**\n * Block Public Access. All four flags on, unless the bucket has open paths:\n * then a *policy* may make it public (`BlockPublicPolicy`,\n * `RestrictPublicBuckets` off), and ACLs still may not.\n */\nexport function publicAccessBlock(open: boolean): {\n\tBlockPublicAcls: boolean;\n\tIgnorePublicAcls: boolean;\n\tBlockPublicPolicy: boolean;\n\tRestrictPublicBuckets: boolean;\n} {\n\treturn {\n\t\tBlockPublicAcls: true,\n\t\tIgnorePublicAcls: true,\n\t\tBlockPublicPolicy: !open,\n\t\tRestrictPublicBuckets: !open,\n\t};\n}\n\n/** The one CORS rule: browsers on the stage's sites upload and read. */\nexport interface CorsRule {\n\tAllowedMethods: string[];\n\tAllowedOrigins: string[];\n\tAllowedHeaders: string[];\n\tExposeHeaders: string[];\n\tMaxAgeSeconds: number;\n}\n\nexport function corsRule(origins: readonly string[]): CorsRule {\n\treturn {\n\t\tAllowedMethods: ['GET', 'HEAD', 'POST', 'PUT'],\n\t\tAllowedOrigins: [...new Set(origins)].sort(),\n\t\tAllowedHeaders: ['*'],\n\t\tExposeHeaders: ['ETag'],\n\t\tMaxAgeSeconds: 3000,\n\t};\n}\n\n/**\n * A policy document in one canonical form — keys sorted, a lone string a\n * one-element list, lists sorted — so one AWS reformatted reads as the same\n * document rather than as drift.\n */\nexport function canonicalPolicy(value: unknown): string {\n\treturn JSON.stringify(canonical(value));\n}\n\nfunction canonical(value: unknown, key?: string): unknown {\n\tif (Array.isArray(value)) {\n\t\tconst items = value.map((v) => canonical(v));\n\t\treturn key === 'Statement'\n\t\t\t? items\n\t\t\t: items.map((v) => JSON.stringify(v)).sort();\n\t}\n\tif (value && typeof value === 'object') {\n\t\treturn Object.fromEntries(\n\t\t\tObject.keys(value)\n\t\t\t\t.sort()\n\t\t\t\t.map((k) => {\n\t\t\t\t\tconst v = (value as Record<string, unknown>)[k];\n\t\t\t\t\tconst listy =\n\t\t\t\t\t\tk === 'Action' ||\n\t\t\t\t\t\tk === 'Resource' ||\n\t\t\t\t\t\tk === 'AWS' ||\n\t\t\t\t\t\tk === 'AWS:SourceArn'\n\t\t\t\t\t\t\t? Array.isArray(v)\n\t\t\t\t\t\t\t\t? v\n\t\t\t\t\t\t\t\t: [v]\n\t\t\t\t\t\t\t: v;\n\t\t\t\t\treturn [k, canonical(listy, k)];\n\t\t\t\t}),\n\t\t);\n\t}\n\treturn value;\n}\n","/**\n * An IAM user gkm creates for one thing on a stage, its inline policy, and\n * the access key written into the stage's secrets — as an `s3://` URL for\n * what the `s3` provider gives each bucket and the deploy gives a stage's\n * backups, as an `smtp://` one for the `ses` mail provider.\n *\n * - **The user** is under `/gkm/`, tagged with the deploy identity, the stage\n * and what it is for. One that exists without those tags is someone\n * else's, and is refused rather than taken over.\n * - **Its policy** is read on every run and put back when it drifted.\n * - **Its key**: one, written into the stage's secrets the moment IAM shows\n * its secret. `--rotate-keys` issues a successor and keeps the old one\n * active until the stage has deployed with the new one; the next run after\n * that — or `--retire-old-keys` — deletes it.\n * - **A new key** takes IAM seconds to become usable: the state records when\n * it was issued, and a check made with it waits that out\n * ({@link whileKeyIsNew}).\n */\n\nimport * as s3Url from '@geekmidas/storage/s3-url';\nimport type { ResourceRecord } from '../deploy/StateStore.js';\nimport {\n\tAccessKeyLimit,\n\tBucketKeySetElsewhere,\n\tIamUserNotOwned,\n\tRotationInProgress,\n} from './s3/errors.js';\nimport { IAM_USER_PATH } from './s3/naming.js';\nimport { canonicalPolicy } from './s3/policy.js';\nimport type { EnsureContext, ProviderConfig, StateEntry } from './types.js';\n\ntype IamModule = typeof import('@aws-sdk/client-iam');\n\n/** The tags gkm finds its own buckets and users by. */\nexport const TAG_PROJECT = 'gkm:project';\nexport const TAG_STAGE = 'gkm:stage';\nexport const TAG_CONSTRUCT = 'gkm:construct';\n\n/** What creating a user and its key is done through. */\nexport interface IamClients {\n\tIAM: IamModule;\n\tiam: InstanceType<IamModule['IAMClient']>;\n\t/** The region the key's URL names. */\n\tregion: string;\n\t/** An emulator's endpoint, written into the URL when there is one. */\n\tendpoint?: string;\n}\n\n/** What creating a user and its key reads from a provisioning run. */\nexport type KeyContext = Pick<\n\tEnsureContext<ProviderConfig, unknown>,\n\t| 'identity'\n\t| 'stage'\n\t| 'state'\n\t| 'change'\n\t| 'dryRun'\n\t| 'secrets'\n\t| 'writeSecrets'\n\t| 'rotateKeys'\n\t| 'retireOldKeys'\n\t| 'log'\n>;\n\n/** The keys gkm tags a bucket and a user with. */\nexport function identityTags(\n\tctx: Pick<KeyContext, 'identity' | 'stage'>,\n\tid: string,\n) {\n\treturn [\n\t\t{ Key: TAG_PROJECT, Value: ctx.identity.key },\n\t\t{ Key: TAG_STAGE, Value: ctx.stage },\n\t\t{ Key: TAG_CONSTRUCT, Value: id },\n\t];\n}\n\n/** A read whose \"there is none\" answer is one of `missing`. */\nasync function readOr<T>(\n\tread: () => Promise<T>,\n\tmissing: readonly string[],\n): Promise<T | undefined> {\n\ttry {\n\t\treturn await read();\n\t} catch (error) {\n\t\tconst e = error as { name?: string; Code?: string };\n\t\tif (missing.includes(e?.Code ?? e?.name ?? '')) return undefined;\n\t\tthrow error;\n\t}\n}\n\n/** IAM returns a policy document URL-encoded; an emulator may not. */\nfunction decodePolicy(document: string): string {\n\ttry {\n\t\treturn decodeURIComponent(document);\n\t} catch {\n\t\treturn document;\n\t}\n}\n\nexport interface IamUserInput {\n\t/** What it is for: a bucket construct's id, or `backups`. */\n\tid: string;\n\t/** `gkm-<project>-<stage>-<id>`. */\n\tuser: string;\n\t/** The inline policy's name. */\n\tpolicyName: string;\n\tpolicy: object;\n\t/** The policy's change line: `this bucket only`. */\n\tdescribe: string;\n}\n\n/**\n * The user and its inline policy: found — and refused when it is not this\n * stage's — or created, and the policy put back when it drifted.\n *\n * @throws {IamUserNotOwned}\n */\nexport async function ensureIamUser(\n\tctx: KeyContext,\n\tclients: IamClients,\n\tinput: IamUserInput,\n): Promise<{ user: string; exists: boolean }> {\n\tconst { IAM, iam } = clients;\n\tconst { id, user, policy } = input;\n\tconst entry: StateEntry = { key: `iam-user:${id}`, type: 'iam-user' };\n\tconst found = await readOr(\n\t\t() => iam.send(new IAM.GetUserCommand({ UserName: user })),\n\t\t['NoSuchEntity', 'NoSuchEntityException'],\n\t);\n\n\tif (found?.User) {\n\t\tconst tags = await iam.send(\n\t\t\tnew IAM.ListUserTagsCommand({ UserName: user }),\n\t\t);\n\t\tconst tag = (key: string) => tags.Tags?.find((t) => t.Key === key)?.Value;\n\t\tif (\n\t\t\tfound.User.Path !== IAM_USER_PATH ||\n\t\t\ttag(TAG_PROJECT) !== ctx.identity.key ||\n\t\t\ttag(TAG_STAGE) !== ctx.stage\n\t\t) {\n\t\t\tthrow new IamUserNotOwned(user, ctx.identity.key, ctx.stage);\n\t\t}\n\t\tawait ctx.state.ready(entry, user);\n\t} else {\n\t\tawait ctx.change(\n\t\t\t{\n\t\t\t\tconstruct: id,\n\t\t\t\tresource: `IAM user ${user}`,\n\t\t\t\tchange: `create under ${IAM_USER_PATH}`,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tawait ctx.state.pending(entry);\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.CreateUserCommand({\n\t\t\t\t\t\tUserName: user,\n\t\t\t\t\t\tPath: IAM_USER_PATH,\n\t\t\t\t\t\tTags: identityTags(ctx, id),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tawait ctx.state.ready(entry, user);\n\t\t\t},\n\t\t);\n\t}\n\n\tconst exists = Boolean(found?.User) || !ctx.dryRun;\n\tconst current = exists\n\t\t? await readOr(\n\t\t\t\t() =>\n\t\t\t\t\tiam.send(\n\t\t\t\t\t\tnew IAM.GetUserPolicyCommand({\n\t\t\t\t\t\t\tUserName: user,\n\t\t\t\t\t\t\tPolicyName: input.policyName,\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t['NoSuchEntity', 'NoSuchEntityException'],\n\t\t\t)\n\t\t: undefined;\n\tconst document = current?.PolicyDocument\n\t\t? JSON.parse(decodePolicy(current.PolicyDocument))\n\t\t: undefined;\n\tif (!document || canonicalPolicy(document) !== canonicalPolicy(policy)) {\n\t\tawait ctx.change(\n\t\t\t{\n\t\t\t\tconstruct: id,\n\t\t\t\tresource: `IAM user ${user}`,\n\t\t\t\tchange: `policy ${input.policyName}: ${input.describe}`,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.PutUserPolicyCommand({\n\t\t\t\t\t\tUserName: user,\n\t\t\t\t\t\tPolicyName: input.policyName,\n\t\t\t\t\t\tPolicyDocument: JSON.stringify(policy),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t}\n\treturn { user, exists };\n}\n\n/**\n * The secret a user's access key is written into, and how: an `s3://` URL\n * for a bucket ({@link s3KeySecret}), an `smtp://` one for mail.\n */\nexport interface KeySecret {\n\t/** The secret's key: `UPLOADS_URL`, `BACKUPS_URL`, `MAIL_URL`. */\n\tkey: string;\n\t/**\n\t * The access key a stored value holds — or `undefined` when it holds\n\t * none this user could have issued for it, so a new one is.\n\t *\n\t * @throws when the value is another resource's, set by hand\n\t */\n\tkeyIdOf(value: string): string | undefined;\n\t/** The value for a newly issued key. */\n\tvalue(accessKeyId: string, secretAccessKey: string): string;\n\t/**\n\t * A value holding the right key whose address drifted: what it should\n\t * be, and the change line. `undefined` when it is right.\n\t */\n\trepair?(value: string): { value: string; change: string } | undefined;\n}\n\n/**\n * A bucket's URL as a key's secret: `s3://KEY:SECRET@bucket?region=…`.\n *\n * @throws {BucketKeySetElsewhere} from `keyIdOf`, when the URL names another bucket\n */\nexport function s3KeySecret(\n\tctx: Pick<KeyContext, 'stage'>,\n\tclients: Pick<IamClients, 'region' | 'endpoint'>,\n\tinput: { bucket: string; urlKey: string },\n): KeySecret {\n\tconst { bucket, urlKey } = input;\n\tconst parse = (value: string) => {\n\t\tlet parsed: s3Url.S3Address | undefined;\n\t\ttry {\n\t\t\tparsed = s3Url.parse(value);\n\t\t} catch {\n\t\t\tparsed = undefined;\n\t\t}\n\t\tif (parsed?.bucket !== bucket) {\n\t\t\tthrow new BucketKeySetElsewhere(\n\t\t\t\turlKey,\n\t\t\t\tbucket,\n\t\t\t\tparsed?.bucket ?? value.replace(/\\/\\/[^@]*@/, '//'),\n\t\t\t\tctx.stage,\n\t\t\t);\n\t\t}\n\t\treturn parsed;\n\t};\n\treturn {\n\t\tkey: urlKey,\n\t\tkeyIdOf: (value) => parse(value).accessKeyId,\n\t\tvalue: (accessKeyId, secretAccessKey) =>\n\t\t\ts3Url.build({\n\t\t\t\tbucket,\n\t\t\t\tregion: clients.region,\n\t\t\t\t...(clients.endpoint\n\t\t\t\t\t? { endpoint: clients.endpoint, forcePathStyle: true }\n\t\t\t\t\t: {}),\n\t\t\t\taccessKeyId,\n\t\t\t\tsecretAccessKey,\n\t\t\t}),\n\t\trepair(value) {\n\t\t\t// The key is good; the address must name where the bucket is.\n\t\t\tconst address = parse(value);\n\t\t\tif (address.region === clients.region) return undefined;\n\t\t\treturn {\n\t\t\t\tvalue: s3Url.build({ ...address, region: clients.region }),\n\t\t\t\tchange: `name ${clients.region}, the bucket's region (it said ${address.region ?? 'none'})`,\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport interface AccessKeyInput {\n\t/** What it is for, as {@link IamUserInput.id}. */\n\tid: string;\n\tuser: string;\n\t/** Whether the user exists yet — false in a dry run that would create it. */\n\texists: boolean;\n\t/** Where the key is written. */\n\tsecret: KeySecret;\n}\n\n/**\n * The user's access key, in the stage's secrets as `secret` writes it.\n *\n * - First run: one key, written into the stage's secrets.\n * - `--rotate-keys`: a second key, written in place of the first; the first\n * stays active until the stage has deployed with the second, and the next\n * run after that deploy — or `--retire-old-keys` — deletes it.\n * - A key the secrets no longer hold (a store emptied by hand): replaced the\n * same way, since its secret cannot be read back.\n *\n * @throws whatever `secret.keyIdOf` throws for a value set elsewhere\n * @throws {RotationInProgress} on `--rotate-keys` with the last rotation's old key still active\n * @throws {AccessKeyLimit} when the user has two keys gkm did not record\n */\nexport async function ensureAccessKey(\n\tctx: KeyContext,\n\tclients: IamClients,\n\tinput: AccessKeyInput,\n): Promise<void> {\n\tconst { IAM, iam } = clients;\n\tconst { id, user, secret } = input;\n\tconst entryKey = `iam-access-key:${id}`;\n\tconst record = ctx.state.record(entryKey);\n\n\tconst given = ctx.secrets[secret.key];\n\tconst inUrl = given !== undefined ? secret.keyIdOf(given) : undefined;\n\n\tconst listed = input.exists\n\t\t? ((\n\t\t\t\tawait iam.send(new IAM.ListAccessKeysCommand({ UserName: user }))\n\t\t\t).AccessKeyMetadata?.map((k) => k.AccessKeyId!) ?? [])\n\t\t: [];\n\n\tlet current = record?.status === 'ready' ? record.id : undefined;\n\tlet previous =\n\t\ttypeof record?.data?.previous === 'string'\n\t\t\t? record.data.previous\n\t\t\t: undefined;\n\tconst rotatedAt =\n\t\ttypeof record?.data?.rotatedAt === 'string'\n\t\t\t? record.data.rotatedAt\n\t\t\t: undefined;\n\tconst entry = (data: Record<string, unknown> = {}): StateEntry => ({\n\t\tkey: entryKey,\n\t\ttype: 'iam-access-key',\n\t\tdata: { user, ...data },\n\t});\n\n\t// The old key of a rotation: deleted once the stage deployed after it.\n\tif (previous && current) {\n\t\tconst deployed =\n\t\t\trotatedAt !== undefined &&\n\t\t\tctx.state.lastDeployedAt !== undefined &&\n\t\t\tctx.state.lastDeployedAt > rotatedAt;\n\t\tif (ctx.retireOldKeys || deployed) {\n\t\t\tconst old = previous;\n\t\t\tconst keep = current;\n\t\t\tawait ctx.change(\n\t\t\t\t{\n\t\t\t\t\tconstruct: id,\n\t\t\t\t\tresource: `IAM user ${user}`,\n\t\t\t\t\tchange: `delete the rotated-out access key ${old}`,\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\tif (listed.includes(old)) {\n\t\t\t\t\t\tawait iam.send(\n\t\t\t\t\t\t\tnew IAM.DeleteAccessKeyCommand({\n\t\t\t\t\t\t\t\tUserName: user,\n\t\t\t\t\t\t\t\tAccessKeyId: old,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tawait ctx.state.ready(entry(), keep);\n\t\t\t\t},\n\t\t\t);\n\t\t\tprevious = undefined;\n\t\t} else {\n\t\t\tctx.log(\n\t\t\t\t` ${id}: the old access key ${previous} stays active until '${ctx.stage}' is deployed with the new one; the next deploy after that deletes it (or pass --retire-old-keys)`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// No record, and the secrets hold a key of this user's: adopt it.\n\tif (!current && inUrl && listed.includes(inUrl)) {\n\t\tawait ctx.state.ready(entry(), inUrl);\n\t\tcurrent = inUrl;\n\t}\n\n\tconst valid =\n\t\tcurrent !== undefined && listed.includes(current) && inUrl === current;\n\tif (valid && !ctx.rotateKeys) {\n\t\tconst repaired = given !== undefined ? secret.repair?.(given) : undefined;\n\t\tif (repaired) {\n\t\t\tawait ctx.change(\n\t\t\t\t{ construct: id, resource: secret.key, change: repaired.change },\n\t\t\t\t() => ctx.writeSecrets({ [secret.key]: repaired.value }),\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\tif (ctx.rotateKeys && previous) {\n\t\tthrow new RotationInProgress(id, previous, ctx.stage);\n\t}\n\n\tconst outgoing = current && listed.includes(current) ? current : undefined;\n\tif (listed.length >= 2) throw new AccessKeyLimit(user, listed);\n\n\tconst why = !current\n\t\t? 'create an access key'\n\t\t: ctx.rotateKeys\n\t\t\t? 'rotate: issue a new access key'\n\t\t\t: 'issue a new access key (the secrets no longer hold the recorded one)';\n\tawait ctx.change(\n\t\t{ construct: id, resource: `IAM user ${user}`, change: why },\n\t\tasync () => {\n\t\t\tawait ctx.state.pending(entry(outgoing ? { previous: outgoing } : {}));\n\t\t\tconst created = await iam.send(\n\t\t\t\tnew IAM.CreateAccessKeyCommand({ UserName: user }),\n\t\t\t);\n\t\t\tconst key = created.AccessKey!;\n\t\t\t// Into the stage's secrets before anything else: IAM shows a secret\n\t\t\t// once, and a key whose secret is lost is a key to replace.\n\t\t\tawait ctx.writeSecrets({\n\t\t\t\t[secret.key]: secret.value(key.AccessKeyId!, key.SecretAccessKey!),\n\t\t\t});\n\t\t\t// When it was issued: IAM takes seconds to make a new key usable,\n\t\t\t// and the deploy's check waits for one this young.\n\t\t\tconst issuedAt = new Date().toISOString();\n\t\t\tawait ctx.state.ready(\n\t\t\t\tentry(\n\t\t\t\t\toutgoing\n\t\t\t\t\t\t? { previous: outgoing, rotatedAt: issuedAt, issuedAt }\n\t\t\t\t\t\t: { issuedAt },\n\t\t\t\t),\n\t\t\t\tkey.AccessKeyId!,\n\t\t\t);\n\t\t},\n\t);\n\tif (outgoing) {\n\t\tctx.log(\n\t\t\t` ${secret.key} holds the new key. This deploy moves '${ctx.stage}' onto it; the next deploy after it deletes the old key ${outgoing}`,\n\t\t);\n\t}\n}\n\n/** How long a key issued this recently counts as new to IAM. */\nconst NEW_KEY_WINDOW_MS = 10 * 60 * 1000;\n\n/** The waits between asks while a new key becomes usable: about a minute. */\nlet newKeyWaits: readonly number[] = [2000, 4000, 8000, 15000, 15000, 15000];\n\n/** For tests: the waits for a new key. Returns the old ones. */\nexport function useNewKeyWaits(waits: readonly number[]): readonly number[] {\n\tconst previous = newKeyWaits;\n\tnewKeyWaits = waits;\n\treturn previous;\n}\n\n/**\n * When the key in a URL was issued, if the stage's state says it was just\n * now — the record of `id`'s key naming that very key.\n */\nexport function issuedJustNow(\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined,\n\tid: string,\n\taccessKeyId: string,\n): string | undefined {\n\tconst record = resources?.[`iam-access-key:${id}`];\n\tconst issuedAt = record?.data?.issuedAt;\n\tif (record?.id !== accessKeyId || typeof issuedAt !== 'string') {\n\t\treturn undefined;\n\t}\n\tconst age = Date.now() - Date.parse(issuedAt);\n\treturn age >= 0 && age < NEW_KEY_WINDOW_MS ? issuedAt : undefined;\n}\n\n/**\n * `ask` again, for about a minute, while it is `refused` and the key was\n * issued just now — IAM refuses a key for seconds after making it. Returns\n * the last answer and how long was waited.\n */\nexport async function whileKeyIsNew<T>(\n\tfirst: T,\n\toptions: {\n\t\tissuedAt: string | undefined;\n\t\trefused: (answer: T) => boolean;\n\t\task: () => Promise<T>;\n\t\t/** Said once, before the first wait. */\n\t\tonWait?: () => void;\n\t},\n): Promise<{ answer: T; waited: number }> {\n\tlet answer = first;\n\tlet waited = 0;\n\tif (!options.issuedAt || !options.refused(answer)) return { answer, waited };\n\toptions.onWait?.();\n\tfor (const wait of newKeyWaits) {\n\t\tawait new Promise((resolve) => setTimeout(resolve, wait));\n\t\twaited += wait;\n\t\tanswer = await options.ask();\n\t\tif (!options.refused(answer)) break;\n\t}\n\treturn { answer, waited };\n}\n"],"mappings":";;;AAuBA,MAAM,aAAa,WAAmB,gBAAgB;;;;;;;;;AAUtD,SAAgB,WACf,QACA,UAQI,CAAC,GACY;CACjB,OAAO;EACN,SAAS;EACT,WAAW;GACV;IACC,KAAK;IACL,QAAQ;IACR,QAAQ;KACP;KACA;KACA;KACA;KACA;KACA,GAAI,QAAQ,aAAa,CAAC,qBAAqB,IAAI,CAAC;IACrD;IACA,UAAU,GAAG,UAAU,MAAM,EAAE;GAChC;GACA;IACC,KAAK;IACL,QAAQ;IACR,QAAQ;KACP;KACA;KACA;IACD;IACA,UAAU,UAAU,MAAM;GAC3B;GACA,GAAI,QAAQ,iBACT,CACA;IACC,KAAK;IACL,QAAQ;IACR,QAAQ;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require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_workspace = require("./workspace-wTLnc1Ef.cjs");
|
|
3
|
+
let _geekmidas_storage_s3_url = require("@geekmidas/storage/s3-url");
|
|
4
|
+
_geekmidas_storage_s3_url = require_rolldown_runtime.__toESM(_geekmidas_storage_s3_url, 1);
|
|
5
|
+
//#region src/providers/s3/policy.ts
|
|
6
|
+
const bucketArn = (bucket) => `arn:aws:s3:::${bucket}`;
|
|
7
|
+
/**
|
|
8
|
+
* What the app's key may do: objects in this bucket, and listing it — and
|
|
9
|
+
* nothing else in the account.
|
|
10
|
+
*
|
|
11
|
+
* Multipart uploads are in it because a presigned upload of a large file is
|
|
12
|
+
* one, and an abandoned one is cleaned up by the app. Reading old versions is
|
|
13
|
+
* added only when the bucket keeps them.
|
|
14
|
+
*/
|
|
15
|
+
function userPolicy(bucket, options = {}) {
|
|
16
|
+
return {
|
|
17
|
+
Version: "2012-10-17",
|
|
18
|
+
Statement: [
|
|
19
|
+
{
|
|
20
|
+
Sid: "GkmObjects",
|
|
21
|
+
Effect: "Allow",
|
|
22
|
+
Action: [
|
|
23
|
+
"s3:GetObject",
|
|
24
|
+
"s3:PutObject",
|
|
25
|
+
"s3:DeleteObject",
|
|
26
|
+
"s3:AbortMultipartUpload",
|
|
27
|
+
"s3:ListMultipartUploadParts",
|
|
28
|
+
...options.versioning ? ["s3:GetObjectVersion"] : []
|
|
29
|
+
],
|
|
30
|
+
Resource: `${bucketArn(bucket)}/*`
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
Sid: "GkmBucket",
|
|
34
|
+
Effect: "Allow",
|
|
35
|
+
Action: [
|
|
36
|
+
"s3:ListBucket",
|
|
37
|
+
"s3:GetBucketLocation",
|
|
38
|
+
"s3:ListBucketMultipartUploads"
|
|
39
|
+
],
|
|
40
|
+
Resource: bucketArn(bucket)
|
|
41
|
+
},
|
|
42
|
+
...options.eventsTopicArn ? [{
|
|
43
|
+
Sid: "GkmEvents",
|
|
44
|
+
Effect: "Allow",
|
|
45
|
+
Action: "sns:ConfirmSubscription",
|
|
46
|
+
Resource: options.eventsTopicArn
|
|
47
|
+
}] : []
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One open pattern as the resource it is public on. A `**` is S3's `*`; a
|
|
53
|
+
* single `*` is too, which crosses `/` where the construct's own check does
|
|
54
|
+
* not — the construct is the stricter of the two (see `bucketPolicy` in
|
|
55
|
+
* reconcile, which the local MinIO is given the same way).
|
|
56
|
+
*/
|
|
57
|
+
function openResource(bucket, pattern) {
|
|
58
|
+
const path = pattern.replace(/^\/+/, "").replace(/\*\*/g, "*");
|
|
59
|
+
return `${bucketArn(bucket)}/${path}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The bucket's own policy: every request refused unless it came over TLS,
|
|
63
|
+
* and — only when a file server opens paths on it — `s3:GetObject` on
|
|
64
|
+
* exactly those prefixes: to anyone, or, when a CDN serves them, to
|
|
65
|
+
* CloudFront alone, for exactly the stage's distributions. Behind a CDN the
|
|
66
|
+
* bucket is never public: a key outside the open prefixes is refused to
|
|
67
|
+
* CloudFront too, so the edge answers it 403.
|
|
68
|
+
*/
|
|
69
|
+
function bucketPolicy(bucket, open = [], options = {}) {
|
|
70
|
+
const statements = [{
|
|
71
|
+
Sid: "GkmDenyInsecureTransport",
|
|
72
|
+
Effect: "Deny",
|
|
73
|
+
Principal: "*",
|
|
74
|
+
Action: "s3:*",
|
|
75
|
+
Resource: [bucketArn(bucket), `${bucketArn(bucket)}/*`],
|
|
76
|
+
Condition: { Bool: { "aws:SecureTransport": "false" } }
|
|
77
|
+
}];
|
|
78
|
+
const resources = [...new Set(open.map((p) => openResource(bucket, p)))].sort();
|
|
79
|
+
if (open.length > 0 && options.cdn) statements.push({
|
|
80
|
+
Sid: "GkmCdnRead",
|
|
81
|
+
Effect: "Allow",
|
|
82
|
+
Principal: { Service: "cloudfront.amazonaws.com" },
|
|
83
|
+
Action: "s3:GetObject",
|
|
84
|
+
Resource: resources,
|
|
85
|
+
Condition: { StringEquals: { "AWS:SourceArn": [...new Set(options.cdn.distributionArns)].sort() } }
|
|
86
|
+
});
|
|
87
|
+
else if (open.length > 0) statements.push({
|
|
88
|
+
Sid: "GkmOpenPaths",
|
|
89
|
+
Effect: "Allow",
|
|
90
|
+
Principal: "*",
|
|
91
|
+
Action: "s3:GetObject",
|
|
92
|
+
Resource: resources
|
|
93
|
+
});
|
|
94
|
+
if (options.sesWrite) statements.push({
|
|
95
|
+
Sid: "GkmSesWritesMail",
|
|
96
|
+
Effect: "Allow",
|
|
97
|
+
Principal: { Service: "ses.amazonaws.com" },
|
|
98
|
+
Action: "s3:PutObject",
|
|
99
|
+
Resource: `${bucketArn(bucket)}/${options.sesWrite.prefix}*`,
|
|
100
|
+
Condition: { StringEquals: { "aws:SourceAccount": options.sesWrite.account } }
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
Version: "2012-10-17",
|
|
104
|
+
Statement: statements
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Block Public Access. All four flags on, unless the bucket has open paths:
|
|
109
|
+
* then a *policy* may make it public (`BlockPublicPolicy`,
|
|
110
|
+
* `RestrictPublicBuckets` off), and ACLs still may not.
|
|
111
|
+
*/
|
|
112
|
+
function publicAccessBlock(open) {
|
|
113
|
+
return {
|
|
114
|
+
BlockPublicAcls: true,
|
|
115
|
+
IgnorePublicAcls: true,
|
|
116
|
+
BlockPublicPolicy: !open,
|
|
117
|
+
RestrictPublicBuckets: !open
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function corsRule(origins) {
|
|
121
|
+
return {
|
|
122
|
+
AllowedMethods: [
|
|
123
|
+
"GET",
|
|
124
|
+
"HEAD",
|
|
125
|
+
"POST",
|
|
126
|
+
"PUT"
|
|
127
|
+
],
|
|
128
|
+
AllowedOrigins: [...new Set(origins)].sort(),
|
|
129
|
+
AllowedHeaders: ["*"],
|
|
130
|
+
ExposeHeaders: ["ETag"],
|
|
131
|
+
MaxAgeSeconds: 3e3
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A policy document in one canonical form — keys sorted, a lone string a
|
|
136
|
+
* one-element list, lists sorted — so one AWS reformatted reads as the same
|
|
137
|
+
* document rather than as drift.
|
|
138
|
+
*/
|
|
139
|
+
function canonicalPolicy(value) {
|
|
140
|
+
return JSON.stringify(canonical(value));
|
|
141
|
+
}
|
|
142
|
+
function canonical(value, key) {
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
const items = value.map((v) => canonical(v));
|
|
145
|
+
return key === "Statement" ? items : items.map((v) => JSON.stringify(v)).sort();
|
|
146
|
+
}
|
|
147
|
+
if (value && typeof value === "object") return Object.fromEntries(Object.keys(value).sort().map((k) => {
|
|
148
|
+
const v = value[k];
|
|
149
|
+
return [k, canonical(k === "Action" || k === "Resource" || k === "AWS" || k === "AWS:SourceArn" ? Array.isArray(v) ? v : [v] : v, k)];
|
|
150
|
+
}));
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/providers/iam.ts
|
|
155
|
+
/**
|
|
156
|
+
* An IAM user gkm creates for one thing on a stage, its inline policy, and
|
|
157
|
+
* the access key written into the stage's secrets — as an `s3://` URL for
|
|
158
|
+
* what the `s3` provider gives each bucket and the deploy gives a stage's
|
|
159
|
+
* backups, as an `smtp://` one for the `ses` mail provider.
|
|
160
|
+
*
|
|
161
|
+
* - **The user** is under `/gkm/`, tagged with the deploy identity, the stage
|
|
162
|
+
* and what it is for. One that exists without those tags is someone
|
|
163
|
+
* else's, and is refused rather than taken over.
|
|
164
|
+
* - **Its policy** is read on every run and put back when it drifted.
|
|
165
|
+
* - **Its key**: one, written into the stage's secrets the moment IAM shows
|
|
166
|
+
* its secret. `--rotate-keys` issues a successor and keeps the old one
|
|
167
|
+
* active until the stage has deployed with the new one; the next run after
|
|
168
|
+
* that — or `--retire-old-keys` — deletes it.
|
|
169
|
+
* - **A new key** takes IAM seconds to become usable: the state records when
|
|
170
|
+
* it was issued, and a check made with it waits that out
|
|
171
|
+
* ({@link whileKeyIsNew}).
|
|
172
|
+
*/
|
|
173
|
+
/** The tags gkm finds its own buckets and users by. */
|
|
174
|
+
const TAG_PROJECT = "gkm:project";
|
|
175
|
+
const TAG_STAGE = "gkm:stage";
|
|
176
|
+
const TAG_CONSTRUCT = "gkm:construct";
|
|
177
|
+
/** The keys gkm tags a bucket and a user with. */
|
|
178
|
+
function identityTags(ctx, id) {
|
|
179
|
+
return [
|
|
180
|
+
{
|
|
181
|
+
Key: TAG_PROJECT,
|
|
182
|
+
Value: ctx.identity.key
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
Key: TAG_STAGE,
|
|
186
|
+
Value: ctx.stage
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
Key: TAG_CONSTRUCT,
|
|
190
|
+
Value: id
|
|
191
|
+
}
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
/** A read whose "there is none" answer is one of `missing`. */
|
|
195
|
+
async function readOr(read, missing) {
|
|
196
|
+
try {
|
|
197
|
+
return await read();
|
|
198
|
+
} catch (error) {
|
|
199
|
+
const e = error;
|
|
200
|
+
if (missing.includes(e?.Code ?? e?.name ?? "")) return void 0;
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** IAM returns a policy document URL-encoded; an emulator may not. */
|
|
205
|
+
function decodePolicy(document) {
|
|
206
|
+
try {
|
|
207
|
+
return decodeURIComponent(document);
|
|
208
|
+
} catch {
|
|
209
|
+
return document;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The user and its inline policy: found — and refused when it is not this
|
|
214
|
+
* stage's — or created, and the policy put back when it drifted.
|
|
215
|
+
*
|
|
216
|
+
* @throws {IamUserNotOwned}
|
|
217
|
+
*/
|
|
218
|
+
async function ensureIamUser(ctx, clients, input) {
|
|
219
|
+
const { IAM, iam } = clients;
|
|
220
|
+
const { id, user, policy } = input;
|
|
221
|
+
const entry = {
|
|
222
|
+
key: `iam-user:${id}`,
|
|
223
|
+
type: "iam-user"
|
|
224
|
+
};
|
|
225
|
+
const found = await readOr(() => iam.send(new IAM.GetUserCommand({ UserName: user })), ["NoSuchEntity", "NoSuchEntityException"]);
|
|
226
|
+
if (found?.User) {
|
|
227
|
+
const tags = await iam.send(new IAM.ListUserTagsCommand({ UserName: user }));
|
|
228
|
+
const tag = (key) => tags.Tags?.find((t) => t.Key === key)?.Value;
|
|
229
|
+
if (found.User.Path !== "/gkm/" || tag("gkm:project") !== ctx.identity.key || tag("gkm:stage") !== ctx.stage) throw new require_workspace.IamUserNotOwned(user, ctx.identity.key, ctx.stage);
|
|
230
|
+
await ctx.state.ready(entry, user);
|
|
231
|
+
} else await ctx.change({
|
|
232
|
+
construct: id,
|
|
233
|
+
resource: `IAM user ${user}`,
|
|
234
|
+
change: `create under ${require_workspace.IAM_USER_PATH}`
|
|
235
|
+
}, async () => {
|
|
236
|
+
await ctx.state.pending(entry);
|
|
237
|
+
await iam.send(new IAM.CreateUserCommand({
|
|
238
|
+
UserName: user,
|
|
239
|
+
Path: require_workspace.IAM_USER_PATH,
|
|
240
|
+
Tags: identityTags(ctx, id)
|
|
241
|
+
}));
|
|
242
|
+
await ctx.state.ready(entry, user);
|
|
243
|
+
});
|
|
244
|
+
const exists = Boolean(found?.User) || !ctx.dryRun;
|
|
245
|
+
const current = exists ? await readOr(() => iam.send(new IAM.GetUserPolicyCommand({
|
|
246
|
+
UserName: user,
|
|
247
|
+
PolicyName: input.policyName
|
|
248
|
+
})), ["NoSuchEntity", "NoSuchEntityException"]) : void 0;
|
|
249
|
+
const document = current?.PolicyDocument ? JSON.parse(decodePolicy(current.PolicyDocument)) : void 0;
|
|
250
|
+
if (!document || canonicalPolicy(document) !== canonicalPolicy(policy)) await ctx.change({
|
|
251
|
+
construct: id,
|
|
252
|
+
resource: `IAM user ${user}`,
|
|
253
|
+
change: `policy ${input.policyName}: ${input.describe}`
|
|
254
|
+
}, async () => {
|
|
255
|
+
await iam.send(new IAM.PutUserPolicyCommand({
|
|
256
|
+
UserName: user,
|
|
257
|
+
PolicyName: input.policyName,
|
|
258
|
+
PolicyDocument: JSON.stringify(policy)
|
|
259
|
+
}));
|
|
260
|
+
});
|
|
261
|
+
return {
|
|
262
|
+
user,
|
|
263
|
+
exists
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* A bucket's URL as a key's secret: `s3://KEY:SECRET@bucket?region=…`.
|
|
268
|
+
*
|
|
269
|
+
* @throws {BucketKeySetElsewhere} from `keyIdOf`, when the URL names another bucket
|
|
270
|
+
*/
|
|
271
|
+
function s3KeySecret(ctx, clients, input) {
|
|
272
|
+
const { bucket, urlKey } = input;
|
|
273
|
+
const parse = (value) => {
|
|
274
|
+
let parsed;
|
|
275
|
+
try {
|
|
276
|
+
parsed = _geekmidas_storage_s3_url.parse(value);
|
|
277
|
+
} catch {
|
|
278
|
+
parsed = void 0;
|
|
279
|
+
}
|
|
280
|
+
if (parsed?.bucket !== bucket) throw new require_workspace.BucketKeySetElsewhere(urlKey, bucket, parsed?.bucket ?? value.replace(/\/\/[^@]*@/, "//"), ctx.stage);
|
|
281
|
+
return parsed;
|
|
282
|
+
};
|
|
283
|
+
return {
|
|
284
|
+
key: urlKey,
|
|
285
|
+
keyIdOf: (value) => parse(value).accessKeyId,
|
|
286
|
+
value: (accessKeyId, secretAccessKey) => _geekmidas_storage_s3_url.build({
|
|
287
|
+
bucket,
|
|
288
|
+
region: clients.region,
|
|
289
|
+
...clients.endpoint ? {
|
|
290
|
+
endpoint: clients.endpoint,
|
|
291
|
+
forcePathStyle: true
|
|
292
|
+
} : {},
|
|
293
|
+
accessKeyId,
|
|
294
|
+
secretAccessKey
|
|
295
|
+
}),
|
|
296
|
+
repair(value) {
|
|
297
|
+
const address = parse(value);
|
|
298
|
+
if (address.region === clients.region) return void 0;
|
|
299
|
+
return {
|
|
300
|
+
value: _geekmidas_storage_s3_url.build({
|
|
301
|
+
...address,
|
|
302
|
+
region: clients.region
|
|
303
|
+
}),
|
|
304
|
+
change: `name ${clients.region}, the bucket's region (it said ${address.region ?? "none"})`
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The user's access key, in the stage's secrets as `secret` writes it.
|
|
311
|
+
*
|
|
312
|
+
* - First run: one key, written into the stage's secrets.
|
|
313
|
+
* - `--rotate-keys`: a second key, written in place of the first; the first
|
|
314
|
+
* stays active until the stage has deployed with the second, and the next
|
|
315
|
+
* run after that deploy — or `--retire-old-keys` — deletes it.
|
|
316
|
+
* - A key the secrets no longer hold (a store emptied by hand): replaced the
|
|
317
|
+
* same way, since its secret cannot be read back.
|
|
318
|
+
*
|
|
319
|
+
* @throws whatever `secret.keyIdOf` throws for a value set elsewhere
|
|
320
|
+
* @throws {RotationInProgress} on `--rotate-keys` with the last rotation's old key still active
|
|
321
|
+
* @throws {AccessKeyLimit} when the user has two keys gkm did not record
|
|
322
|
+
*/
|
|
323
|
+
async function ensureAccessKey(ctx, clients, input) {
|
|
324
|
+
const { IAM, iam } = clients;
|
|
325
|
+
const { id, user, secret } = input;
|
|
326
|
+
const entryKey = `iam-access-key:${id}`;
|
|
327
|
+
const record = ctx.state.record(entryKey);
|
|
328
|
+
const given = ctx.secrets[secret.key];
|
|
329
|
+
const inUrl = given !== void 0 ? secret.keyIdOf(given) : void 0;
|
|
330
|
+
const listed = input.exists ? (await iam.send(new IAM.ListAccessKeysCommand({ UserName: user }))).AccessKeyMetadata?.map((k) => k.AccessKeyId) ?? [] : [];
|
|
331
|
+
let current = record?.status === "ready" ? record.id : void 0;
|
|
332
|
+
let previous = typeof record?.data?.previous === "string" ? record.data.previous : void 0;
|
|
333
|
+
const rotatedAt = typeof record?.data?.rotatedAt === "string" ? record.data.rotatedAt : void 0;
|
|
334
|
+
const entry = (data = {}) => ({
|
|
335
|
+
key: entryKey,
|
|
336
|
+
type: "iam-access-key",
|
|
337
|
+
data: {
|
|
338
|
+
user,
|
|
339
|
+
...data
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
if (previous && current) {
|
|
343
|
+
const deployed = rotatedAt !== void 0 && ctx.state.lastDeployedAt !== void 0 && ctx.state.lastDeployedAt > rotatedAt;
|
|
344
|
+
if (ctx.retireOldKeys || deployed) {
|
|
345
|
+
const old = previous;
|
|
346
|
+
const keep = current;
|
|
347
|
+
await ctx.change({
|
|
348
|
+
construct: id,
|
|
349
|
+
resource: `IAM user ${user}`,
|
|
350
|
+
change: `delete the rotated-out access key ${old}`
|
|
351
|
+
}, async () => {
|
|
352
|
+
if (listed.includes(old)) await iam.send(new IAM.DeleteAccessKeyCommand({
|
|
353
|
+
UserName: user,
|
|
354
|
+
AccessKeyId: old
|
|
355
|
+
}));
|
|
356
|
+
await ctx.state.ready(entry(), keep);
|
|
357
|
+
});
|
|
358
|
+
previous = void 0;
|
|
359
|
+
} else ctx.log(` ${id}: the old access key ${previous} stays active until '${ctx.stage}' is deployed with the new one; the next deploy after that deletes it (or pass --retire-old-keys)`);
|
|
360
|
+
}
|
|
361
|
+
if (!current && inUrl && listed.includes(inUrl)) {
|
|
362
|
+
await ctx.state.ready(entry(), inUrl);
|
|
363
|
+
current = inUrl;
|
|
364
|
+
}
|
|
365
|
+
if (current !== void 0 && listed.includes(current) && inUrl === current && !ctx.rotateKeys) {
|
|
366
|
+
const repaired = given !== void 0 ? secret.repair?.(given) : void 0;
|
|
367
|
+
if (repaired) await ctx.change({
|
|
368
|
+
construct: id,
|
|
369
|
+
resource: secret.key,
|
|
370
|
+
change: repaired.change
|
|
371
|
+
}, () => ctx.writeSecrets({ [secret.key]: repaired.value }));
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (ctx.rotateKeys && previous) throw new require_workspace.RotationInProgress(id, previous, ctx.stage);
|
|
375
|
+
const outgoing = current && listed.includes(current) ? current : void 0;
|
|
376
|
+
if (listed.length >= 2) throw new require_workspace.AccessKeyLimit(user, listed);
|
|
377
|
+
const why = !current ? "create an access key" : ctx.rotateKeys ? "rotate: issue a new access key" : "issue a new access key (the secrets no longer hold the recorded one)";
|
|
378
|
+
await ctx.change({
|
|
379
|
+
construct: id,
|
|
380
|
+
resource: `IAM user ${user}`,
|
|
381
|
+
change: why
|
|
382
|
+
}, async () => {
|
|
383
|
+
await ctx.state.pending(entry(outgoing ? { previous: outgoing } : {}));
|
|
384
|
+
const key = (await iam.send(new IAM.CreateAccessKeyCommand({ UserName: user }))).AccessKey;
|
|
385
|
+
await ctx.writeSecrets({ [secret.key]: secret.value(key.AccessKeyId, key.SecretAccessKey) });
|
|
386
|
+
const issuedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
387
|
+
await ctx.state.ready(entry(outgoing ? {
|
|
388
|
+
previous: outgoing,
|
|
389
|
+
rotatedAt: issuedAt,
|
|
390
|
+
issuedAt
|
|
391
|
+
} : { issuedAt }), key.AccessKeyId);
|
|
392
|
+
});
|
|
393
|
+
if (outgoing) ctx.log(` ${secret.key} holds the new key. This deploy moves '${ctx.stage}' onto it; the next deploy after it deletes the old key ${outgoing}`);
|
|
394
|
+
}
|
|
395
|
+
/** How long a key issued this recently counts as new to IAM. */
|
|
396
|
+
const NEW_KEY_WINDOW_MS = 6e5;
|
|
397
|
+
/** The waits between asks while a new key becomes usable: about a minute. */
|
|
398
|
+
let newKeyWaits = [
|
|
399
|
+
2e3,
|
|
400
|
+
4e3,
|
|
401
|
+
8e3,
|
|
402
|
+
15e3,
|
|
403
|
+
15e3,
|
|
404
|
+
15e3
|
|
405
|
+
];
|
|
406
|
+
/**
|
|
407
|
+
* When the key in a URL was issued, if the stage's state says it was just
|
|
408
|
+
* now — the record of `id`'s key naming that very key.
|
|
409
|
+
*/
|
|
410
|
+
function issuedJustNow(resources, id, accessKeyId) {
|
|
411
|
+
const record = resources?.[`iam-access-key:${id}`];
|
|
412
|
+
const issuedAt = record?.data?.issuedAt;
|
|
413
|
+
if (record?.id !== accessKeyId || typeof issuedAt !== "string") return;
|
|
414
|
+
const age = Date.now() - Date.parse(issuedAt);
|
|
415
|
+
return age >= 0 && age < NEW_KEY_WINDOW_MS ? issuedAt : void 0;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* `ask` again, for about a minute, while it is `refused` and the key was
|
|
419
|
+
* issued just now — IAM refuses a key for seconds after making it. Returns
|
|
420
|
+
* the last answer and how long was waited.
|
|
421
|
+
*/
|
|
422
|
+
async function whileKeyIsNew(first, options) {
|
|
423
|
+
let answer = first;
|
|
424
|
+
let waited = 0;
|
|
425
|
+
if (!options.issuedAt || !options.refused(answer)) return {
|
|
426
|
+
answer,
|
|
427
|
+
waited
|
|
428
|
+
};
|
|
429
|
+
options.onWait?.();
|
|
430
|
+
for (const wait of newKeyWaits) {
|
|
431
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
432
|
+
waited += wait;
|
|
433
|
+
answer = await options.ask();
|
|
434
|
+
if (!options.refused(answer)) break;
|
|
435
|
+
}
|
|
436
|
+
return {
|
|
437
|
+
answer,
|
|
438
|
+
waited
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
Object.defineProperty(exports, "TAG_PROJECT", {
|
|
443
|
+
enumerable: true,
|
|
444
|
+
get: function() {
|
|
445
|
+
return TAG_PROJECT;
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
Object.defineProperty(exports, "TAG_STAGE", {
|
|
449
|
+
enumerable: true,
|
|
450
|
+
get: function() {
|
|
451
|
+
return TAG_STAGE;
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
Object.defineProperty(exports, "bucketPolicy", {
|
|
455
|
+
enumerable: true,
|
|
456
|
+
get: function() {
|
|
457
|
+
return bucketPolicy;
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
Object.defineProperty(exports, "canonicalPolicy", {
|
|
461
|
+
enumerable: true,
|
|
462
|
+
get: function() {
|
|
463
|
+
return canonicalPolicy;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
Object.defineProperty(exports, "corsRule", {
|
|
467
|
+
enumerable: true,
|
|
468
|
+
get: function() {
|
|
469
|
+
return corsRule;
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
Object.defineProperty(exports, "ensureAccessKey", {
|
|
473
|
+
enumerable: true,
|
|
474
|
+
get: function() {
|
|
475
|
+
return ensureAccessKey;
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
Object.defineProperty(exports, "ensureIamUser", {
|
|
479
|
+
enumerable: true,
|
|
480
|
+
get: function() {
|
|
481
|
+
return ensureIamUser;
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
Object.defineProperty(exports, "identityTags", {
|
|
485
|
+
enumerable: true,
|
|
486
|
+
get: function() {
|
|
487
|
+
return identityTags;
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
Object.defineProperty(exports, "issuedJustNow", {
|
|
491
|
+
enumerable: true,
|
|
492
|
+
get: function() {
|
|
493
|
+
return issuedJustNow;
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
Object.defineProperty(exports, "publicAccessBlock", {
|
|
497
|
+
enumerable: true,
|
|
498
|
+
get: function() {
|
|
499
|
+
return publicAccessBlock;
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
Object.defineProperty(exports, "s3KeySecret", {
|
|
503
|
+
enumerable: true,
|
|
504
|
+
get: function() {
|
|
505
|
+
return s3KeySecret;
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
Object.defineProperty(exports, "userPolicy", {
|
|
509
|
+
enumerable: true,
|
|
510
|
+
get: function() {
|
|
511
|
+
return userPolicy;
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
Object.defineProperty(exports, "whileKeyIsNew", {
|
|
515
|
+
enumerable: true,
|
|
516
|
+
get: function() {
|
|
517
|
+
return whileKeyIsNew;
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
//# sourceMappingURL=iam-WIoKnLBp.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-WIoKnLBp.cjs","names":["IamUserNotOwned","IAM_USER_PATH","s3Url","BucketKeySetElsewhere","RotationInProgress","AccessKeyLimit"],"sources":["../src/providers/s3/policy.ts","../src/providers/iam.ts"],"sourcesContent":["/**\n * The documents the `s3` provider writes: the user's inline policy, the\n * bucket's policy, its CORS rule and its public access block.\n *\n * Pure, so each is tested as JSON and compared with what AWS holds on every\n * run — a document that differs is drift, and is put back.\n */\n\n/** One IAM or bucket policy statement. */\nexport interface PolicyStatement {\n\tSid: string;\n\tEffect: 'Allow' | 'Deny';\n\tPrincipal?: '*' | { AWS: string | string[] } | { Service: string };\n\tAction: string | string[];\n\tResource: string | string[];\n\tCondition?: Record<string, Record<string, string | string[]>>;\n}\n\nexport interface PolicyDocument {\n\tVersion: '2012-10-17';\n\tStatement: PolicyStatement[];\n}\n\nconst bucketArn = (bucket: string) => `arn:aws:s3:::${bucket}`;\n\n/**\n * What the app's key may do: objects in this bucket, and listing it — and\n * nothing else in the account.\n *\n * Multipart uploads are in it because a presigned upload of a large file is\n * one, and an abandoned one is cleaned up by the app. Reading old versions is\n * added only when the bucket keeps them.\n */\nexport function userPolicy(\n\tbucket: string,\n\toptions: {\n\t\tversioning?: boolean;\n\t\t/**\n\t\t * The bucket's events topic, when a subscriber watches it: the worker\n\t\t * confirms the subscriptions the deploy made with this key, and does\n\t\t * nothing else to the topic.\n\t\t */\n\t\teventsTopicArn?: string;\n\t} = {},\n): PolicyDocument {\n\treturn {\n\t\tVersion: '2012-10-17',\n\t\tStatement: [\n\t\t\t{\n\t\t\t\tSid: 'GkmObjects',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t's3:GetObject',\n\t\t\t\t\t's3:PutObject',\n\t\t\t\t\t's3:DeleteObject',\n\t\t\t\t\t's3:AbortMultipartUpload',\n\t\t\t\t\t's3:ListMultipartUploadParts',\n\t\t\t\t\t...(options.versioning ? ['s3:GetObjectVersion'] : []),\n\t\t\t\t],\n\t\t\t\tResource: `${bucketArn(bucket)}/*`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tSid: 'GkmBucket',\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: [\n\t\t\t\t\t's3:ListBucket',\n\t\t\t\t\t's3:GetBucketLocation',\n\t\t\t\t\t's3:ListBucketMultipartUploads',\n\t\t\t\t],\n\t\t\t\tResource: bucketArn(bucket),\n\t\t\t},\n\t\t\t...(options.eventsTopicArn\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSid: 'GkmEvents',\n\t\t\t\t\t\t\tEffect: 'Allow' as const,\n\t\t\t\t\t\t\tAction: 'sns:ConfirmSubscription',\n\t\t\t\t\t\t\tResource: options.eventsTopicArn,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t],\n\t};\n}\n\n/**\n * One open pattern as the resource it is public on. A `**` is S3's `*`; a\n * single `*` is too, which crosses `/` where the construct's own check does\n * not — the construct is the stricter of the two (see `bucketPolicy` in\n * reconcile, which the local MinIO is given the same way).\n */\nexport function openResource(bucket: string, pattern: string): string {\n\tconst path = pattern.replace(/^\\/+/, '').replace(/\\*\\*/g, '*');\n\treturn `${bucketArn(bucket)}/${path}`;\n}\n\n/**\n * The bucket's own policy: every request refused unless it came over TLS,\n * and — only when a file server opens paths on it — `s3:GetObject` on\n * exactly those prefixes: to anyone, or, when a CDN serves them, to\n * CloudFront alone, for exactly the stage's distributions. Behind a CDN the\n * bucket is never public: a key outside the open prefixes is refused to\n * CloudFront too, so the edge answers it 403.\n */\nexport function bucketPolicy(\n\tbucket: string,\n\topen: readonly string[] = [],\n\toptions: {\n\t\tcdn?: { distributionArns: readonly string[] };\n\t\t/**\n\t\t * SES may write received mail under this prefix — the bucket an inbox\n\t\t * owns — and only for this account's receipt rules.\n\t\t */\n\t\tsesWrite?: { prefix: string; account: string };\n\t} = {},\n): PolicyDocument {\n\tconst statements: PolicyStatement[] = [\n\t\t{\n\t\t\tSid: 'GkmDenyInsecureTransport',\n\t\t\tEffect: 'Deny',\n\t\t\tPrincipal: '*',\n\t\t\tAction: 's3:*',\n\t\t\tResource: [bucketArn(bucket), `${bucketArn(bucket)}/*`],\n\t\t\tCondition: { Bool: { 'aws:SecureTransport': 'false' } },\n\t\t},\n\t];\n\tconst resources = [\n\t\t...new Set(open.map((p) => openResource(bucket, p))),\n\t].sort();\n\tif (open.length > 0 && options.cdn) {\n\t\tstatements.push({\n\t\t\tSid: 'GkmCdnRead',\n\t\t\tEffect: 'Allow',\n\t\t\tPrincipal: { Service: 'cloudfront.amazonaws.com' },\n\t\t\tAction: 's3:GetObject',\n\t\t\tResource: resources,\n\t\t\tCondition: {\n\t\t\t\tStringEquals: {\n\t\t\t\t\t'AWS:SourceArn': [...new Set(options.cdn.distributionArns)].sort(),\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t} else if (open.length > 0) {\n\t\tstatements.push({\n\t\t\tSid: 'GkmOpenPaths',\n\t\t\tEffect: 'Allow',\n\t\t\tPrincipal: '*',\n\t\t\tAction: 's3:GetObject',\n\t\t\tResource: resources,\n\t\t});\n\t}\n\tif (options.sesWrite) {\n\t\tstatements.push({\n\t\t\tSid: 'GkmSesWritesMail',\n\t\t\tEffect: 'Allow',\n\t\t\tPrincipal: { Service: 'ses.amazonaws.com' },\n\t\t\tAction: 's3:PutObject',\n\t\t\tResource: `${bucketArn(bucket)}/${options.sesWrite.prefix}*`,\n\t\t\tCondition: {\n\t\t\t\tStringEquals: { 'aws:SourceAccount': options.sesWrite.account },\n\t\t\t},\n\t\t});\n\t}\n\treturn { Version: '2012-10-17', Statement: statements };\n}\n\n/**\n * Block Public Access. All four flags on, unless the bucket has open paths:\n * then a *policy* may make it public (`BlockPublicPolicy`,\n * `RestrictPublicBuckets` off), and ACLs still may not.\n */\nexport function publicAccessBlock(open: boolean): {\n\tBlockPublicAcls: boolean;\n\tIgnorePublicAcls: boolean;\n\tBlockPublicPolicy: boolean;\n\tRestrictPublicBuckets: boolean;\n} {\n\treturn {\n\t\tBlockPublicAcls: true,\n\t\tIgnorePublicAcls: true,\n\t\tBlockPublicPolicy: !open,\n\t\tRestrictPublicBuckets: !open,\n\t};\n}\n\n/** The one CORS rule: browsers on the stage's sites upload and read. */\nexport interface CorsRule {\n\tAllowedMethods: string[];\n\tAllowedOrigins: string[];\n\tAllowedHeaders: string[];\n\tExposeHeaders: string[];\n\tMaxAgeSeconds: number;\n}\n\nexport function corsRule(origins: readonly string[]): CorsRule {\n\treturn {\n\t\tAllowedMethods: ['GET', 'HEAD', 'POST', 'PUT'],\n\t\tAllowedOrigins: [...new Set(origins)].sort(),\n\t\tAllowedHeaders: ['*'],\n\t\tExposeHeaders: ['ETag'],\n\t\tMaxAgeSeconds: 3000,\n\t};\n}\n\n/**\n * A policy document in one canonical form — keys sorted, a lone string a\n * one-element list, lists sorted — so one AWS reformatted reads as the same\n * document rather than as drift.\n */\nexport function canonicalPolicy(value: unknown): string {\n\treturn JSON.stringify(canonical(value));\n}\n\nfunction canonical(value: unknown, key?: string): unknown {\n\tif (Array.isArray(value)) {\n\t\tconst items = value.map((v) => canonical(v));\n\t\treturn key === 'Statement'\n\t\t\t? items\n\t\t\t: items.map((v) => JSON.stringify(v)).sort();\n\t}\n\tif (value && typeof value === 'object') {\n\t\treturn Object.fromEntries(\n\t\t\tObject.keys(value)\n\t\t\t\t.sort()\n\t\t\t\t.map((k) => {\n\t\t\t\t\tconst v = (value as Record<string, unknown>)[k];\n\t\t\t\t\tconst listy =\n\t\t\t\t\t\tk === 'Action' ||\n\t\t\t\t\t\tk === 'Resource' ||\n\t\t\t\t\t\tk === 'AWS' ||\n\t\t\t\t\t\tk === 'AWS:SourceArn'\n\t\t\t\t\t\t\t? Array.isArray(v)\n\t\t\t\t\t\t\t\t? v\n\t\t\t\t\t\t\t\t: [v]\n\t\t\t\t\t\t\t: v;\n\t\t\t\t\treturn [k, canonical(listy, k)];\n\t\t\t\t}),\n\t\t);\n\t}\n\treturn value;\n}\n","/**\n * An IAM user gkm creates for one thing on a stage, its inline policy, and\n * the access key written into the stage's secrets — as an `s3://` URL for\n * what the `s3` provider gives each bucket and the deploy gives a stage's\n * backups, as an `smtp://` one for the `ses` mail provider.\n *\n * - **The user** is under `/gkm/`, tagged with the deploy identity, the stage\n * and what it is for. One that exists without those tags is someone\n * else's, and is refused rather than taken over.\n * - **Its policy** is read on every run and put back when it drifted.\n * - **Its key**: one, written into the stage's secrets the moment IAM shows\n * its secret. `--rotate-keys` issues a successor and keeps the old one\n * active until the stage has deployed with the new one; the next run after\n * that — or `--retire-old-keys` — deletes it.\n * - **A new key** takes IAM seconds to become usable: the state records when\n * it was issued, and a check made with it waits that out\n * ({@link whileKeyIsNew}).\n */\n\nimport * as s3Url from '@geekmidas/storage/s3-url';\nimport type { ResourceRecord } from '../deploy/StateStore.js';\nimport {\n\tAccessKeyLimit,\n\tBucketKeySetElsewhere,\n\tIamUserNotOwned,\n\tRotationInProgress,\n} from './s3/errors.js';\nimport { IAM_USER_PATH } from './s3/naming.js';\nimport { canonicalPolicy } from './s3/policy.js';\nimport type { EnsureContext, ProviderConfig, StateEntry } from './types.js';\n\ntype IamModule = typeof import('@aws-sdk/client-iam');\n\n/** The tags gkm finds its own buckets and users by. */\nexport const TAG_PROJECT = 'gkm:project';\nexport const TAG_STAGE = 'gkm:stage';\nexport const TAG_CONSTRUCT = 'gkm:construct';\n\n/** What creating a user and its key is done through. */\nexport interface IamClients {\n\tIAM: IamModule;\n\tiam: InstanceType<IamModule['IAMClient']>;\n\t/** The region the key's URL names. */\n\tregion: string;\n\t/** An emulator's endpoint, written into the URL when there is one. */\n\tendpoint?: string;\n}\n\n/** What creating a user and its key reads from a provisioning run. */\nexport type KeyContext = Pick<\n\tEnsureContext<ProviderConfig, unknown>,\n\t| 'identity'\n\t| 'stage'\n\t| 'state'\n\t| 'change'\n\t| 'dryRun'\n\t| 'secrets'\n\t| 'writeSecrets'\n\t| 'rotateKeys'\n\t| 'retireOldKeys'\n\t| 'log'\n>;\n\n/** The keys gkm tags a bucket and a user with. */\nexport function identityTags(\n\tctx: Pick<KeyContext, 'identity' | 'stage'>,\n\tid: string,\n) {\n\treturn [\n\t\t{ Key: TAG_PROJECT, Value: ctx.identity.key },\n\t\t{ Key: TAG_STAGE, Value: ctx.stage },\n\t\t{ Key: TAG_CONSTRUCT, Value: id },\n\t];\n}\n\n/** A read whose \"there is none\" answer is one of `missing`. */\nasync function readOr<T>(\n\tread: () => Promise<T>,\n\tmissing: readonly string[],\n): Promise<T | undefined> {\n\ttry {\n\t\treturn await read();\n\t} catch (error) {\n\t\tconst e = error as { name?: string; Code?: string };\n\t\tif (missing.includes(e?.Code ?? e?.name ?? '')) return undefined;\n\t\tthrow error;\n\t}\n}\n\n/** IAM returns a policy document URL-encoded; an emulator may not. */\nfunction decodePolicy(document: string): string {\n\ttry {\n\t\treturn decodeURIComponent(document);\n\t} catch {\n\t\treturn document;\n\t}\n}\n\nexport interface IamUserInput {\n\t/** What it is for: a bucket construct's id, or `backups`. */\n\tid: string;\n\t/** `gkm-<project>-<stage>-<id>`. */\n\tuser: string;\n\t/** The inline policy's name. */\n\tpolicyName: string;\n\tpolicy: object;\n\t/** The policy's change line: `this bucket only`. */\n\tdescribe: string;\n}\n\n/**\n * The user and its inline policy: found — and refused when it is not this\n * stage's — or created, and the policy put back when it drifted.\n *\n * @throws {IamUserNotOwned}\n */\nexport async function ensureIamUser(\n\tctx: KeyContext,\n\tclients: IamClients,\n\tinput: IamUserInput,\n): Promise<{ user: string; exists: boolean }> {\n\tconst { IAM, iam } = clients;\n\tconst { id, user, policy } = input;\n\tconst entry: StateEntry = { key: `iam-user:${id}`, type: 'iam-user' };\n\tconst found = await readOr(\n\t\t() => iam.send(new IAM.GetUserCommand({ UserName: user })),\n\t\t['NoSuchEntity', 'NoSuchEntityException'],\n\t);\n\n\tif (found?.User) {\n\t\tconst tags = await iam.send(\n\t\t\tnew IAM.ListUserTagsCommand({ UserName: user }),\n\t\t);\n\t\tconst tag = (key: string) => tags.Tags?.find((t) => t.Key === key)?.Value;\n\t\tif (\n\t\t\tfound.User.Path !== IAM_USER_PATH ||\n\t\t\ttag(TAG_PROJECT) !== ctx.identity.key ||\n\t\t\ttag(TAG_STAGE) !== ctx.stage\n\t\t) {\n\t\t\tthrow new IamUserNotOwned(user, ctx.identity.key, ctx.stage);\n\t\t}\n\t\tawait ctx.state.ready(entry, user);\n\t} else {\n\t\tawait ctx.change(\n\t\t\t{\n\t\t\t\tconstruct: id,\n\t\t\t\tresource: `IAM user ${user}`,\n\t\t\t\tchange: `create under ${IAM_USER_PATH}`,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tawait ctx.state.pending(entry);\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.CreateUserCommand({\n\t\t\t\t\t\tUserName: user,\n\t\t\t\t\t\tPath: IAM_USER_PATH,\n\t\t\t\t\t\tTags: identityTags(ctx, id),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tawait ctx.state.ready(entry, user);\n\t\t\t},\n\t\t);\n\t}\n\n\tconst exists = Boolean(found?.User) || !ctx.dryRun;\n\tconst current = exists\n\t\t? await readOr(\n\t\t\t\t() =>\n\t\t\t\t\tiam.send(\n\t\t\t\t\t\tnew IAM.GetUserPolicyCommand({\n\t\t\t\t\t\t\tUserName: user,\n\t\t\t\t\t\t\tPolicyName: input.policyName,\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t['NoSuchEntity', 'NoSuchEntityException'],\n\t\t\t)\n\t\t: undefined;\n\tconst document = current?.PolicyDocument\n\t\t? JSON.parse(decodePolicy(current.PolicyDocument))\n\t\t: undefined;\n\tif (!document || canonicalPolicy(document) !== canonicalPolicy(policy)) {\n\t\tawait ctx.change(\n\t\t\t{\n\t\t\t\tconstruct: id,\n\t\t\t\tresource: `IAM user ${user}`,\n\t\t\t\tchange: `policy ${input.policyName}: ${input.describe}`,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tawait iam.send(\n\t\t\t\t\tnew IAM.PutUserPolicyCommand({\n\t\t\t\t\t\tUserName: user,\n\t\t\t\t\t\tPolicyName: input.policyName,\n\t\t\t\t\t\tPolicyDocument: JSON.stringify(policy),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t}\n\treturn { user, exists };\n}\n\n/**\n * The secret a user's access key is written into, and how: an `s3://` URL\n * for a bucket ({@link s3KeySecret}), an `smtp://` one for mail.\n */\nexport interface KeySecret {\n\t/** The secret's key: `UPLOADS_URL`, `BACKUPS_URL`, `MAIL_URL`. */\n\tkey: string;\n\t/**\n\t * The access key a stored value holds — or `undefined` when it holds\n\t * none this user could have issued for it, so a new one is.\n\t *\n\t * @throws when the value is another resource's, set by hand\n\t */\n\tkeyIdOf(value: string): string | undefined;\n\t/** The value for a newly issued key. */\n\tvalue(accessKeyId: string, secretAccessKey: string): string;\n\t/**\n\t * A value holding the right key whose address drifted: what it should\n\t * be, and the change line. `undefined` when it is right.\n\t */\n\trepair?(value: string): { value: string; change: string } | undefined;\n}\n\n/**\n * A bucket's URL as a key's secret: `s3://KEY:SECRET@bucket?region=…`.\n *\n * @throws {BucketKeySetElsewhere} from `keyIdOf`, when the URL names another bucket\n */\nexport function s3KeySecret(\n\tctx: Pick<KeyContext, 'stage'>,\n\tclients: Pick<IamClients, 'region' | 'endpoint'>,\n\tinput: { bucket: string; urlKey: string },\n): KeySecret {\n\tconst { bucket, urlKey } = input;\n\tconst parse = (value: string) => {\n\t\tlet parsed: s3Url.S3Address | undefined;\n\t\ttry {\n\t\t\tparsed = s3Url.parse(value);\n\t\t} catch {\n\t\t\tparsed = undefined;\n\t\t}\n\t\tif (parsed?.bucket !== bucket) {\n\t\t\tthrow new BucketKeySetElsewhere(\n\t\t\t\turlKey,\n\t\t\t\tbucket,\n\t\t\t\tparsed?.bucket ?? value.replace(/\\/\\/[^@]*@/, '//'),\n\t\t\t\tctx.stage,\n\t\t\t);\n\t\t}\n\t\treturn parsed;\n\t};\n\treturn {\n\t\tkey: urlKey,\n\t\tkeyIdOf: (value) => parse(value).accessKeyId,\n\t\tvalue: (accessKeyId, secretAccessKey) =>\n\t\t\ts3Url.build({\n\t\t\t\tbucket,\n\t\t\t\tregion: clients.region,\n\t\t\t\t...(clients.endpoint\n\t\t\t\t\t? { endpoint: clients.endpoint, forcePathStyle: true }\n\t\t\t\t\t: {}),\n\t\t\t\taccessKeyId,\n\t\t\t\tsecretAccessKey,\n\t\t\t}),\n\t\trepair(value) {\n\t\t\t// The key is good; the address must name where the bucket is.\n\t\t\tconst address = parse(value);\n\t\t\tif (address.region === clients.region) return undefined;\n\t\t\treturn {\n\t\t\t\tvalue: s3Url.build({ ...address, region: clients.region }),\n\t\t\t\tchange: `name ${clients.region}, the bucket's region (it said ${address.region ?? 'none'})`,\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport interface AccessKeyInput {\n\t/** What it is for, as {@link IamUserInput.id}. */\n\tid: string;\n\tuser: string;\n\t/** Whether the user exists yet — false in a dry run that would create it. */\n\texists: boolean;\n\t/** Where the key is written. */\n\tsecret: KeySecret;\n}\n\n/**\n * The user's access key, in the stage's secrets as `secret` writes it.\n *\n * - First run: one key, written into the stage's secrets.\n * - `--rotate-keys`: a second key, written in place of the first; the first\n * stays active until the stage has deployed with the second, and the next\n * run after that deploy — or `--retire-old-keys` — deletes it.\n * - A key the secrets no longer hold (a store emptied by hand): replaced the\n * same way, since its secret cannot be read back.\n *\n * @throws whatever `secret.keyIdOf` throws for a value set elsewhere\n * @throws {RotationInProgress} on `--rotate-keys` with the last rotation's old key still active\n * @throws {AccessKeyLimit} when the user has two keys gkm did not record\n */\nexport async function ensureAccessKey(\n\tctx: KeyContext,\n\tclients: IamClients,\n\tinput: AccessKeyInput,\n): Promise<void> {\n\tconst { IAM, iam } = clients;\n\tconst { id, user, secret } = input;\n\tconst entryKey = `iam-access-key:${id}`;\n\tconst record = ctx.state.record(entryKey);\n\n\tconst given = ctx.secrets[secret.key];\n\tconst inUrl = given !== undefined ? secret.keyIdOf(given) : undefined;\n\n\tconst listed = input.exists\n\t\t? ((\n\t\t\t\tawait iam.send(new IAM.ListAccessKeysCommand({ UserName: user }))\n\t\t\t).AccessKeyMetadata?.map((k) => k.AccessKeyId!) ?? [])\n\t\t: [];\n\n\tlet current = record?.status === 'ready' ? record.id : undefined;\n\tlet previous =\n\t\ttypeof record?.data?.previous === 'string'\n\t\t\t? record.data.previous\n\t\t\t: undefined;\n\tconst rotatedAt =\n\t\ttypeof record?.data?.rotatedAt === 'string'\n\t\t\t? record.data.rotatedAt\n\t\t\t: undefined;\n\tconst entry = (data: Record<string, unknown> = {}): StateEntry => ({\n\t\tkey: entryKey,\n\t\ttype: 'iam-access-key',\n\t\tdata: { user, ...data },\n\t});\n\n\t// The old key of a rotation: deleted once the stage deployed after it.\n\tif (previous && current) {\n\t\tconst deployed =\n\t\t\trotatedAt !== undefined &&\n\t\t\tctx.state.lastDeployedAt !== undefined &&\n\t\t\tctx.state.lastDeployedAt > rotatedAt;\n\t\tif (ctx.retireOldKeys || deployed) {\n\t\t\tconst old = previous;\n\t\t\tconst keep = current;\n\t\t\tawait ctx.change(\n\t\t\t\t{\n\t\t\t\t\tconstruct: id,\n\t\t\t\t\tresource: `IAM user ${user}`,\n\t\t\t\t\tchange: `delete the rotated-out access key ${old}`,\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\tif (listed.includes(old)) {\n\t\t\t\t\t\tawait iam.send(\n\t\t\t\t\t\t\tnew IAM.DeleteAccessKeyCommand({\n\t\t\t\t\t\t\t\tUserName: user,\n\t\t\t\t\t\t\t\tAccessKeyId: old,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tawait ctx.state.ready(entry(), keep);\n\t\t\t\t},\n\t\t\t);\n\t\t\tprevious = undefined;\n\t\t} else {\n\t\t\tctx.log(\n\t\t\t\t` ${id}: the old access key ${previous} stays active until '${ctx.stage}' is deployed with the new one; the next deploy after that deletes it (or pass --retire-old-keys)`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// No record, and the secrets hold a key of this user's: adopt it.\n\tif (!current && inUrl && listed.includes(inUrl)) {\n\t\tawait ctx.state.ready(entry(), inUrl);\n\t\tcurrent = inUrl;\n\t}\n\n\tconst valid =\n\t\tcurrent !== undefined && listed.includes(current) && inUrl === current;\n\tif (valid && !ctx.rotateKeys) {\n\t\tconst repaired = given !== undefined ? secret.repair?.(given) : undefined;\n\t\tif (repaired) {\n\t\t\tawait ctx.change(\n\t\t\t\t{ construct: id, resource: secret.key, change: repaired.change },\n\t\t\t\t() => ctx.writeSecrets({ [secret.key]: repaired.value }),\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\tif (ctx.rotateKeys && previous) {\n\t\tthrow new RotationInProgress(id, previous, ctx.stage);\n\t}\n\n\tconst outgoing = current && listed.includes(current) ? current : undefined;\n\tif (listed.length >= 2) throw new AccessKeyLimit(user, listed);\n\n\tconst why = !current\n\t\t? 'create an access key'\n\t\t: ctx.rotateKeys\n\t\t\t? 'rotate: issue a new access key'\n\t\t\t: 'issue a new access key (the secrets no longer hold the recorded one)';\n\tawait ctx.change(\n\t\t{ construct: id, resource: `IAM user ${user}`, change: why },\n\t\tasync () => {\n\t\t\tawait ctx.state.pending(entry(outgoing ? { previous: outgoing } : {}));\n\t\t\tconst created = await iam.send(\n\t\t\t\tnew IAM.CreateAccessKeyCommand({ UserName: user }),\n\t\t\t);\n\t\t\tconst key = created.AccessKey!;\n\t\t\t// Into the stage's secrets before anything else: IAM shows a secret\n\t\t\t// once, and a key whose secret is lost is a key to replace.\n\t\t\tawait ctx.writeSecrets({\n\t\t\t\t[secret.key]: secret.value(key.AccessKeyId!, key.SecretAccessKey!),\n\t\t\t});\n\t\t\t// When it was issued: IAM takes seconds to make a new key usable,\n\t\t\t// and the deploy's check waits for one this young.\n\t\t\tconst issuedAt = new Date().toISOString();\n\t\t\tawait ctx.state.ready(\n\t\t\t\tentry(\n\t\t\t\t\toutgoing\n\t\t\t\t\t\t? { previous: outgoing, rotatedAt: issuedAt, issuedAt }\n\t\t\t\t\t\t: { issuedAt },\n\t\t\t\t),\n\t\t\t\tkey.AccessKeyId!,\n\t\t\t);\n\t\t},\n\t);\n\tif (outgoing) {\n\t\tctx.log(\n\t\t\t` ${secret.key} holds the new key. This deploy moves '${ctx.stage}' onto it; the next deploy after it deletes the old key ${outgoing}`,\n\t\t);\n\t}\n}\n\n/** How long a key issued this recently counts as new to IAM. */\nconst NEW_KEY_WINDOW_MS = 10 * 60 * 1000;\n\n/** The waits between asks while a new key becomes usable: about a minute. */\nlet newKeyWaits: readonly number[] = [2000, 4000, 8000, 15000, 15000, 15000];\n\n/** For tests: the waits for a new key. Returns the old ones. */\nexport function useNewKeyWaits(waits: readonly number[]): readonly number[] {\n\tconst previous = newKeyWaits;\n\tnewKeyWaits = waits;\n\treturn previous;\n}\n\n/**\n * When the key in a URL was issued, if the stage's state says it was just\n * now — the record of `id`'s key naming that very key.\n */\nexport function issuedJustNow(\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined,\n\tid: string,\n\taccessKeyId: string,\n): string | undefined {\n\tconst record = resources?.[`iam-access-key:${id}`];\n\tconst issuedAt = record?.data?.issuedAt;\n\tif (record?.id !== accessKeyId || typeof issuedAt !== 'string') {\n\t\treturn undefined;\n\t}\n\tconst age = Date.now() - Date.parse(issuedAt);\n\treturn age >= 0 && age < NEW_KEY_WINDOW_MS ? issuedAt : undefined;\n}\n\n/**\n * `ask` again, for about a minute, while it is `refused` and the key was\n * issued just now — IAM refuses a key for seconds after making it. Returns\n * the last answer and how long was waited.\n */\nexport async function whileKeyIsNew<T>(\n\tfirst: T,\n\toptions: {\n\t\tissuedAt: string | undefined;\n\t\trefused: (answer: T) => boolean;\n\t\task: () => Promise<T>;\n\t\t/** Said once, before the first wait. */\n\t\tonWait?: () => void;\n\t},\n): Promise<{ answer: T; waited: number }> {\n\tlet answer = first;\n\tlet waited = 0;\n\tif (!options.issuedAt || !options.refused(answer)) return { answer, waited };\n\toptions.onWait?.();\n\tfor (const wait of newKeyWaits) {\n\t\tawait new Promise((resolve) => setTimeout(resolve, wait));\n\t\twaited += wait;\n\t\tanswer = await options.ask();\n\t\tif (!options.refused(answer)) break;\n\t}\n\treturn { answer, waited };\n}\n"],"mappings":";;;;;AAuBA,MAAM,aAAa,WAAmB,gBAAgB;;;;;;;;;AAUtD,SAAgB,WACf,QACA,UAQI,CAAC,GACY;CACjB,OAAO;EACN,SAAS;EACT,WAAW;GACV;IACC,KAAK;IACL,QAAQ;IACR,QAAQ;KACP;KACA;KACA;KACA;KACA;KACA,GAAI,QAAQ,aAAa,CAAC,qBAAqB,IAAI,CAAC;IACrD;IACA,UAAU,GAAG,UAAU,MAAM,EAAE;GAChC;GACA;IACC,KAAK;IACL,QAAQ;IACR,QAAQ;KACP;KACA;KACA;IACD;IACA,UAAU,UAAU,MAAM;GAC3B;GACA,GAAI,QAAQ,iBACT,CACA;IACC,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,UAAU,QAAQ;GACnB,CACD,IACC,CAAC;EACL;CACD;AACD;;;;;;;AAQA,SAAgB,aAAa,QAAgB,SAAyB;CACrE,MAAM,OAAO,QAAQ,QAAQ,QAAQ,EAAE,CAAC,CAAC,QAAQ,SAAS,GAAG;CAC7D,OAAO,GAAG,UAAU,MAAM,EAAE,GAAG;AAChC;;;;;;;;;AAUA,SAAgB,aACf,QACA,OAA0B,CAAC,GAC3B,UAOI,CAAC,GACY;CACjB,MAAM,aAAgC,CACrC;EACC,KAAK;EACL,QAAQ;EACR,WAAW;EACX,QAAQ;EACR,UAAU,C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