DB multi-session MFA Part 1: implement basic "tsh db exec"#53296
DB multi-session MFA Part 1: implement basic "tsh db exec"#53296
Conversation
5398325 to
a39bdbc
Compare
2481051 to
c7cbb50
Compare
0d40eed to
f4e7900
Compare
Tener
left a comment
There was a problem hiding this comment.
Really cool feature, I can see using it myself in the future 👍
I gave it some thought though and I think we should optimise for multi-database, scriptable experience. To me, that means a few features:
- Fault tolerance. It shouldn't be a fatal error if a subset of databases is unreachable.
- Machine readable output. As a user, I want predictable way of processing the script results further. More on that below.
- Some sort of summary once execution finishes. For each accessed database information about command executed, output files (if any), time, exit code etc.
- (Nice to have) Configurable timeouts for individual commands.
- (Nice to have) Configurable command to run.
- (Nice to have) A way to see which database names were provided, but couldn't be found; I guess a line in execution summary?
Two main modes for output, to me, are:
- Split output
- one file per executed command.
- based in output dir
- execution summary file, if requested, json format
- Combined output
- default to stdout, but may be redirected to file using flag. MFA prompts etc. would still use stdout!
- each line prefixed with the unique database name
- may use JSON/CSV(?)
- also optional summary
28087c8 to
1398bc7
Compare
1398bc7 to
64e6c76
Compare
r0mant
left a comment
There was a problem hiding this comment.
lgtm with a few comments
| case defaults.ProtocolMySQL: | ||
| return c.getMySQLExecCommand(query) | ||
| default: | ||
| return nil, trace.BadParameter("unsupported database protocol: %v", c.db) |
There was a problem hiding this comment.
Let's try to make errors less generic.
| return nil, trace.BadParameter("unsupported database protocol: %v", c.db) | |
| return nil, trace.NotImplemented("%q databases do not support exec commands yet", c.db) |
There was a problem hiding this comment.
it was pointed out earlier that tsh will catch NotImplemented error and print an error stating server needs to be updated:
teleport/tool/tsh/common/tsh.go
Lines 1697 to 1699 in 7648803
I've updated the error message but kept trace.BadParameter for now. we should improve the way tsh handles NotImplemented in the future.
| } | ||
| }() | ||
|
|
||
| return trace.Wrap(group.Wait()) |
There was a problem hiding this comment.
Is there any sort of timeout on the execution?
There was a problem hiding this comment.
no. the timeout will vary depending on the command to be executed. we can add a new flag in the future if a user asks for it. for now, user can always ctrl-c to kill it.
0325a54 to
1300f3d
Compare
…/51679_base_tsh_db_exec
* Implement basic "tsh db exec" * adding ut * minor refactor, fix race, rename iter func * add help * always use service name * overwrite max connections with env var * single get databases call * remove prefix output * fix some flags * iterutils * ensure each database * add summery * refactor, tests * revert auto rename change by editor * revert migrate * remove unused var * review comments * renaming --max-connections to --parallel * make exec return result instead of error * hint TELEPORT_PARALLEL_JOBS * fix golint * address PR comments
* DB multi-session MFA Part 1: implement basic "tsh db exec" (#53296) * Implement basic "tsh db exec" * adding ut * minor refactor, fix race, rename iter func * add help * always use service name * overwrite max connections with env var * single get databases call * remove prefix output * fix some flags * iterutils * ensure each database * add summery * refactor, tests * revert auto rename change by editor * revert migrate * remove unused var * review comments * renaming --max-connections to --parallel * make exec return result instead of error * hint TELEPORT_PARALLEL_JOBS * fix golint * address PR comments * DB multi-session MFA Part 2: MFA reuse for GenerateUserCerts (#54069) * enable multi-session mfa * add ut * add lib/client ut * fix ut and proofread * result.MFAResponse --> result.ReusableMFAResponse * use errors.Is * address comments * fix logger * fix test * remove new tests from master
related:
This PR implements basic
tsh db execwithout the MFA partUsage examples:
Simple: selection by names and sequential
Search by labels, and run in parallel
Search by keyword, and sample summary.json