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

Port pre-assignment #146

Closed
wants to merge 14 commits into from
Closed

Port pre-assignment #146

wants to merge 14 commits into from

Conversation

santomet
Copy link

If you use authentication keys, you can also pre-assign the port that a particular host can bind
with this option:

--use-ports-from-keys

It is slightly abusing the auth_keys specifications (sshd(8)) according to which you can specify
SSH options within the keys. Your line in pubkeys directory might look like this:

sishport="12345" ssh-rsa THE_PUBKEY_IS_HERE comment@HOSTNAME

Sish will allow the host to use only this particular port for TCP forwarding.
This might be useful for managing multiple computers to which 3rd party might have access.
If you do this for every machine, none of them can block the pre-designated port dedicated for the other
even if somebody tried to mangle the settings.

@santomet
Copy link
Author

This is linked to issue #144

@santomet
Copy link
Author

This time lint says
golangci-lint found no issues
Not sure where is the problem with CI

@antoniomika
Copy link
Owner

Hrm, it looks like something changed with GitHub actions. Let me look into that...

utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
@antoniomika
Copy link
Owner

I've went ahead and fixed the actions, just rebase your PR onto the latest master and you should be good to go!

@santomet
Copy link
Author

Ok, so I have reimplemented it completely. certHolder is now a map and I reworked CheckPort and GetRandomPortInRange so that it makes much more sense now. Also, I am using permitlisten now and also support multiple possible ports that can be allocated

@antoniomika
Copy link
Owner

Hey @santomet! Mind rebasing on top of master?

sshmuxer/tcphandler.go Outdated Show resolved Hide resolved
utils/utils.go Outdated
@@ -262,7 +292,7 @@ func WatchCerts() {
// loadCerts loads public keys from the keys directory into a slice that is used
// authenticating a user.
func loadCerts() {
tmpCertHolder := make([]ssh.PublicKey, 0)
tmpCertHolder := make(map[string][]string)
Copy link
Owner

Choose a reason for hiding this comment

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

This should still be publickey. We want to compare them byte by byte.

Copy link
Author

Choose a reason for hiding this comment

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

This still works as expected, the key in Extensions["pubKey"] is string anyway! Also, we need something comparable if we want a map

Copy link
Owner

Choose a reason for hiding this comment

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

You can still do a reference of the publickey string to a ssh.PublicKey object!

Copy link
Owner

Choose a reason for hiding this comment

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

I actually like the use of the struct retaining the public key and options. Then we can preload the options into a map[string]string to allow them for easy access (and therefore we can implement more of them easily!)

Copy link
Author

@santomet santomet Nov 19, 2020

Choose a reason for hiding this comment

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

Good, let's make options as map[string][]string because you can specify multiple permitlistens. We will do a poor man's multimap with this. We can also put comment into the structure for future use.
Ad ssh.PublicKey OK I can store that but not sure if there is any real reason

cmd/sish.go Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@santomet santomet requested a review from antoniomika November 20, 2020 14:08
utils/utils.go Show resolved Hide resolved
utils/utils.go Show resolved Hide resolved
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", bindPort))
if err != nil {
return GetRandomPortInRange(portRange)
if len(authPorts) == 1 {
return 0
Copy link
Owner

Choose a reason for hiding this comment

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

0 will be a random port anyway. We want to still get a random port in a range (i.e. 1024-2048)

Copy link
Author

Choose a reason for hiding this comment

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

No, my intention, in this case, is to block it. If all the ports in permitlisten are bind, you should not be able to create the tunnel

Copy link
Author

Choose a reason for hiding this comment

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

bump

Copy link
Owner

Choose a reason for hiding this comment

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

We need to update the method to return an error then. I think returning 0 would still allow the tunnel to bind, wouldn't it?

utils/utils.go Outdated Show resolved Hide resolved
utils/utils.go Show resolved Hide resolved
utils/utils.go Show resolved Hide resolved
utils/utils.go Outdated Show resolved Hide resolved
Base automatically changed from master to main February 13, 2021 19:37
@antoniomika
Copy link
Owner

Hi @santomet,

Closing this for now since there haven't been any updates. If you end up updating, feel free to reopen the PR!

@santomet
Copy link
Author

Hi,
Sorry to hear that, I would like to resolve that four conversations first. Can you please look at that?

@bibo38
Copy link
Contributor

bibo38 commented Dec 31, 2021

@antoniomika bump and I think, that @santomet cannot reopen the PR by himself

@antoniomika antoniomika reopened this Dec 31, 2021
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", bindPort))
if err != nil {
return GetRandomPortInRange(portRange)
if len(authPorts) == 1 {
return 0
Copy link
Owner

Choose a reason for hiding this comment

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

We need to update the method to return an error then. I think returning 0 would still allow the tunnel to bind, wouldn't it?

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.

3 participants