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

RDS.Signer is not implemented? #1823

Closed
isaacl opened this issue Dec 22, 2020 · 14 comments
Closed

RDS.Signer is not implemented? #1823

isaacl opened this issue Dec 22, 2020 · 14 comments
Assignees
Labels
feature-request New feature or enhancement. May require GitHub community feedback.

Comments

@isaacl
Copy link

isaacl commented Dec 22, 2020

RDS.Signer is the V2 impl for RDS IAM token generation. I don't see that here?

@isaacl isaacl added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 22, 2020
@AllanZhengYP AllanZhengYP added feature-request New feature or enhancement. May require GitHub community feedback. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 23, 2020
@willfarrell
Copy link

I'm currently updating https://github.com/middyjs/middy. Would really like to include the middleware that allows this in the next release.

@nwitte-rocketloans
Copy link

This is something that is needed because there is no other way of doing this outside of the CLI or aws-sdk v2.

@clafollett
Copy link

I agree with @nwitte-rocketloans , we are in the process of green fielding a new architecture and were looking to use IAM auth for Aurora PostgreSQL. All of our lambdas will be written against aws-sdk v3.

@xsalazar
Copy link

Would also love to see this implemented in v3

@bendrucker
Copy link

I tried to implement this using the @aws-sdk packages. The implementation in v2 is pretty hacky and the low level packages in v3 should make signing a lot simpler and more comparable to other SDKs. The function below generates URLs that are structurally valid (all the same query params as the CLI) but in my testing are not accepted by a database, presumably because of a signature mismatch.

const { HttpRequest } = require('@aws-sdk/protocol-http')
const { SignatureV4 } = require('@aws-sdk/signature-v4')
const { Hash } = require('@aws-sdk/hash-node')
const { formatUrl } = require('@aws-sdk/util-format-url')

async function getAuthToken({ hostname, port, username, region, credentials }) {
  const protocol = 'https'

  const signer = new SignatureV4({
    service: 'rds-db',
    region,
    credentials,
    sha256: Hash.bind(null, 'sha256')
  })

  const request = new HttpRequest({
    method: 'GET',
    protocol,
    hostname,
    port,
    query: {
      Action: 'connect',
      DBUser: username
    }
  })

  const presigned = await signer.presign(request, {
    expiresIn: 900
  })

  return formatUrl(presigned).replace(`${protocol}://`, '')
}

credentials can be a CredentialProvider or a literal Credentials object.

For now I'm calling out to the CLI which is acceptable in the context I need RDS access via IAM. If anyone wants to keep debugging, using a mocked time and an expected signature/URL could be helpful. Happy to take up a PR or just be able to share a working userland implementation if anyone can spot the issue.

@70nyIT
Copy link

70nyIT commented Jun 4, 2021

Definitively something needed!

@avivek
Copy link

avivek commented Jun 14, 2021

Is this something that is being considered?
Would really love to have this feature.

@AllanZhengYP AllanZhengYP added this to To do in High Priority Jul 26, 2021
@AllanZhengYP AllanZhengYP self-assigned this Jul 26, 2021
@MasterOdin
Copy link

@bendrucker Thanks for posting that code. It looks like you were just missing the headers object on the request with host key:

  const request = new HttpRequest({
    method: 'GET',
    protocol,
    hostname,
    port,
    query: {
      Action: 'connect',
      DBUser: username,
    },
    headers: {
      host: `${hostname}:${port}`,
    },
  });

Doing this, I was able to connect and successfully query the DB!

@bendrucker
Copy link

Really appreciate the extra eyes @MasterOdin, that's a good catch! Figured it was something simple that was missing. I went ahead and published https://github.com/bendrucker/aws-sdk-js-v3-rds-signer to make this easy to adopt.

npm install --save aws-sdk-js-v3-rds-signer

The Signer object is pretty similar to the v2 one but it just returns a promise for the token directly. If you have issues/comments, please open issues on that repo to avoid creating noise for subscribers here.

In the (private) project where I'd previously called out to the AWS CLI I was able to successfully swap over to this and connect.

@mikicho
Copy link

mikicho commented Oct 24, 2021

Thanks @bendrucker! I can't believe this isn't fixed already. maybe consider opening a PR?

jgoeglein pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue Dec 6, 2021
jgoeglein pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue Dec 6, 2021
jgoeglein pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue Dec 6, 2021
jgoeglein pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue Dec 6, 2021
jgoeglein pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue Dec 8, 2021
jgoeglein pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue Dec 8, 2021
jgoeglein pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue Dec 8, 2021
jgoeglein pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue Dec 8, 2021
@willfarrell
Copy link

willfarrell commented Jan 27, 2022

Looks like last July this was a To Do within High Priority (https://github.com/aws/aws-sdk-js-v3/projects/1). Lets hope it will be resolved soon.

@benasher44
Copy link

Looks like it's being implemented here: #3084

AllanZhengYP pushed a commit to AllanZhengYP/aws-sdk-js-v3 that referenced this issue May 4, 2022
AllanZhengYP pushed a commit to AllanZhengYP/aws-sdk-js-v3 that referenced this issue May 4, 2022
AllanZhengYP pushed a commit to AllanZhengYP/aws-sdk-js-v3 that referenced this issue May 4, 2022
AllanZhengYP pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue May 9, 2022
AllanZhengYP pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue May 9, 2022
AllanZhengYP pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue May 9, 2022
AllanZhengYP pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue May 19, 2022
AllanZhengYP pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue May 19, 2022
AllanZhengYP pushed a commit to jgoeglein/aws-sdk-js-v3 that referenced this issue May 19, 2022
AllanZhengYP added a commit that referenced this issue May 23, 2022
* feat(rds-signer): add RDS Signer (#1823)

* chore(rds-signer): update dependencies

* feat(rds-signer): allow skipping port

* feat(rds-signer): support node default credential and region provider

Co-authored-by: AllanZhengYP <zheallan@amazon.com>
@trivikr
Copy link
Member

trivikr commented May 24, 2022

Implemented in #3084

It will be released with v3.98.0 today.

@trivikr trivikr closed this as completed May 24, 2022
High Priority automation moved this from To do to Done May 24, 2022
@github-actions
Copy link

github-actions bot commented Jun 8, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request New feature or enhancement. May require GitHub community feedback.
Projects
Development

No branches or pull requests