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
[WIP] Support for "permitlisten=..." option for -R style forwarding #65
Conversation
b460d44
to
946597c
Compare
| debug("allow remote port forwarding to host %s port %d", host, port); | ||
|
|
||
| permitted_listens = xreallocarray(permitted_listens, | ||
| num_permitted_listens + 1, sizeof(*permitted_listens)); |
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.
This indentation does not match OpenBSD style guide:
Indentation is an 8 character tab. Second level indents are four spaces. All code should fit in 80 columns.
Not only here, but also in other places.
|
Can you specify multiple instances of permitlisten? IOW, could I say restrict,command="echo 'Port forwarding only account.'",permitlisten="localhost:8080",permitlisten="localhost:8081" ssh-rsa AAAAB3Nza... and allow remote connectinos from both 8080 and 8081? I'm also wondering if this is a useful framework for specifying what local forwards are allowed. Say you had an authorized_keys file containing restrict,command="echo 'Port forwarding only account.'",permitforward="10.1.2.3:80" ssh-rsa AAAAB3Nza... which allowed ssh -o ExitOnForwardFailure=yes -L 8080:10.1.2.3:80 root@localhost -p 2222 -N but not a different host like ssh -o ExitOnForwardFailure=yes -L 8080:192.168.2.3:80 root@localhost -p 2222 -N or or a different port like ssh -o ExitOnForwardFailure=yes -L 8080:10.1.2.3:8080 root@localhost -p 2222 -N Potentially useful but not required would be the ability to wildcard (or omit) the port, or use CIDR notation for the host/net... Just thinking out loud here. |
|
Oh.. NM. I dug into the code and I see permitopen does just that. Yay! |
|
Yup, you got that right, it works just like permitopen. |
|
Hello, sorry if this is the wrong place. I've been trying this feature for hours and I think there may be an issue with it. When using (restrict,permitlisten="host:port") in the authorized_keys, it fails with (debug1: Remote: Server has disabled port forwarding.) If you use 'port-forwarding' and 'permitlisten', it works - and you can try the "wrong" port and it fails as expected. So I know the feature works, but when used with 'restrict' it seems to only work if you also use 'port-forwarding' as well. This is on CentOS 8 (OpenSSH_8.0p1, OpenSSL 1.1.1c FIPS 28 May 2019). Can anyone point me in the right direction? |
|
Do you have |
|
@Jakuje yes (its on by default and mine is not defined off), but I tried with using 127.0.0.1 vs localhost and that does not work as well. I actually couldn't get '127.0.0.1' working at all. What I'd like to work: How I got it working: Sanity check, change the allowed port: Here is something else, when the port is wrong and it fails (expected) I see this: However, when you remove 'port-fowarding' from the authorized_keys, you see this: So what that is saying to me is that 'permitlisten' is not overriding the 'restrict' option, as suggested here that it should. |
In both OpenSSH 8.0 and CentOS 8 it defaults to https://github.com/openssh/openssh-portable/blob/V_8_0/sshd_config.5#L1595 If you believe there is a bug in the permitlisten implementation (or documentation), open a bug in https://bugzilla.mindrot.org/ |
|
@Jakuje thank you for the reply, I'll try a few more things and I will probably submit a bug. And yes I was looking at a different (online) version of the man pages that said the default was on - system man pages clearly state the default is off as you suggested so thank you for clarifying. |
|
Just following up - I found the behavior is exactly the same for 'permitopen', so now I believe it has nothing to do with this feature but rather just how the restrictions work in general. I did file a bug because I believe this causes a gap in the restriction methods. Thanks again for the replies. |
|
Now this is really going off topic, but if you are not happy with how openssh restrictions behave, it is incredibly easy to write your own SSH daemon on top of something like the gliderlabs/ssh library. I ended up doing that for my company and it works beautifully on a mega large scale. It allows much tighter control than openssh does in config -- which is only natural if you're using code instead of config. I'm sure the openssh-library would allow similar things. |
* Fixed duplicate symbol tun_fwd_ifnames * Revert formatting changes done by IDE
I am aware that this is not the right place for patches, but it's makes it easier to review while it's WIP.
Adds support for
permitlisten=...for -R style forwarding:authorized_keys file:
This is allowed:
This is not: