Skip to content

Commit 95d03b3

Browse files
Upgrade: [dependabot] - sync Copilot instructions (#651)
Syncing Copilot instructions from central repo. Ref: `main` Co-authored-by: eps-create-pull-request[bot] <270920461+eps-create-pull-request[bot]@users.noreply.github.com>
1 parent 223f1ef commit 95d03b3

File tree

9 files changed

+635
-15
lines changed

9 files changed

+635
-15
lines changed

.github/copilot-instructions.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
- Follow clean code principles
33
- Write comprehensive tests
44
- Use meaningful variable names
5-
- Use British English spelling
5+
6+
## Project-Specific instructions
7+
Check the following files for any project-specific coding standards or guidelines:
8+
- .github/instructions/project/instructions.md
9+
- If no project-specific conventions are defined there, use the general and language-specific best practices referenced below.
10+
- Language-specific instructions may also be found in the language-specific instruction files listed below. Always check those for any additional guidelines or standards that may apply to your codebase.
611

712
## Language-Specific Instructions
813
Always follow security best practices as outlined in:
9-
- .github/instructions/general/SECURITY.md
14+
- .github/instructions/general/security.instructions.md
1015
Follow additional language-specific guidelines in:
11-
- .github/instructions/language-specific/INSTRUCTIONS-CDK.md
12-
- .github/instructions/language-specific/INSTRUCTIONS-CLOUDFORMATION.md
13-
- .github/instructions/language-specific/INSTRUCTIONS-JAVA.md
14-
- .github/instructions/language-specific/INSTRUCTIONS-KOTLIN.md
15-
- .github/instructions/language-specific/INSTRUCTIONS-PYTHON.md
16-
- .github/instructions/language-specific/INSTRUCTIONS-TERRAFORM.md
17-
- .github/instructions/language-specific/INSTRUCTIONS-SAM.md
18-
- .github/instructions/language-specific/INSTRUCTIONS-TYPESCRIPT.md
19-
20-
## Project-Specific Rules
16+
- .github/instructions/languages/cdk.instructions.md
17+
- .github/instructions/languages/cloudformation.instructions.md
18+
- .github/instructions/languages/python.instructions.md
19+
- .github/instructions/languages/terraform.instructions.md
20+
- .github/instructions/languages/sam.instructions.md
21+
- .github/instructions/languages/typescript.instructions.md

.github/instructions/general/SECURITY.md renamed to .github/instructions/general/security.instructions.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
2-
applyTo: '*'
2+
applyTo: '**/*'
33
description: "Comprehensive secure coding instructions for all languages and frameworks, based on OWASP Top 10 and industry best practices."
44
---
5+
6+
This file is mastered in https://github.com/NHSDigital/eps-copilot-instructions and is automatically synced to all EPS repositories. To suggest changes, please open an issue or pull request in the eps-copilot-instructions repository.
7+
58
# Secure Coding and OWASP Guidelines
69

710
## Instructions

.github/instructions/languages/INSTRUCTIONS-CDK.md renamed to .github/instructions/languages/cdk.instructions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ description: 'Guidelines for writing, reviewing, and maintaining AWS CDK (TypeSc
33
applyTo: 'packages/cdk/**/*.ts'
44
---
55

6+
This file is mastered in https://github.com/NHSDigital/eps-copilot-instructions and is automatically synced to all EPS repositories. To suggest changes, please open an issue or pull request in the eps-copilot-instructions repository.
7+
68
# AWS CDK TypeScript Development
79

810
This file provides instructions for generating, reviewing, and maintaining AWS CDK code in the `packages/cdk` folder. It covers best practices, code standards, architecture, and validation for infrastructure-as-code using AWS CDK in TypeScript.
@@ -90,7 +92,7 @@ export class CptsApiAppStack extends Stack {
9092
## Validation and Verification
9193

9294
- Build: `make cdk-synth`
93-
- Lint: `npm run lint --workspace packges/cdk`
95+
- Lint: `npm run lint --workspace packages/cdk`
9496

9597
## Maintenance
9698

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
description: 'Guidelines for writing, reviewing, and maintaining cloudformation templates'
3+
applyTo: 'cloudformation/**'
4+
---
5+
6+
This file is mastered in https://github.com/NHSDigital/eps-copilot-instructions and is automatically synced to all EPS repositories. To suggest changes, please open an issue or pull request in the eps-copilot-instructions repository.
7+
8+
## General
9+
- Prefer YAML (not JSON). Follow existing style in [cloudformation/account_resources.yml](cloudformation/account_resources.yml), [cloudformation/ci_resources.yml](cloudformation/ci_resources.yml), [cloudformation/artillery_resources.yml](cloudformation/artillery_resources.yml), [cloudformation/account_resources_bootstrap.yml](cloudformation/account_resources_bootstrap.yml), [cloudformation/management.yml](cloudformation/management.yml).
10+
- Always start with `AWSTemplateFormatVersion: "2010-09-09"`.
11+
- Keep descriptions concise (> operator used only for multi‑line).
12+
- Use logical region `eu-west-2` unless cross‑region behavior explicitly required.
13+
- Maintain tagging pattern: version, stack, repo, cfnDriftDetectionGroup (see deployment scripts in [.github/scripts/release_code.sh](.github/scripts/release_code.sh) and [.github/scripts/create_changeset_existing_tags.sh](.github/scripts/create_changeset_existing_tags.sh)).
14+
15+
## Parameters
16+
- Reuse and align parameter naming with existing templates: `LogRetentionDays`, `Env`, `SplunkHECEndpoint`, `DeployDriftDetection`.
17+
- For numeric retention days replicate allowed values list from [SAMtemplates/lambda_resources.yaml](SAMtemplates/lambda_resources.yaml) or [cloudformation/account_resources.yml](cloudformation/account_resources.yml).
18+
- Use `CommaDelimitedList` for OIDC subject claim filters like in [cloudformation/ci_resources.yml](cloudformation/ci_resources.yml).
19+
20+
## Conditions
21+
- Follow pattern `ShouldDeployDriftDetection` (see [SAMtemplates/lambda_resources.yaml](SAMtemplates/lambda_resources.yaml)); avoid ad‑hoc condition names.
22+
- If creating a never-used placeholder stack use pattern from [cloudformation/empty_stack.yml](cloudformation/empty_stack.yml).
23+
24+
## IAM Policies
25+
- Split large CloudFormation execution permissions across multiple managed policies (A, B, C, D) to keep each rendered size < 6144 chars (see check logic in [scripts/check_policy_length.py](scripts/check_policy_length.py)).
26+
- Scope resources minimally; prefer specific ARNs (e.g. logs, KMS aliases) as in [cloudformation/account_resources.yml](cloudformation/account_resources.yml).
27+
- When granting CloudFormation execution access: separate IAM‑focused policy (`GrantCloudFormationExecutionAccessIAMPolicy`) from broad service policies.
28+
- Use exports for policy ARNs with naming `ci-resources:GrantCloudFormationExecutionAccessPolicyA` pattern.
29+
30+
## KMS
31+
- Alias naming: `alias/CloudwatchLogsKmsKeyAlias`, `alias/SecretsKMSKeyAlias`, `alias/ArtifactsBucketKMSKeyAlias` (see [cloudformation/account_resources.yml](cloudformation/account_resources.yml), [cloudformation/account_resources_bootstrap.yml](cloudformation/account_resources_bootstrap.yml)).
32+
- Grant encrypt/decrypt explicitly for principals (e.g. API Gateway, Lambda) mirroring key policy blocks in [cloudformation/account_resources.yml](cloudformation/account_resources.yml).
33+
34+
## Secrets / Parameters
35+
- SecretsManager resources must depend on alias if needed (`DependsOn: SecretsKMSKeyKMSKeyAlias`) like in [cloudformation/account_resources_bootstrap.yml](cloudformation/account_resources_bootstrap.yml).
36+
- Export secret IDs (not ARNs unless specifically required) using colon-separated naming with stack name (pattern in outputs section of account templates).
37+
- Default placeholder value `ChangeMe` for bootstrap secrets.
38+
39+
## S3 Buckets
40+
- Apply `PublicAccessBlockConfiguration` and encryption blocks consistent with [cloudformation/account_resources.yml](cloudformation/account_resources.yml).
41+
- Suppress guard rules using `Metadata.guard.SuppressedRules` where legacy exceptions exist (e.g. replication / logging) matching existing patterns.
42+
43+
## Lambda / SAM
44+
- Shared lambda resources belong in SAM template ([SAMtemplates/lambda_resources.yaml](SAMtemplates/lambda_resources.yaml)); CloudFormation templates should not duplicate build-specific metadata.
45+
- Suppress cfn-guard rules where justified via `Metadata.guard.SuppressedRules` (e.g. `LAMBDA_INSIDE_VPC`, `LAMBDA_CONCURRENCY_CHECK`) only if precedent exists.
46+
47+
## Exports & Cross Stack
48+
- Output export naming pattern: `!Join [":", [!Ref "AWS::StackName", "ResourceLogicalName"]]`.
49+
- Reference exports via `!ImportValue stack-name:ExportName` (see Proxygen role usage in [SAMtemplates/lambda_resources.yaml](SAMtemplates/lambda_resources.yaml)).
50+
- Avoid changing existing export names (breaking downstream stacks and scripts).
51+
52+
## OIDC / Roles
53+
- Federated trust for GitHub actions must use conditions:
54+
- `token.actions.githubusercontent.com:aud: sts.amazonaws.com`
55+
- `ForAnyValue:StringLike token.actions.githubusercontent.com:sub: <ClaimFilters>`
56+
(pattern in roles inside [cloudformation/ci_resources.yml](cloudformation/ci_resources.yml)).
57+
- When adding a new OIDC role add matching parameter `<RoleName>ClaimFilters` and outputs `<RoleName>` and `<RoleName>Name`.
58+
59+
## Drift Detection
60+
- Tag stacks with `cfnDriftDetectionGroup` (deployment scripts handle this). Config rules should filter on `TagKey: cfnDriftDetectionGroup` and specific `TagValue` (patterns in [SAMtemplates/lambda_resources.yaml](SAMtemplates/lambda_resources.yaml)).
61+
- Avoid duplicating rule identifiers; follow `${AWS::StackName}-CloudFormationDriftDetector-<Group>`.
62+
63+
## Route53
64+
- Environment hosted zones template ([cloudformation/eps_environment_route53.yml](cloudformation/eps_environment_route53.yml)) uses parameter `environment`; management template updates NS records referencing environment zones.
65+
66+
## Style / Lint / Guard
67+
- Keep resources grouped with `#region` / `#endregion` comments as in existing templates for readability.
68+
- Use `Metadata.cfn-lint.config.ignore_checks` only when upstream spec mismatch (example: W3037 in large policy templates).
69+
- Ensure new templates pass `make lint-cloudformation` and `make cfn-guard` (scripts: [scripts/run_cfn_guard.sh](scripts/run_cfn_guard.sh)).
70+
71+
## Naming Conventions
72+
- Logical IDs: PascalCase (`ArtifactsBucketKMSKey`, `CloudFormationDeployRole`).
73+
- Managed policy logical IDs end with `Policy` or `ManagedPolicy`.
74+
- KMS Key alias logical IDs end with `Alias` (e.g. `CloudwatchLogsKmsKeyAlias`).
75+
- Secrets logical IDs end with `Secret`.
76+
77+
## Security
78+
- Block public access for all buckets unless explicitly required.
79+
- Encrypt logs with KMS key; provide alias export (see `CloudwatchLogsKmsKeyAlias`).
80+
- Limit wildcard `Resource: "*"` where service requires (e.g. some IAM, CloudFormation actions). Prefer service/resource ARNs otherwise.
81+
82+
## When Adding New Resource Types
83+
- Update execution policies in [cloudformation/ci_resources.yml](cloudformation/ci_resources.yml) minimally; do not expand existing broad statements unnecessarily.
84+
- Run policy length check (`make test` invokes [scripts/check_policy_length.py](scripts/check_policy_length.py)) after modifications.
85+
86+
## Do Not
87+
- Do not hardcode account IDs; use `${AWS::AccountId}`.
88+
- Do not remove existing exports or rename keys.
89+
- Do not inline large policy statements in a single managed policy if size risk exists.
90+
91+
## Examples
92+
- IAM Role with OIDC trust: replicate structure from `CloudFormationDeployRole` in [cloudformation/ci_resources.yml](cloudformation/ci_resources.yml).
93+
- KMS key + alias + usage policy: follow `ArtifactsBucketKMSKey` block in [cloudformation/account_resources.yml](cloudformation/account_resources.yml).
94+
95+
## Testing
96+
- After changes: run `make lint-cloudformation` and `make cfn-guard`.
97+
- For SAM-related cross-stack exports ensure `sam build` (see [Makefile](Makefile)) passes.
98+
99+
## Automation Awareness
100+
- Deployment scripts expect unchanged parameter names & export patterns (see [.github/scripts/execute_changeset.sh](.github/scripts/execute_changeset.sh), [.github/scripts/release_code.sh](.github/scripts/release_code.sh)).
101+
- Changes to tagging keys must be reflected in release / changeset scripts; avoid unless necessary.
102+
103+
## Preferred Patterns Summary
104+
- Exports: colon join
105+
- Tags: version, stack, repo, cfnDriftDetectionGroup
106+
- Conditions: prefixed with `Should`
107+
- Claim filter parameters: `<RoleName>ClaimFilters`
108+
- Secrets: depend on KMS alias, default `ChangeMe`
109+
110+
Use these rules to guide completions for any new or modified CloudFormation template in this repository.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
description: 'Guidelines for writing high-quality, maintainable python code with best practices for logging, error handling, code organization, naming, formatting, and style.'
3+
applyTo: '**/*.py'
4+
---
5+
6+
This file is mastered in https://github.com/NHSDigital/eps-copilot-instructions and is automatically synced to all EPS repositories. To suggest changes, please open an issue or pull request in the eps-copilot-instructions repository.
7+
8+
# Python Copilot Instructions
9+
10+
These instructions are designed to guide GitHub Copilot in generating effective, maintainable, and domain-appropriate Python code. They are intended to be generic and applicable to a wide range of Python projects.
11+
12+
## 1. Code Organization & Structure
13+
- Organize code into logical modules and packages. Use directories such as `core/`, `services/`, `utils/` for separation of concerns.
14+
- Place entry points (e.g., `handler.py`) at the top level of the main package.
15+
- Use `__init__.py` files to define package boundaries and expose public APIs.
16+
- Group related functions and classes together. Avoid large monolithic files.
17+
- Store tests in a dedicated `tests/` directory, mirroring the structure of the main codebase.
18+
19+
## 2. Naming Conventions
20+
- Use `snake_case` for function and variable names.
21+
- Use `PascalCase` for class names.
22+
- Prefix private functions and variables with a single underscore (`_`).
23+
- Name modules and packages using short, descriptive, lowercase names.
24+
- Use clear, descriptive names for all symbols. Avoid abbreviations unless they are widely understood.
25+
26+
## 3. Formatting & Style
27+
- Follow [PEP 8](https://peps.python.org/pep-0008/) for code style and formatting.
28+
- Use 4 spaces per indentation level. Do not use tabs.
29+
- Limit lines to 120 characters.
30+
- Use blank lines to separate functions, classes, and logical sections.
31+
- Place imports at the top of each file, grouped by standard library, third-party, and local imports.
32+
- Use single quotes for strings unless double quotes are required.
33+
- Add docstrings to all public modules, classes, and functions. Use triple double quotes for docstrings.
34+
35+
## 4. Logging Best Practices
36+
- Use the standard `logging` library for all logging.
37+
- Configure logging in the main entry point or via a dedicated utility module.
38+
- Use appropriate log levels: `debug`, `info`, `warning`, `error`, `critical`.
39+
- Avoid logging sensitive information.
40+
- Include contextual information in log messages (e.g., function names, parameters, error details).
41+
- Example:
42+
```python
43+
import logging
44+
logger = logging.getLogger(__name__)
45+
logger.info('Processing event: %s', event)
46+
```
47+
48+
## 5. Error Handling Best Practices
49+
- Use `try`/`except` blocks to handle exceptions gracefully.
50+
- Catch specific exceptions rather than using bare `except`.
51+
- Log exceptions with stack traces using `logger.exception()`.
52+
- Raise custom exceptions for domain-specific errors.
53+
- Validate inputs and fail fast with clear error messages.
54+
- Example:
55+
```python
56+
try:
57+
result = process_event(event)
58+
except ValueError as e:
59+
logger.error('Invalid event: %s', e)
60+
raise
61+
```
62+
63+
## 6. Testing Guidelines
64+
- Write unit tests for all public functions and classes.
65+
- Use `pytest` as the preferred testing framework.
66+
- Name test files and functions using `test_` prefix.
67+
- Use fixtures for setup and teardown.
68+
- Mock external dependencies in tests.
69+
- Ensure tests are isolated and repeatable.
70+
71+
## 7. Dependency Management
72+
- Use `pyproject.toml` to specify dependencies.
73+
- Never use `requirements.txt` to specify dependencies.
74+
- Pin versions for critical dependencies.
75+
- Avoid unnecessary dependencies.
76+
77+
## 8. Documentation
78+
- Document all public APIs with clear docstrings.
79+
- Use [Google](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) or [NumPy](https://numpydoc.readthedocs.io/en/latest/format.html) style for docstrings.
80+
- Provide usage examples in README files.
81+
82+
## 9. Security & Privacy
83+
- Do not log or expose secrets, credentials, or sensitive data.
84+
- Validate and sanitize all external inputs.
85+
- Use environment variables for configuration secrets.
86+
87+
## 10. General Guidelines
88+
- Prefer readability and simplicity over cleverness.
89+
- Refactor duplicated code into reusable functions or classes.
90+
- Use type hints for function signatures and variables where appropriate.
91+
- Avoid global variables; use function arguments or class attributes.
92+
93+
---

0 commit comments

Comments
 (0)