Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-rds): grantConnect for DatabaseProxy yields incorrect policy #12415

Closed
jdvornek opened this issue Jan 8, 2021 · 2 comments · Fixed by #12416
Closed

(aws-rds): grantConnect for DatabaseProxy yields incorrect policy #12415

jdvornek opened this issue Jan 8, 2021 · 2 comments · Fixed by #12416
Assignees
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1

Comments

@jdvornek
Copy link
Contributor

jdvornek commented Jan 8, 2021

Originally from a comment in #11851.

DatabaseProxy::grantConnect() generates a Policy that includes a resource referring to the DatabaseProxy itself. Per the documentation, the resource should be constructed to allow access to the rds-db service and also include the database user from the proxy secret.

Reproduction Steps

const {App, Stack} = require('@aws-cdk/core');
const {Role, ServicePrincipal} = require('@aws-cdk/aws-iam');
const {Vpc} = require('@aws-cdk/aws-ec2');
const {DatabaseCluster, DatabaseClusterEngine, AuroraMysqlEngineVersion} = require('@aws-cdk/aws-rds');

const app = new App();

class DBPermTestStack extends Stack {
  constructor(scope, id) {
    super(scope, id);
    const vpc = new Vpc(this, 'VPC');
    const db = new DatabaseCluster(this, 'DB', {
      engine: DatabaseClusterEngine.auroraMysql({version: AuroraMysqlEngineVersion.VER_2_09_1}),
      instanceProps: {
        vpc
      }
    });
    const proxy = db.addProxy('Proxy', {
      secrets: [db.secret],
      vpc,
      iamAuth: true
    });
    const role = new Role(this, 'Role', {
      assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com')
    });
    proxy.grantConnect(role);
  }
}
new DBPermTestStack(app, 'PermissionsTest');

What did you expect to happen?

I expected a Policy as follows:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": "rds-db:connect",
            "Resource": "arn:aws:rds-db:us-west-2:0123456789100:dbuser:prx-012345678910/admin",
            "Effect": "Allow"
        }
     ]
 }

What actually happened?

A Policy was generated as follows:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": "rds-db:connect",
            "Resource": "arn:aws:rds:us-west-2:0123456789100:db-proxy:prx-012345678910",
            "Effect": "Allow"
        }
    ]
}

Environment

  • CDK CLI Version : 1.83.0 (build 827c5f4)
  • Framework Version: 1.83.0
  • Node.js Version: v14.15.4
  • OS : macOS Catalina 10.15.7
  • Language (Version): Javascript

Other

DatabaseProxy::grantConnect() was requested in #10133 and merged in #12243.


This is 🐛 Bug Report

@jdvornek jdvornek added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 8, 2021
@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label Jan 8, 2021
jdvornek added a commit to jdvornek/aws-cdk that referenced this issue Jan 8, 2021
fixes aws#12415

To generate the correct policy, the DatabaseProxy ARN is parsed
and the resulting components are used along with a new parameter
to grantConnect.

The unit test was updated and passes. Caveat lector, I was not
able to get a full docker build or a full local build to work on
my box.

I'm not sure if this should be considered a breaking change. While
it technically alters the functionality of a published function,
the current behavior provides no utility.
jdvornek added a commit to jdvornek/aws-cdk that referenced this issue Jan 8, 2021
fixes aws#12415

To generate the correct policy, the DatabaseProxy ARN is parsed
and the resulting components are used along with a new parameter
to grantConnect.

The unit test was updated and passes. Caveat lector, I was not
able to get a full docker build or a full local build to work on
my box.

I'm not sure if this should be considered a breaking change. While
it technically alters the functionality of a published function,
the current behavior provides no utility.
@skinny85 skinny85 added effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 12, 2021
@mergify mergify bot closed this as completed in #12416 Feb 16, 2021
mergify bot pushed a commit that referenced this issue Feb 16, 2021
fixes #12415

To generate the correct policy, the DatabaseProxy ARN is parsed
and the resulting components are used along with a new parameter
to grantConnect.

The unit test was updated and passes. Caveat lector, I was not
able to get a full docker build or a full local build to work on
my box.

I'm not sure if this should be considered a breaking change. While
it technically alters the functionality of a published function,
the current behavior provides no utility.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

NovakGu pushed a commit to NovakGu/aws-cdk that referenced this issue Feb 18, 2021
…12416)

fixes aws#12415

To generate the correct policy, the DatabaseProxy ARN is parsed
and the resulting components are used along with a new parameter
to grantConnect.

The unit test was updated and passes. Caveat lector, I was not
able to get a full docker build or a full local build to work on
my box.

I'm not sure if this should be considered a breaking change. While
it technically alters the functionality of a published function,
the current behavior provides no utility.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
eladb pushed a commit that referenced this issue Feb 22, 2021
fixes #12415

To generate the correct policy, the DatabaseProxy ARN is parsed
and the resulting components are used along with a new parameter
to grantConnect.

The unit test was updated and passes. Caveat lector, I was not
able to get a full docker build or a full local build to work on
my box.

I'm not sure if this should be considered a breaking change. While
it technically alters the functionality of a published function,
the current behavior provides no utility.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@cad0p
Copy link

cad0p commented Jul 9, 2023

It's fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants