update tsh db resource selection#28505
Conversation
There was a problem hiding this comment.
First quick pass looks reasonable. I have left some comment and I will take a second look on Monday.
Additionally I think that other cli should be also updated like tctl that allows to operate on db object by name and the Discovery Name fix will also impact Teleport web UI and Teleport Connect.
I would love to test this change with backend alignment to check backward compatibility.
smallinsky
left a comment
There was a problem hiding this comment.
The PR LGTM but I wonder about your thoughts about an alternative approach that will be less "aggressive" in terms of tsh,tctl web UI integrations.
Namely, right now we are changing the database.Name value and setting it to the full resource name and introducing the DiscoveredNameLabel that contains Short Database Name (User Readable db name prefix) that needs to be aligned on client sides.
but by switching this logic we can leave the database.Name unchanged and add a new filed like databse.FullName that will be used as the backend key for db resource objects and needs to be aligned on client sides.
So even if for old tsh clients like 13.0.0 without this alignment the legacy flow will be unchanged.
I worry that changing the backend key like this will create problems and make rollbacks difficult. Here's why:
Consider instead the scenario where we don't change the backend key, and just add a label like I'm doing in this implementation:
|
| | `exists(labels["env"])` | resources with a label key `env`; label value unchecked | | ||
| | `!exists(labels["env"])` | resources without a label key `env`; label value unchecked | | ||
| | `search("foo", "bar", "some phrase")` | fuzzy match against common resource fields | | ||
| | `hasPrefix(name, "foo")` | resources with a name that starts with the prefix `foo` | |
There was a problem hiding this comment.
What kind of backwards compatibility consequences does adding this new function have?
There was a problem hiding this comment.
if the tsh version is newer than auth/proxy version, then tsh will get a predicate error when it tries to use it. For that reason, I have logic in tsh that detects this scenario and falls back to just filtering resources client side without using hasPrefix predicate to make the API list resources request.
9934e02 to
88c5196
Compare
* add --labels and --query to tsh db subcommands
* tsh db [login | logout | env | config | connect]
* tsh proxy db
* add hasPrefix to predicate lang
* add teleport.dev/discovered-name
* print "discovered name" of databases discovered by discovery service,
which is the name of the database resource in the cloud, when using
tsh db ls without --verbose flag. This avoids printing verbose
uniquely identifying names when discovery service is updated to append
a uniquely identify suffix to discovered databases in AWS/Azure/GCP.
* tsh db ls --verbose ignores the label
* fix db connect string in tsh db ls
* select database by prefix, labels, and/or query predicate.
* chooses active database by exact match if the "prefix" matches exactly
and no labels/predicate is given.
* logout of a subset of databases with tsh db logout.
* print an "ambiguous match" error if prefix/labels/query matches
multiple databases where one is required.
* move all --labels cli flags to cf.Labels from cf.UserHost
* update tsh db tests
* speedup slow tsh db tests
* postgres/mysql profile respect home dir
* rename test cases for consistency
* test database listing uses discovered-name
* test login/env/config/logout with prefix/label/predicate selectors
* test active db filtering logic
88c5196 to
0abf7a0
Compare
|
@GavinFrazar See the table below for backport results.
|
Backport #28505 to branch/v13
|
Let me know if this was brought up during the review, but I think this PR introduced a regression. I have two databases, postgres and postgres2, and I can no longer interact with postgres by just doing stuff like |
This PR implements the
tsh dbandtsh proxy dbUX for RFD 129:resource selection
Specifically, the following commands have been changed to support
--labelsand--query(predicate lang query) flags when selecting a database, and additionally selects a database by name prefix:tsh db lstsh db ls(without --verbose flag) will now look for a labelteleport.internal/discovered-nameand print that instead of the full database name.This label will be added by the discovery service (with future changes to discovery service); its value will be the name of the database in AWS/GCP/Azure.
If
tsh db ls --verboseis used, then the listings will ignore that label and just print whatever the database name is. This is to avoid printing verbose database names generated by the discovery service.predicate lang
The
hasPrefixpredicate has been added to resource predicate parsing, e.g.--query 'hasPrefix(name, "foo")'queries for resources that have "foo" as a prefix of their name.tsh db <subcommand>will query for databases by prefix, unless an active (already logged in) cert is selected. For backwards compatibility,tshwill detect predicate parser errors and fallback to matching database names by prefix on client side instead of usinghasPrefix.backporting
This PR will be backported to v13 to avoid poor UX when users have an older
tshthan the discovery service when new discovery service version starts appending a uniquely identifying suffix to discovered resources.TODO in subsequent PRs:
tsh kubeandtsh appto support the sameteleport.internal/discovered-namecontaining the originally discovered resource name.Example session:
Related issue:
Changelog:
tsh dbcommands can choose a database using a prefix of the database's name instead of requiring the full database name. Additionally,--labelsand--query(predicate lang) can be used to narrow down the intended database selection when multiple databases match a given prefix name. Lastly, if the given "prefix" matches any database name fully, then that database is selected over any other databases that have a name starting with the prefix, e.g.tsh db login foo-dbwill choose databasefoo-dband ignore databasefoo-db-2.