-
-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: kazk <[email protected]>
- Loading branch information
Showing
8 changed files
with
733 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use http::Uri; | ||
use hyper::client::HttpConnector; | ||
use k8s_openapi::api::core::v1::ConfigMap; | ||
use tower::ServiceBuilder; | ||
|
||
use kube::{ | ||
api::{Api, ListParams}, | ||
client::{ConfigExt, ProxyConnector}, | ||
Client, Config, | ||
}; | ||
|
||
/* | ||
// Need to set `client_certs` so that `mitmproxy` can make requests as an authorized user. | ||
// | ||
// Store client certs and key as PEM (adjust the query for your user): | ||
```bash | ||
kubectl config view \ | ||
--raw \ | ||
-o jsonpath='{.users[?(@.name == "admin@k3d-dev")].user.client-certificate-data}' \ | ||
| base64 -d \ | ||
> client-certs.pem | ||
kubectl config view \ | ||
--raw \ | ||
-o jsonpath='{.users[?(@.name == "admin@k3d-dev")].user.client-key-data}' \ | ||
| base64 -d \ | ||
>> client-certs.pem | ||
``` | ||
// `--ssl-insecure` is necessary because the API server uses self signed certificates: | ||
```bash | ||
mitmproxy -p 5000 --ssl-insecure --set client_certs=$(pwd)/client-certs.pem | ||
# or | ||
mitmweb -p 5000 --ssl-insecure --set client_certs=$(pwd)/client-certs.pem | ||
``` | ||
// After running this example, you should be able to inspect | ||
// `GET /api/v1/namespaces/default/configmaps` | ||
*/ | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
std::env::set_var("RUST_LOG", "trace"); | ||
// TODO Client should use ProxyConnector based on environment variables or proxy_url | ||
// std::env::set_var("HTTPS_PROXY", "http://localhost:5000"); | ||
tracing_subscriber::fmt::init(); | ||
|
||
let mut config = Config::infer().await?; | ||
config.accept_invalid_certs = true; | ||
let connector = { | ||
let tls = config.native_tls_connector()?; | ||
let mut http = HttpConnector::new(); | ||
http.enforce_http(false); | ||
let proxy_url = "http://localhost:5000".parse::<Uri>().unwrap(); | ||
ProxyConnector::native_tls(proxy_url, http, tls) | ||
}; | ||
|
||
let service = ServiceBuilder::new() | ||
.layer(config.base_uri_layer()) | ||
.layer(tower_http::trace::TraceLayer::new_for_http()) | ||
.service(hyper::Client::builder().build(connector)); | ||
let client = Client::new(service, config.default_namespace); | ||
|
||
let cms: Api<ConfigMap> = Api::namespaced(client, "default"); | ||
for cm in cms.list(&ListParams::default()).await? { | ||
println!("{:?}", cm); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.