Skip to content

Commit 239c25d

Browse files
rakhul-mongooutcomes-winter-rakhulsprakashParthasarathyV
authored
feat: CLOUDP-380111 Add project-service-account-secret resource (#1578)
Co-authored-by: Rakhul S Prakash <rakhul.s.prakash@peerislands.io> Co-authored-by: ParthasarathyV <114770988+ParthasarathyV@users.noreply.github.com>
1 parent ad51861 commit 239c25d

23 files changed

Lines changed: 1073 additions & 0 deletions

.github/workflows/contract-testing.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
private-endpoint-service: ${{ steps.filter.outputs.private-endpoint-service }}
3333
privatelink-endpoint-service-data-federation-online-archive: ${{ steps.filter.outputs.privatelink-endpoint-service-data-federation-online-archive }}
3434
project: ${{ steps.filter.outputs.project }}
35+
project-service-account-secret: ${{ steps.filter.outputs.project-service-account-secret }}
3536
resource-policy: ${{ steps.filter.outputs.resource-policy }}
3637
search-deployment: ${{ steps.filter.outputs.search-deployment }}
3738
search-index: ${{ steps.filter.outputs.search-index }}
@@ -90,6 +91,8 @@ jobs:
9091
- 'cfn-resources/privatelink-endpoint-service-data-federation-online-archive/**'
9192
project:
9293
- 'cfn-resources/project/**'
94+
project-service-account-secret:
95+
- 'cfn-resources/project-service-account-secret/**'
9396
resource-policy:
9497
- 'cfn-resources/resource-policy/**'
9598
search-deployment:
@@ -970,6 +973,46 @@ jobs:
970973
971974
make run-contract-testing
972975
make delete-test-resources
976+
project-service-account-secret:
977+
needs: change-detection
978+
if: ${{ needs.change-detection.outputs.project-service-account-secret == 'true' }}
979+
runs-on: ubuntu-latest
980+
steps:
981+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
982+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
983+
with:
984+
go-version-file: 'cfn-resources/go.mod'
985+
- name: setup Atlas CLI
986+
uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b
987+
- uses: aws-actions/setup-sam@d78e1a4a9656d3b223e59b80676a797f20093133
988+
with:
989+
use-installer: true
990+
- uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7
991+
with:
992+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }}
993+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }}
994+
aws-region: eu-west-1
995+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
996+
with:
997+
python-version: '3.9'
998+
cache: 'pip' # caching pip dependencies
999+
- run: pip install cloudformation-cli cloudformation-cli-go-plugin
1000+
- name: Run the Contract test
1001+
shell: bash
1002+
env:
1003+
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
1004+
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
1005+
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
1006+
MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
1007+
MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action
1008+
run: |
1009+
cd cfn-resources/project-service-account-secret
1010+
make create-test-resources
1011+
1012+
cat inputs/*
1013+
1014+
make run-contract-testing
1015+
make delete-test-resources
9731016
resource-policy:
9741017
needs: change-detection
9751018
if: ${{ needs.change-detection.outputs.resource-policy == 'true' }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"typeName": "MongoDB::Atlas::ProjectServiceAccountSecret",
3+
"language": "go",
4+
"runtime": "provided.al2",
5+
"entrypoint": "bootstrap",
6+
"testEntrypoint": "bootstrap",
7+
"settings": {
8+
"import_path": "github.com/mongodb/mongodbatlas-cloudformation-resources/project-service-account-secret",
9+
"protocolVersion": "2.0.0",
10+
"pluginVersion": "2.0.4"
11+
}
12+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.PHONY: build test clean
2+
tags=logging callback metrics scheduler
3+
cgo=0
4+
goos=linux
5+
goarch=amd64
6+
CFNREP_GIT_SHA?=$(shell git rev-parse HEAD)
7+
ldXflags=-s -w -X github.com/mongodb/mongodbatlas-cloudformation-resources/util.defaultLogLevel=info -X github.com/mongodb/mongodbatlas-cloudformation-resources/version.Version=${CFNREP_GIT_SHA}
8+
ldXflagsD=-X github.com/mongodb/mongodbatlas-cloudformation-resources/util.defaultLogLevel=debug -X github.com/mongodb/mongodbatlas-cloudformation-resources/version.Version=${CFNREP_GIT_SHA}
9+
10+
build:
11+
cfn generate
12+
env GOOS=$(goos) CGO_ENABLED=$(cgo) GOARCH=$(goarch) go build -ldflags="$(ldXflags)" -tags="$(tags)" -o bin/bootstrap cmd/main.go
13+
14+
debug:
15+
cfn generate
16+
env GOOS=$(goos) CGO_ENABLED=$(cgo) GOARCH=$(goarch) go build -ldflags="$(ldXflagsD)" -tags="$(tags)" -o bin/debug cmd/main.go
17+
18+
clean:
19+
rm -rf bin
20+
21+
submit: clean build # submit to private registry must use release build not debug build
22+
@echo "==> Submitting to private registry for testing"
23+
cfn submit --set-default --region us-east-1
24+
25+
create-test-resources:
26+
@echo "==> Creating test files and resources for contract testing"
27+
./test/contract-testing/cfn-test-create.sh
28+
29+
delete-test-resources:
30+
@echo "==> Delete test resources used for contract testing"
31+
./test/contract-testing/cfn-test-delete.sh
32+
33+
run-contract-testing:
34+
@echo "==> Run contract testing"
35+
make build
36+
sam local start-lambda &
37+
cfn test --function-name TestEntrypoint --verbose
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# MongoDB::Atlas::ProjectServiceAccountSecret
2+
3+
## Description
4+
5+
The Project Service Account Secret resource provides a secret for a Service Account at the project level. This resource lets you create and delete secrets for Project Service Accounts. For more information, see [Create One Project Service Account Secret](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Service-Accounts/operation/createGroupServiceAccountSecret) in the MongoDB Atlas API documentation.
6+
7+
~> **IMPORTANT WARNING:** Managing Service Account Secrets with CloudFormation **exposes sensitive organizational secrets** in CloudFormation's outputs and logs. We suggest following [AWS Secrets Manager best practices](https://docs.aws.amazon.com/secretsmanager/latest/userguide/best-practices.html) for handling sensitive data.
8+
9+
-> **NOTE:** This resource does not support updates. Any property change will trigger a replacement (delete + create). To rotate secrets, simply replace the resource.
10+
11+
## Requirements
12+
13+
To securely give CloudFormation access to your Atlas credentials, you must
14+
set up an [AWS Profile](/README.md#mongodb-atlas-api-keys-credential-management).
15+
16+
## Attributes and Parameters
17+
18+
See the [resource docs](docs/README.md).
19+
20+
## Cloudformation Examples
21+
22+
See the examples [CFN Template](/examples/project-service-account-secret/README.md) for example resource.
23+
24+
## Important Notes
25+
26+
- The `Secret` property contains the actual secret value and is only returned once during creation
27+
- This resource does not support updates - any change will trigger a replacement
28+
- Secrets have an expiration time controlled by `SecretExpiresAfterHours`
29+
- The minimum and maximum expiration times are controlled by your organization's settings

cfn-resources/project-service-account-secret/cmd/main.go

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

cfn-resources/project-service-account-secret/cmd/resource/config.go

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

0 commit comments

Comments
 (0)