-
Notifications
You must be signed in to change notification settings - Fork 56
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
feat: support read-write device.id in tedge cert/connect #3326
base: main
Are you sure you want to change the base?
feat: support read-write device.id in tedge cert/connect #3326
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command to create a CSR must also be updated to set the device id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the device id has been set using tedge config set device.id
, then the device id should no more be mandatory for tedge cert create
.
We also need to take care of the paths for the cloud specific certificates.
For instance, the following sequence of command is error prone:
# Trying to create a certificate for an unknown cloud profile (okay: the error is detected)
$ tedge cert create --device-id demo-c8y c8y --profile foo
Error: missing configuration parameter
Caused by:
Unknown profile `foo` for the multi-profile property c8y
# Creating the cloud profile
$ tedge config set c8y.device.id device-c8y-foo --profile foo
# Now that the cloud profile exists, the cert creat command runs
# BUT
# - --device-id is required while set in the config
# - the value set on the command line erases the config
# - the certificate is created globally (because no specific paths were configured for this profile)
$ tedge cert create --device-id some-other-device-id c8y --profile foo
Error: failed to create a test certificate for the device some-other-device-id.
Caused by:
A certificate already exists and would be overwritten.
Existing file: "/etc/tedge/device-certs/demo-device-888.pem"
Run `tedge cert remove` first to generate a new certificate.
@didier-wenzek
For the rest, I would like to implement to have the consistent behavour as However, on the condition, if |
In that case this is a bug.
Perfect. One just to be cautious taking the most specific device id (i.e. the id for the requested cloud and profile if given).
Yes raising an error is the way to go. But make sure the comparison is done on the device id specific for the requested cloud. I.e. if |
Codecov ReportAttention: Patch coverage is Additional details and impacted files📢 Thoughts on this report? Let us know! |
Robot Results
|
7dcb459
to
77e1ecd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick test this seems to be working well. It will be much easier to use the CLI with the persisted device id.
#[test_case("c8y-foo-test", Some("c8y-foo-test"), Some(CloudArg::C8y{ profile: Some("foo".parse().unwrap()) }), toml::toml!{ | ||
[device] | ||
id = "test" | ||
[c8y.device] | ||
id = "c8y-test" | ||
})] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this case actually occur in practice? If someone hasn't got any configurations for a profile, the profile doesn't exist and that will cause an error elsewhere in tedge cert create
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice, tedge cert create
will return an error because no profile for "foo" exists. So the following toml
fie is more realistic. Though the result get_device_id()
is the same.
[device]
id = "test"
[c8y.device]
id = "c8y-test"
[c8y.profiles.foo.device]
cert_path = "/path/to/cert.pem"
key_path = "/path/to/key.pem"
crates/core/tedge/src/error.rs
Outdated
r#"The given device ID '{input_id}' doesn't match the one in the config '{config_id}'. | ||
Run `tedge config unset {writable_key}` first to unset the device ID."# | ||
)] | ||
UnmatchedDeviceId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnmatchedDeviceId { | |
MismatchedDeviceId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in ed40433
@@ -102,6 +102,10 @@ impl TEdgeConfigLocation { | |||
Ok(TEdgeConfig::from_dto(&dto, self)) | |||
} | |||
|
|||
pub fn load_dto_with_file_and_env(&self) -> Result<TEdgeConfigDto, TEdgeConfigError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn load_dto_with_file_and_env(&self) -> Result<TEdgeConfigDto, TEdgeConfigError> { | |
pub fn load_dto_from_toml_and_env(&self) -> Result<TEdgeConfigDto, TEdgeConfigError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in bfc6e14
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: Rina Fujino <[email protected]>
Examples: `tedge cert create --device-id foo` -> `device.id` is set to foo `tedge cert create --device-id bar c8y` -> `c8y.device.id` is set to bar `tedge cert create --device-id baz c8y --profile new` -> `c8y.profiles.new.device.id` is set to baz Signed-off-by: Rina Fujino <[email protected]>
Signed-off-by: Rina Fujino <[email protected]>
Signed-off-by: Rina Fujino <[email protected]>
* tedge connect c8y uses device.id directly. The CN from certificate is no longer used to determine device.id * tedge connect c8y returns an error if device.id mismatches the certificate's CN when auth method is certificate Signed-off-by: Rina Fujino <[email protected]>
77e1ecd
to
247d7f8
Compare
Signed-off-by: Rina Fujino <[email protected]>
Signed-off-by: Rina Fujino <[email protected]>
Proposed changes
This PR aims to open up
device.id
as read-write key. This is the last piece of supporting basic authentication, as it needsdevice.id
but not need for device cert.TODOs:
tedge cert/connect part
tedge cert create
writesdevice.id
intedge.toml
explicitly.tedge connect
returns an error ifdevice.id
mismatches the certificate's CN. The only exception is whenc8y.auth_mode
isbasic
.smart_rest_one
system test to confirm thattedge connect c8y
usesdevice.id
directly when using basic auth.tedge cert create-csr
also setsdevice.id
if not configured.tedge cert create
should work without--device-id
option whendevice.id
is already set.device.id
when the values of option--device-id
and configdevice.id
are conflicting. This case should return an error.tedge_config part (originally started in the PR #3318 by @jarhodes314 )
get_device_id_from_config()
function totedge_config
to keepconfig.device.id()
as private. refactor: support writable device ids #3318 (comment)doc part
tedge cert
doctedge conect
docTypes of changes
Paste Link to the issue
#3242
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments