Skip to content

[v10] NodeJoin script: fix when no labels are provided#15755

Merged
marcoandredinis merged 1 commit into
branch/v10from
bot/backport-15709-branch/v10
Sep 1, 2022
Merged

[v10] NodeJoin script: fix when no labels are provided#15755
marcoandredinis merged 1 commit into
branch/v10from
bot/backport-15709-branch/v10

Conversation

@marcoandredinis
Copy link
Copy Markdown
Contributor

Backport #15709 to branch/v10

@marcoandredinis marcoandredinis enabled auto-merge (squash) August 23, 2022 08:34
@marcoandredinis marcoandredinis added the discover Issues related to Teleport Discover label Aug 24, 2022
@marcoandredinis marcoandredinis force-pushed the bot/backport-15709-branch/v10 branch 6 times, most recently from 4956ef7 to 12c3d48 Compare August 30, 2022 10:53
@marcoandredinis marcoandredinis requested review from r0mant and removed request for r0mant August 31, 2022 21:44
@marcoandredinis marcoandredinis force-pushed the bot/backport-15709-branch/v10 branch from 12c3d48 to bb43244 Compare August 31, 2022 21:45
@marcoandredinis marcoandredinis force-pushed the bot/backport-15709-branch/v10 branch from bb43244 to 13eaeda Compare August 31, 2022 22:00
Recently we added a way to add labels on newly added nodes based on the
token.
Each token now has a list of SuggestedLabels, which are used to feed
that list.

However, if that list is empty, the generated script would trigger the
following error:
`teleport: error: unexpected`

This happens when running the `teleport node configure ...` command.

This happens because the command is generating an empty argument `""`
when running the `teleport node configure ...` command.
So it looks like this:
```bash
${TELEPORT_BINARY_DIR}/teleport node configure \
      --token token \
      joinmethod \
      --ca-pin pin \
      --auth-server host:port \
      "" \
      --output someport
```
That empty argument breaks things.

So, in order to fix it, we are going to change the default value when no
labels are provided.
Instead of an empty string, we'll use an empty array.

Demo (teleport node configure message removed for brev
No label
```bash
$ LABELS_FLAG=(); f=$(mktemp -d)/node.yaml; teleport node configure --auth-server w:1 "${LABELS_FLAG[@]}" --output $f && yq .s
sh_service.labels $f

enabled: "yes"
commands:
  - name: hostname
    command: [hostname]
    period: 1m0s

```

Single label
```bash
$ LABELS_FLAG=(--labels x=y); f=$(mktemp -d)/node.yaml; teleport node configure --auth-server w:1 "${LABELS_FLAG[@]}" --output $f && yq .ssh_service $f

enabled: "yes"
labels:
  x: "y"
commands:
  - name: hostname
    command: [hostname]
    period: 1m0s

```

Multiple labels
```bash
$ LABELS_FLAG=(--labels x=y,dev=prod); f=$(mktemp -d)/node.yaml; teleport node configure --auth-server w:1 "${LABELS_FLAG[@]}" --output $f && yq .ssh_service $f

enabled: "yes"
labels:
  dev: prod
  x: "y"
commands:
  - name: hostname
    command: [hostname]
    period: 1m0s
```
@marcoandredinis marcoandredinis force-pushed the bot/backport-15709-branch/v10 branch from 13eaeda to e6d6ab6 Compare September 1, 2022 07:14
@marcoandredinis marcoandredinis merged commit 4c1f307 into branch/v10 Sep 1, 2022
@github-actions github-actions Bot deleted the bot/backport-15709-branch/v10 branch September 1, 2022 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport discover Issues related to Teleport Discover

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants