@aws/nx-plugin-mcp 1.0.0-rc.40 → 1.0.0-rc.42
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/docs/guides/py-agent.mdx
CHANGED
|
@@ -583,6 +583,50 @@ To invoke your AG-UI agent from a React website, use the <Link path="/guides/con
|
|
|
583
583
|
Refer to the <Link path="/guides/connection/react-agui">`connection` generator guide</Link> for details about how the connection is set up.
|
|
584
584
|
</OptionFilter>
|
|
585
585
|
|
|
586
|
+
## Securing your Agent
|
|
587
|
+
|
|
588
|
+
<Snippet name="agent/securing-your-agent" parentHeading="Securing your Agent" />
|
|
589
|
+
|
|
590
|
+
<Tabs syncKey="agent-framework">
|
|
591
|
+
<TabItem label="Strands" _filter={{ framework: 'strands' }}>
|
|
592
|
+
```python
|
|
593
|
+
# agent.py
|
|
594
|
+
import os
|
|
595
|
+
|
|
596
|
+
from strands import Agent
|
|
597
|
+
from strands.models import BedrockModel
|
|
598
|
+
|
|
599
|
+
model = BedrockModel(
|
|
600
|
+
model_id=os.environ.get("MODEL_ID"),
|
|
601
|
+
guardrail_id=os.environ["GUARDRAIL_ID"],
|
|
602
|
+
guardrail_version=os.environ.get("GUARDRAIL_VERSION", "DRAFT"),
|
|
603
|
+
)
|
|
604
|
+
|
|
605
|
+
agent = Agent(model=model)
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
See the Strands [Guardrails](https://strandsagents.com/docs/user-guide/safety-security/guardrails/) guide for more detail.
|
|
609
|
+
</TabItem>
|
|
610
|
+
<TabItem label="LangChain" _filter={{ framework: 'langchain' }}>
|
|
611
|
+
```python
|
|
612
|
+
# agent.py
|
|
613
|
+
import os
|
|
614
|
+
|
|
615
|
+
from langchain_aws import ChatBedrockConverse
|
|
616
|
+
|
|
617
|
+
model = ChatBedrockConverse(
|
|
618
|
+
model=os.environ.get("MODEL_ID"),
|
|
619
|
+
guardrail_config={
|
|
620
|
+
"guardrailIdentifier": os.environ["GUARDRAIL_ID"],
|
|
621
|
+
"guardrailVersion": os.environ.get("GUARDRAIL_VERSION", "DRAFT"),
|
|
622
|
+
},
|
|
623
|
+
)
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
See the [`ChatBedrockConverse`](https://docs.langchain.com/oss/python/integrations/chat/bedrock_converse) documentation for the `guardrail_config` fields.
|
|
627
|
+
</TabItem>
|
|
628
|
+
</Tabs>
|
|
629
|
+
|
|
586
630
|
## Connections
|
|
587
631
|
|
|
588
632
|
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
@@ -136,6 +136,49 @@ A default `Content-Security-Policy` is enforced. It restricts scripts and framin
|
|
|
136
136
|
|
|
137
137
|
`runtime-config.json` is served with `Cache-Control: no-cache` so that browsers always fetch the latest configuration after a redeploy, rather than using a stale cached copy.
|
|
138
138
|
|
|
139
|
+
#### Custom Domain & TLS
|
|
140
|
+
|
|
141
|
+
By default the distribution uses the default CloudFront domain name (`*.cloudfront.net`) and its default certificate, which does not support enforcing a minimum TLS version of 1.2. To serve your website from your own domain, supply an [ACM certificate](https://docs.aws.amazon.com/acm/latest/userguide/acm-overview.html) (which must reside in `us-east-1` for use with CloudFront) and your domain names — a minimum TLS version of 1.2 is then enforced for viewers:
|
|
142
|
+
|
|
143
|
+
<Infrastructure>
|
|
144
|
+
<Fragment slot="cdk">
|
|
145
|
+
Pass the `certificate` and `domainNames` props through in your generated website construct in `packages/common/constructs/src/app/static-websites`:
|
|
146
|
+
|
|
147
|
+
```ts {6-9}
|
|
148
|
+
export class MyWebsite extends StaticWebsite {
|
|
149
|
+
constructor(scope: Construct, id: string) {
|
|
150
|
+
super(scope, id, {
|
|
151
|
+
websiteName: 'MyWebsite',
|
|
152
|
+
websiteFilePath: ...,
|
|
153
|
+
domainNames: ['www.example.com'],
|
|
154
|
+
certificate: Certificate.fromCertificateArn(scope, 'Cert',
|
|
155
|
+
'arn:aws:acm:us-east-1:123456789012:certificate/...'),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
</Fragment>
|
|
161
|
+
<Fragment slot="terraform">
|
|
162
|
+
Set the `custom_domain_names` and `acm_certificate_arn` variables in your generated website module in `packages/common/terraform/src/app/static-websites`:
|
|
163
|
+
|
|
164
|
+
```hcl {5-6}
|
|
165
|
+
module "static_website" {
|
|
166
|
+
source = "../../../core/static-website"
|
|
167
|
+
website_name = "my-website"
|
|
168
|
+
website_file_path = ...
|
|
169
|
+
custom_domain_names = ["www.example.com"]
|
|
170
|
+
acm_certificate_arn = "arn:aws:acm:us-east-1:123456789012:certificate/..."
|
|
171
|
+
|
|
172
|
+
providers = {
|
|
173
|
+
aws.us_east_1 = aws.us_east_1
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
</Fragment>
|
|
178
|
+
</Infrastructure>
|
|
179
|
+
|
|
180
|
+
You will also need to create DNS records (for example in Route 53) pointing your domain at the CloudFront distribution.
|
|
181
|
+
|
|
139
182
|
## Implementing your React Website
|
|
140
183
|
|
|
141
184
|
The [React documentation](https://react.dev/learn) is a good place to start to learn the basics of building with React.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Security
|
|
3
|
+
description: Security features included in projects generated by the Nx Plugin for AWS
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import Link from '@components/link.astro';
|
|
7
|
+
|
|
8
|
+
:::caution[Reporting Security Issues]
|
|
9
|
+
To report a potential security issue in the Nx Plugin for AWS itself, please refer to [SECURITY.md](https://github.com/awslabs/nx-plugin-for-aws/blob/main/SECURITY.md) — do not create a public GitHub issue.
|
|
10
|
+
:::
|
|
11
|
+
|
|
12
|
+
## Security Controls
|
|
13
|
+
|
|
14
|
+
Projects scaffolded by the Nx Plugin for AWS include a number of security controls out of the box. This page provides an overview of those controls and links to the relevant guides for more detail.
|
|
15
|
+
|
|
16
|
+
### Infrastructure Scanning
|
|
17
|
+
|
|
18
|
+
Infrastructure projects are configured with [Checkov](https://www.checkov.io/) as part of the `build` target, so insecure infrastructure configuration fails the build:
|
|
19
|
+
|
|
20
|
+
- CDK projects synthesize CloudFormation templates which are scanned by Checkov. See <Link path="/guides/typescript-infrastructure#security-testing">Security Testing</Link> for details.
|
|
21
|
+
- Terraform projects run Checkov directly against your Terraform code. See <Link path="/guides/terraform-project">Terraform Projects</Link>.
|
|
22
|
+
|
|
23
|
+
Where vended infrastructure suppresses a Checkov rule, the suppression is scoped to the specific resource and annotated with a justification. The shared `suppressRules` helper requires a reason for every suppression, and we recommend following the same practice in your own code. See <Link path="/guides/typescript-infrastructure#suppressing-checkov-checks">Suppressing Checkov Checks</Link>.
|
|
24
|
+
|
|
25
|
+
### Container Image Scanning
|
|
26
|
+
|
|
27
|
+
Projects which build container images (for example agents, MCP servers, and database migration images) include a `trivy` target which scans images for HIGH and CRITICAL vulnerabilities before they are deployed, failing the build on findings. See <Link path="/guides/docker-bundling">Docker Bundling</Link> for details, including how to suppress findings with a `.trivyignore` file.
|
|
28
|
+
|
|
29
|
+
### Credential Scanning
|
|
30
|
+
|
|
31
|
+
Workspaces include [git-secrets](https://github.com/awslabs/git-secrets) pre-commit hooks which scan staged files for AWS credential patterns, preventing accidental commits of access keys and other sensitive values. See the <Link path="/guides/workspace#git-secrets">Git Secrets</Link> section of the workspace guide.
|
|
32
|
+
|
|
33
|
+
### Authentication
|
|
34
|
+
|
|
35
|
+
APIs, agents, and MCP servers use AWS IAM (SigV4) authentication by default:
|
|
36
|
+
|
|
37
|
+
- <Link path="/guides/trpc">tRPC</Link>, <Link path="/guides/fastapi">FastAPI</Link>, and <Link path="/guides/ts-smithy-api">Smithy</Link> APIs default to IAM authentication, with Cognito and custom authorizers available as options. The vended custom authorizer stub denies requests by default.
|
|
38
|
+
- <Link path="/guides/ts-agent">Agents</Link> and <Link path="/guides/ts-mcp-server">MCP servers</Link> deployed to Amazon Bedrock AgentCore Runtime use IAM (SigV4) authentication by default, with JWT-based Cognito authentication as an option.
|
|
39
|
+
- The <Link path="/guides/react-website-auth">website auth generator</Link> vends an Amazon Cognito user pool with multi-factor authentication (MFA) required, a strong password policy, and deletion protection enabled.
|
|
40
|
+
|
|
41
|
+
### Encryption
|
|
42
|
+
|
|
43
|
+
Vended infrastructure encrypts data in transit and at rest:
|
|
44
|
+
|
|
45
|
+
- Websites are served via CloudFront with HTTP redirected to HTTPS, and a response headers policy including HTTP Strict Transport Security (HSTS), a Content Security Policy, and other <Link path="/guides/react-website#security-headers">security headers</Link>. A WAF with AWS managed rules is associated with the distribution.
|
|
46
|
+
- S3 buckets block all public access, enforce SSL-only access via bucket policies, are encrypted (KMS with key rotation for website content), and deliver server access logs to CloudWatch log groups encrypted with customer-managed KMS keys, where they can be queried with Logs Insights and alarmed on.
|
|
47
|
+
- API access logs are written to CloudWatch log groups encrypted with customer-managed KMS keys with rotation enabled.
|
|
48
|
+
- <Link path="/guides/ts-rdb">Aurora databases</Link> enable storage encryption with a customer-managed KMS key, generate credentials in AWS Secrets Manager (never hardcoded), and support automatic credential rotation.
|
|
49
|
+
|
|
50
|
+
### Least Privilege
|
|
51
|
+
|
|
52
|
+
Vended CDK constructs and Terraform modules follow least privilege:
|
|
53
|
+
|
|
54
|
+
- Constructs expose `grant*` methods (for example `grantInvokeAccess` on APIs and agents, `grantConnect` on databases) so consumers grant only the access they need.
|
|
55
|
+
- IAM policies in vended infrastructure are scoped to specific resources and actions. Where a wildcard resource is required by the AWS service (for example `ecr:GetAuthorizationToken`), it is limited to those actions and scoped with conditions where supported.
|
|
56
|
+
|
|
57
|
+
### Dependency Licensing
|
|
58
|
+
|
|
59
|
+
The <Link path="/guides/license">license generator</Link> configures automated license header management and dependency license checking against an allowlist of approved licenses, helping you catch problematic transitive dependencies before they ship.
|
|
60
|
+
|
|
61
|
+
## Responsibility
|
|
62
|
+
|
|
63
|
+
Security and compliance is a shared responsibility. AWS describes this through the [Shared Responsibility Model](https://aws.amazon.com/compliance/shared-responsibility-model/), which distinguishes between security *of* the cloud (the responsibility of AWS) and security *in* the cloud (your responsibility as the customer).
|
|
64
|
+
|
|
65
|
+
The Nx Plugin for AWS helps you address parts of your side of that model. Its generators vend secure foundations and encode AWS best practices within the scope of the code they produce — the controls described above. This reduces the effort required to build securely, but it does not transfer ownership of security to the plugin.
|
|
66
|
+
|
|
67
|
+
**You own the code that is generated into your workspace and remain responsible for its security.** Once vended, generated code is yours to modify, extend, and operate, and it must be treated the same as any other code you author.
|
|
68
|
+
|
|
69
|
+
In particular:
|
|
70
|
+
|
|
71
|
+
- **The scope of the plugin is limited to its generators.** The plugin has no knowledge of your application's business logic, data classification, threat model, or regulatory obligations, and cannot make decisions that depend on them.
|
|
72
|
+
- **Authentication is configured, but authorization is not.** APIs are protected with authentication by default (for example IAM/SigV4), but the plugin cannot determine *which* authenticated principals should be permitted to perform *which* operations on *which* resources. Fine-grained authorization depends on your business logic and must be designed, implemented, and tested by you.
|
|
73
|
+
- **Generated code is a starting point, not a finished product.** As you add functionality, you introduce security considerations the plugin cannot anticipate — input validation, data handling, secrets management, dependency choices, and integrations with other systems.
|
|
74
|
+
|
|
75
|
+
Accordingly, you should review generated code and the applications you build on top of it in line with your own organisation's security policies, standards, and review processes, and subject them to the same threat modelling, security testing, and approval gates you apply to any production workload. The controls vended by the plugin are intended to complement those processes, not to replace them.
|
package/docs/guides/ts-agent.mdx
CHANGED
|
@@ -483,6 +483,28 @@ To invoke your AG-UI agent from a React website, use the <Link path="/guides/con
|
|
|
483
483
|
Refer to the <Link path="/guides/connection/react-agui">`connection` generator guide</Link> for details about how the connection is set up.
|
|
484
484
|
</OptionFilter>
|
|
485
485
|
|
|
486
|
+
## Securing your Agent
|
|
487
|
+
|
|
488
|
+
<Snippet name="agent/securing-your-agent" parentHeading="Securing your Agent" />
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
// agent.ts
|
|
492
|
+
import { Agent } from '@strands-agents/sdk';
|
|
493
|
+
import { BedrockModel } from '@strands-agents/sdk/models/bedrock';
|
|
494
|
+
|
|
495
|
+
const model = new BedrockModel({
|
|
496
|
+
modelId: process.env.MODEL_ID,
|
|
497
|
+
guardrailConfig: {
|
|
498
|
+
guardrailIdentifier: process.env.GUARDRAIL_ID!,
|
|
499
|
+
guardrailVersion: process.env.GUARDRAIL_VERSION ?? 'DRAFT',
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
const agent = new Agent({ model, /* ... */ });
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
See the Strands [Guardrails](https://strandsagents.com/docs/user-guide/safety-security/guardrails/) guide for more detail.
|
|
507
|
+
|
|
486
508
|
## Connections
|
|
487
509
|
|
|
488
510
|
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Securing your Agent
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Agents act on untrusted input and can drive real actions through their tools, so it's worth considering security from the start. The following practices apply to the generated agent.
|
|
6
|
+
|
|
7
|
+
### Treat model input and output as untrusted
|
|
8
|
+
|
|
9
|
+
Prompts can contain adversarial instructions (prompt injection), and model output is non-deterministic — neither should be trusted in security-sensitive logic:
|
|
10
|
+
|
|
11
|
+
- Define strict input schemas for your tools, as in the generated example tool. Constrain values to what the tool actually needs (enums, length limits, numeric ranges) rather than accepting free-form strings.
|
|
12
|
+
- Never pass model output directly into shell commands, SQL queries, code evaluation, or rendered HTML without validation or encoding.
|
|
13
|
+
- Apply authorization checks in your tools and downstream services — don't rely on the system prompt to prevent the model from misusing a tool it has access to.
|
|
14
|
+
|
|
15
|
+
Strands' [Prompt Engineering](https://strandsagents.com/docs/user-guide/safety-security/prompt-engineering/) and [Responsible AI](https://strandsagents.com/docs/user-guide/safety-security/responsible-ai/) guides cover writing robust, safety-conscious system prompts.
|
|
16
|
+
|
|
17
|
+
### Scope tool permissions tightly
|
|
18
|
+
|
|
19
|
+
Grant the agent's IAM role only the permissions its tools need. The vended CDK constructs and Terraform modules expose `grant*` methods and scoped policies for this purpose — for example granting an agent access to invoke a specific API rather than attaching broad managed policies. Where a tool acts on behalf of a user, prefer authorizing the action using the calling user's identity (passed through via the request context) over the agent's own ambient permissions.
|
|
20
|
+
|
|
21
|
+
### Provide a kill switch
|
|
22
|
+
|
|
23
|
+
Because model behaviour can change in unexpected ways, plan for quickly disabling or swapping the model without a code change:
|
|
24
|
+
|
|
25
|
+
- Read the model ID from configuration (for example a `MODEL_ID` environment variable) so operators can switch or roll back to a different model by updating configuration.
|
|
26
|
+
- Gate the agent behind a feature flag so its AI functionality can be disabled entirely. When disabled, return a generic message rather than an error, and ensure the rest of your application degrades gracefully.
|
|
27
|
+
|
|
28
|
+
Document how to flip these controls in your operational runbook.
|
|
29
|
+
|
|
30
|
+
### Protect sensitive data
|
|
31
|
+
|
|
32
|
+
- Avoid logging prompts and completions, which may contain user data. The generated agent's model error logging hook logs error metadata only, not conversation content — keep this property when adding your own logging.
|
|
33
|
+
- Return generic error messages to users; log detailed errors server-side.
|
|
34
|
+
- Isolate conversation state between users and sessions, and authorize access to any persisted session data.
|
|
35
|
+
- Redact personally identifiable information (PII) from prompts and outputs — either with a Bedrock Guardrail sensitive information filter (below) or, for Strands agents, the approaches in the [PII Redaction](https://strandsagents.com/docs/user-guide/safety-security/pii-redaction/) guide.
|
|
36
|
+
|
|
37
|
+
### Amazon Bedrock Guardrails
|
|
38
|
+
|
|
39
|
+
[Amazon Bedrock Guardrails](https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails.html) provide configurable content filters, denied topics, and sensitive information (PII) filters which are evaluated on model input and output. You can attach a guardrail to the model used by the generated agent:
|