Files
teleport/lib/web/scripts/node-join
Vitor EnesandEdoardo Spadolini 6a1d1aedc3 Emit new AgentMetadataEvent (#22068)
* Emit new `AgentMetadataEvent`

Part of https://github.com/gravitational/cloud/issues/3550.

This commits adds a new `UpstreamInventoryAgentMetadata` that is sent
from a Teleport agent to an auth server.
Once received, it is transformed into an `AgentMetadataEvent` and sent
to PreHog.

Most `UpstreamInventoryAgentMetadata` fields are intentionally kept as
empty in this PR. Follow up PRs will be opened with the mechanisms
required to fill them (as described in #21337).

* server_id -> host_id

* compute OS and host architecture

* Compute OS version and container runtime

* Close stream if agent receives an agent metadata message

* cmd -> exec ; file -> read

* implement fetchOSVersion for linux

* Remove unused import

* Add note about `agentMetadataCh`

* Allow commands with args

* Remove parseFun abstraction

* fetch glibc version

* fetch container orchestrator

* Fix lint

* Fix TODO

* Add note about glibc version

* cmd -> command

* fetch cloud environment

* fetch install methods

* GLibCVersion -> GlibcVersion

* Use `http.NewRequestWithContext`

* Add missing comment

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* GLibCVersion -> GlibcVersion

* Fix lint

* Fix helm unit tests

* Add missing comments

* 5 second timeout on http requests

* Spawn gorountine that fetches metadata on each new stream

* Use `defaults.HTTPClient()`

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Add missing import

* Handle error

* Revert "Spawn gorountine that fetches metadata on each new stream"

This reverts commit fe4f2790be.

* Send agent metadata to auth server once per stream

* Improve note about agentMetadataDone

* Don't process command output & file content on the agent

Since agents cannot be trusted, regex validation and sanitization should
happen in PreHog anyways. So this commit removes such logic in favor of
moving it to PreHog.

* Fix lint

* Trim space

* Move handling of `AgentMetadataEvent` to `handleControlStream`

* Use cached hello message

* Move metadata files to lib/inventory/metadata

* make sending of agent metadata more self contained

* Minimize diff

* Send all system roles to PreHog

* Remove unused import

* Add parsing of command output / file content back

* Usage reporter refactor

* Usage reporter refactor

* Add missing handling of inventory agent metadata msg

* Fix ICS usage reporter

* Improve comments

* Add cached `metadata.Get*` methods

* Use systemctl status instead of is-active

* Add `Metadata` struct

* return pointer in `FetchMetadata`

* Pass context to `GetMetadata`

* metadataFetchConfig -> fetchConfig

* GetMetadata -> Get

* Add note about `Get` result

* Ensure install methods are non-nil

* Exit `metadata.Get` if context is closed

* Replace sync.Once with atomic.Bool.Swap

* Initialize channel

* Fix lint

* Fix lint

* Make `metadata.Get` return an error instead of bool

* Allow multiple true/false values for env vars

* Use `strings.Cut`

* Use /etc/os-release ID instead of NAME

* Improve `autoEmitMetadata`

* Use `gnu_get_libc_version`

* Ubuntu -> ubuntu

* Use GOARCH

* gofmt

* Move import C up

* Variables may include quotes

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Default values for ID and VERSION_ID

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Blank lines are permitted

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* Anonymize host id

---------

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2023-03-10 12:45:29 +00:00
..

Automated node join script for Teleport

This is an automated node join script for Teleport, which does the following:

  • checks for an existing Teleport process, data directory, config file or Teleport binaries (and provides details how to clean up if any of these are present)
  • tests connectivity to the given Teleport server host and port
    • using either nc, telnet or /dev/tcp if available - if none of these are available this step is skipped
  • detects OS, distribution, architecture and appropriate Teleport package format, then downloads this package to a temporary directory and installs it
    • tar for tarball extraction if needed
    • dpkg for .deb installs
    • dnf, yum or rpm for .rpm installs
  • generates a Teleport config to set up a node and writes it to disk
  • installs and starts Teleport
    • via systemd on Linux
    • via launchctl on MacOS
  • cleans up downloaded archives afterwards

Things it doesn't do (yet):

  • validate the checksum of the downloaded Teleport artifact against the published checksum

Supported operating systems, architectures and distributions

  • Linux

    • Architectures
      • i386
      • x86_64
      • armv7l
      • aarch64 (no Teleport binaries available yet)
    • Any Debian-based distribution
      • Debian 8+
      • Ubuntu 18.04+
        • uses .deb package
    • Any CentOS-based distribution
      • CentOS 6+*
      • RHEL 6+*
        • CentOS 6 and RHEL 6 will use the special centos6 tarball package to handle the lower glibc version.
      • Fedora 27+
      • Amazon Linux 2+
        • uses .rpm package
    • Any other distribution
      • uses .tar.gz tarball package
  • MacOS

    • Architectures
      • x86_64
      • aarch64 (no Teleport binaries available yet)
    • MacOS 10.12+
      • uses .tar.gz tarball package

Arguments

Required arguments:

Flag Description Example value Required
-v Teleport version 4.3.5 yes
-h Hostname for the Teleport Proxy Service teleport.example.com yes
-j A valid node join token ool7ahpo4thohmeuS1gieY7laiwae7oo yes
-c The CA pin hash of the cluster being joined sha256:6abdd3a143a230fd31c9706d668bba3ee25a6e0eec54fcd69680c1ec0530fe9c yes
-p Port connect to on the Teleport Proxy Service 3080 no

If any of these arguments is not provided via CLI flags, they will be requested interactively at runtime.

Optional extra flags:

Flag Description Example value Required
-q Enable quiet mode n/a no
-l Write logs to file /var/log/teleport-node-installer.log no

Example usage

$ bash ./install.sh \
    -j ool7ahpo4thohmeuS1gieY7laiwae7oo \
    -c sha256:6abdd3a143a230fd31c9706d668bba3ee25a6e0eec54fcd69680c1ec0530fe9c \
    -h teleport.example.com \
    -p 3080 \
    -v 4.3.5