Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/web/join_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ func getJoinScript(ctx context.Context, settings scriptSettings, m nodeAPIGetter
}

var buf bytes.Buffer
var appServerResourceLabels []string
// If app install mode is requested but parameters are blank for some reason,
// we need to return an error.
if settings.appInstallMode {
Expand All @@ -640,6 +641,12 @@ func getJoinScript(ctx context.Context, settings scriptSettings, m nodeAPIGetter
if !appURIPattern.MatchString(settings.appURI) {
return "", trace.BadParameter("appURI %q contains invalid characters", settings.appURI)
}

suggestedLabels := token.GetSuggestedLabels()
appServerResourceLabels, err = scripts.MarshalLabelsYAML(suggestedLabels, 4)
if err != nil {
return "", trace.Wrap(err)
}
}

if settings.discoveryInstallMode {
Expand Down Expand Up @@ -689,6 +696,7 @@ func getJoinScript(ctx context.Context, settings scriptSettings, m nodeAPIGetter
"installUpdater": strconv.FormatBool(settings.installUpdater),
"version": shsprintf.EscapeDefaultContext(version),
"appInstallMode": strconv.FormatBool(settings.appInstallMode),
"appServerResourceLabels": appServerResourceLabels,
"appName": shsprintf.EscapeDefaultContext(settings.appName),
"appURI": shsprintf.EscapeDefaultContext(settings.appURI),
"joinMethod": shsprintf.EscapeDefaultContext(settings.joinMethod),
Expand Down
11 changes: 11 additions & 0 deletions lib/web/join_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,17 @@ func TestGetNodeJoinScript(t *testing.T) {
require.Contains(t, script, fmt.Sprintf("%s=%s", types.InternalResourceIDLabel, internalResourceID))
},
},
{
desc: "app server labels",
settings: scriptSettings{token: validToken, appInstallMode: true, appName: "app-name", appURI: "app-uri"},
errAssert: require.NoError,
extraAssertions: func(script string) {
require.Contains(t, script, `APP_NAME='app-name'`)
require.Contains(t, script, `APP_URI='app-uri'`)
require.Contains(t, script, `public_addr`)
require.Contains(t, script, fmt.Sprintf(" labels:\n %s: %s", types.InternalResourceIDLabel, internalResourceID))
},
},
} {
t.Run(test.desc, func(t *testing.T) {
script, err := getJoinScript(context.Background(), test.settings, m)
Expand Down
8 changes: 8 additions & 0 deletions lib/web/scripts/node-join/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ get_yaml_list() {
install_teleport_app_config() {
log "Writing Teleport app service config to ${TELEPORT_CONFIG_PATH}"
CA_PINS_CONFIG=$(get_yaml_list "ca_pin" "${CA_PIN_HASHES}" " ")
# This file is processed by `shellschek` as part of the lint step
# It detects an issue because of un-set variables - $index and $line. This check is called SC2154.
# However, that's not an issue, because those variables are replaced when we run go's text/template engine over it.
# When executing the script, those are no long variables but actual values.
# shellcheck disable=SC2154
cat << EOF > ${TELEPORT_CONFIG_PATH}
version: v3
teleport:
Expand All @@ -463,6 +468,9 @@ app_service:
- name: "${APP_NAME}"
uri: "${APP_URI}"
public_addr: ${APP_PUBLIC_ADDR}
labels:{{range $index, $line := .appServerResourceLabels}}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you need a conditional here to handle the case when labels is empty?

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.

we don't have to, this is valid labels: (no values), i also tested it without adding labels to double check

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.

Some day (🤞) I will convert this script to go (the same thing we did for Server Auto Discovery scripts), and it will be much simpler to do these things

{{$line -}}
{{end}}
EOF
}
# installs the provided teleport config (for database service)
Expand Down