Commit graph

483 commits

Author SHA1 Message Date
Andrew Lytvynov 92ed2db38a Fixing golint warnings, batch 1
Mostly cosmetic changes:
- making receiver names consistent
- renaming `foo.FooBar` to `foo.Bar` (using package name as prefix)
- removing redundant `else` branches
- changing `a += 1` to `a++`
2020-10-13 00:22:49 +00:00
Andrew Lytvynov e095e30342 Add kubernetes cluster name to TLS certs
K8s cluster name is specified during login (for now) and gets plumbed to
a new extensions on the TLS cert. The name is validated against all
known k8s clusters reported via proxy heartbeats. If no name is
provided, the extension remains empty.

The name in the cert will get used by proxies for routing, once we fully
support multiple k8s clusters per teleport cluster.

This was tested with direct and github login flows.
2020-10-07 16:26:54 +00:00
Andrew Lytvynov 63da43245e Validate node_labels syntax at role creation time
Also improve error output and user validation.
Based on missed feedback in https://github.com/gravitational/teleport/pull/4253#pullrequestreview-499061448
2020-10-05 18:00:55 +00:00
Andrew Lytvynov 39895db54c Override role session TTL for k8s principals in tctl auth sign
When running 'tctl auth sign' as an admin, we override the TTL on
roles/logins to allow making long-lived creds.
We didn't do that for k8s users/groups and silently filtered them out.
This change makes them consistent.
2020-10-05 16:07:47 +00:00
Andrew Lytvynov 3c2e4e2ec1 Add cluster_name to proxy kubernetes config
Cluster name from this field plug all clusters from kubeconfig are
stored on the auth server via heartbeats.
This info will later be used to route k8s requests back to proxies.

Updates https://github.com/gravitational/teleport/issues/3952
2020-09-30 15:56:31 +00:00
Andrew Lytvynov 75d7fbb508 Migrate services.MatchLabels to parse.Matcher
This should be backwards-compatible plus add the {{regexp.match(...)}}
and {{regexp.not_match(...)}} functions.
2020-09-29 21:25:50 +00:00
Andrew Lytvynov bb69574e02 utils/parse: support string literal expressions
No need to handle literal expressions (e.g. without "{{foo.bar}}"
substitutions) at the higher level. Something like "foo" is a valid
expression which always returns "foo" regardless of traits.
2020-09-29 21:25:50 +00:00
Andrew Lytvynov 8aacdc1b0f Update github.com/russellhaering/goxmldsig to v1.1.0
See https://github.com/russellhaering/goxmldsig/security/advisories/GHSA-q547-gmf8-8jr7
2020-09-29 17:51:50 +00:00
Sasha Klizhentas d160507430 Session streaming
This commit introduces GRPC API for streaming sessions.

It adds structured events and sync streaming
that avoids storing events on disk.

You can find design in rfd/0002-streaming.md RFD.
2020-09-28 23:08:56 -07:00
Forrest Marshall ae2336dfd0 concurrent session control
Adds support for Concurrent Session Control and a new
semaphore API.  Roles now support two new configuration
options, `max_ssh_connections` and `max_ssh_sessions`
which correspond to the total number of authenticated
ssh connections per cluster, and the number of ssh sessions
within a connection respectively.  Attempting to exceed
these limits generate variants of the `session.rejected`
audit event and cause the connection/session to be
rejected.
2020-09-17 11:02:35 -07:00
Sasha Klizhentas 0f4e82548f Initial work on semaphores 2020-09-17 11:02:35 -07:00
Andrew Lytvynov 6a14edcf1f Keep RemoteCluster resources up-to-date in the backend
Prior to this commit, RemoteCluster resource data was dynamically
generated from TunnelConnection resources.

