Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Set permissions on generated keys to be user-only on Unix systems #225

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

protochron
Copy link
Contributor

Set the permissions on generated keys to 0600 and the directory to
0700 on Unix systems. Windows permissions are a no-op due to having to
call the Windows APIs directly which is not very straightforward in
Rust.

Partial fix for #218.

@protochron
Copy link
Contributor Author

protochron commented Jan 6, 2022

I can leave this as is and add in Windows as a follow-up PR or leave this up until that work is finished. Let me know what you'd prefer!

brooksmtownsend
brooksmtownsend previously approved these changes Jan 6, 2022
Copy link
Member

@brooksmtownsend brooksmtownsend left a comment

Choose a reason for hiding this comment

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

~/.wash ➜ ll
Permissions Size User   Date Modified Name
drwxr-xr-x     - brooks 29 Nov  2021  contexts/
drwx------     - brooks  6 Jan 09:36  keys/
drwxr-xr-x     - brooks  6 Jan 09:29  prekeys/
.rw-r--r--   634 brooks  5 Jan 13:00  host_config.json

~/.wash ➜ ll prekeys
Permissions Size User   Date Modified Name
.rw-r--r--    58 brooks 29 Nov  2021  brooks_account.nk
.rw-r--r--    58 brooks 30 Nov  2021  clinicapi_module.nk
...

~/.wash ➜ ll
Permissions Size User   Date Modified Name
drwxr-xr-x     - brooks 29 Nov  2021  contexts/
drwx------     - brooks  6 Jan 09:36  keys/
drwxr-xr-x     - brooks  6 Jan 09:29  prekeys/
.rw-r--r--   634 brooks  5 Jan 13:00  host_config.json

~/.wash ➜ ll keys
Permissions Size User   Date Modified Name
.rw-------    58 brooks  6 Jan 09:36  brooks_account.nk
.rw-------    58 brooks  6 Jan 09:36  echo_module.nk

LGTM! Cool thing is that this will also retroactively fix the permissions of the keys directory too (not existing keys) so this will improve security regardless.

I don't have any reservation with accepting the partial fix and accepting Windows later, especially for something that's non-breaking

@brooksmtownsend
Copy link
Member

@protochron looks like you might just need a rebase since we merged another PR

thomastaylor312
thomastaylor312 previously approved these changes Jan 6, 2022
Copy link
Contributor

@thomastaylor312 thomastaylor312 left a comment

Choose a reason for hiding this comment

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

This is totally fine to merge now if you want to handle windows in a follow up. I couldn't figure out the windows stuff myself in another project, so if you know how, I'll probably end up copying it!

fs::create_dir_all(Path::new(&path).parent().unwrap())?;
let mut f = File::create(path)?;
let key_path = Path::new(&path).parent().unwrap();
fs::create_dir_all(key_path)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I feel like this might be a bit cleaner if we create an ensure_key_dir function that makes sure the directory exists with the correct permissions and a write_key function that takes the bytes and does everything to create the file with the right permissions. To be clear, this is only a nit though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, but I might tackle that in a follow-up PR, since I may end up reworking that function anyway

@protochron
Copy link
Contributor Author

@brooksmtownsend rebased! I think someone needs to approve running the other github actions.

brooksmtownsend
brooksmtownsend previously approved these changes Jan 7, 2022
Copy link
Member

@brooksmtownsend brooksmtownsend left a comment

Choose a reason for hiding this comment

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

Just approved the test re-run, still LGTM!

Set the permissions on generated keys to `0600` and the directory to
`0700` on Unix systems. Windows permissions are a no-op due to having to
call the Windows APIs directly which is not very straightforward in
Rust.

Partial fix for wasmCloud#218.

Signed-off-by: Dan Norris <protochron@users.noreply.github.com>
@thomastaylor312 thomastaylor312 merged commit 296e3b9 into wasmCloud:main Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants