Skip to content

Commit ad51861

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

24 files changed

Lines changed: 1093 additions & 0 deletions

.github/workflows/contract-testing.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
online-archive: ${{ steps.filter.outputs.online-archive }}
2828
organization: ${{ steps.filter.outputs.organization }}
2929
service-account: ${{ steps.filter.outputs.service-account }}
30+
service-account-secret: ${{ steps.filter.outputs.service-account-secret }}
3031
private-endpoint-aws: ${{ steps.filter.outputs.private-endpoint-aws }}
3132
private-endpoint-service: ${{ steps.filter.outputs.private-endpoint-service }}
3233
privatelink-endpoint-service-data-federation-online-archive: ${{ steps.filter.outputs.privatelink-endpoint-service-data-federation-online-archive }}
@@ -79,6 +80,8 @@ jobs:
7980
- 'cfn-resources/organization/**'
8081
service-account:
8182
- 'cfn-resources/service-account/**'
83+
service-account-secret:
84+
- 'cfn-resources/service-account-secret/**'
8285
private-endpoint-aws:
8386
- 'cfn-resources/private-endpoint-aws/**'
8487
private-endpoint-service:
@@ -760,6 +763,46 @@ jobs:
760763
cat inputs/inputs_1_create.json
761764
cat inputs/inputs_1_update.json
762765
766+
make run-contract-testing
767+
make delete-test-resources
768+
service-account-secret:
769+
needs: change-detection
770+
if: ${{ needs.change-detection.outputs.service-account-secret == 'true' }}
771+
runs-on: ubuntu-latest
772+
steps:
773+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
774+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
775+
with:
776+
go-version-file: 'cfn-resources/go.mod'
777+
- name: setup Atlas CLI
778+
uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b
779+
- uses: aws-actions/setup-sam@d78e1a4a9656d3b223e59b80676a797f20093133
780+
with:
781+
use-installer: true
782+
- uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7
783+
with:
784+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }}
785+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }}
786+
aws-region: eu-west-1
787+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
788+
with:
789+
python-version: '3.9'
790+
cache: 'pip' # caching pip dependencies
791+
- run: pip install cloudformation-cli cloudformation-cli-go-plugin
792+
- name: Run the Contract test
793+
shell: bash
794+
env:
795+
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
796+
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
797+
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
798+
MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
799+
MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action
800+
run: |
801+
cd cfn-resources/service-account-secret
802+
make create-test-resources
803+
804+
cat inputs/*
805+
763806
make run-contract-testing
764807
make delete-test-resources
765808
private-endpoint-aws:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"typeName": "MongoDB::Atlas::ServiceAccountSecret",
3+
"language": "go",
4+
"runtime": "provided.al2",
5+
"entrypoint": "bootstrap",
6+
"testEntrypoint": "bootstrap",
7+
"settings": {
8+
"import_path": "github.com/mongodb/mongodbatlas-cloudformation-resources/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::ServiceAccountSecret
2+
3+
## Description
4+
5+
The Service Account Secret resource provides a secret for a Service Account at the organization level. This resource lets you create and delete secrets for Service Accounts. For more information, see [Create One Organization Service Account Secret](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Service-Accounts/operation/createOrgServiceAccountSecret) 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/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/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/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)