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

Auto Discover Servers: recover from bad configuration #44282

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

marcoandredinis
Copy link
Contributor

The auto discover flow will run a command for all the target servers.
If the server joins teleport, then the instance is skipped.

When running the auto discover on the target instance, if teleport is already installed, the installation procedure exits.

It might happen that server cannot join the cluster because it was configured to join with an invalid token (non existent, wrong roles, ...).
Even if the user fixes the Matcher's installation params, the new configuration won't be applied, because, as said above, the procedure exits.
This PR changes the installation procedure use to auto-enroll servers. If the target configuration is different than the existing one, then teleport server is restarted.
If it stays the same, then it will no restart. This is to prevent unnecessary restarts of the service.

Demo after fixing the token
image

Context: #37620

changelog: Re-create teleport configuration when the node fails to join the cluster during Server Auto Discover.

lib/srv/server/installer/autodiscover.go Outdated Show resolved Hide resolved
lib/srv/server/installer/autodiscover.go Outdated Show resolved Hide resolved
lib/srv/server/installer/autodiscover.go Outdated Show resolved Hide resolved
lib/srv/server/installer/autodiscover.go Show resolved Hide resolved
return nil
}

func checksum(filename string) (string, error) {
f, err := utils.OpenFileAllowingUnsafeLinks(filename)
Copy link
Member

Choose a reason for hiding this comment

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

I see that tctl already has a similar function, but the usage of utils.OpenFileAllowingUnsafeLinks does raise my eyebrow. Would it be possible to use utils.OpenFileNoUnsafeLinks instead? If not, then I think it'd be a good idea to leave a comment explaining why following symlinks is warranted in this case. I don't have enough context on this code to assess this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it to use utils.OpenFileNoUnsafeLinks.
This happens for two files and those files are written by teleport node configure which creates the files and no symlinks.
Also, we expect no manual intervention in these files because teleport is meant to be installed automatically.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ravicious @marcoandredinis is it really necessary to block symlinks here? this breaks the tests on my macbook where /var is a symlink. How do we know /etc won't be a symlink and why should we care?

IIRC the reason to avoid reading files from symlinks is to avoid reading them as root and leaking info about files owned by other users to an unprivileged user who created a malicious symlink

    --- FAIL: TestAutoDiscoverNode/gcp_adds_a_label_with_the_project_id (0.01s)
        autodiscover_test.go:369:
                Error Trace:    /Users/nic/src/teleport/lib/srv/server/installer/autodiscover_test.go:369
                Error:          Received unexpected error:
                                opening file /var/folders/x_/33kp49n52rg8hs97k5m96rnw0000gn/T/TestAutoDiscoverNodegcp_adds_a_label_with_the_project_id462103172/001/etc/teleport.yaml, symlink not allowed in path: /var
                Test:           TestAutoDiscoverNode/gcp_adds_a_label_with_the_project_id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it back to utils.OpenFileAllowingUnsafeLinks
#46600

@marcoandredinis marcoandredinis force-pushed the marco/autodiscoverserver_recover_badconfig branch 2 times, most recently from 3b02d29 to 5a041ab Compare July 17, 2024 19:01
lib/srv/server/installer/autodiscover.go Outdated Show resolved Hide resolved
@marcoandredinis marcoandredinis force-pushed the marco/autodiscoverserver_recover_badconfig branch from 5a041ab to f3be074 Compare July 19, 2024 07:23
@marcoandredinis marcoandredinis added this pull request to the merge queue Jul 19, 2024
Merged via the queue into master with commit cbf2a9d Jul 19, 2024
37 checks passed
@marcoandredinis marcoandredinis deleted the marco/autodiscoverserver_recover_badconfig branch July 19, 2024 08:05
@public-teleport-github-review-bot

@marcoandredinis See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Create PR

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.

4 participants