Skip to content

Add agentless installer in the teleport discovery service#19648

Merged
lxea merged 12 commits intomasterfrom
lxea/agentless-discovery
Jan 24, 2023
Merged

Add agentless installer in the teleport discovery service#19648
lxea merged 12 commits intomasterfrom
lxea/agentless-discovery

Conversation

@lxea
Copy link
Copy Markdown
Contributor

@lxea lxea commented Dec 23, 2022

This is partially work in progress as it requires support for agentless inventory management in order to have ssh nodes show in the teleport ui/tsh ls output

Agentless discovery allows the discovery service to update the OpenSSH config in EC2 instances in order to add the teleport CA and enable certificate based authentication.

The following is executed on discovered nodes

  sudo /usr/bin/teleport join \
	  --openssh-config=/etc/ssh/sshd_config \
	  --join-method=iam \
	  --token="$1" \
	  --proxy-server="{{ .PublicProxyAddr }}" \
	  --additional-principals="$PUBLIC_IP" \
	  --restart-sshd

This will update the openssh config with the following configuration options

### Section created by 'teleport  join'
TrustedUserCaKeys /etc/ssh/teleport_user_ca.pub
HostKey /etc/ssh/teleport
HostCertificate /etc/ssh/teleport-cert.pub
### Section end

It will also write the certs and keys.

Agentless discovery can be enabled with the following config

discovery_service:
  enabled: yes
  aws:
    - types: ["ec2"]
      regions: ["eu-central-1"]
      install:
        install_teleport: false # enables agentless installation

@github-actions github-actions Bot requested review from greedy52 and zmb3 December 23, 2022 16:56
fi

