Skip to content

Commit 832d4d4

Browse files
committed
feat(sftp): adding sftp support to the server
This commit allows *read* access to the files in a container via the `sftp` protocol which is implemented by `scp` among others. Additionally: - `ContainerExt.name_any` now matches the API that `ResourceExt` uses. - `Proc` allows for trivial execution on pods and receiving stdout/stderr. - `session::State` got moved into its own file. - `session::State` can now pass `Channel` around.
1 parent 68ae49a commit 832d4d4

File tree

15 files changed

+1088
-105
lines changed

15 files changed

+1088
-105
lines changed

Cargo.lock

+95
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ reqwest = { version = "0.12.7", features = ["json", "stream", "multipart"] }
5959
ringbuffer = "0.15.0"
6060
russh = "0.45.0"
6161
russh-keys = "0.45.0"
62+
russh-sftp = "2.0.3"
6263
schemars = { version = "0.8.21", features = ["chrono"] }
6364
serde = { version = "1.0.208", features = ["derive"] }
6465
serde_json = "1.0.124"
@@ -74,6 +75,7 @@ tracing = "0.1.40"
7475
tracing-error = { version = "0.2.0", features = ["traced-error"] }
7576
tracing-log = "0.2.0"
7677
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
78+
umask = "2.1.0"
7779
warp = "0.3.7"
7880

7981

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ You can:
1010

1111
- Get a shell in running pods - just like you would with SSH normally.
1212
- Access the logs for running and exited containers in a pod.
13+
- `scp` files from pods. sftp clients work as well.
1314

1415
![demo](./assets/demo.gif)
1516

@@ -45,14 +46,52 @@ You can:
4546
From this point, here's a few suggestions for things to check out:
4647

4748
- Start a new pod. It'll show up in the dashboard immediately!
49+
4850
- Exec into a pod. Select the pod you want and go to the `Shell` tab. You'll be
4951
able to pick the command to exec and then be shell'd into the pod directly.
52+
5053
- Follow the logs. Logs for all containers in a pod are streamed to the `Logs`
5154
tab when you've selected a pod from the main list.
5255

56+
- `scp` some files out of a container:
57+
58+
```bash
59+
scp -P 2222 me@localhost:/default/my-pod/etc/hosts /tmp
60+
```
61+
5362
[cli-download]: https://github.com/grampelberg/kuberift/releases
5463
[k3d]: https://k3d.io
5564

65+
## Interaction
66+
67+
### SSH
68+
69+
To get to the dashboard, you can run:
70+
71+
```bash
72+
ssh anything@my-remote-host-or-ip -p 2222
73+
```
74+
75+
As you're authenticated either via OpenID or public key, the username is not
76+
used.
77+
78+
### SFTP
79+
80+
The cluster is represented by a file tree:
81+
82+
```bash
83+
/<namespace>/<pod-name>/<container-name>/<file-path>
84+
```
85+
86+
For the `nginx` pod running in `default`, you would do something like:
87+
88+
```bash
89+
scp -P 2222 me@localhost:/default/nginx/nginx/etc/hosts /tmp
90+
```
91+
92+
It can be a little easier to navigate all this with an sftp client as that'll
93+
render the file tree natively for you.
94+
5695
## Deployment
5796

5897
The `kuberift` server needs access to your cluster's API server and credentials
@@ -241,6 +280,13 @@ the design decisions section for an explanation of what's happening there.
241280
- table_filter_total - Number of times a table was filtered.
242281
- widget_views_total - Number of times a widget was created by resource
243282
(container, pod) and type (cmd, log, yaml, ...).
283+
- requests_total - Number of requests that have come in by type (pty, sftp).
284+
- sftp_active_sessions - Total number of active sessions currently.
285+
- sftp_bytes_total - Total number of bytes transferred via sftp by direction
286+
(read, write).
287+
- sftp_files_total - Total number of files by direction (sent, received).
288+
- sftp_stat_total - Total number of times `stat` was called on a path.
289+
- sftp_list_total - Total number of times `list` was called on a path.
244290

245291
## Design Decisions
246292

TODO.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## TODO
1+
# TODO
2+
3+
## Authorization
24

35
- Groups are probably what most users are going to want to use to configure all
46
this. The closest to the OpenID spec would be via adding extra scopes that add
@@ -13,6 +15,31 @@
1315
handled in the provider backend and it is unclear how easy that'll be. It is
1416
possible in auth0, so I'll go down this route for now.
1517
18+
Note: it looks like Google might require addition verification to get the
19+
`groups()` scope "externally".
20+
21+
## TUI
22+
1623
- Is there a way to do FPS on a per-session basis with prometheus? Naively the
1724
way to do it would be to have a per-session label value, but that would be
1825
crazy for cardinality.
26+
27+
## SFTP
28+
29+
- Document that the permissions here are different than for the dashboard. You
30+
can get away with `get` and `exec` on ~everything as long as you use `scp`.
31+
Anything `sftp` is going to do a `readdir` and require `list`.
32+
- The API for `russh_sftp` feels nicer than the one for dashboard currently -
33+
hand off a channel entirely instead of dealing with `data()` to begin with.
34+
Should `Dashboard` get reimplemented to take something like
35+
`async Read + Write` instead? I think I didn't do it this way to being with
36+
because of writes being consumed entirely.
37+
- Allow globs in file paths, eg `/*/nginx**/etc/passwd`.
38+
- Return an error that is nicer than "no files found" when a container doesn't
39+
have cat/ls.
40+
41+
## SSH Functionality
42+
43+
- Allow `ssh` directly into a pod without starting the dashboard.
44+
- Enable `ssh -L` for forwarding requests _into_ a pod.
45+
- Enable `ssh -R` for forwarding a remote service _into_ a localhost.

src/identity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use k8s_openapi::api::authorization::v1::{
77
ResourceAttributes, SelfSubjectAccessReview, SelfSubjectAccessReviewSpec,
88
SubjectAccessReviewStatus,
99
};
10+
pub use key::Key;
1011
use kube::api::{Api, PostParams};
1112

1213
use crate::ssh::{Authenticate, Controller};

src/resources.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
pub mod age;
22
pub mod container;
3+
pub mod file;
34
pub mod pod;
45
pub mod store;
56

67
use color_eyre::Section;
78
use eyre::{eyre, Result};
9+
pub use file::File;
810
use futures::StreamExt;
911
use itertools::Itertools;
1012
use json_value_merge::Merge;

0 commit comments

Comments
 (0)