Skip to content

Commit ff74b90

Browse files
committed
Use install.sh in discovery's default installer
1 parent 8f25fb6 commit ff74b90

File tree

4 files changed

+92
-8
lines changed

4 files changed

+92
-8
lines changed

lib/auth/grpcserver.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4526,7 +4526,15 @@ func (g *GRPCServer) GetInstaller(ctx context.Context, req *types.ResourceReques
45264526
if trace.IsNotFound(err) {
45274527
switch req.Name {
45284528
case installers.InstallerScriptName:
4529-
return installer.DefaultInstaller, nil
4529+
_, err = auth.authServer.GetAutoUpdateAgentRollout(ctx)
4530+
switch {
4531+
case trace.IsNotFound(err):
4532+
return installer.LegacyDefaultInstaller, nil
4533+
case err != nil:
4534+
return nil, trace.Wrap(err, "failed to get query autoupdate state to build installer")
4535+
default:
4536+
return installer.NewDefaultInstaller, nil
4537+
}
45304538
case installers.InstallerScriptNameAgentless:
45314539
return installers.DefaultAgentlessInstaller, nil
45324540
}
@@ -4551,8 +4559,20 @@ func (g *GRPCServer) GetInstallers(ctx context.Context, _ *emptypb.Empty) (*type
45514559
return nil, trace.Wrap(err)
45524560
}
45534561
var installersV1 []*types.InstallerV1
4562+
4563+
var defaultInstaller *types.InstallerV1
4564+
_, err = auth.authServer.GetAutoUpdateAgentRollout(ctx)
4565+
switch {
4566+
case trace.IsNotFound(err):
4567+
defaultInstaller = installer.LegacyDefaultInstaller
4568+
case err != nil:
4569+
return nil, trace.Wrap(err, "failed to get query autoupdate state to build installer")
4570+
default:
4571+
defaultInstaller = installer.NewDefaultInstaller
4572+
}
4573+
45544574
defaultInstallers := map[string]*types.InstallerV1{
4555-
types.DefaultInstallerScriptName: installer.DefaultInstaller,
4575+
types.DefaultInstallerScriptName: defaultInstaller,
45564576
installers.InstallerScriptNameAgentless: installers.DefaultAgentlessInstaller,
45574577
}
45584578

lib/auth/grpcserver_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ import (
4747
otlpresourcev1 "go.opentelemetry.io/proto/otlp/resource/v1"
4848
otlptracev1 "go.opentelemetry.io/proto/otlp/trace/v1"
4949
"google.golang.org/protobuf/testing/protocmp"
50+
"google.golang.org/protobuf/types/known/durationpb"
5051
"google.golang.org/protobuf/types/known/emptypb"
5152

5253
"github.com/gravitational/teleport"
5354
"github.com/gravitational/teleport/api/client/proto"
5455
"github.com/gravitational/teleport/api/constants"
5556
apidefaults "github.com/gravitational/teleport/api/defaults"
57+
autoupdatev1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1"
5658
clusterconfigpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/clusterconfig/v1"
5759
mfav1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/mfa/v1"
5860
"github.com/gravitational/teleport/api/internalutils/stream"
@@ -61,6 +63,7 @@ import (
6163
"github.com/gravitational/teleport/api/observability/tracing"
6264
"github.com/gravitational/teleport/api/trail"
6365
"github.com/gravitational/teleport/api/types"
66+
"github.com/gravitational/teleport/api/types/autoupdate"
6467
"github.com/gravitational/teleport/api/types/installers"
6568
"github.com/gravitational/teleport/api/utils"
6669
"github.com/gravitational/teleport/api/utils/keys"
@@ -4611,12 +4614,21 @@ func TestGRPCServer_GetInstallers(t *testing.T) {
46114614
tests := []struct {
46124615
name string
46134616
inputInstallers map[string]string
4617+
hasAgentRollout bool
46144618
expectedInstallers map[string]string
46154619
}{
46164620
{
46174621
name: "default installers only",
46184622
expectedInstallers: map[string]string{
4619-
types.DefaultInstallerScriptName: installer.DefaultInstaller.GetScript(),
4623+
types.DefaultInstallerScriptName: installer.LegacyDefaultInstaller.GetScript(),
4624+
installers.InstallerScriptNameAgentless: installers.DefaultAgentlessInstaller.GetScript(),
4625+
},
4626+
},
4627+
{
4628+
name: "new default installers",
4629+
hasAgentRollout: true,
4630+
expectedInstallers: map[string]string{
4631+
types.DefaultInstallerScriptName: installer.NewDefaultInstaller.GetScript(),
46204632
installers.InstallerScriptNameAgentless: installers.DefaultAgentlessInstaller.GetScript(),
46214633
},
46224634
},
@@ -4627,7 +4639,7 @@ func TestGRPCServer_GetInstallers(t *testing.T) {
46274639
},
46284640
expectedInstallers: map[string]string{
46294641
"my-custom-installer": "echo test",
4630-
types.DefaultInstallerScriptName: installer.DefaultInstaller.GetScript(),
4642+
types.DefaultInstallerScriptName: installer.LegacyDefaultInstaller.GetScript(),
46314643
installers.InstallerScriptNameAgentless: installers.DefaultAgentlessInstaller.GetScript(),
46324644
},
46334645
},
@@ -4649,6 +4661,25 @@ func TestGRPCServer_GetInstallers(t *testing.T) {
46494661
require.NoError(t, err)
46504662
})
46514663

4664+
if tc.hasAgentRollout {
4665+
rollout, err := autoupdate.NewAutoUpdateAgentRollout(
4666+
&autoupdatev1pb.AutoUpdateAgentRolloutSpec{
4667+
StartVersion: "1.2.3",
4668+
TargetVersion: "1.2.4",
4669+
Schedule: autoupdate.AgentsScheduleImmediate,
4670+
AutoupdateMode: autoupdate.AgentsUpdateModeEnabled,
4671+
Strategy: autoupdate.AgentsStrategyTimeBased,
4672+
MaintenanceWindowDuration: durationpb.New(1 * time.Hour),
4673+
})
4674+
require.NoError(t, err)
4675+
_, err = grpc.AuthServer.CreateAutoUpdateAgentRollout(ctx, rollout)
4676+
require.NoError(t, err)
4677+
4678+
t.Cleanup(func() {
4679+
assert.NoError(t, grpc.AuthServer.DeleteAutoUpdateAgentRollout(ctx))
4680+
})
4681+
}
4682+
46524683
for name, script := range tc.inputInstallers {
46534684
installer, err := types.NewInstallerV1(name, script)
46544685
require.NoError(t, err)

lib/srv/server/installer/autodiscover.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ func (ani *AutoDiscoverNodeInstaller) Install(ctx context.Context) error {
226226
ani.Logger.InfoContext(ctx, "Detected cloud provider", "cloud", imdsClient.GetType())
227227

228228
// Check if teleport is already installed and install it, if it's absent.
229+
// In the new autoupdate install flow, teleport-update should have already
230+
// taken care of installing teleport.
229231
if _, err := os.Stat(ani.binariesLocation.Teleport); err != nil {
230232
ani.Logger.InfoContext(ctx, "Installing teleport")
231233
if err := ani.installTeleportFromRepo(ctx); err != nil {

lib/srv/server/installer/defaultinstallers.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,50 @@ import (
2626
"github.com/gravitational/teleport/lib/web/scripts/oneoff"
2727
)
2828

29-
// DefaultInstaller represents the default installer script provided by teleport.
30-
var DefaultInstaller = oneoffScriptToDefaultInstaller()
29+
// Depending on your cluster setup we have 2 installers:
30+
// - LegacyDefaultInstaller which uses oneoff.sh to download teleport and run "teleport install".
31+
// Teleport install does package-based installations.
32+
// -
3133

32-
func oneoffScriptToDefaultInstaller() *types.InstallerV1 {
33-
argsList := []string{
34+
// LegacyDefaultInstaller represents the default installer script provided by teleport.
35+
var (
36+
// LegacyDefaultInstaller uses oneoff.sh to download the Teleport tarball and run `teleport install`.
37+
// The Teleport install command handles both Teleport installation and agent configuration.
38+
LegacyDefaultInstaller = oneoffScriptToDefaultInstaller()
39+
40+
// NewDefaultInstaller installs Teleport by calling the standard "/scripts/install.sh" route on the proxy.
41+
// After successfully installing Teleport, it will invoke the same `teleport install`
42+
// command as the LegacyDefaultInstaller which will only take care of configuring Teleport.
43+
NewDefaultInstaller = types.MustNewInstallerV1(installers.InstallerScriptName, execGenericInstallScript+configureTeleport)
44+
45+
execGenericInstallScript = `#!/bin/bash
46+
set -euo pipefail
47+
48+
INSTALL_SCRIPT_URL="https://{{.PublicProxyAddr}}/scripts/install.sh"
49+
50+
echo "Offloading the installation part to the generic Teleport install script hosted at: $INSTALL_SCRIPT_URL"
51+
52+
curl "$INSTALL_SCRIPT_URL" | sudo bash
53+
`
54+
configureTeleport = `#!/bin/bash
55+
set -euo pipefail
56+
57+
echo "Configuring the Teleport agent"
58+
59+
set +x
60+
sudo teleport ` + strings.Join(argsList, " ")
61+
62+
argsList = []string{
3463
"install", "autodiscover-node",
3564
"--public-proxy-addr={{.PublicProxyAddr}}",
3665
"--teleport-package={{.TeleportPackage}}",
3766
"--repo-channel={{.RepoChannel}}",
3867
"--auto-upgrade={{.AutomaticUpgrades}}",
3968
"--azure-client-id={{.AzureClientID}}",
4069
}
70+
)
4171

72+
func oneoffScriptToDefaultInstaller() *types.InstallerV1 {
4273
script, err := oneoff.BuildScript(oneoff.OneOffScriptParams{
4374
EntrypointArgs: strings.Join(argsList, " "),
4475
SuccessMessage: "Teleport is installed and running.",

0 commit comments

Comments
 (0)