IMDS_TOKEN=$(curl -m5 -sS -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 300")
PUBLIC_IP=$(curl -m5 -sS -H "X-aws-ec2-metadata-token: ${IMDS_TOKEN}" http://169.254.169.254/latest/meta-data/public-ipv4)
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.

what happens when the instance has no public IP?

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.

I'm not sure, I'm also not sure what the most appropriate behavior here is in the first place, should it also include a private ip in the principals maybe?

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.

Updated this to also include the local-ipv4

Comment thread api/types/installers/agentless-installer.sh.tmpl Outdated
Comment thread api/types/installers/agentless-installer.sh.tmpl Outdated
Comment thread lib/auth/auth.go Outdated
Comment thread lib/config/fileconf.go Outdated
Comment thread tool/teleport/common/teleport.go Outdated
Comment thread tool/teleport/common/teleport.go Outdated
Comment thread tool/teleport/common/teleport.go Outdated
Comment thread api/types/installers/agentless-installer.sh.tmpl Outdated
Comment thread tool/teleport/common/teleport.go
Comment thread tool/teleport/common/teleport.go Outdated
@lxea lxea force-pushed the lxea/agentless-discovery branch 2 times, most recently from 761b891 to cf7cb15 Compare December 30, 2022 15:00
@jakule jakule self-requested a review January 10, 2023 02:43
Comment thread api/types/installers/agentless-installer.sh.tmpl Outdated
Comment thread api/types/installers/agentless-installer.sh.tmpl
Comment thread api/types/installers/agentless-installer.sh.tmpl Outdated
Comment thread api/types/installers/agentless-installer.sh.tmpl Outdated
Comment thread lib/auth/auth.go Outdated
Comment thread lib/config/fileconf.go Outdated
Comment thread tool/teleport/common/teleport.go Outdated
Comment thread tool/teleport/common/teleport.go
Comment thread tool/teleport/common/teleport.go
Comment thread tool/teleport/common/teleport.go
@lxea lxea force-pushed the lxea/agentless-discovery branch 5 times, most recently from b0f361b to 1196114 Compare January 11, 2023 14:04
Comment thread tool/teleport/common/teleport.go Outdated
Comment thread tool/teleport/common/teleport.go Outdated
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.

interesting. first time seeing authclient. we have so many different ways connecting.

@lxea lxea force-pushed the lxea/agentless-discovery branch from 80089cd to cbcc506 Compare January 16, 2023 12:12
Comment thread tool/teleport/common/teleport.go Outdated
Comment thread tool/teleport/common/teleport.go Outdated
Comment thread tool/teleport/common/teleport.go Outdated
Comment thread tool/teleport/common/teleport.go Outdated
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.

If this write fails for any reason, we will leave the teleportKey on the disk. The same apply to teleportUserCA (then teleportCert and teleportKey will be left). Should we remove it on the write error?

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.

I'm not sure which would be preferred, I'm inclined to leave them there, maybe a log message that there may be files left behind if writekeys has an error could be good?

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.

@r0mant Any thoughts? I think that if the installation fails, we should leave the machine in the same state as if the installation would never happen. Otherwise, we may encounter weird errors on the second attempt.

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.

I agree, we should clean stuff up.

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.

But the code should tolerate files potentially being already present there just in case we failed to clean them up or something.

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.

tolerate files potentially being already

I think this is more complicated in practice. First of all, we already recommend installing our certificates in /etc/ssh for proxy recording https://goteleport.com/docs/server-access/guides/recording-proxy-mode/
If we decide to "ignore already existing files", we may override some existing files not created by Teleport. TBH now when I think about it, I don't see why we would keep our certificates or any other files outside of /etc/teleport. I think that the only file that we need to modify outside of that directory is sshd config.
This is what I would do:

  1. Create /etc/teleport if doesn't exist
  2. Create /etc/teleport/agentless directory if doesn't exist. If the directory already exists, remove it (that should cover "failed previous installations" case).
  3. Write all certs and keys inside /etc/teleport/agentless.
  4. Create a backup of the sshd config (/etc/ssh/sshd_config.teleport maybe?).
  5. Update the original sshd config and test it.
  6. Restart sshd daemon.

In case of any failures, we would need to just remove /etc/teleport/agentless. This directory should also be added to our RPM/DEB packages to be removed on "uninstall" comments. In case of sshd failures, we should still be able to revert all changes as we will have the backed-up config.

That being said, this process (current and described here) will fail if a machine has SELinux enabled as Teleport process even running as a root won't have access to modify sshd config. I don't think that SELinux support should be included in the first implementation anyways. I just want to mention that we should be prepared to see errors related to it.

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.

1. Create `/etc/teleport` if doesn't exist

2. Create `/etc/teleport/agentless` directory if doesn't exist. If the directory already exists, remove it (that should cover "failed previous installations" case).

3. Write all certs and keys inside `/etc/teleport/agentless`.

4. Create a backup of the sshd config (`/etc/ssh/sshd_config.teleport` maybe?).

5. Update the original sshd config and test it.

6. Restart sshd daemon.

Updated to do the above

In case of any failures, we would need to just remove /etc/teleport/agentless. This directory should also be added to our RPM/DEB packages to be removed on "uninstall" comments. In case of sshd failures, we should still be able to revert all changes as we will have the backed-up config.

Where do I need to update the RPM/DEB packages for this? Is it in teleport.git?

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.

No idea. We're using https://fpm.readthedocs.io/en/v1.15.0/ so this is probably a good place to start.
TBH I'd just create a TODO comment and address that later. I don't think we have any custom script already added to DEB/RPM and adding the first one can be a pain (we could introduce some potential side effects).

@tcsc Correct me on the custom RPM/DEB scripts if I'm wrong.

Comment thread tool/teleport/common/teleport.go Outdated
@lxea lxea force-pushed the lxea/agentless-discovery branch 3 times, most recently from b88d0c4 to af8524c Compare January 18, 2023 12:01
Copy link
Copy Markdown
Contributor

@jakule jakule left a comment

Choose a reason for hiding this comment

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

I know this is not the last part, so I'm fine approving it, but can we add more tests to this functionality later?

Comment thread tool/teleport/common/teleport.go Outdated
@lxea lxea force-pushed the lxea/agentless-discovery branch 5 times, most recently from ffb4473 to 014027d Compare January 24, 2023 12:25
@lxea lxea force-pushed the lxea/agentless-discovery branch from 4f8305c to affd278 Compare January 24, 2023 13:56
@lxea lxea merged commit 6698555 into master Jan 24, 2023
@lxea lxea deleted the lxea/agentless-discovery branch January 24, 2023 15:08
lxea pushed a commit that referenced this pull request Jan 24, 2023
#20607)

* Add agentless installer

* Resolve comments

* Resolve comments

* Use GetCertAuthorities locally

* Try to get IMDS hostname

* Try get imds hostname first

This seems to be how its implemented for non-agentless nodes

* Use FIPS cipher suites

* use the openssh ca, resolve comments

* write keys to /etc/teleport/agentless by default

* Resolve comment

* lints

* test fixes

* Fix cipher suites selection with teleport openssh join
rosstimothy added a commit that referenced this pull request Jan 24, 2023
Reverts the addition of github.com/hashicorp/go-uuid from #19648
and adds a depguard rule to ensure that github.com/google/uuid is
encorced moving forward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants