|
| 1 | +/** |
| 2 | + * MIT No Attribution |
| 3 | + * |
| 4 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 7 | + * the Software without restriction, including without limitation the rights to |
| 8 | + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 9 | + * the Software, and to permit persons to whom the Software is furnished to do so. |
| 10 | + * |
| 11 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 12 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 14 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 15 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 16 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 17 | + * SOFTWARE. |
| 18 | + */ |
| 19 | + |
| 20 | +import { Duration, RemovalPolicy } from 'aws-cdk-lib'; |
| 21 | +import * as s3 from 'aws-cdk-lib/aws-s3'; |
| 22 | +import { Construct } from 'constructs'; |
| 23 | + |
| 24 | +/** |
| 25 | + * How long a noncurrent (superseded) object version is retained before expiry. |
| 26 | + * The registry is immutable-per-version, so overwrites at a live key should not |
| 27 | + * happen; this rule reaps versions left behind by a ``removed`` tombstone or an |
| 28 | + * operational re-put, keeping storage bounded without touching current objects. |
| 29 | + */ |
| 30 | +export const REGISTRY_ARTIFACT_NONCURRENT_TTL_DAYS = 90; |
| 31 | + |
| 32 | +/** |
| 33 | + * Properties for the RegistryArtifactsBucket construct. |
| 34 | + */ |
| 35 | +export interface RegistryArtifactsBucketProps { |
| 36 | + /** |
| 37 | + * Removal policy for the bucket. Registry artifacts are referenced by pinned |
| 38 | + * task records for audit/reproducibility, so production should RETAIN; the |
| 39 | + * construct default stays DESTROY for the sample stack's dev-first posture. |
| 40 | + * @default RemovalPolicy.DESTROY |
| 41 | + */ |
| 42 | + readonly removalPolicy?: RemovalPolicy; |
| 43 | + |
| 44 | + /** |
| 45 | + * Whether to auto-delete objects when the bucket is removed (so ``cdk |
| 46 | + * destroy`` does not need a manual bucket-empty first). Mirrors the other |
| 47 | + * sample-stack buckets. |
| 48 | + * @default true |
| 49 | + */ |
| 50 | + readonly autoDeleteObjects?: boolean; |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * S3 bucket for agent asset registry artifact bytes (#246; see |
| 55 | + * docs/design/REGISTRY.md §3.4 and ADR-018). |
| 56 | + * |
| 57 | + * Stores the artifact for each published asset version — the MCP server config |
| 58 | + * JSON, Cedar policy text, or skill prompt fragment — under the key |
| 59 | + * ``{kind}/{namespace}/{name}/{version}/artifact``. Metadata lives in |
| 60 | + * ``RegistryAssetsTable``; only the bytes live here. |
| 61 | + * |
| 62 | + * Differs from the ephemeral ``EcsPayloadBucket``: artifacts are durable |
| 63 | + * (referenced by pinned task records for audit and reproducibility), so |
| 64 | + * **versioning is ON** and there is no whole-object TTL — only a noncurrent- |
| 65 | + * version expiry to bound storage. Immutability of a published |
| 66 | + * ``(kind, namespace, name, version)`` is enforced at the DynamoDB write (409 |
| 67 | + * on collision), not by S3 object-lock, so a ``removed`` status can tombstone a |
| 68 | + * record without a compliance-grade byte delete. |
| 69 | + * |
| 70 | + * Security / hygiene (parity with the other sample buckets): |
| 71 | + * - ``blockPublicAccess: BLOCK_ALL`` + ``enforceSSL: true`` — no public read, |
| 72 | + * TLS-only transport. |
| 73 | + * - ``encryption: S3_MANAGED`` — server-side encryption at rest. |
| 74 | + * - ``versioned: true`` — retain superseded bytes for audit. |
| 75 | + */ |
| 76 | +export class RegistryArtifactsBucket extends Construct { |
| 77 | + /** The underlying S3 bucket. */ |
| 78 | + public readonly bucket: s3.Bucket; |
| 79 | + |
| 80 | + constructor(scope: Construct, id: string, props: RegistryArtifactsBucketProps = {}) { |
| 81 | + super(scope, id); |
| 82 | + |
| 83 | + this.bucket = new s3.Bucket(this, 'Bucket', { |
| 84 | + blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, |
| 85 | + encryption: s3.BucketEncryption.S3_MANAGED, |
| 86 | + enforceSSL: true, |
| 87 | + versioned: true, |
| 88 | + lifecycleRules: [ |
| 89 | + { |
| 90 | + id: 'registry-artifact-noncurrent-expiry', |
| 91 | + enabled: true, |
| 92 | + noncurrentVersionExpiration: Duration.days(REGISTRY_ARTIFACT_NONCURRENT_TTL_DAYS), |
| 93 | + // Reap incomplete multipart uploads after 1 day so stale upload parts |
| 94 | + // (which object/version expiry does not cover) do not linger. |
| 95 | + abortIncompleteMultipartUploadAfter: Duration.days(1), |
| 96 | + }, |
| 97 | + ], |
| 98 | + removalPolicy: props.removalPolicy ?? RemovalPolicy.DESTROY, |
| 99 | + autoDeleteObjects: props.autoDeleteObjects ?? true, |
| 100 | + }); |
| 101 | + } |
| 102 | +} |
0 commit comments