-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
identity: add spire identity client #2580
Merged
Merged
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c156aa2
identity: add spire identity client
zaharidichev 189c777
alter tests
zaharidichev d1665b3
move grpc client to app/src
zaharidichev 6b8120e
Merge branch 'main' into zd/add-spire-client
zaharidichev ba38986
address nits
zaharidichev 514e3f9
Merge branch 'main' into zd/add-spire-client
zaharidichev c9bdbb7
feedback from @olix0r
zaharidichev f3f0469
add test to verify that creds propagation fails when tls is Store is …
zaharidichev c2ca723
feedback
zaharidichev 27d4888
panic on error
zaharidichev cd3dcc5
do not emit proto package in client impl
zaharidichev a2ce50f
Merge branch 'main' into zd/add-spire-client
zaharidichev 3757c91
update lock file
zaharidichev a8620b3
spire: add required header to request
zaharidichev b07e30c
lint
zaharidichev f6e0e81
fix logging
zaharidichev 47f6887
Merge branch 'main' into zd/add-spire-client
zaharidichev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,67 @@ | ||
pub use linkerd_app_core::identity::spire_client; | ||
use linkerd_app_core::{exp_backoff::ExponentialBackoff, Error}; | ||
use std::sync::Arc; | ||
use tokio::net::UnixStream; | ||
use tokio::sync::watch; | ||
use tonic::transport::{Endpoint, Uri}; | ||
|
||
const UNIX_PREFIX: &str = "unix:"; | ||
const TONIC_DEFAULT_URI: &str = "http://[::]:50051"; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Config { | ||
pub(crate) socket_addr: Arc<String>, | ||
pub(crate) backoff: ExponentialBackoff, | ||
} | ||
|
||
// Connects to SPIRE workload API via Unix Domain Socket | ||
pub struct Client { | ||
config: Config, | ||
} | ||
|
||
// === impl Client === | ||
|
||
impl From<Config> for Client { | ||
fn from(config: Config) -> Self { | ||
Self { config } | ||
} | ||
} | ||
|
||
impl tower::Service<()> for Client { | ||
type Response = tonic::Response<watch::Receiver<spire_client::SvidUpdate>>; | ||
type Error = Error; | ||
type Future = futures::future::BoxFuture<'static, Result<Self::Response, Self::Error>>; | ||
|
||
fn poll_ready( | ||
&mut self, | ||
_cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<Result<(), Self::Error>> { | ||
std::task::Poll::Ready(Ok(())) | ||
} | ||
|
||
fn call(&mut self, _req: ()) -> Self::Future { | ||
let socket = self.config.socket_addr.clone(); | ||
let backoff = self.config.backoff; | ||
Box::pin(async move { | ||
// Strip the 'unix:' prefix for tonic compatibility. | ||
let stripped_path = socket | ||
.strip_prefix(UNIX_PREFIX) | ||
.unwrap_or(socket.as_str()) | ||
.to_string(); | ||
|
||
// We will ignore this uri because uds do not use it | ||
// if your connector does use the uri it will be provided | ||
// as the request to the `MakeConnection`. | ||
let chan = Endpoint::try_from(TONIC_DEFAULT_URI)? | ||
.connect_with_connector(tower::util::service_fn(move |_: Uri| { | ||
UnixStream::connect(stripped_path.clone()) | ||
})) | ||
.await?; | ||
|
||
let api = spire_client::Api::watch(chan, backoff); | ||
let receiver = api.spawn_watch(()).await?; | ||
|
||
Ok(receiver) | ||
}) | ||
} | ||
} |
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,27 @@ | ||
[package] | ||
name = "linkerd-proxy-spire-client" | ||
version = "0.1.0" | ||
authors = ["Linkerd Developers <[email protected]>"] | ||
license = "Apache-2.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
futures = { version = "0.3", default-features = false } | ||
linkerd-error = { path = "../../error" } | ||
linkerd-proxy-http = { path = "../../proxy/http" } | ||
linkerd-identity = { path = "../../identity" } | ||
spiffe-proto = { path = "../../../spiffe-proto" } | ||
linkerd-tonic-watch = { path = "../../tonic-watch" } | ||
linkerd-exp-backoff = { path = "../../exp-backoff" } | ||
linkerd-stack = { path = "../../stack" } | ||
tokio = { version = "1", features = ["time", "sync"] } | ||
tonic = "0.10" | ||
tower = "0.4" | ||
tracing = "0.1" | ||
x509-parser = "0.15.1" | ||
asn1 = { version = "0.6", package = "simple_asn1" } | ||
|
||
[dev-dependencies] | ||
rcgen = "0.11.3" | ||
tokio-test = "0.4" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to move this into the Provider type to avoid having redundant enums?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used in the
App
, here. It was returning acontrol::ControlAddr
before.