Skip to content

Secret Manager Templates

Compare
Choose a tag to compare
@mariotoffia mariotoffia released this 12 May 19:02
· 35 commits to master since this release

This release adds templates for simplifying creation of rotate-able secrets by just including a struct.

For example

type MyServiceContext struct {
	DbCtx    support.SecretsManagerRDSPostgreSQLRotationSingleUser `asm:"dbctx, strkey=password"`
	Settings struct {
		BatchSize int    `json:"batchsize"`
		Signer    string `json:"signer,omitempty"`
	} `pms:"settings"`
}

The SecretsManagerRDSPostgreSQLRotationSingleUser looks like this

// SecretsManagerBaseTemplate is the basis for all managed
// template that may be rotated
type SecretsManagerBaseTemplate struct {
	// Engine is required
	Engine ASMEngine `json:"engine"`
	// Host is required: instance host name/resolvable DNS name
	Host string `json:"host"`
	// Username is required: username
	Username string `json:"username"`
	// Password is required: password. If you provision the
	// secret through cloudformation template, this property
	// must be omitted but set the strkey=password in order
	// for cloud formation to auto generate a password upon
	// provisioning.
	Password string `json:"password,omitempty"`
	// DbName is optional, will default to None if missing
	DbName string `json:"dbname,omitempty"`
	// Port is optional, will default to 3306, 1521, 5432, 1433
	// depending on which database used.
	Port string `json:"port,omitempty"`
}

type SecretsManagerRDSPostgreSQLRotationSingleUser struct {
	SecretsManagerBaseTemplate
}

If this is reported it may output something like this (that one may use in ssm-cdk-generator to create deployable CDK Construct - Cloud Formation)

{
  "type": "secrets-manager",
  "fqname": "/prod/test-service/dbctx",
  "keyid": "",
  "description": "",
  "tags": {},
  "details": {
    "strkey": "password"
  },
  "value": "{\"engine\":\"postgres\",\"host\":\"pgsql-17.toffia.se\",\"username\":\"gördis\",\"dbname\":\"mydb\"}",
  "valuetype": "SecureString"
},
{
  "type": "parameter-store",
  "fqname": "/prod/test-service/settings",
  "keyid": "",
  "description": "",
  "tags": {},
  "details": {
    "pattern": "",
    "tier": "Standard"
  },
  "value": "{\"batchsize\":77,\"signer\":\"mto\"}",
  "valuetype": "String"
}