Keep using TunnelConnections, but record any changes to RemoteCluster in
the backend too. This lets us preserve the LastHeartbeat field after
TunnelConnections get deleted (as they do when a reverse tunnel
disconnects).
2020-08-28 00:28:45 +00:00
Lisa Kim 1b886bb197
Refactor create/delete user (#4185)
* Check if user exists before creating/updating to return clearer error message
* Remove unnecessary checking if user exists before creating
* When creating user, set CreatedBy if not set by original caller
2020-08-17 14:13:38 -07:00
Forrest Marshall 9b515415b8 verify ProxyWatcher reset behavior in test suite 2020-07-28 16:24:45 -07:00
Forrest Marshall e9326d7370 re-init proxywatcher on empty proxy list 2020-07-28 16:24:45 -07:00
Forrest Marshall eefef4ddb7 improve label fmt enforcement 2020-07-23 22:51:05 -07:00
Andrew Lytvynov 1b7401f670 Plumb RouteToCluster through SSO login flows
This lets the user log into a leaf cluster directly via tsh and
provision the correct k8s credentials for it.
2020-07-01 18:15:48 +00:00
Andrew Lytvynov 2172965057 Remove alg argument from CertAuthority.Signers
It's no longer needed, since CertAuthority contains the signing
algorithm internally.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov d7dc41659d Use CA signing alg from config file on manual rotation
This allows users to manually switch to a different algorithm by:
- setting the config file field
- running "tctl auth rotate"

If config file field is not set, existing signing algorithm of the CA is
preserved.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov 6746213886 Preserve SSH signing alg for existing CAs
Store the signing algorithm along the CA private key. When reading old
CAs that don't have it set, default to UNKNOWN proto enum which
corresponds to the old SHA1-based signing alg.

The only time you get a SHA2 signature is when creating a fresh cluster
and generating a new CA. This can be disabled in the config.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov 9bc8fb3ae0 Add ca_signing_algo to the config file
This allows users to override the SHA2 signing algorithms we default to
now for compatibility with the (very) old OpenSSH versions.

For host and user certs, use the CA signing algo for their own
handshakes. This allows us to propagate the signing algo from auth
server everywhere else.
2020-06-24 21:25:33 +00:00
Andrew Lytvynov 96f56f3f40 Enforce SHA-512 for RSA SSH signatures
Motivation:

    x/crypto/ssh defaults to using SHA-1 for signatures:
    https://github.com/golang/crypto/blob/master/ssh/keys.go#L963-L982
    Because Teleport uses RSA for user, host and CA keys, we end up with
    SHA-1 by default.

    SHA-1 is now considered weak and OpenSSH plans to deprecate it:
    https://www.openssh.com/txt/release-8.3

Fix:

    Wrap all RSA `ssh.Signer`s and override `SignWithAlgorithm` to
    provide `SigAlgoRSASHA2512` if not otherwise specified. This will
    only affect new certs, existing certs will use `SigAlgoRSA` until
    rotated. For CA certs (e.g. exported with `tctl auth export`) users
    might need to manually rotate.

Limited local testing with openssh 8.2 client and
`-oHostKeyAlgorithms=-ssh-rsa` confirms that this works with a new
cluster and fails with an old one.
2020-06-24 21:25:33 +00:00
Forrest Marshall dfd40d21f5 proxy X11 forwarding support
- Role options now include a `permit_x11_forwarding` bool
which is set to `false` by default.

- Recording proxies now forward X11 requests and channels
when when permitted by RBAC.

- User certs will now include the `permit-X11-forwarding`
extension when permitted by RBAC.

- If X11 forwarding is requested for a session a new `x11`
audit event is emitted by recording proxies.
2020-06-24 11:40:47 -07:00
Andrew Lytvynov 5bd66a396e Plumb caller username for CRUD events via contexts
Our auth middleware already attaches a TLS identity as context value.
Plumb contexts through and extract the username when recording events.
If the received context doesn't have an identity attached, use "system"
as username.

Lots of noise here due to missing context.Context plumbing :(
We should eventually plumb contexts to all those RPC interfaces.

Updates #3816
2020-06-18 19:01:35 +00:00
Forrest Marshall 361deb89c0 fix access request delete event filtering 2020-06-09 15:25:49 -07:00
Russell Jones 829bc68fdd Update account name for OTP token.
Update account name in OTP token to first attempt to get the public
address of one of the proxies, if not available then fallback to the
hostname of the first proxy, if not available then fallback to the name
of the cluster, if not available fallback to the hostname of the auth
server.
2020-06-05 17:51:01 -07:00
Lisa Kim d33789dcc6
Emit correct event user when deleting user (#3710)
* Add DeleteUser to auth proto
* By default DeleteUser will call out to grpc, but if failed, fallback to REST
2020-06-01 17:06:28 -07:00
Andrew Lytvynov 1d9e01bb80 errcheck: add missing error checks in lib/service* 2020-06-01 17:00:07 +00:00
Andrew Lytvynov 2d28c7b5da Allow TLS cert creation without kube users/groups
This is a reasonable situation, users are not required to have kube
principals. Skip that error on login.
2020-05-21 20:37:28 +00:00
Andrew Lytvynov 4b5cd7e68f gosimple: simplify or remote return statements 2020-05-15 16:32:45 +00:00
Andrew Lytvynov 2a93910fa2 gosimple: remove unnecessary blank identifiers in for loops 2020-05-15 16:32:45 +00:00
Andrew Lytvynov a48c40ad78 gosimple: replace time.Now().Sub(x) with time.Since(x) 2020-05-15 16:32:45 +00:00
Andrew Lytvynov e5478c937d Remove unnecessary type conversions
Caught by `unconvert` linter. No behavior changes here.
2020-05-11 16:44:27 +00:00
Andrew Lytvynov 44cfbd4b6d Fix common misspellings detected by misspell linter 2020-05-11 16:44:27 +00:00
Andrew Lytvynov b1eae4ac4c Remove unused functions and methods throughout lib/...
This code is not caught by linters because it's exported and they assume
there's some external users.
Since teleport is relatively self-contained, we can tell for sure
whether something is called or not.
2020-05-06 00:02:53 +00:00
Lisa Kim 118ad19101
Emit correct event user who updates user records (#3635)
* Add UpdateUser rpc to proto
* Differentiate between create and update in github,oidc,saml
* Edit updated_by event field to be more generic (used with contexts to capture user modifying records)
* Update security issue by removing secrets from user when update/upsert/create (forrest)
* Update createUser in resource_command and require force for updates
2020-05-05 16:49:32 -07:00
Andrew Lytvynov 24afdc0de6 Ensure all tests run exactly once per package
With gocheck, tests only run if you call `check.TestingT(t)` from a
dummy `func Test(t *testing.T)`.

Added the missing dummy function call in: `lib/services/suite`,
`lib/shell`. The `lib/shell` tests also turned out to be broken.

If you call the dummy wrapper twice, all tests will run twice.
This was happening in `lib/events/s3sessions` and `lib/services/local`.
2020-04-30 16:35:35 +00:00
Andrew Lytvynov 24ae390bb9 Fix staticcheck findings in lib/services/...
Fixed findings:
```
lib/services/github_test.go:99:2: SA4006: this value of `kubeUsers` is never used (staticcheck)
	logins, kubeGroups, kubeUsers = connector.MapClaims(GithubClaims{
	^
lib/services/github_test.go:107:2: SA4006: this value of `kubeUsers` is never used (staticcheck)
	logins, kubeGroups, kubeUsers = connector.MapClaims(GithubClaims{
	^
lib/services/local/configuration_test.go:84:2: SA4006: this value of `clusterConfig` is never used (staticcheck)
	clusterConfig, err := services.NewClusterConfig(services.ClusterConfigSpecV3{
	^
lib/services/local/configuration_test.go:102:2: SA4006: this value of `clusterConfig` is never used (staticcheck)
	clusterConfig, err := services.NewClusterConfig(services.ClusterConfigSpecV3{})
	^
lib/services/local/presence_test.go:108:2: SA4006: this value of `gotTC` is never used (staticcheck)
	gotTC, err = presenceBackend.GetTrustedCluster("foo")
	^
lib/services/suite/suite.go:157:2: SA4006: this value of `err` is never used (staticcheck)
	out, err := s.WebS.GetUser("user1", false)
	^
lib/services/suite/suite.go:208:2: SA4006: this value of `u` is never used (staticcheck)
	u, err = s.WebS.GetUser("foo", false)
	^
lib/services/suite/suite.go:277:2: SA4006: this value of `err` is never used (staticcheck)
	err = s.CAS.CompareAndSwapCertAuthority(&newCA, ca)
	^
lib/services/suite/suite.go:339:2: SA4006: this value of `err` is never used (staticcheck)
	out, err = s.PresenceS.GetProxies()
	^
lib/services/suite/suite.go:1136:5: SA4006: this value of `err` is never used (staticcheck)
				role, err := services.NewRole("role1", services.RoleSpecV3{
				^
lib/services/suite/suite.go:1166:5: SA4006: this value of `err` is never used (staticcheck)
				err := s.Users().UpsertUser(user)
				^
```
2020-04-28 15:17:44 +00:00
Andrew Lytvynov 2dc8690e9a Add --k8s-users flag to tctl users add
This allows users to be provided with k8s usernames, in addition to
groups. Default this flag to local login, same as for SSH logins.
2020-04-24 16:23:18 +00:00
Andrew Lytvynov 3f9b14b5f7 Add internal.kubernetes_users to kubernetes_users on admin role
With OSS version and without using the github connector (only local
auth), logged in user won't have any `kubernetes_groups`. Without
usernames too, user can login but can't use kubectl.
2020-04-24 16:23:18 +00:00
Andrew Lytvynov 7ccdd87496 Enable more Go linters: varcheck,bodyclose,structcheck
All changes should be noop, except for
`integration/integration_test.go`.

The integration test was ignoring `recordingMode` test case parameter
and always used `RecordAtNode`. When switching to `recordingMode`, test
cases with `RecordAtProxy` fail with a confusing error about missing
user agent. Filed https://github.com/gravitational/teleport/issues/3606
to track that separately and unblock enabling `structcheck` linter.
2020-04-24 15:52:43 +00:00
Forrest Marshall 4e9eed9ac0 cache event fanout & reversetunnel improvements
- cache now perforams in-memory fanout of events, eliminating
spurious event generation due to cache init/reset.

- removed old unused logic from reversetunnel agents.

- replaced seekpool with simpler ttl-cache and semaphore-like
lease system.

- add jittered backoff to agent connection attempts to
reduce "thundering herd" effect.

- improved reversetunnel logging.

- improved LB usage in tests.
2020-04-23 14:03:52 -07:00
Andrew Lytvynov a7d9a03a09 Improve error messages for trusted cluster updates
Trusted cluster objects need to be re-created for most updates other
than enable/disable. Suggest that via error messages to the user.

Fixes #2998
2020-04-23 17:04:23 +00:00
Andrew Lytvynov d1ea40d074 Enable linters: deadcode,goimports,govet,typecheck
And fix the relevant findings for these linters.

Also, set extra flags for `golangci-lint run` to make sure no findings
are suppressed.
2020-04-17 17:46:51 +00:00
Alexey Kontsevoy 3c670d5d58
Merge Teleport V4.3 UI branch to master (#3583)
* Add monorepo

* Add reset/passwd capability for local users (#3287)

* Add UserTokens to allow password resets

* Pass context down through ChangePasswordWithToken

* Rename UserToken to ResetPasswordToken

* Add auto formatting for proto files

* Add common Marshaller interfaces to reset password token

* Allow enterprise "tctl" reuse OSS user methods (#3344)

* Pass localAuthEnabled flag to UI (#3412)

* Added LocalAuthEnabled prop to WebConfigAuthSetting struct in webconfig.go
* Added LocalAuthEnabled state as part of webCfg in  apiserver.go

* update e-refs

* Fix a regression bug after merge

* Update tctl CLI output msgs (#3442)

* Use local user client when resolving user roles

* Update webapps ref

* Add and retrieve fields from Cluster struct (#3476)

* Set Teleport versions for node, auth, proxy init heartbeat
* Add and retrieve fields NodeCount, PublicURL, AuthVersion from Clusters
* Remove debug logging to avoid log pollution when getting public_addr of proxy
* Create helper func GuessProxyHost to get the public_addr of a proxy host
* Refactor newResetPasswordToken to use GuessProxyHost and remove publicUrl func

* Remove webapps submodule

* Add webassets submodule

* Replace webapps sub-module reference with webassets

* Update webassets path in Makefile

* Update webassets

1b11b26 Simplify and clean up Makefile (#62) https://github.com/gravitational/webapps/commit/1b11b26

* Retrieve cluster details for user context (#3515)

* Let GuessProxyHost also return proxy's version
* Unit test GuessProxyHostAndVersion & GetClusterDetails

* Update webassets

4dfef4e Fix build pipeline (#66) https://github.com/gravitational/webapps/commit/4dfef4e

* Update e-ref

* Update webassets

0647568 Fix OSS redirects https://github.com/gravitational/webapps/commit/0647568

* update e-ref

* Update webassets

e0f4189 Address security audit warnings Updates  "minimist" package which is used by 7y old "optimist". https://github.com/gravitational/webapps/commit/e0f4189

* Add new attr to Session struct (#3574)

* Add fields ServerHostname and ServerAddr
* Set these fields on newSession

* Ensure webassets submodule during build

* Update e-ref

* Ensure webassets before running unit-tests

* Update E-ref

Co-authored-by: Lisa Kim <lisa@gravitational.com>
Co-authored-by: Pierre Beaucamp <pierre@gravitational.com>
Co-authored-by: Jenkins <jenkins@gravitational.io>
2020-04-15 15:35:26 -04:00
Andrew Lytvynov f8661edea3 Clean up dead code across the codebase
Spring cleaning!
A very mechanical cleanup using several linters (unused, deadcode,
structcheck). Build and tests still pass so no behavior should be
affected.
2020-04-09 21:10:12 +00:00
Alexander Klizhentas 924dd8fdb0 Adds support for custom OIDC prompts (#3409)
This commit adds support for custom OIDC prompt values.

Read about possible prompt values here:

https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest

Three cases are possible:

* Prompt value is not set, this defaults to
OIDC prompt value to select_account value to preserve backwards
compatibility.

```yaml
kind: oidc
version: v2
metadata:
  name: connector
spec:
  prompt: 'login consent'
```

* Prompt value is set to empty string, it will be omitted
from the auth request.

```yaml
kind: oidc
version: v2
metadata:
  name: connector
spec:
  prompt: ''
```

* Prompt value is set to non empty string, it will be included
in the auth request as is.

```yaml
kind: oidc
version: v2
metadata:
  name: connector
spec:
  prompt: 'login consent'
```

Tested with Auth0 OIDC connector on teleport 4.2 enterprise.
2020-03-20 17:57:05 -07:00
Alexander Klizhentas 73ecb48232
Adds support for kubernetes_users, extend interpolation (#3404) (#3418)
This commit fixes #3369, refs #3374

It adds support for kuberenetes_users section in roles,
allowing Teleport proxy to impersonate user identities.

It also extends variable interpolation syntax by adding
suffix and prefix to variables and function `email.local`:

Example:

```yaml
kind: role
version: v3
metadata:
  name: admin
spec:
  allow:
    # extract email local part from the email claim
    logins: ['{{email.local(external.email)}}']

    # impersonate a kubernetes user with IAM prefix
    kubernetes_users: ['IAM#{{external.email}}']

  # the deny section uses the identical format as the 'allow' section.
  # the deny rules always override allow rules.
  deny: {}
```

Some notes on email.local behavior:

* This is the only function supported in the template variables for now
* In case if the email.local will encounter invalid email address,
it will interpolate to empty value, will be removed from resulting
output.

Changes in impersonation behavior:

* By default, if no kubernetes_users is set, which is a majority of cases,
  user will impersonate themselves, which is the backwards-compatible behavior.

* As long as at least one `kubernetes_users` is set, the forwarder will start
  limiting the list of users allowed by the client to impersonate.

* If the users' role set does not include actual user name, it will be rejected,
  otherwise there will be no way to exclude the user from the list).

* If the `kuberentes_users` role set includes only one user
  (quite frequently that's the real intent), teleport will default to it,
  otherwise it will refuse to select.

  This will enable the use case when `kubernetes_users` has just one field to
  link the user identity with the IAM role, for example `IAM#{{external.email}}`

* Previous versions of the forwarding proxy were denying all external
impersonation headers, this commit allows 'Impesrsonate-User' and
'Impersonate-Group' header values that are allowed by role set.

* Previous versions of the forwarding proxy ignored 'Deny' section of the roles
when applied to impersonation, this commit fixes that - roles with deny
kubernetes_users and kubernetes_groups section will not allow
impersonation of those users and groups.
2020-03-07 16:32:37 -08:00
Russell Jones de25684689 Added testing.Verbose to allow silencing of tests. 2020-02-06 11:15:44 -08:00
Forrest Marshall 257274b26f Implement per-resource PluginData storage (#3286)
- Also addresses #3282 by adding retries for CompareAndSwap
on SetAccessRequestState and UpdatePluginData.
2020-01-30 14:27:40 -08:00