in lib/redis-rbac-secret-manager.ts [77:117]
constructor(scope: cdk.Construct, id: string, props: RedisRbacUserProps) {
super(scope, id);
this.rbacUserId = props.redisUserId
this.rbacUserName = props.redisUserName
if (!props.kmsKey) {
this.kmsKey = new kms.Key(this, 'kmsForSecret', {
alias: 'redisRbacUser/'+this.rbacUserName,
enableKeyRotation: true
});
} else {
this.kmsKey = props.kmsKey;
}
this.rbacUserSecret = new secretsmanager.Secret(this, 'secret', {
generateSecretString: {
secretStringTemplate: JSON.stringify({ username: props.redisUserName }),
generateStringKey: 'password',
excludeCharacters: '@%*()_+=`~{}|[]\\:";\'?,./'
},
encryptionKey: this.kmsKey
});
const user = new elasticache.CfnUser(this, 'redisuser', {
engine: 'redis',
userName: props.redisUserName,
accessString: props.accessString? props.accessString : "off +get ~keys*",
userId: props.redisUserId,
passwords: [this.rbacUserSecret.secretValueFromJson('password').toString()]
})
user.node.addDependency(this.rbacUserSecret)
if(props.principals){
props.principals.forEach( (item) => {
this.grantReadSecret(item)
});
}
}