-
Notifications
You must be signed in to change notification settings - Fork 2.1k
validate node hostnames when they are being created or updated #46892
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
Changes from all commits
48bb4f5
0ec015e
f94448d
28530e1
7889ce8
d5fb2fe
e9eb1f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ import ( | |
| "github.com/gravitational/teleport/lib/services/local" | ||
| "github.com/gravitational/teleport/lib/session" | ||
| "github.com/gravitational/teleport/lib/tlsca" | ||
| "github.com/gravitational/teleport/lib/utils" | ||
| ) | ||
|
|
||
| // ServerWithRoles is a wrapper around auth service | ||
|
|
@@ -976,6 +977,11 @@ func (a *ServerWithRoles) UpsertNode(ctx context.Context, s types.Server) (*type | |
| if err := a.action(s.GetNamespace(), types.KindNode, types.VerbCreate, types.VerbUpdate); err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
| if hostname := s.GetHostname(); hostname != "" { | ||
| if err := utils.ValidateNodeHostname(hostname); err != nil { | ||
| return nil, trace.Wrap(err) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I lean toward never hard rejecting any invalid hostnames, and always permitting access, but obfuscating the hostname. Imagine that Teleport is the only means by which an admin has access to the host to change the hostname and we've now prevented them from being able to modify the hostname by rejecting here. |
||
| } | ||
| } | ||
| return a.authServer.UpsertNode(ctx, s) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,6 +348,14 @@ func (s *PresenceService) UpsertNode(ctx context.Context, server types.Server) ( | |
| if n := server.GetNamespace(); n != apidefaults.Namespace { | ||
| return nil, trace.BadParameter("cannot place node in namespace %q, custom namespaces are deprecated", n) | ||
| } | ||
| if err := utils.ValidateNodeHostname(server.GetHostname()); err != nil { | ||
| s.log.Warnf( | ||
|
capnspacehook marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be misleading if this hostname violates the newly enforced length restriction. Perhaps the message here should be a bit more vague and include the error message instead? |
||
| `Node %q is configured with an invalid hostname. Future versions of Teleport will change the hostname of nodes with invalid hostnames. | ||
| Please update this hostname to a hostname only consisting of alphanumeric characters and the symbols '.' and '-'.`, | ||
| server.GetHostname(), | ||
| ) | ||
| } | ||
|
|
||
| rev := server.GetRevision() | ||
| value, err := services.MarshalServer(server) | ||
| if err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -61,6 +61,7 @@ import ( | |||||||
| aws_sync "github.com/gravitational/teleport/lib/srv/discovery/fetchers/aws-sync" | ||||||||
| "github.com/gravitational/teleport/lib/srv/discovery/fetchers/db" | ||||||||
| "github.com/gravitational/teleport/lib/srv/server" | ||||||||
| "github.com/gravitational/teleport/lib/utils" | ||||||||
| "github.com/gravitational/teleport/lib/utils/spreadwork" | ||||||||
| ) | ||||||||
|
|
||||||||
|
|
@@ -945,6 +946,15 @@ func (s *Server) heartbeatEICEInstance(instances *server.EC2Instances) { | |||||||
|
|
||||||||
| continue | ||||||||
| } | ||||||||
| // Only validate the hostname of new nodes to ensure existing nodes that existed | ||||||||
| // before hostname validation was checked are unaffected | ||||||||
| if len(existingNodes) == 0 { | ||||||||
| err := utils.ValidateNodeHostname(eiceNode.GetHostname()) | ||||||||
| if err != nil { | ||||||||
|
Comment on lines
+952
to
+953
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: reduce the error scope
Suggested change
|
||||||||
| s.Log.Warnf("Error validating the hostname %q of node with name %q: %v", eiceNode.GetHostname(), eiceNode.GetName(), err) | ||||||||
| continue | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| eiceNodeExpiration := s.clock.Now().Add(s.jitter(serverExpirationDuration)) | ||||||||
| eiceNode.SetExpiry(eiceNodeExpiration) | ||||||||
|
|
||||||||
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.
We should cap the number of invalid nodes added here to protect against consuming too much memory(what if all my nodes now have an invalid hostname 😨?) and to reduce overwhelming consumers of the notification. If the notification content is too large, we may be unable to persist the notification, and would also be hard for a user to digest. We probably want some happy medium since we also don't want one notification for each invalid hostname.