Skip to content

Conversation

mariuspod
Copy link
Contributor

Proposed Changes

In this change I've added a new beacon_node cli flag --execution-jwt-secret-key for passing the JWT secret directly as string.

Without this flag, it was non-trivial to pass a secrets file containing a JWT secret key without compromising its contents into some management repo or fiddling around with manual file mounts for cloud-based deployments.

When used in combination with environment variables, the secret can be injected into container-based systems like docker & friends quite easily.

It's both possible to either specify the file_path to the JWT secret or pass the JWT secret directly.

I've modified the docs and attached a test as well.

Additional Info

The logic has been adapted a bit so that either one of --execution-jwt or --execution-jwt-secret-key must be set when specifying --execution-endpoint so that it's still compatible with the semantics before this change and there's at least one secret provided.

@CLAassistant
Copy link

CLAassistant commented Sep 12, 2022

CLA assistant check
All committers have signed the CLA.

@paulhauner paulhauner added the ready-for-review The code is ready for review label Sep 13, 2022
@paulhauner
Copy link
Member

Thanks for the contribution @mariuspod. It looks like cargo fmt is unhappy, you could fix this by running cargo fmt (ensuring you're on the latest Rust version).

@mariuspod
Copy link
Contributor Author

thanks for the hint, I've just pushed another commit after running the formatter.

@mariuspod
Copy link
Contributor Author

@paulhauner if there's anything I could change for this PR, please let me know.

Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Heyo, apologies for the delay here. I think this got swept up in all the merge excitement.

Thanks for this contribution, especially for implementing a test and updating the documentation ❤️ I have a few suggestions, please let me know what you think :)

@paulhauner paulhauner added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Sep 28, 2022
@paulhauner paulhauner self-assigned this Sep 28, 2022
…cret-key and --execution-jwt as conflicting.
@mariuspod
Copy link
Contributor Author

mariuspod commented Sep 28, 2022

@paulhauner Thanks for your review! I agree to all of your recommendations and have updated the code.
I was unsure about the .to_string() on the error message string itself but I kept it for consistency.

@paulhauner paulhauner added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Sep 29, 2022
Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, just a couple more along the same lines 🙏

use std::io::Write;
secret_file = client_config.data_dir.join(DEFAULT_JWT_FILE);
let mut jwt_secret_key_file = File::create(secret_file.clone())
.expect("Error while creating jwt_secret_key file!");
Copy link
Member

Choose a reason for hiding this comment

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

I missed this on the last review sorry, but this expect will panic. Something like this would be more suitable:

Suggested change
.expect("Error while creating jwt_secret_key file!");
.map_err(|e| "Error while creating jwt_secret_key file: {:?}")?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's nice! So this handles the error and exits early without panicking, very cool. Will implement it like you proposed.

.expect("Error while creating jwt_secret_key file!");
jwt_secret_key_file
.write_all(jwt_secret_key.as_bytes())
.expect("Error occured while writing to jwt_secret_key file!");
Copy link
Member

Choose a reason for hiding this comment

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

As above 🙏

@paulhauner paulhauner added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Sep 29, 2022
@mariuspod
Copy link
Contributor Author

I've added a call to format! inside the map_err block to interpolate the error object into the message. Your suggestion didn't include this, and I was wondering if there was some rust magic that defaults to format! inside the map_err if nothing else is specified 🤔

Anyways the tests are passing on my local machine with this 🎉

@mariuspod
Copy link
Contributor Author

mariuspod commented Sep 29, 2022

nvm, just tried without the format! and then the compiler gives a warning about the unused var so I guess no magic here 😅

warning: unused variable: `e`
311 |                 .map_err(|e| "Error while creating jwt_secret_key file: {:?}")?;
    |                           ^ help: if this is intentional, prefix it with an underscore: `_e`

@mariuspod
Copy link
Contributor Author

for some reason this test failed only on windows. It seems unrelated to my changes: subnet_service::tests::attestation_service::test_same_subnet_unsubscription
What do you think ?

@michaelsproul
Copy link
Member

@mariuspod Yeah that's a spurious failure. A flaky test that sometimes fails on slow hardware (we'll make it less flaky... soon).

@michaelsproul michaelsproul added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Oct 3, 2022
Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the contribution ❤️

This is ready to be merged with the next bors batch!

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Oct 4, 2022
@paulhauner
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Oct 4, 2022
## Proposed Changes

In this change I've added a new beacon_node cli flag `--execution-jwt-secret-key` for passing the JWT secret directly as string.

Without this flag, it was non-trivial to pass a secrets file containing a JWT secret key without compromising its contents into some management repo or fiddling around with manual file mounts for cloud-based deployments.

When used in combination with environment variables, the secret can be injected into container-based systems like docker & friends quite easily.

It's both possible to either specify the file_path to the JWT secret or pass the JWT secret directly.

I've modified the docs and attached a test as well.

## Additional Info

The logic has been adapted a bit so that either one of `--execution-jwt` or `--execution-jwt-secret-key` must be set when specifying `--execution-endpoint` so that it's still compatible with the semantics before this change and there's at least one secret provided.
@bors
Copy link

bors bot commented Oct 4, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Oct 4, 2022
## Proposed Changes

In this change I've added a new beacon_node cli flag `--execution-jwt-secret-key` for passing the JWT secret directly as string.

Without this flag, it was non-trivial to pass a secrets file containing a JWT secret key without compromising its contents into some management repo or fiddling around with manual file mounts for cloud-based deployments.

When used in combination with environment variables, the secret can be injected into container-based systems like docker & friends quite easily.

It's both possible to either specify the file_path to the JWT secret or pass the JWT secret directly.

I've modified the docs and attached a test as well.

## Additional Info

The logic has been adapted a bit so that either one of `--execution-jwt` or `--execution-jwt-secret-key` must be set when specifying `--execution-endpoint` so that it's still compatible with the semantics before this change and there's at least one secret provided.
@bors
Copy link

bors bot commented Oct 4, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Oct 4, 2022
## Proposed Changes

In this change I've added a new beacon_node cli flag `--execution-jwt-secret-key` for passing the JWT secret directly as string.

Without this flag, it was non-trivial to pass a secrets file containing a JWT secret key without compromising its contents into some management repo or fiddling around with manual file mounts for cloud-based deployments.

When used in combination with environment variables, the secret can be injected into container-based systems like docker & friends quite easily.

It's both possible to either specify the file_path to the JWT secret or pass the JWT secret directly.

I've modified the docs and attached a test as well.

## Additional Info

The logic has been adapted a bit so that either one of `--execution-jwt` or `--execution-jwt-secret-key` must be set when specifying `--execution-endpoint` so that it's still compatible with the semantics before this change and there's at least one secret provided.
@bors bors bot changed the title Pass EL JWT secret key via cli flag [Merged by Bors] - Pass EL JWT secret key via cli flag Oct 4, 2022
@bors bors bot closed this Oct 4, 2022
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
## Proposed Changes

In this change I've added a new beacon_node cli flag `--execution-jwt-secret-key` for passing the JWT secret directly as string.

Without this flag, it was non-trivial to pass a secrets file containing a JWT secret key without compromising its contents into some management repo or fiddling around with manual file mounts for cloud-based deployments.

When used in combination with environment variables, the secret can be injected into container-based systems like docker & friends quite easily.

It's both possible to either specify the file_path to the JWT secret or pass the JWT secret directly.

I've modified the docs and attached a test as well.

## Additional Info

The logic has been adapted a bit so that either one of `--execution-jwt` or `--execution-jwt-secret-key` must be set when specifying `--execution-endpoint` so that it's still compatible with the semantics before this change and there's at least one secret provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants