Commit Graph
40 Commits
Author SHA1 Message Date
rosstimothy 9d066364a8 Migrate GetCertAuthorities to gRPC (#22985)
Adds a new `GetCertAuthorities` unary RPC to
`teleport.v1.trust.TrustService` and deprecates the equivalent
HTTP endpoint. All associated interfaces have been updated to remove
the marshal options as well.
2023-03-14 14:45:01 +00:00
Tiago Silva 674a3a1ec1 Removes deprecated KindKubeService objects (#22663)
This PR removes the `types.KindKubeService` objects that were
deprecated in Teleport 11.

Teleport 12 removed the double heartbeat and for Teleport 13 we can
safely drop the support of the old hearbeat based on `types.Server`
objects.

Clients older than Teleport 12 connecting to a Teleport 13 server will
fail since they cannot heartbeat using the old mechanism.
2023-03-13 10:55:39 +00:00
rosstimothy 95d6d0fee1 Migrate GetCertAuthority to gRPC (#22624)
The HTTP client created by `auth.NewClient` has an idle timeout of
30s and each instance periodically gets cert authorities in
`TeleportProcess.syncRotationStateCycle`. If there has been no
activity when the ticker expires then the request will result in a
brand new connection to Auth to be established. This can cause a
spikes in open file descriptors on the Proxy when there are a large
number of instances connected via a tunnel.

To prevent periodic dialing when retrieving cert authorities the
endpoint has been migrated to the new Trust gRPC service. For now
only the get endpoint has been migrated but the rest of the CRUD
operations for cert authorities should be migrated from the HTTP
api to the gRPC service as well.
2023-03-10 14:32:34 +00:00
8e05bcbb1b Export CRL and Database CA in DER format (#22578)
* feat(tctl): auth export type db der

* feat(tctl): add "crl" command to export revocation lists

* Apply suggestions from code review

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* chore(tctl): change command description

* Apply suggestions from code review

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* feat(auth): enable role admin to call generate crl

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
Co-authored-by: Marek Smoliński <marek@goteleport.com>
2023-03-10 14:30:07 +00:00
Zac Bergquist 2ae9d770fc Refactor tctl's dependencies (#22693)
* Move configuration from lib/service to lib/service/servicecfg

The new servicecfg package will hold only configuration for services.
This will allow other packages (like tctl and tsh) to depend on
servicecfg without pulling in all of lib/service (which has a number
of platform-specific details).

This is the first step towards being able to build tctl for Windows.

* Move PAM and BPF config into servicecfg

This breaks a compile-time dependency on BPF/PAM for tctl.
2023-03-09 17:48:36 +00:00
Tiago Silva ddd1055552 fix tctl auth sign --format kubernetes when using remote auth server (#20497)
This PR fixes `tctl auth sign --format kubernetes`  when used with remote auth servers running with multiplex mode.

Fixes #20499
2023-01-23 19:02:42 +00:00
Tiago Silva 2c2510345f Allow users to merge multiple clusters in the same kubeconfig file when using tctl auth sign --format kubernetes (#18475)
When using `tctl auth sign --format kubernetes`, `tctl` only allowed a single cluster per `kubeconfig`.

This PR allows `tctl` to multiple calls of `tctl auth sign --format kubernetes` to be written to the same file without destroying previously introduced changes.

Fixes #18080
2022-11-16 17:42:59 +00:00
Marek Smoliński a60174cc4f Fix tctl auth sign call for Snowflake in trusted clusters env (#17263) 2022-10-12 11:28:38 +02:00
Brian Joerger 3a5a285883 Generalize private keys in tsh (PIV integration) (#15334)
Primary Changes:
 - Remove reliance on Private Key PEM:
 - Update native and keygen packages to return PrivateKey instead of PEM key
 - Add new PrivateKey interface which implements crypto.Signer
 - Replace PEM encoded private key usage where possible
 - Replace calls to tls.(Load)X509KeyPair with keys.(Load)X509KeyPair in
client packages

Minor Changes:
 - Remove unused agent.AddedKey return from LoadKey
 - Simplify sshutils and removed unused code paths
 - Add ecdsa and ed25519 key support
2022-08-25 23:26:44 +00:00
Anton Miniailo 1e5826d16c Make tctl auth sign to write out kube TLS server name if TLS routing is enabled (#15536)
* Make tctl write out kube tls server name if tls routing is enabled

Fixes #14489

* Extract kube TLS name generation function to shareable location

We want tctl to be able to use this function as well, so we're locating it
in a place where both tctl and tsh can use it.
Also changing input parameter to k8s host, since it doesn't really care
 about port number.
2022-08-17 22:36:51 +00: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 306d011151 Deprecate ca_signature_algo config (#13033)
After the merge of https://github.com/gravitational/teleport/pull/12674 we no longer use the following configuration:
```yaml
teleport:
    ca_signature_algo: "rsa-sha2-512"
```
As we now rely upon the `x/crypto` package to choose the signing algorithm (it defaults to `rsa-sha2-512`)

**Demo**
If we set `ca_signature_algo` (the value is irrelevant) and start `teleport` we get:
```shell
root@marco:/workspace# teleport start --debug
2022-06-02T09:33:58Z WARN             ca_signing_algo config option is deprecated and will be ignored, we'll always default to rsa-sha2-512. config/configuration.go:348
2022-06-02T09:33:58Z INFO             Generating new host UUID: b001159a-10e0-49a7-b4dc-61c73fbe9e42. service/service.go:726
...
```

Fixes #12905
2022-06-06 16:18:15 +01:00
Gabriel Corado 6f971d1fb7 Generate database access credentials with tctl auth sign command (#10785)
* feat(tctl): sign command to generate database access credentials

* feat(tctl): make auth sign parameters app-name and db-name mutually exclusive

* feat(tctl): add flag db-user to auth sign command

* test(tctl): remove references to deprecated package ioutil

* test(tctl): update test to check error type

* chore(tctl): add godoc to `getDatabaseServer` function

* refactor(tctl): rename database-related flags in auth sign

* refactor(tctl): rename flag from `db` to `db-service`
2022-04-04 18:21:23 +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
rosstimothy 550d23d15d Fix goroutine and memory leak in watchCertAuthorities (#10871)
* Fix goroutine and memory leak in watchCertAuthorities

The CA Watcher was blocking both on writing to a channel when the watcher
was closed and on HTTP calls that had no request timeout or context passed
to cause cancellation.

All resourceWatcher implementations that had a bug which may cause them to block
on writing to a channel forever were fixed by selecting on the write and ctx.Done.

Adding context.Context to all Get/Put/Post/Delete methods on the auth HTTPClient to
force callers to propagate context. Prior all calls used context.TODO which
prevents requests from being properly cancelled.

Add context propagation to RotateCertAuthority, RotateExternalCertAuthority,
GetCertAuthority, GetCertAuthorities. This is needed to get the correct ctx
from the CertAtuhorityWatcher all the way down to the HTTPClient that makes
the call.

Closes #10648
2022-03-10 11:05:39 -05:00
Vitor Enes f314e59ad2 Default to https scheme for --proxy argument in tctl auth sign (#10844)
Before this commit, if `--proxy` was set, it would be passed as it to the kubeconfig file. Due to this, if the `--proxy` URL did not have a scheme, it would default to `http`,  leading to the issue reported in https://github.com/gravitational/cloud/issues/1358.

With this commit, we now try to parse the `--proxy` URL and set its scheme to `https` in case it's not set.
In case it's set, we only allow `--proxy` URLs with the `http` and `https` schemes.
2022-03-07 10:04:53 +00:00
Jakub Nyckowski 75e24cbd54 Display correct error message when host is missing in tctl auth sign (#10588) 2022-02-28 15:22:51 -05:00
Marek Smoliński fbd5a2aafd Fix tsh tctl do not load all CAS (#9357) 2022-01-31 13:35:15 +01:00
Justinas StankevičiusandRoman Tkachenko bcafd5e671 tctl: allow issuing app access certificates via tctl auth sign (#8717)
* tctl auth sign: allow signing app certificates

* Test app cert issuance

* Factor out getApplicationServer

* Inline app session ID initialization

* Use deep struct assertion for RouteToApp

* Use proper context in getApplicationServer

Co-authored-by: Roman Tkachenko <roman@gravitational.com>

Co-authored-by: Roman Tkachenko <roman@gravitational.com>
2021-11-11 08:18:47 -08:00
Roman Tkachenko 36998cf566 Add CockroachDB support (#8505) 2021-10-12 14:30:59 -07:00
Roman Tkachenko 288c5519ce Accept multiple SANs in tctl auth sign for databases (#8449) 2021-10-05 16:00:28 -07:00
Alan Parra dba49bfad6 Lint and fix missing license headers (#8075)
Introduce new make targets to check and add license headers to files
("make lint-license" and "make fix-license"). License checking is now a part of
"make lint" as well.

Initial attempts used goheader, but it caused "make lint-go" to become about 9x
slower (if not more), plus it only targets go files. Google's addlicense is fast
enough and targets however many file types we want.

Existing files that were missing licenses got the header added, using the
current year as the license date.

* Introduce lint-license and fix-license make targets
* Ignore generated files
* Add license to go files
* Replace irregular licenses with standard copyright/license
* Add license to proto files
* Install addlicense in build.assets Dockerfile
2021-08-30 09:44:09 -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
Roman Tkachenko 0392dd86f7 Include O in MongoDB certs and improve some errors (#7575) 2021-07-19 11:17:33 -07:00
Brian Joerger bd07d7be20 CheckAndSetDefaults sets all defaults. (#6846) 2021-06-18 12:57:29 -07:00
Andrej Tokarčík d63d144e8e Move ClusterID field from ClusterConfig to ClusterName (#7050) 2021-06-18 18:42:09 +02:00
Andrew Lytvynov d4247cb150 hsm: migrate CA storage schema (#7245)
* hsm: migrate CA storage schema

Migrate types.CertAuthorityV2 schema according to
https://github.com/gravitational/teleport/blob/master/rfd/0025-hsm.md#backend-storage

Includes proto changes, types.CertAuthority wrapper changes and data
migration.

Note that we keep and update the old fields for backwards-compatibility.
If a cluster is upgraded to v7 and then downgraded back to v6,
everything should keep working.

* Address review feedback
2021-06-16 12:17:03 -05:00
Brian Joerger 7bff7c41bd Remove API aliases (#6983) 2021-06-04 13:29:31 -07:00
Andrew Lytvynov b092fa9143 When exporting a kubeconfig, overwrite the target file (#5297)
* When exporting a kubeconfig, optionally overwrite the target file

Running `tctl auth sign ---out=filepath` or `tsh login --out=filepath`
might overwrite the target `filepath` regardless of its existing
contents.

Make the tools prompt the user before overwriting (by default) and
provide a flag to always force the overwrite (for automation).

Without overwrites, writing kubeconfig could fail if parsing the
existing file as a kubeconfig fails.
2021-01-27 10:00:52 -08:00
Roman Tkachenko 8e1865464b Database access (#5005) 2021-01-14 18:21:38 -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
joerger f020f75078 Refactor API client into a separate package. 2020-12-29 10:06:37 -08:00
Andrew Lytvynov b16ad647b4 Kubernetes request routing and cluster registration (#4670)
This change has several parts: cluster registration, cache updates,
routing and a new tctl flag.

> cluster registration

Cluster registration means adding `KubernetesClusters` to `ServerSpec`
for servers with `KindKubeService`.

`kubernetes_service` instances will parse their kubeconfig or local
`kube_cluster_name` and add them to their `ServerSpec` sent to the auth
server. They are effectively declaring that "I can serve k8s requests
for k8s cluster X".

> cache updates

This is just cache plumbing for `kubernetes_service` presence, so that
other teleport processes can fetch all of kube services. It was missed
in the previous PR implementing CRUD for `kubernetes_service`.

> routing

Now the fun part - routing logic. This logic lives in
`/lib/kube/proxy/forwarder.go` and is shared by both `proxy_service`
(with kubernetes integration enabled) and `kubernetes_service`.

The target k8s cluster name is passed in the client cert, along with k8s
users/groups information.

`kubernetes_service` only serves requests for its direct k8s cluster
(from `Forwarder.creds`) and doesn't route requests to other teleport
instances.

`proxy_service` can serve requests:
- directly to a k8s cluster (the way it works pre-5.0)
- to a leaf teleport cluster (also same as pre-5.0, based on
  `RouteToCluster` field in the client cert)
- to a `kubernetes_service` (directly or over a tunnel)

The last two modes require the proxy to generate an ephemeral client TLS
cert to do an outbound mTLS connection.

> tctl flag

A flag `--kube-cluster-name` for `tctl auth sign --format=kubernetes`
which allows generating client certs for non-default k8s cluster name
(as long as it's registered in a cluster).
I used this for testing, but it could be used for automation too.
2020-11-09 19:40:02 +00:00
Chris Nelson 7719444579 --cluster renamed to --kube-cluster 2020-10-06 16:09:27 +00:00
Chris Nelson 10c40195b2 re-add tests in new format 2020-10-06 16:09:27 +00:00
Chris Nelson 42dbafe0c6 go fmt 2020-10-06 16:09:27 +00:00
Chris Nelson b47fed02b0 add test 2020-10-06 16:09:27 +00:00
Andrew Lytvynov 46a1321051 Use the correct k8s port in tctl auth sign --format=kubernetes
Previously, it used the public_addr of the proxy directly.
Now it parses it and replaces the port with k8s port.
2020-10-05 18:01:06 +00:00
Andrew Lytvynov a45f763305 Propagate CA certs when generating kubeconfig via tctl
`identityfile.Write` assumes that `key.TrustedCA` is populated when
writing a kubeconfig. It's where it takes the CA cert from.
`identityfile.Write` also, confusingly, had a separate `certAuthorities`
argument carrying the same information.

On `tctl auth sign --format=kubernetes --user=foo` we only populated the
`certAuthorities` argument, but not `key.TrustedCA`.

To fix this, and avoid future confusion, remote `certAuthorities`
arugment entirely and always pass CA certs via `key.TrustedCA`. Add a
happy path unit test to make sure it doesn't break in the future.

Also, improve error output a bit and make `--out` a required flag.
2020-06-26 17:55:38 +00:00