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

Add connection-update-secret #756

Merged
merged 3 commits into from
Apr 11, 2024
Merged

Add connection-update-secret #756

merged 3 commits into from
Apr 11, 2024

Conversation

cressie176
Copy link
Collaborator

@cressie176 cressie176 commented Feb 22, 2024

Add support connection update-secret as per #755. I have asked @mortdiggiddy to test

JSON=amqp-rabbitmq-0.9.1.json
RABBITMQ_CODEGEN=https://raw.githubusercontent.com/rabbitmq/rabbitmq-codegen
AMQP_JSON=$(RABBITMQ_CODEGEN)/$(RABBITMQ_SRC_VERSION)/$(JSON)
AMQP_JSON=https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/$(RABBITMQ_SRC_VERSION)/deps/rabbitmq_codegen/$(JSON)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated to the latest spec, from the RabbitMQ monorepo.
Also closes #613

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There really isn’t a standard convention here that I know of for the ‘reason’

updateSecret(newSecret, reason, cb) {
this.connection._updateSecret(newSecret, reason, cb);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was in two minds whether to default reason, but decided against it as I wasn't sure what a sensible default value would be. Happy to reconsider.

newSecret,
reason
});
this.on('update-secret-ok', cb);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change to this.once

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the event handler because I couldn't see another way of getting a callback into the channel0 accept function

@@ -611,6 +619,9 @@ function channel0(connection) {
else if (f.id === defs.ConnectionUnblocked) {
connection.emit('unblocked');
}
else if (f.id === defs.ConnectionUpdateSecretOk) {
connection.emit('update-secret-ok');
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where channel 0 accepts the update-secret ok confirmation frame. I decided not to report an error a confirmation is received without the update-secret operation ever having been sent.

As previously mentioned I used event emitters because I couldn't see how else to invoke the updateSecret callback.

Copy link

@mortdiggiddy mortdiggiddy Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may already have been administered, but the new "secret" can be either a password or JWT to my knowledge. I am guessing the AMQP 0-9-1 protocol already takes care of everything once the frame is sent over?

If JWT, this would pipe into updating whatever authentication mechanism exists that decodes and verifies the new JWT.

I imagine that somewhere in the libs that a new exp (expiration) value is set which is responsible for many of the 403 access denied errors when trying to publish to a connection that has expired.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RabbitMQ docs are pretty light, but the spec only has two arguments...

{
    "id": 70,
    "arguments": [
    {
      "type": "longstr",
      "name": "new-secret"
    },
    {
      "type": "shortstr",
      "name": "reason"
    }
  ],
  "name": "update-secret",
  "synchronous": true
}

So I assume it's also handled transparently.

connect(kCallback(function(c) {
c.updateSecret(Buffer.from('new secret'), 'no reason', doneCallback(done));
}));
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests the callback version of updateSecret. Not a great test as there are no side effects to assert. I checked that the operation and reply are sent/received via WireShark though.

@mortdiggiddy
Copy link

Will be doing some ad-hoc testing in the next few days, then I will try to add some formalized tests.

Thanks for the speedy response this is going to be helpful.

@cressie176
Copy link
Collaborator Author

Great thanks. One thing to be aware of...

lib/defs.js isn't committed to GitHub, so if you were going to add the GitHub URL to package.json, it won't work. Instead do something like...

  1. fork the branch
  2. run make clean lib/defs.js from the command line to build
  3. remove lib/defs.js from .gitignore
  4. commit & push
  5. Reference your fork from package.json

@cressie176 cressie176 merged commit 992919c into main Apr 11, 2024
6 checks passed
@cressie176 cressie176 deleted the connection-update-secret branch April 11, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants