Skip to content

Commit

Permalink
Restore MajorVersion template var for Installers (#24388) (#24434)
Browse files Browse the repository at this point in the history
* Restore MajorVersion template var for Installers

* Set Version for Installers template
  • Loading branch information
marcoandredinis committed Apr 12, 2023
1 parent c1c9e8f commit f1fa741
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/types/installers/installers.go
Expand Up @@ -49,6 +49,8 @@ var DefaultAgentlessInstaller = types.MustNewInstallerV1(InstallerScriptNameAgen
type Template struct {
// PublicProxyAddr is public address of the proxy
PublicProxyAddr string
// MajorVersion is the major version of the Teleport auth node
MajorVersion string
// TeleportPackage is the teleport package to use. `teleport` or
// `teleport-ent` depending on if the cluster is enterprise or not.
TeleportPackage string
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/server-access/guides/azure-discovery.mdx
Expand Up @@ -294,6 +294,8 @@ The `installer` resource has the following templating options:
installing from the repository.
- `{{ .PublicProxyAddr }}`: the public address of the Teleport Proxy Service to
connect to.
- `{{ .RepoChannel }}`: Optional package repository (apt/yum) channel name.
Has format `<channel>/<version>` e.g. stable/v12. See [installation](https://goteleport.com/docs/installation/#linux) for more details.

These can be used as follows:

Expand All @@ -305,6 +307,7 @@ spec:
script: |
echo {{ .PublicProxyAddr }}
echo Teleport-{{ .MajorVersion }}
echo Repository Channel: {{ .RepoChannel }}
version: v1
```

Expand All @@ -314,6 +317,7 @@ with the following contents:
```sh
echo teleport.example.com
echo Teleport-(=teleport.version=)
echo Repository Channel: stable/v(=teleport.version=)
```

The default installer will take the following actions:
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/server-access/guides/ec2-discovery.mdx
Expand Up @@ -340,6 +340,8 @@ The `installer` resource has the following templating options:
installing from the repository.
- `{{ .PublicProxyAddr }}`: the public address of the Teleport Proxy Service to
connect to.
- `{{ .RepoChannel }}`: Optional package repository (apt/yum) channel name.
Has format `<channel>/<version>` e.g. stable/v12. See [installation](https://goteleport.com/docs/installation/#linux) for more details.

These can be used as follows:

Expand All @@ -351,6 +353,7 @@ spec:
script: |
echo {{ .PublicProxyAddr }}
echo Teleport-{{ .MajorVersion }}
echo Repository Channel: {{ .RepoChannel }}
version: v1
```

Expand All @@ -360,6 +363,7 @@ with the following contents:
```sh
echo teleport.example.com
echo Teleport-(=teleport.version=)
echo Repository Channel: stable/v(=teleport.version=)
```

The default installer will take the following actions:
Expand Down
1 change: 1 addition & 0 deletions lib/web/apiserver.go
Expand Up @@ -1567,6 +1567,7 @@ func (h *Handler) installer(w http.ResponseWriter, r *http.Request, p httprouter

tmpl := installers.Template{
PublicProxyAddr: h.cfg.PublicProxyAddr,
MajorVersion: version,
TeleportPackage: teleportPackage,
RepoChannel: repoChannel,
}
Expand Down
26 changes: 26 additions & 0 deletions lib/web/apiserver_test.go
Expand Up @@ -2355,6 +2355,32 @@ func TestPingAutomaticUpgrades(t *testing.T) {

// TestInstallerRepoChannel ensures the returned installer script has the proper repo channel
func TestInstallerRepoChannel(t *testing.T) {
t.Run("documented variables are injected", func(t *testing.T) {
s := newWebSuiteWithConfig(t, webSuiteConfig{
authPreferenceSpec: &types.AuthPreferenceSpecV2{
Type: constants.Local,
SecondFactor: constants.SecondFactorOn,
Webauthn: &types.Webauthn{RPID: "localhost"},
},
})
wc := s.client(t)
// Variables documented here: https://goteleport.com/docs/server-access/guides/ec2-discovery/#step-67-optional-customize-the-default-installer-script
err := s.server.Auth().SetInstaller(s.ctx, types.MustNewInstallerV1("custom", `#!/usr/bin/env bash
echo {{ .PublicProxyAddr }}
echo Teleport-{{ .MajorVersion }}
echo Repository Channel: {{ .RepoChannel }}
`))
require.NoError(t, err)

re, err := wc.Get(s.ctx, wc.Endpoint("webapi", "scripts", "installer", "custom"), url.Values{})
require.NoError(t, err)

responseString := string(re.Bytes())

// Variables must be injected
require.Contains(t, responseString, "echo Teleport-v")
require.Contains(t, responseString, "echo Repository Channel: stable/v")
})
t.Run("cloud with automatic upgrades", func(t *testing.T) {
modules.SetTestModules(t, &modules.TestModules{TestFeatures: modules.Features{
Cloud: true,
Expand Down

0 comments on commit f1fa741

Please sign in to comment.