Skip to content

Sanitize SSH server hostnames#48988

Merged
r0mant merged 3 commits intomasterfrom
tross/host_re_name
Nov 15, 2024
Merged

Sanitize SSH server hostnames#48988
r0mant merged 3 commits intomasterfrom
tross/host_re_name

Conversation

@rosstimothy
Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy commented Nov 14, 2024

Prevents any invalid and malicious hostnames, but replacing them with known valid data already associated with the host. This was chosen instead of rejecting to persist the server resource in an attempt to continue providing access to the host in order to remedy the invalid hostname.

Any servers that represent a Teleport ssh_service with an invalid hostname will be replaced by the host UUID. Any static OpenSSH servers will have invalid hostnames replaced with the address. This will continue to allow the hosts to be dialable. In order to make these hosts discoverable, the invalid hostname will be set in the "teleport.internal/invalid-hostname" label.

Updates https://github.com/gravitational/teleport-private/issues/1676.

Changelog: Enforce stricter requirements for SSH hostnames. Hostnames will only be allowed if they are less than 257 characters and consist of only alphanumeric characters and the symbols '.' and '-'. Any hostname that violates the new restrictions will be changed, the original hostname will be move to the teleport.internal/invalid-hostname label for discoverability. Any Teleport agents with an invalid hostname will be replaced with the host UUID. Any Agentless OpenSSH Servers with an invalid hostname will be replaced with the host of the address, if it is valid, or a randomly generated identifier. Any hosts with invalid hostnames should be updated to comply with the new requirements to avoid Teleport renaming them.

@rosstimothy rosstimothy force-pushed the tross/host_re_name branch 3 times, most recently from 5ca1e51 to cce5716 Compare November 14, 2024 19:21
@rosstimothy rosstimothy force-pushed the tross/host_re_name branch 2 times, most recently from 2779014 to ef388bd Compare November 14, 2024 19:46
Prevents any invalid and malicious hostnames, but replacing them with
known valid data already associated with the host. This was chosen
instead of rejecting to persist the server resource in an attempt to
continue providing access to the host in order to remedy the invalid
hostname.

Any servers that represent a Teleport ssh_service with an invalid
hostname will be replaced by the host UUID. Any static OpenSSH servers
will have invalid hostnames replaced with the address. This will continue
to allow the hosts to be dialable. In order to make these hosts
discoverable, the invalid hostname will be set in the
"teleport.internal/invalid-hostname" label.

Updates gravitational/teleport-private#1676.
Comment thread lib/auth/auth.go
return trace.Wrap(err)
}

host = id.String()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we prefix these hostnames with something to better identify them as invalid? Do we want these hosts to appear at the top of the list in the UI so that they are more discoverable?

@rosstimothy rosstimothy marked this pull request as ready for review November 14, 2024 20:07
Comment thread lib/auth/auth.go Outdated
return false, nil
}

if _, err := a.Services.UpsertNode(a.closeCtx, srv); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will resurrect a manually deleted openssh node if it happens at the wrong time; seeing as this is intended to only happen once per host, couldn't we use a conditional update?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to use the new PresenceInternal.UpdateNode in f6c9997.

@r0mant r0mant mentioned this pull request Nov 15, 2024
5 tasks
@rosstimothy rosstimothy added this pull request to the merge queue Nov 15, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 15, 2024
@rosstimothy rosstimothy added this pull request to the merge queue Nov 15, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 15, 2024
@r0mant r0mant added this pull request to the merge queue Nov 15, 2024
Merged via the queue into master with commit 3c3b0b9 Nov 15, 2024
@r0mant r0mant deleted the tross/host_re_name branch November 15, 2024 19:23
@public-teleport-github-review-bot
Copy link
Copy Markdown

@rosstimothy See the table below for backport results.

Branch Result
branch/v17 Create PR

@webvictim
Copy link
Copy Markdown
Contributor

For anyone reading this in future, this also affects hostnames overridden using the teleport.nodename syntax in the Teleport config file:

teleport:
  nodename: invalid_hostname

Users upgrading to v17 who previously had hostnames that did not match the approved pattern will now see the machine's actual hostname, rather than the now-invalid one set in the config file. This can be validated using tctl get nodes/<uuid> to see the presence of the teleport.internal/invalid-hostname label which was added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants