Commit Graph
29 Commits
Author SHA1 Message Date
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Lisa Kim bc81db4655 Use field hostname for node resource for predicate expr using "name" identifier (#16902)
* Predicate expressions using the "name" identifier will now use
  field "hostname" when `ls` querying for nodes, as expected by
  the user
* Change predicate expression for access request that use
  name identifier to using the actual json field names
2022-10-04 00:20:04 +00:00
Joel fbb23cf68c Implement RFD 82: Session Tracker Resource RBAC (#15760) 2022-09-20 15:38:48 +00:00
Alan Parra a75fcc21d8 Update golangci-lint to 1.49.0 (#16507)
Update metalinter, fix a few lint warnings and replace deprecated linters.

`deadcode`, `structcheck` and `varcheck` are abandoned and now replaced by [`unused`][1].

Since 1.19, `go fmt` reformats godocs according to https://go.dev/doc/comment. I've done a bulk-reformatting of the codebase to keep the linter happy. Backporting is mostly harmless (the exception being `lib/services/role_test.go`, that for some reason breaks the _old_ linter using the new format).

[1]: https://golangci-lint.run/usage/linters/

* Bump golangci-lint version
* Replace abandoned linters
* Fix bodyclose on lib/auth/github.com
* Fix bodyclose on lib/kube/proxy/streamproto/proto_test.go
* Fix bodyclose on lib/srv/alpnproxy/proxy_test.go
* Fix bodyclose on lib/web/conn_upgrade_test.go
* Silence staticcheck on lib/kube/proxy/forwarder_test.go
* Silence staticcheck on lib/utils/certs_test.go
* Address BuildNameToCertificate deprecation warnings
* Run `go fmt ./...`
* Run `go fmt ./...` on api/
* Ignore formatting in role_test.go
* Remove redundant initializers in lib/srv/uacc/
* Update e/
2022-09-19 22:38:59 +00:00
Tim Buckley 81f42bbaed Add where predicate and Machine ID support to SSH host certificates (#16261)
* Add `where` predicate and Machine ID support to SSH host certificates

This adds `where` RBAC predicate support to `host_cert`
pseudo-resources, and adds support for requesting host certs to
Machine ID (with or without these RBAC predicates).

More specifically, this:
 * Makes 3 new set functions available during `where` predicate
   evaluation: `all_equal`, `all_end_with`, and `is_subset`. These
   make it possible to examine the `host_cert.principals` field.
 * Adds a new optional `host_cert` field to the standard `where`
   context. It's only ever set specifically in `GenerateHostCert()`.
 * Sets a custom context in `GenerateHostCert()` to pass along host
   cert parameters.
 * Makes current config available to tbot config templates
 * Adds a new `ssh_host_cert` config template to Machine ID
 * Refactors `tbot/config` tests to use shared mock bot / auth
   implementations.

Host certs can be requested in Machine ID by adding a new config
template:
```yaml
destinations:
  - directory: /opt/machine-id
    configs:
      - ssh_host_cert:
          principals: [foo.example.com]
```

Bots will need a role like the following:
```yaml
kind: role
metadata:
  name: hostcert-bot
version: v5
spec:
  allow:
    rules:
      - resources:
          - host_cert
        verbs:
          - create
        where: 'is_subset(host_cert.principals, "foo.example.com")'
```

See the RFD for more information:
https://github.com/gravitational/teleport/blob/master/rfd/0083-machine-id-host-certs.md

* Fix lint failure

* Improve doc comments on the new predicate functions.

* Address review feedback

* Address review feedback

- Remove `AuthenticatedUserClientFromIdentity`'s unnecessary
  AuthServer param
- Add missing doc comments
- Pull out `getTestIdent` from the Kubernetes template test
- Move various test helpers into their own file
- Unexport new predicate functions
2022-09-14 20:18:05 +00:00
Lisa Kim 6116ccf37a Improve error message for resource predicate query (#12262) 2022-04-29 21:29:27 +00:00
Zac Bergquist 06d488ff31 Fix desktop session playback RBAC (#10570)
The RBAC for sessions code was using SSH-specific queries to check
for session end events. Migrate to the newer search, which is both
more efficient and supports desktop events as well.

Fixes #10507
2022-02-28 14:05:31 -07:00
Lisa Kim 198dec05f1 Implement resource boolean expression parser (#10008)
Created a predicate parser that's customized for our 
ResourceWithLabels. Plan is to allow UI and CLI users 
to use this predicate language to filter resources by 
labels and json fields.

Also updates vulcand/predicate to latest v1.2.0

Part of RFD 55
2022-02-04 13:52:16 -08:00
Alan ParraandAndrej Tokarčík 64679d2db8 Implement where conditions for active sessions (#9040)
Implements RFD 45 / "where" conditions for active sessions[1].

In few words, the purpose of the RFD is to allow the creation of roles that
permits users to only join a subset of active sessions (for example, only their
own sessions).

Implementation goes a bit further than the RFD, allowing the conditions to be
applied to  `update` and `delete` verbs as well.

Originally implemented by @andrejtokarcik (#8568), tweaks by @codingllama.

[1] https://github.com/gravitational/teleport/blob/master/rfd/0045-ssh_session-where-condition.md


* Implement where conditions for active sessions list/read
* actionWithConditionForList => actionForListWithCondition
* Make Context-exposed sessions follow the RFD API
* Add tests for "where" conditions on active sessions
* Fix typos
* Fix typos and spacing
* Rename "parties" to "participants" in the context session
* Update RFD to reflect PR changes

Update RFD to reflect PR changes

Specifically, mark as implemented and rename `parties` to `participants`.

* Push list authz logic to ServerWithRoles, obsolete cond
* Remove cond from GetSessions signature
* Simplify cast in lib.utils.Fields.GetString
* Add TODO to refactor SearchSessionEvents / stored sessions

Co-authored-by: Andrej Tokarčík <andrej@goteleport.com>
2021-11-18 15:05:13 -08:00
Andrej Tokarčík b86fa7bfa8 Implement where conditions for session recordings list/read (#8289) 2021-10-08 10:18:22 -07:00
Brian Joerger 9b8b9d6d0c rollback - Upgrade api version. (#7751) 2021-07-30 15:34:19 -07:00
Brian Joerger c040aca4c1 Upgrade api version. (#7609) 2021-07-28 13:51:21 -07:00
Brian Joerger 24063e65f0 Remove SetTTL methods in favor of SetExpiry. (#7234) 2021-06-18 13:35:02 -05:00
Brian Joerger 7bff7c41bd Remove API aliases (#6983) 2021-06-04 13:29:31 -07:00
Andrew Lytvynov 84a7230e6e Move CheckAndSetDefaults definition to types.Resource (#6825)
All resources should implement it, reduce some code duplication in
interfaces.
2021-05-13 14:02:56 -07:00
Forrest Marshall 59d2379b94 custom approval conditions 2021-03-24 14:33:40 -07:00
Alexander Klizhentas f17625c1a8 Adds controls for impersonation requests. (#6009) (#6073)
Fixes #5352

```yaml
allow:
  impersonate:
    users: ['alice', 'bob']
    roles: ['*']
    where: 'contains(user.spec.traits["groups"], impersonate_role.traits)'
```

Adds "impersonator" to all X.509 and SSH client certs
issued using impersonation and does best effort to track
requests by impersonators in audit events.

Limits certs TTL to the impersonator's max session TTL.

Prevents impersonating users to recursively impersonate
other users.

Allows impersonating users to renew their own certificate,
for example to set route to cluster.

Adds missing token permission for editor role.
2021-03-19 16:04:43 -07:00
Brian Joerger a555844116 Refactor API Dependencies - clockwork (#5253)
Deprecate SetTTL method in favor of SetExpiry and remove other dependencies on clockwork.
2021-01-20 15:55:32 -08:00
Brian Joerger 76b6b6d84d Refactor lib/utils/parse dependency in api package. (#5261) 2021-01-19 11:32:07 -08:00
Brian Joerger 3c3ce160d9 Move API types and functionality from lib/services to api/types. (#5143) 2021-01-11 10:02:34 -08:00
Andrew Lytvynov 44cfbd4b6d Fix common misspellings detected by misspell linter 2020-05-11 16:44:27 +00:00
Russell Jones 9135a5ade7 Use roles and traits in certificate for RBAC.
If an attacker can force a username change at an IdP, upon second login,
the services.User object of the original user can be updated with new
roles and traits. If these new roles and traits differ, the original
user can have their privileges raised (or lowered).

To mitigate this, encode roles and traits within the certificate and use
these when fetching roles to make RBAC decisions. If roles and traits are
not encoded within an certificate (for example for old style SSH
certificates then fallback to using the services.User object and log a
warning.
2019-09-03 13:44:20 -07:00
Sasha Klizhentas 8356ae6a74 Use in-memory cache for the auth server API.
This commit expands the usage of the caching layer
for auth server API:

* Introduces in-memory cache that is used to serve all
Auth server API requests. This is done to achieve scalability
on 10K+ node clusters, where each node fetches certificate authorities,
roles, users and join tokens. It is not possible to scale
DynamoDB backend or other backends on 10K reads per seconds
on a single shard or partition. The solution is to introduce
an in-memory cache of the backend state that is always used
for reads.

* In-memory cache has been expanded to support all resources
required by the auth server.

* Experimental `tctl top` command has been introduced to display
common single node metrics.

Replace SQLite Memory Backend with BTree

SQLite in memory backend was suffering from
high tail latencies under load (up to 8 seconds
in 99.9%-ile on load configurations).

This commit replaces the SQLite memory caching
backend with in-memory BTree backend that
brought down tail latencies to 2 seconds (99.9%-ile)
and brought overall performance improvement.
2019-04-12 14:23:09 -07:00
Sasha Klizhentas f40df845db Events and GRPC API
This commit introduces several key changes to
Teleport backend and API infrastructure
in order to achieve scalability improvements
on 10K+ node deployments.

Events and plain keyspace
--------------------------

New backend interface supports events,
pagination and range queries
and moves away from buckets to
plain keyspace, what better aligns
with DynamoDB and Etcd featuring similar
interfaces.

All backend implementations are
exposing Events API, allowing
multiple subscribers to consume the same
event stream and avoid polling database.

Replacing BoltDB, Dir with SQLite
-------------------------------

BoltDB backend does not support
having two processes access the database at the
same time. This prevented Teleport
using BoltDB backend to be live reloaded.

SQLite supports reads/writes by multiple
processes and makes Dir backend obsolete
as SQLite is more efficient on larger collections,
supports transactions and can detect data
corruption.

Teleport automatically migrates data from
Bolt and Dir backends into SQLite.

GRPC API and protobuf resources
-------------------------------

GRPC API has been introduced for
the auth server. The auth server now serves both GRPC
and JSON-HTTP API on the same TLS socket and uses
the same client certificate authentication.

All future API methods should use GRPC and HTTP-JSON
API is considered obsolete.

In addition to that some resources like
Server and CertificateAuthority are now
generated from protobuf service specifications in
a way that is fully backward compatible with
original JSON spec and schema, so the same resource
can be encoded and decoded from JSON, YAML
and protobuf.

All models should be refactored
into new proto specification over time.

Streaming presence service
--------------------------

In order to cut bandwidth, nodes
are sending full updates only when changes
to labels or spec have occured, otherwise
new light-weight GRPC keep alive updates are sent
over to the presence service, reducing
bandwidth usage on multi-node deployments.

In addition to that nodes are no longer polling
auth server for certificate authority rotation
updates, instead they subscribe to event updates
to detect updates as soon as they happen.

This is a new API, so the errors are inevitable,
that's why polling is still done, but
on a way slower rate.
2018-12-10 17:20:24 -08:00
Sasha Klizhentas 3e144cb900 Teleport certificate authority rotation.
This commit implements #1860

During the the rotation procedure issuing TLS and SSH
certificate authorities are re-generated and all internal
components of the cluster re-register to get new
credentials.

The rotation procedure is based on a distributed
state machine algorithm - certificate authorities have
explicit rotation state and all parts of the cluster sync
local state machines by following transitions between phases.

Operator can launch CA rotation in auto or manual modes.

In manual mode operator moves cluster bewtween rotation states
and watches the states of the components to sync.

In auto mode state transitions are happening automatically
on a specified schedule.

The design documentation is embedded in the code:

lib/auth/rotate.go
2018-04-30 12:58:57 -07:00
Sasha Klizhentas c4a72fd353 add rule checks and evaluation priorities
This commit improves error handling and improves rule evaluatons
by introducing rule priorities.

Roles are now checked for syntax errors in 'where' and 'actions'
sections what was not done before.

In case if several equivalent rules are specified, new rule
evaluations are now going into effect:

More specific rule will be matched first.

* Rule matching wildcard resource is less specific
than same rule matching specific resourc
* Rule that has wildcard verbs is less specific
than the same rules matching specific verb
* Rule that has where section is more specific
than the same rule without where section
* Rule that has actions list is more specific than
rule without actions list.
2017-11-21 15:15:09 -08:00
Sasha Klizhentas 2a60416bf0 tweak log action 2017-08-25 11:29:33 -07:00
Sasha Klizhentas d7e5f7f4f6 add tests 2017-08-25 10:51:49 -07:00
Sasha Klizhentas 1fded0886a scaffolding for rules matchers 2017-08-24 20:24:47 -07:00