Skip to content

Commit

Permalink
feat(rds): eliminating the need for explicit secret.grantRead() inv…
Browse files Browse the repository at this point in the history
…okes when using DataAPI with Aurora cluster (#29399)

### Issue # (if applicable)

Closes #29362.

### Reason for this change

As discussed [there](#29338 (comment)), we should invoke `secret.grantRead()` explicitly when using DataAPI with Aurora cluster.
Because it's inconvenient for users, I made  `secret.grantRead()` be invoked within `cluster.grantDataApiAccess()`.

### Description of changes

- move `cluster.secret` from `DatabaseClusterNew` to `DatabaseClusterBase` to use it within `DatabaseClusterBase.grantDataApiAccess()`
- add `secret.grantRead()` in `cluster.grantDataApiAccess()`
- add `secret` property to `DatabaseClusterAttributes`

#### Points of concern

`DatabaseClusterBase` class is extended by `ImportedDatabaseCluster` class. Therefore, it is necessary to define `ImportedDatabaseCluster.secret`.

I simply added `secret` props to `DatabaseClusterAttributes` but I cannot believe this is the best way.
Other ways are..
- add `secretArn` to `DatabaseClusterAttributes`
- don't add secret info and `ImportedDatabaseCluster.secret` becomes always undefined

### Description of how you validated changes



### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
badmintoncryer committed Mar 14, 2024
1 parent 9076d6e commit bc9d0b4
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 169 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -10,7 +10,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC"
"Value": "cluster-data-api/VPC"
}
]
}
Expand Down Expand Up @@ -39,7 +39,7 @@
},
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PublicSubnet1"
"Value": "cluster-data-api/VPC/PublicSubnet1"
}
],
"VpcId": {
Expand All @@ -53,7 +53,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PublicSubnet1"
"Value": "cluster-data-api/VPC/PublicSubnet1"
}
],
"VpcId": {
Expand Down Expand Up @@ -94,7 +94,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PublicSubnet1"
"Value": "cluster-data-api/VPC/PublicSubnet1"
}
]
}
Expand All @@ -114,7 +114,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PublicSubnet1"
"Value": "cluster-data-api/VPC/PublicSubnet1"
}
]
},
Expand Down Expand Up @@ -147,7 +147,7 @@
},
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PublicSubnet2"
"Value": "cluster-data-api/VPC/PublicSubnet2"
}
],
"VpcId": {
Expand All @@ -161,7 +161,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PublicSubnet2"
"Value": "cluster-data-api/VPC/PublicSubnet2"
}
],
"VpcId": {
Expand Down Expand Up @@ -202,7 +202,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PublicSubnet2"
"Value": "cluster-data-api/VPC/PublicSubnet2"
}
]
}
Expand All @@ -222,7 +222,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PublicSubnet2"
"Value": "cluster-data-api/VPC/PublicSubnet2"
}
]
},
Expand Down Expand Up @@ -255,7 +255,7 @@
},
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PrivateSubnet1"
"Value": "cluster-data-api/VPC/PrivateSubnet1"
}
],
"VpcId": {
Expand All @@ -269,7 +269,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PrivateSubnet1"
"Value": "cluster-data-api/VPC/PrivateSubnet1"
}
],
"VpcId": {
Expand Down Expand Up @@ -324,7 +324,7 @@
},
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PrivateSubnet2"
"Value": "cluster-data-api/VPC/PrivateSubnet2"
}
],
"VpcId": {
Expand All @@ -338,7 +338,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC/PrivateSubnet2"
"Value": "cluster-data-api/VPC/PrivateSubnet2"
}
],
"VpcId": {
Expand Down Expand Up @@ -375,7 +375,7 @@
"Tags": [
{
"Key": "Name",
"Value": "cluster-kerberos/VPC"
"Value": "cluster-data-api/VPC"
}
]
}
Expand Down Expand Up @@ -543,6 +543,16 @@
"Properties": {
"PolicyDocument": {
"Statement": [
{
"Action": [
"secretsmanager:DescribeSecret",
"secretsmanager:GetSecretValue"
],
"Effect": "Allow",
"Resource": {
"Ref": "DatabaseSecretAttachmentE5D1B020"
}
},
{
"Action": [
"rds-data:BatchExecuteStatement",
Expand Down Expand Up @@ -575,16 +585,6 @@
]
]
}
},
{
"Action": [
"secretsmanager:DescribeSecret",
"secretsmanager:GetSecretValue"
],
"Effect": "Allow",
"Resource": {
"Ref": "DatabaseSecretAttachmentE5D1B020"
}
}
],
"Version": "2012-10-17"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bc9d0b4

Please sign in to comment.