Skip to content

Add logging#283

Merged
geonnave merged 1 commit intolake-rs:mainfrom
geonnave:add-logs
May 31, 2024
Merged

Add logging#283
geonnave merged 1 commit intolake-rs:mainfrom
geonnave:add-logs

Conversation

@geonnave
Copy link
Copy Markdown
Collaborator

Towards #280. Still couldn't get defmt-or-log to work, but was able to have it working with just log.

Using log adds about 1 KB of overhead when using the no_std example (cargo size --target='thumbv7em-none-eabihf' --no-default-features --features="crypto-cryptocell310, ead-authz, rtt" --release)

This branch:

   text    data     bss     dec     hex filename
  66928       8    1120   68056   109d8 lakers-no_std

main:

   text    data     bss     dec     hex filename
  65852       0    1112   66964   10594 lakers-no_std

@chrysn
Copy link
Copy Markdown
Member

chrysn commented May 28, 2024

Note that a user can still make this zero cost in the binary / at runtime by enabling the log/release_max_level_off feature, so I wouldn't worry about the cost here.

Do we need to defined policy around whether the security critical (hax compiled) parts may log? If critical parts don't log, that makes it easy on the safety/privacy aspects, because code outside that (even though being in the same crate) should probably not get access to secrets anyway. (We may want to vet debug impls for that though). If we log from critical code, is there a log level that is guaranteed not to contain key material? I'm unsure of the answer because while logged keys and secrets are useful during plug tests, they are a no-go in production systems. Not sure whether setting up cfg flags around it helps.

@geonnave
Copy link
Copy Markdown
Collaborator Author

make this zero cost by enabling the log/release_max_level_off feature

Thanks for the heads up, added a way to set it from the application.

As for the policy, yes that's important. As a first step, I was first looking into adding some sort of skip directive for the Debug derives in the state structs (e.g. to avoid logging secrets), but it turns out it is still not supported in Rust.

@geonnave
Copy link
Copy Markdown
Collaborator Author

We can start with very basic logs just to "know where it went wrong", and build on top of it. Pushed a commit in that direction. Results look like this:

$ RUST_LOG=debug cargo run --bin coapserver
     Running `target/debug/coapserver`
[2024-05-29T07:09:37Z INFO  coapserver] Starting EDHOC CoAP Server
Waiting for CoAP messages...
Received message from 127.0.0.1:33736
[2024-05-29T07:09:40Z INFO  lakers] Initializing EdhocInitiator
[2024-05-29T07:09:40Z INFO  lakers] Enter process_message_1
[2024-05-29T07:09:40Z DEBUG lakers_shared::edhoc_parser] Enter parse_message_1
[2024-05-29T07:09:40Z DEBUG lakers_shared::edhoc_parser] Enter parse_suites_i
[2024-05-29T07:09:40Z INFO  lakers] Enter prepare_message_2
Received message from 127.0.0.1:36994
Received message 3
Found state with connection identifier ConnId(3)
[2024-05-29T07:09:40Z INFO  lakers] Enter parse_message_3
[2024-05-29T07:09:40Z DEBUG lakers_shared::edhoc_parser] Enter decode_plaintext_3
[2024-05-29T07:09:40Z INFO  lakers] Enter credential_check_or_fetch
[2024-05-29T07:09:40Z INFO  lakers] Enter verify_message_3
EDHOC exchange successfully completed

@geonnave geonnave marked this pull request as ready for review May 29, 2024 07:15
@chrysn
Copy link
Copy Markdown
Member

chrysn commented May 29, 2024 via email

@geonnave geonnave force-pushed the add-logs branch 2 times, most recently from 7856d02 to 249ee96 Compare May 29, 2024 14:03
can be disabled in releases with a feature:
`log/release_max_level_off`
thus providing zero-cost for embedded deployments
@geonnave
Copy link
Copy Markdown
Collaborator Author

@chrysn I changed the level to trace!, and moved the log dependency to the application, so that the library doesn't need an extra flag for that.

@geonnave geonnave merged commit 67754f5 into lake-rs:main May 31, 2024
@geonnave geonnave deleted the add-logs branch May 31, 2024 12:16
@chrysn
Copy link
Copy Markdown
Member

chrysn commented May 31, 2024 via email

@geonnave geonnave mentioned this pull request Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants