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

feat: Add read-only mode for terminal sessions #104

Merged

Conversation

ChetanXpro
Copy link
Contributor

@ChetanXpro ChetanXpro commented Dec 19, 2024

  • Add support for read-only viewer access via --enable-readers flag
  • Implement write permissions check for terminal operations
  • New users default to read-only mode if no write password is provided.
  • Add visual indicator for read-only mode in UI
  • Disable terminal editing and controls for read-only users

Fixes #72

Demo:
https://github.com/user-attachments/assets/95434d88-5895-4db2-ad2e-577bbb061616

- Add support for read-only viewer access via --enable-readers flag
- Implement write permissions check for terminal operations
- New users default to read-only when write password not provided
- Add visual indicator for read-only mode in UI
- Disable terminal editing and controls for read-only users
@ekzhang
Copy link
Owner

ekzhang commented Dec 24, 2024

Woohoo! The video you sent looks great. Let me check the code now, there's also a couple minor changes we could make to the interface.

Copy link
Owner

@ekzhang ekzhang 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 fantastic! Thanks for implementing this. I'm super excited to have this feature out. I think we could add tests + figure out how to unify the same Encrypt struct for the two kinds of passwords (auth key and write key) and we'd be set.

image

As for the display on the frontend, I like what you did with stopping the events from going off. The server error handling also looks robust. In this display though, I think we might want to make the "Read Only" badge smaller, maybe move it to the right of the status line. And in the NameList component, move the read-only users below the read-write users, and gray out their names with lower opacity? What do you think?

Something like this:

Having read-only users not be able to move terminals might be a point of contention, but I think it makes sense personally! This way you can share the link more widely with a group without having to worry about people potentially resizing or moving stuff. And in practice it's probably not too bad, since the editor will usually position the terminal how they would like.

Happy holidays! :)

Cargo.lock Outdated Show resolved Hide resolved
crates/sshx-core/proto/sshx.proto Outdated Show resolved Hide resolved
crates/sshx-core/proto/sshx.proto Outdated Show resolved Hide resolved
crates/sshx-server/Cargo.toml Outdated Show resolved Hide resolved
crates/sshx-server/src/grpc.rs Outdated Show resolved Hide resolved
crates/sshx-server/src/web/socket.rs Show resolved Hide resolved
crates/sshx-server/src/web/socket.rs Outdated Show resolved Hide resolved
@@ -113,7 +113,8 @@ impl ClientSocket {

async fn authenticate(&mut self) {
let encrypted_zeros = self.encrypt.zeros().into();
self.send(WsClient::Authenticate(encrypted_zeros)).await;
self.send(WsClient::Authenticate(encrypted_zeros, None))
Copy link
Owner

Choose a reason for hiding this comment

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

I do think we should write at least one test for this read/write functionality so we're sure that it's working according to spec and continues working as such, is that something you'd be able to take on?

crates/sshx/src/controller.rs Outdated Show resolved Hide resolved
crates/sshx/src/main.rs Outdated Show resolved Hide resolved
@ChetanXpro
Copy link
Contributor Author

Thanks for the feedback! I’ll add the tests and unify the Encrypt struct. I agree with your suggestions for the frontend changes, and I’ll make those adjustments

I’ll fix everything and update the PR. Happy holidays!

- Update read-only badge styles and poistion
- Use subtle instead of constant_time_eq dependency
- Add constant-time comparison for encrypted_zeros
- Improve write password entropy
- Optimize user scope updates to avoid double broadcast
- Sort cargo dependencies
- format cli display properly
@ChetanXpro
Copy link
Contributor Author

fixed most of the issues. tests and the Encrypt struct updates are remaining - working on those now.

now we are now creating the write password in the controller itself and only saving the write password encryption zeros in metadata and snapshot.

Copy link
Owner

@ekzhang ekzhang left a comment

Choose a reason for hiding this comment

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

Very good! Only a couple minor things and adding a test. Feel free to make the changes if you'd like, otherwise I'm happy to take the rest (will be just a few minutes and then the test).

Thanks so much for your help! Happy new year.

crates/sshx-server/src/web/socket.rs Outdated Show resolved Hide resolved
crates/sshx/src/controller.rs Outdated Show resolved Hide resolved
crates/sshx/src/main.rs Outdated Show resolved Hide resolved
crates/sshx/src/main.rs Outdated Show resolved Hide resolved
src/lib/Session.svelte Outdated Show resolved Hide resolved
src/lib/Session.svelte Outdated Show resolved Hide resolved
src/lib/srocket.ts Outdated Show resolved Hide resolved
@ChetanXpro
Copy link
Contributor Author

fixed most of the issues. Let me know if I missed something.
also, I added a test for read/write permissions. Should we cover more in the test, or is this enough?

@ekzhang
Copy link
Owner

ekzhang commented Dec 30, 2024

Test looks great 👍 — just what I was looking for!

@ekzhang ekzhang enabled auto-merge (squash) December 30, 2024 02:09
@ekzhang ekzhang merged commit 3220a1d into ekzhang:main Dec 30, 2024
5 checks passed
@lukehsiao
Copy link

Thank you for this! I'm super excited for this feature, I suspect this will push sshx to be the default for terminal sharing at $WORK.

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.

[Feature] Different user permissions
3 participants