Commit Graph
134 Commits
Author SHA1 Message Date
Justinas Stankevičius c056efe974 Hosted plugins: add plugin management UI prerequisites (#22831)
* Add GetType() to Plugin

* Add Plugins feature flag to web

* Run prettier

* Update e_imports.go with slack plugin subpackage

Respective enterprise changes imports a new subpackage,
which pulls new dependencies.
2023-03-14 12:44:22 +00:00
Isaiah Becker-Mayer e2df4a31ba Fix incorrect login options for Windows Desktops (#22118)
* Removes desktop logins from the ACL and adds them to each Desktop resource
as returned to the frontend. This behavior parallels what's currently being
done with other similar resources such as Nodes, and fixes a bug where
users were able to see all the logins permitted by their roles on every
desktop "connect" dropdown, even if the role permitting that login didn't
apply to a given desktop.

* Extracts common logic out of GetWindowsDesktopLogins (now GetAllowedWindowsDesktopLogins), uses it to create a GetAllowedServerLogins as well, tests both of them together, removing EnumerateServerLogins

* reduce unnecessary looping by using maps

* fixes flakiness by sorting lists

* uses require.ElementsMatch rather than manually sorting lists

* consolidates duplicated logic

* Consolidates separate server and desktop logic into a single GetAllowedLoginsForResource

* fixes tests

* fixes import order and test
2023-02-24 21:06:38 +00:00
Tiago Silva 1bbaf23d86 Add Pod resource search web API (#20183)
This PR introduces a web API for users to search, from the UI, for Kubernetes pods whose access is only granted by their `search_as_roles`.
The new API can be used to create access requests for those resources.

The new API is located
```bash
curl 'https://<proxy_endpoint>:3080/v1/webapi/sites/<teleport_cluster>/pods?kubeCluster=<kube_cluster>&kubeNamespace=<kube_namespace|empty>&searchAsRoles=yes&limit=10&startKey=&query=&search=&sort=name:asc' \
   | jq .
```
The JSON response:

```json
{
  "items": [
    {
      "kind": "pod",
      "name": "coredns-6d4b75cb6d-k84h9",
      "labels": [
        {
          "name": "k8s-app",
          "value": "kube-dns"
        },
        {
          "name": "pod-template-hash",
          "value": "6d4b75cb6d"
        }
      ],
      "namespace": "kube-system",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "etcd-minikube",
      "labels": [
        {
          "name": "component",
          "value": "etcd"
        },
        {
          "name": "tier",
          "value": "control-plane"
        }
      ],
      "namespace": "kube-system",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "kube-apiserver-minikube",
      "labels": [
        {
          "name": "component",
          "value": "kube-apiserver"
        },
        {
          "name": "tier",
          "value": "control-plane"
        }
      ],
      "namespace": "kube-system",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "kube-controller-manager-minikube",
      "labels": [
        {
          "name": "component",
          "value": "kube-controller-manager"
        },
        {
          "name": "tier",
          "value": "control-plane"
        }
      ],
      "namespace": "kube-system",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "kube-proxy-g7j5r",
      "labels": [
        {
          "name": "controller-revision-hash",
          "value": "94985b49"
        },
        {
          "name": "k8s-app",
          "value": "kube-proxy"
        },
        {
          "name": "pod-template-generation",
          "value": "1"
        }
      ],
      "namespace": "kube-system",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "kube-scheduler-minikube",
      "labels": [
        {
          "name": "component",
          "value": "kube-scheduler"
        },
        {
          "name": "tier",
          "value": "control-plane"
        }
      ],
      "namespace": "kube-system",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "nginx-deployment-6595874d85-6j2zm",
      "labels": [
        {
          "name": "app",
          "value": "nginx"
        },
        {
          "name": "pod-template-hash",
          "value": "6595874d85"
        }
      ],
      "namespace": "default",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "nginx-deployment-6595874d85-7xgmb",
      "labels": [
        {
          "name": "app",
          "value": "nginx"
        },
        {
          "name": "pod-template-hash",
          "value": "6595874d85"
        }
      ],
      "namespace": "default",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "nginx-deployment-6595874d85-c4kz8",
      "labels": [
        {
          "name": "app",
          "value": "nginx"
        },
        {
          "name": "pod-template-hash",
          "value": "6595874d85"
        }
      ],
      "namespace": "default",
      "cluster": "minikube"
    },
    {
      "kind": "pod",
      "name": "storage-provisioner",
      "labels": [
        {
          "name": "addonmanager.kubernetes.io/mode",
          "value": "Reconcile"
        },
        {
          "name": "integration-test",
          "value": "storage-provisioner"
        }
      ],
      "namespace": "kube-system",
      "cluster": "minikube"
    }
  ],
  "startKey": "teleport-agent-0",
  "totalCount": 11
}
```

Part of #20324 and #19573
Updates #19573
2023-02-09 21:29:58 +00:00
Edward Dowling 9d97ae63fd Add hidden label prefix (#19725) 2023-01-18 17:38:15 +00:00
Lisa Kim f488007ce1 [Discover] Database related tweaks (#19824)
* Return db users and names with fetch databases
* Include checking for AWS RDS Resource ID as valid RDS type
2023-01-05 19:16:45 +00:00
Tiago Silva 40861809a6 Add RoleV6 resource type (#19324)
This PR includes a new Role resource version that is compatible with V5 spec.

The new resource introduces the `kubernetes_resources` definition that allows operators to limit the Kubernetes resources that each member can access. The `kubernetes_resources` entries must follow the following format: `{"kind":"<kind>", "namespace":"<namespace>","name":"<pod>"}`. Currently, it only supports objects of `kind` `pod`. Valid examples `<namespace>/<name>:
- `*/*`: matches all pods in all namespaces.
- `default/*`: matches all pods in the `default` namespace.
- `*/nginx-*`: matches every pod prefixed with `nginx-` in every namespace.

For older resource versions - V5, V4, V3 - `kubernetes_resources` is automatically populated with `{"kind":"pod","namespace":"*","name":"*"}` to keep compatibility. For the newest version, it's mandatory to define its value otherwise access to pods will be denied.

Part of #18434
2023-01-05 09:58:12 +00:00
Marco André Dinis 69dc237fe2 DatabaseService resource: client and server CRUD (#19469)
* DatabaseService resource: client and server CRUD

In the context of Teleport Discover, we must be able to known if there's
any DatabaseService available to proxy a given Database resource.
If there's none available, we will offer a script for the user to run
and install a DatabaseService which proxies the desired Database
resource.

By DatabaseService, we mean the process that Teleport binary manages
when the `teleport.yaml` config has the following section:
```yaml
db_service:
  enabled: "yes"
```

To accomplish this we are creating a new resource: DatabaseService.
The UI will fetch all DatabaseServices and check if there's any
ResourceMatcher that matches the DatabaseLabels.

A previous PR created the DatabaseService resource.

This PR creates all the necessary CRUD operations:
- Add Service to manage DatabaseServices resources in the backend.
- Add GetAll, Upsert, Delete and DeleteAll operations to Client.
- Add DatabaseService support to ListResources.
- Add WebAPI endpoint to list DatabaseServices using ListResources.

The next PR will add the heartbeat mechanism to the DatabaseService
process.
2022-12-21 14:34:36 +01:00
Lisa Kim f8e81e67b0 Remove use of legacy reset password token prefix (#19285)
* Sneak in grammar fix
2022-12-12 23:51:16 +00:00
Matheus 6afd0dbd59 Add license and download verbs to user context ACL and default editor role (#19049) 2022-12-08 18:05:49 +00:00
Lisa Kim 296255f868 [Discover] Add ons for database flow (#19063)
* Add db access rule required for db discovery
  in editors role

For the webapi layer:
* Return db access with user context
* Add AWS RDS fields for creating db request
* Return hostname of each queried db server
2022-12-06 19:20:11 +00:00
MariuszandJim Bishopp f0dbc346e2 hide internal labels from UI (#18638)
* hide labels from UI

* add test cases for hidding teleport.internal/ labels

* move labels logic to separate file

* move constant to right api/types/constants.go

* add godoc to makeLabels and rework label constants

Co-authored-by: Jim Bishopp <jim@goteleport.com>
2022-12-06 09:01:38 +01:00
Zac Bergquist da7680ad0b Use x/exp/slices instead of home grown utilities (#18524)
We were inconsistent throughout the codebase and would sometimes
use the slices package and other times use our own equivalents
in api/.

This removes our versions in favor of the golang.org/x package that
does the same, which has the added benefit of reducing the surface
area of the public API module.

Note: despite existing uses of the slices package, for some reason
it didn't show up in go.mod or go.sum. Fixed that too.
2022-11-17 15:25:46 +00:00
Marco André Dinis 692d2661f4 WebAPI: Get database endpoint (#18041)
* WebAPI: Get database endpoint

This commit creates a new endpoint to return a single databse by its
name.

```
GET /webapi/sites/:site/databases/:database

{
  "name": "<database_name>",
  "desc": "<description>",
  "protocol": "<protocol>",
  "type": "<type>",
  "labels": [
    {"name": "<name>", "value": "<value>"},
    ...
  ],
  "database_users": ["<db_user1>", ...],
  "database_names": ["<db_name1>", ...],
}
```

The `database_users` and `database_names` will list the available
Database User and Names for the current user, based on its roles.
2022-11-10 16:25:09 +00:00
Marco André Dinis 80f4f61032 Create and Update database http endpoints (#17783)
This commit adds two new endpoints:
Create a database with

```
POST .../databases
{
  "name": "<databasename>",
  "protocol": "<protocol>",
  "uri": "<uri>",
  "labels": [{"name":"<name>", "value": "<value>"}...]
}
```

Update a database's `ca_cert` (the only updatable field for now)
```
PUT .../databases/:database
{
  "ca_cert": "------BEGIN CERTIFICATE-----\n <certificate> --END..."
}
```
2022-11-08 11:37:01 +00:00
Lisa Kim ef92182ef4 [reopen] Handle private key policy errors for the web UI (#17928)
- When user registers or resets, when running into
policy errors, we don't send back an error, but instead
a 200 (to indicate user has successfully registered/resetted)
and a flag to determine if policy was enabled
- Send back policy configurations for cluster config,
this will allow the web UI login page to just display
redirection messages without login attempts
- For role configured policy, login attempts will be
required and a specific error will be returned so that
the UI can then better redirect the user
2022-10-31 23:18:54 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Tiago Silva de5228f784 Return allowed kube_users and kube_groups that can be used to access a certain kube_cluster and allow custom request impersonation (#17420)
This PR returns a list of allowed principals that a user is authorized to impersonate for each Kubernetes cluster.

When a Teleport user has multiple Kubernetes users defined for the same Cluster we must allow him to choose one otherwise the request will return an error. Similar to `kubectl get pods --as {user} --as-group {kubeGroup}`.
If the user selects invalid users or groups, it will return invalid Kubernetes principals.

Closes #17382
2022-10-21 09:51:54 +01:00
Ryan Clark 9f9461d5f0 Add labels to Windows Desktop Service, add endpoint for searching them (#16436) 2022-09-23 22:08:04 +00:00
Marco André Dinis c219962ccc ConnectionDiagnostics: SSH Tester (#15413)
This PR implements the SSH Tester for ConnectionDiagnostic feature.
This feature is also known as Test Connection, part of Teleport
Discover.

The goal here is to provide immediante feedback about a newly added
resource. Can the user connect to it?

We are targetting SSH Nodes as a first ResourceKind.

To test the access to an SSH Node we require the ResourceName and a
login username (ssh principal).

Then a series of checks will occur in two places:
- SSH client in the Web server
- SSH server in the SSH agent

The ssh client creates a new Connection Diagnostic with some initial
state.
Then it tries to build up the necessary SSH config
This already gives us a couple of things to check for:
- does the node exist and does the current user (inherited from
  websession) can access it?
- is the node accepting TCP connections (in the specific port)?
- is the node accepting SSH protocol on top of the TCP connection?

Then, the ConnectionDiagnosticID is inject into the certificate and the
SSH Server receives it and will also Append traces into it:
- is the requested principal allowed for the current user?
- does the requested principal exist in the target node?

This is not an exhaustive list of checks.
For a complete list of which checks are verified please see the
TestDiagnoseSSHConnection test.

After all those checks, it returns if the Connection was successful and
what all of the traces generated along the way.


Demo:
![image](https://user-images.githubusercontent.com/689271/187976940-55522fd9-f581-4c6d-9bfc-f6e501c1ed72.png)

![image](https://user-images.githubusercontent.com/689271/187976957-35075112-2b42-4726-8d50-19d02fab2464.png)

![image](https://user-images.githubusercontent.com/689271/187976967-81406e2c-0517-474b-b323-dad1f8be1571.png)
2022-09-02 08:17:21 +00:00
Yassine Bounekhla 6d475e12b2 Add Access Request ID to response for UserContext (#15653) 2022-08-30 20:59:29 +00:00
Isaiah Becker-Mayer 6273856514 Remove directory_sharing build flag (#15789) 2022-08-25 15:15:45 +00:00
Lisa Kim f53f3e77d6 [Discover] Check if user has access to any registered resource (#15637)
* Add connection diagnostic access to UI user context
* Implement resource checker in the web api layer
* Remove setting NeedTotalCount flag for web api list resources
2022-08-24 16:33:03 +00:00
Marco André Dinis 37b80c03b1 Connection Diagnostic: update, traces and ConnectionTester (#15158)
This PR adds the concept of ConnectionTester

ConnectionTester will generate ConnectionDiagnostics by connecting to
the actual resource using a user and some Resource Specific parameters
(principal for SSH access, Database User and Name for Database access,
and so on) and storing the result of multiple checkpoints.

Each resource will have a ConnectionTester (we'll start by SSH access
and then Databases).

It also improves Connection Diagnostics by adding
- update operation (similar to the create one)
- a list of traces, which contain the result of checkpoints in multiple
  steps of the connection flow

As an example, for SSH, we'll have at least the following checks:
- Node is reachable
- User has the right permissions
- Node has the expected Principal

The trigger to test a connection will be an endpoint, because our
primary goal is to let the user test the access right after adding the
resource.

This PR does not implement the actual SSHConnectionTester but creates
most of the boilerplate to do so.

The next PR will focus in adding the actual traces.
2022-08-16 11:03:06 +01:00
Tiago Silva 037daad083 Introduce dedicated server type for Kubernetes resources (#14389)
## What

First part of the Kubernetes [Discovery RFD](https://github.com/gravitational/teleport/pull/13376/) to introduce a Kubernetes server per cluster. 

This PR introduces a separate Kubernetes server that uses the already introduced `KubernetesClusterV3`. 

## Compatibility

In previous versions, Kubernetes Clusters were part of regular `ServerV2` resource and this refactoring deprecates the `ServerV2` usage but keeps them for compatibility with previous version.

Everything is backward compatible, so v10 kubernetes agents and trusted clusters can connect fine.

## Next steps

Once this is merged, a new PR will introduce dynamic registration for Kubernetes Clusters discovered through EKS Discovery.
2022-08-04 14:21:11 +00:00
Marco André Dinis 89f4d5476a Create and List Connection Diagnostics (#14781)
In Teleport Discover, we want to improve the UX of adding a resource.
We'll suggest users to test accessing a resource, and give them immediate feedback using the UI.

Note: we'll add this feature to Server Access, later one we'll add other resources.

After adding a server resource, the user will be presented with a command to test the connection:
`tsh ssh --test-id=123 user@host`

Running that command will provide the user feedback right in the UI of whether or not it worked.
If not, a short message will be displayed describing why it didn't work and how the user can solve the problem.

---

To achieve this we'll need a couple of changes:
1. new resource that stores the result of trying to connect to a given resource, so that the UI can ask for it
2. change `tsh ssh` to receive the `--test-id` flag and write the result to a record of this new resource

This PR addresses 1 - new resource.

A new resource is created:
```
Connection Diagnostics
- success (bool)
- message (string)
```

Two new rpc methods:
- create connection diagnostics
- read connection diagnostics

One new HTTP Endpoint:
- read connection diagnostics

Related to
https://github.com/gravitational/teleport/issues/13957
2022-08-01 08:49:35 +01:00
Lisa Kim 92120a281a Rename web JSON field names and wrap traits (#14611) 2022-07-19 18:44:53 +00:00
Noah Stride 02b4f8575f Configure linter to catch British 🇬🇧 spellings 🇺🇸 🦅 📖 (#14363)
* configure golangci-lint misspell to check for anglicized spellings

* Americanize spellings

* fix aws constant value with british spelling 🇬🇧

* update api types with americanized spellings

* use american spellings .cloudbuild/scripts
2022-07-14 10:51:23 +00:00
Marco André Dinis af2d9c56ea WebAPI: return user traits (#14138)
* WebAPI: read user

We currently need to fetch the whole list of users to get User's
information.
Adding more fields increases the probabilty of having performance
issues.

This PR adds a new endpoint which returns a single user.
This endpoint returns the information we already return when listing
users but also returns the user's traits

This is a follow up of
https://github.com/gravitational/teleport/pull/14076

The following traits are returned:
- Logins
- DB Users
- DB Names
- Kube Users
- Kube Groups
- Windows Logins
- AWS Role ARNs
2022-07-13 10:06:34 +00:00
Russell Jones 22e81dcddb Refactored tests under web package
Refactored all tests under lib/web to use testify instead of gocheck.

Switched backend for most tests to memory.
2022-07-08 13:55:58 -07:00
Isaiah Becker-Mayer 2f83932597 Add directory sharing to the ACL (#14103) 2022-07-07 01:34:04 +00:00
MatheusandNic Klaassen 8ce4e6bfbf Add sshLogins to nodes endpoint on webapi (GET /nodes) (#13266)
* Add sshLogins to nodes endpoint on webapi

* Remove sshLogins from user context endpoint response

Co-authored-by: Nic Klaassen <nic@goteleport.com>
2022-06-14 12:56:16 +00:00
Brian Joerger 0431c0f0fb Remove deprecated node http endpoints (#12970) 2022-06-03 18:15:49 +00:00
Andrew Burke a8ed7bd1fd Automatically import EC2 tags (#12593)
This change allows Teleport to automatically import EC2 tags when running in an EC2 instance.
2022-05-31 23:19:16 +00:00
Isaiah Becker-Mayer ce4d6234ff Add ActiveSessions flag to ACL (#12962)
Adds ActiveSessions to the userContext/acl and changes Sessions to RecordedSessions for clarity's sake
2022-05-30 14:11:25 +00:00
rosstimothy da891423a9 Revert usage of NodeWatcher in web api (#12586)
The web api cannot leverage the NodeWatcher because it needs to
have each request for nodes go through RBAC checks per user. Rolling
back to creating an auth client per user and retrieving nodes
directly from the auth.ClientI.
2022-05-16 23:23:15 +02:00
rosstimothy fa12352214 Stop loading the enitre node set into memory per tsh ssh connection (#12014)
* Prevent proxy from loading entire node set into memory more than once

When establishing a new session to a node, the proxy would load the 
entire node set into memory in an attempt to find the matching host. For
smaller clusters this may not be that problematic. But on larger clusters,
loading >40k nodes into memory from the cache can be quite expensive.
This problem is compounded by the fact that it happened**per** session,
which could potentially cause the proxy to consume all available memory 
and be OOM killed.

A new `NodeWatcher` is introduced which will maintain an in memory list
of all nodes per process. The watcher leverages the existing resource 
watcher system and stores all nodes as types.Server, to eliminate the
cost incurred by unmarshalling the nodes from the cache. The `NodeWatcher`
provides a way to retrieve a filtered list of nodes in order to reduce the number 
of copies made to only the matches.
2022-05-02 15:59:56 -04:00
Lisa Kim 6b3d7eb368 Use the new ListResources in the webapi layer (#11019)
Supports pagination and filtering for the web UI
Part of RFD 55
2022-04-20 04:16:41 +00:00
Zac Bergquist 7e309e9ae2 Remove unused constants (#12033) 2022-04-19 18:59:35 +00:00
Rafał Cieślak ef2ae6f7de Move WebConfig from lib/web/ui to api/client/webclient (#11690)
* Move WebConfig from lib/web/ui to api/client/webclient

Web config was shared with the Web UI through the dynamically generated
/web/config.js file available on the cluster. With the addition of
Teleport Terminal (RFD 63), the Electron app needs to get a hold of this
config as well.

However, unlike the Web UI which directly loads the file and injects
the config this way, any communication between the cluster and Teleport
Terminal is done through the tsh daemon (RFD 63). The tsh daemon needs
to essentially pipe this config from /web/config.js to the gRPC response
it gives to Teleport Terminal.

To achieve this, a GetWebConfig function was added to TeleportClient.
Unfortunately, this breaks the build on Windows as lib/web (where WebConfig
resides) includes code which is not meant to be compiled or run on Windows.

Since we need to share the web config with another frontend application,
it only makes sense to move it to the webclient package. We already have
types shared between the server and the client there, for example the
PingResponse struct.
2022-04-05 08:47:53 +00:00
Zac Bergquist 55cbd0ac97 Remove use of deprecated ioutil package (#11296)
* Remove use of deprecated ioutil package
* Add lint rule to check for ioutil imports
2022-03-21 18:00:34 +00:00
Bernard Kim 079b38caf1 Enable desktop access in Web UI in Cloud clusters (#10969) 2022-03-08 21:43:36 +00:00
Isaiah Becker-Mayer eb71cae26c Adds a DesktopSessionRecording flag to the ACL (#10365)
* Adds a DesktopSessionRecording flag to the ACL to tell the frontend whether or not a user's desktop sessions are being recorded.

* Accounts for the fact that desktop recording may be disabled globally

* fixes linting error
2022-02-18 23:26:37 +00:00
Joel ea810d30d9 Implement Moderated Sessions (#8563)
* Implement Moderated Sessions
2022-02-15 17:02:10 +01:00
Matheus 720a89f77d Expose reverse tunnel address to web ui (#10133)
* Add tunnel public address to web config on cloud instances
2022-02-14 11:56:19 -03:00
Vitor Enes 191d631c38 Replace testify/assert with testify/require (#9925) 2022-02-10 10:47:26 +00:00
Trent Clarke 1cf5a5464a Use buildbox images from quay.io (#10179)
The use of a re-badged buildbox image (rebadging quay.io/gravitational/teleport-buildbox to us-docker.pkg.dev/ci-account/teleport/buildbox-root) is holdover from when CI builds required separate "root user" and "non-root user" images to execute tests under different contexts.

This requirement has since been lifted by using a Go-based build script in CI, and the having to manually invoke a process to re-badge the buildboxes is, tedious, confusing and causing stoppages.

This patch restores the use of buildboxes from quay.io in CI.
2022-02-09 20:56:55 +11:00
Nic Klaassen e00ff42cb8 IAM Join Method (backend implementation) (#10085) 2022-02-08 18:48:13 +00:00
Isaiah Becker-Mayer e8cd8fa040 adds cliipboard to userACL (#10207) 2022-02-08 14:24:16 +00:00
JoelandZac Bergquist 62173e096b use google/uuid instead of pborman/uuid (#9793)
* replace imports

* use google/uuid

* fix test

* reverse changelog changes

* update gomod

* zac steps

* tidy

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-01-19 23:44:48 +00:00
Alan Parra f16e9f5c53 Fix the UI to correctly determine if a user has access to a resource (#9473)
Introduce the GuessIfAccessIsPossible method, so callers may verify if a user
has access to a category of resources, instead of access to a specific resource.

Fixes a bug where the "Session Recordings" menu doesn't show for users with
where-based roles.
2021-12-21 21:54:31 +00:00