Skip to content

Commit 340a9d3

Browse files
authored
Merge pull request #1 from companieshouse/implementation
Initial implementation
2 parents 4f193cc + 7c086ce commit 340a9d3

File tree

13 files changed

+234
-0
lines changed

13 files changed

+234
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @companieshouse/platform-admin

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "terraform"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
reviewers:
8+
- "companieshouse/platform-admin"

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
11
# physical-media-backup-terraform
2+
3+
Infrastructure code for the provisioning of object storage for physical media backups (CD-ROM, DVD-ROM, and floppy disk).
4+
5+
## Overview
6+
7+
An S3 bucket is provisioned, along with an IAM user with suitable policy and credentials, for use with client applications such as [WinSCP](https://winscp.net/eng/index.php) and [Cyberduck](https://cyberduck.io/).
8+
9+
Data is encrypted at rest using [server-side encryption](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingServerSideEncryption.html) with Amazon S3 managed encryption keys (SSE-S3). Server-side encryption with AWS Key Management Service (AWS KMS) keys (SSE-KMS) or customer-provided keys (SSE-C) is explicitly blocked via an S3 bucket policy—by denying `PutObject` requests with the `aws:kms` header—to ensure that objects in the S3 bucket use the same server-side encryption method (i.e. SSE-S3).
10+
11+
## Branching Strategy
12+
13+
This project uses a trunk-based branching strategy and infrastructure changes are versioned and applied from the `main` branch after merge via the [infrastructure pipeline](https://github.com/companieshouse/ci-pipelines/blob/master/pipelines/platform/team-platform/physical-media-backup-terraform):
14+
15+
```mermaid
16+
%%{init: { 'logLevel': 'debug', 'theme': 'default' , 'themeVariables': {
17+
'git0': '#4585ed',
18+
'git1': '#edad45'
19+
} } }%%
20+
gitGraph
21+
commit
22+
branch feature
23+
commit
24+
commit
25+
commit
26+
checkout main
27+
merge feature tag: "1.0.0"
28+
```
29+
## License
30+
31+
This project is subject to the terms of the [MIT License](/LICENSE).

groups/storage/.terraform.lock.hcl

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

groups/storage/data.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
data "aws_iam_policy_document" "data" {
2+
statement {
3+
sid = "AllowDataUserToListBucket"
4+
5+
effect = "Allow"
6+
7+
actions = [
8+
"s3:ListBucket"
9+
]
10+
11+
resources = [
12+
aws_s3_bucket.data.arn
13+
]
14+
}
15+
16+
statement {
17+
sid = "AllowDataUserToPutAndGetObjectsInBucket"
18+
19+
effect = "Allow"
20+
21+
actions = [
22+
"s3:PutObject",
23+
"s3:PutObjectAcl",
24+
"s3:GetObject",
25+
"s3:GetObjectAcl"
26+
]
27+
28+
resources = [
29+
"${aws_s3_bucket.data.arn}/*"
30+
]
31+
}
32+
}
33+
34+
data "aws_iam_policy_document" "bucket" {
35+
statement {
36+
sid = "DenyPutObjectWithKmsEncryptionHeader"
37+
38+
effect = "Deny"
39+
40+
principals {
41+
type = "*"
42+
identifiers = ["*"]
43+
}
44+
45+
actions = [
46+
"s3:PutObject"
47+
]
48+
49+
resources = [
50+
"${aws_s3_bucket.data.arn}/*"
51+
]
52+
53+
condition {
54+
test = "StringEquals"
55+
variable = "s3:x-amz-server-side-encryption"
56+
values = ["aws:kms"]
57+
}
58+
}
59+
}

groups/storage/iam.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_iam_user" "data" {
2+
name = "${var.service}-${var.environment}"
3+
4+
tags = merge(local.common_tags, {
5+
Name = "${var.service}-${var.environment}-data-user"
6+
})
7+
}
8+
9+
resource "aws_iam_access_key" "data" {
10+
user = aws_iam_user.data.name
11+
}
12+
13+
resource "aws_iam_policy" "data" {
14+
name = "${var.service}-${var.environment}-data-user-policy"
15+
description = "IAM policy for data user to access objects in physical media backup bucket"
16+
policy = data.aws_iam_policy_document.data.json
17+
}
18+
19+
resource "aws_iam_user_policy_attachment" "data" {
20+
user = aws_iam_user.data.name
21+
policy_arn = aws_iam_policy.data.arn
22+
}

groups/storage/locals.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
locals {
2+
common_tags = {
3+
Environment = var.environment
4+
Provisioner = "Terraform"
5+
Repository = var.repository
6+
Service = var.service
7+
}
8+
}

groups/storage/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_version = ">= 1.3.0, < 1.4.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 4.0"
8+
}
9+
}
10+
}
11+
12+
provider "aws" {
13+
region = var.region
14+
}
15+
16+
terraform {
17+
backend "s3" {}
18+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
aws_account = "heritage-live"
2+
environment = "live"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
aws_account = "heritage-staging"
2+
environment = "staging"

0 commit comments

Comments
 (0)