Skip to content

Commit 80ff04e

Browse files
authored
[AAM-65858] Add ops-cli Teleport support (#174)
1 parent 96c64cb commit 80ff04e

15 files changed

Lines changed: 467 additions & 197 deletions

File tree

‎README.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,23 @@ If there are connection issues double check that the proxy is running.
538538
...
539539
```
540540
541+
#### Teleport
542+
Teleport (https://goteleport.com/) provides secretless SSH.
543+
`ops` has support for using Teleport as ssh for the following operations: `ssh, tunnel, proxy, ansible play, run and sync`
544+
545+
In order to use Teleport an extra section needs to be added to the cluster config file:
546+
***
547+
```
548+
inventory:
549+
- plugin: cns
550+
args:
551+
teleport_enabled: True -> add this to existing configuration
552+
553+
554+
teleport:
555+
enabled: true -> add this whole block
556+
```
557+
541558
### Play
542559
543560
Run an ansible playbook.
@@ -762,7 +779,7 @@ env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/
762779
763780
## Running tests
764781
765-
- on your machine: `py.test tests`
782+
- on your machine: `python -m pytest tests` or `build_scripts/run_tests.sh`
766783
767784
# Troubleshooting
768785

‎src/ops/cli/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
from subprocess import Popen, PIPE
1313
import sys
14+
from shutil import which
1415

1516

1617
def get_output(command, trim=True):
@@ -41,3 +42,8 @@ def get_config_value(config, key):
4142
err("You must set the %s value in %s.yaml or in the cli as an extra variable: -e %s=value" %
4243
(e.message, config['cluster'], e.message))
4344
sys.exit(1)
45+
46+
def check_if_teleport_binary_installed():
47+
if which("tsh") is None:
48+
err('tsh binary needs to be installed for Teleport to work!')
49+
sys.exit(2)

‎src/ops/cli/parser.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,7 @@ def configure_common_ansible_args(parser):
112112
parser.add_argument('--noscb', action='store_false', dest='use_scb',
113113
help='Disable use of Shell Control Box (SCB) even if '
114114
'it is enabled in the cluster config')
115+
parser.add_argument('--teleport', action='store_false', dest='use_teleport',
116+
help='Use Teleport for SSH')
115117

116118
return parser

‎src/ops/cli/playbook.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ def __init__(self, ops_config, root_dir, inventory_generator,
7373
def run(self, args, extra_args):
7474
logger.info("Found extra_args %s", extra_args)
7575
inventory_path, ssh_config_paths = self.inventory_generator.generate()
76-
ssh_config_path = SshConfigGenerator.get_ssh_config_path(self.cluster_config,
76+
ssh_config_generator = SshConfigGenerator(self.ops_config.package_dir)
77+
ssh_config_path = ssh_config_generator.get_ssh_config_path(self.cluster_config,
7778
ssh_config_paths,
78-
args.use_scb)
79+
args)
80+
7981
ssh_config = f"ANSIBLE_SSH_ARGS='-F {ssh_config_path}'"
8082

8183
ansible_config = "ANSIBLE_CONFIG=%s" % self.ops_config.ansible_config_path

‎src/ops/cli/run.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ def run(self, args, extra_args):
6868
logger.info("Found extra_args %s", extra_args)
6969
inventory_path, ssh_config_paths = self.inventory_generator.generate()
7070
limit = args.host_pattern
71-
ssh_config_path = SshConfigGenerator.get_ssh_config_path(self.cluster_config,
71+
ssh_config_generator = SshConfigGenerator(self.ops_config.package_dir)
72+
ssh_config_path = ssh_config_generator.get_ssh_config_path(self.cluster_config,
7273
ssh_config_paths,
73-
args.use_scb)
74+
args)
7475
extra_args = ' '.join(args.extra_args)
7576
command = """cd {root_dir}
7677
ANSIBLE_SSH_ARGS='-F {ssh_config}' ANSIBLE_CONFIG={ansible_config_path} ansible -i {inventory_path} '{limit}' \\

0 commit comments

Comments
 (0)