Skip to content

Commit 7fa0a9a

Browse files
committed
Use upstream rust-spiffe dependency
Also add a feature for the SPIFFE authenticator, activated by default. Signed-off-by: Hugues de Valon <[email protected]>
1 parent 0cf2993 commit 7fa0a9a

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Executing our tests on Arm64 with Travis CI
2+
dist: focal
23
arch: arm64
34
language: rust
5+
before_script:
6+
- sudo apt-get update && sudo apt-get -y install pkg-config libssl-dev
47
script:
58
- ./tests/ci.sh

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ log = "0.4.11"
1919
derivative = "2.1.1"
2020
zeroize = "1.1.0"
2121
users = "0.10.0"
22-
spiffe = { path = "../../rust-spiffe/spiffe" }
22+
spiffe = { git = "https://github.com/hug-dev/rust-spiffe", branch = "refactor-jwt", optional = true }
2323

2424
[dev-dependencies]
2525
mockstream = "0.0.3"
2626

2727
[features]
28+
default = ["spiffe-auth"]
29+
spiffe-auth = ["spiffe"]
2830
testing = ["parsec-interface/testing"]

src/auth.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// Copyright 2020 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
33
//! Client app authentication data
4-
use crate::error::{ClientErrorKind, Error, Result};
5-
use log::error;
4+
use crate::error::{Error, Result};
65
use parsec_interface::requests::{request::RequestAuth, AuthType};
7-
use spiffe::workload::jwt::JWTClient;
86
use std::convert::TryFrom;
9-
use std::env;
107

118
/// Authentication data used in Parsec requests
129
#[derive(Clone, Debug)]
@@ -27,6 +24,7 @@ pub enum Authentication {
2724
/// Authentication using JWT SVID tokens. The will fetch its JWT-SVID and pass it in the
2825
/// Authentication field. The socket endpoint is found through the SPIFFE_ENDPOINT_SOCKET
2926
/// environment variable.
27+
#[cfg(feature = "spiffe-auth")]
3028
JwtSvid,
3129
}
3230

@@ -37,6 +35,7 @@ impl Authentication {
3735
Authentication::None => AuthType::NoAuth,
3836
Authentication::Direct(_) => AuthType::Direct,
3937
Authentication::UnixPeerCredentials => AuthType::UnixPeerCredentials,
38+
#[cfg(feature = "spiffe-auth")]
4039
Authentication::JwtSvid => AuthType::JwtSvid,
4140
}
4241
}
@@ -53,7 +52,13 @@ impl TryFrom<&Authentication> for RequestAuth {
5352
let current_uid = users::get_current_uid();
5453
Ok(RequestAuth::new(current_uid.to_le_bytes().to_vec()))
5554
}
55+
#[cfg(feature = "spiffe-auth")]
5656
Authentication::JwtSvid => {
57+
use crate::error::ClientErrorKind;
58+
use log::error;
59+
use spiffe::workload::jwt::JWTClient;
60+
use std::env;
61+
5762
let client = JWTClient::new(
5863
&env::var("SPIFFE_ENDPOINT_SOCKET").map_err(|e| {
5964
error!(
@@ -63,10 +68,11 @@ impl TryFrom<&Authentication> for RequestAuth {
6368
Error::Client(ClientErrorKind::NoAuthenticator)
6469
})?,
6570
None,
71+
None,
6672
);
6773
let audience = String::from("parsec");
6874

69-
let result = client.fetch(audience, None).map_err(|e| {
75+
let result = client.fetch(audience).map_err(|e| {
7076
error!("Error while fetching the JWT-SVID ({}).", e);
7177
Error::Client(ClientErrorKind::Spiffe(e))
7278
})?;
@@ -84,6 +90,7 @@ impl PartialEq for Authentication {
8490
(Authentication::Direct(app_name), Authentication::Direct(other_app_name)) => {
8591
app_name == other_app_name
8692
}
93+
#[cfg(feature = "spiffe-auth")]
8794
(Authentication::JwtSvid, Authentication::JwtSvid) => true,
8895
_ => false,
8996
}

src/core/basic_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ impl BasicClient {
258258
AuthType::UnixPeerCredentials => {
259259
self.auth_data = Authentication::UnixPeerCredentials
260260
}
261+
#[cfg(feature = "spiffe-auth")]
261262
AuthType::JwtSvid => self.auth_data = Authentication::JwtSvid,
262263
auth => {
263264
warn!(

src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub enum ClientErrorKind {
4343
/// Required parameter was not provided
4444
MissingParam,
4545
/// Error while using the SPIFFE Workload API
46+
#[cfg(feature = "spiffe-auth")]
4647
Spiffe(spiffe::workload::Error),
4748
}
4849

@@ -67,6 +68,7 @@ impl fmt::Display for ClientErrorKind {
6768
ClientErrorKind::NoProvider => write!(f, "client is missing an implicit provider"),
6869
ClientErrorKind::NoAuthenticator => write!(f, "service is not reporting any authenticators or none of the reported ones are supported by the client"),
6970
ClientErrorKind::MissingParam => write!(f, "one of the `Option` parameters was required but was not provided"),
71+
#[cfg(feature = "spiffe-auth")]
7072
ClientErrorKind::Spiffe(error) => error.fmt(f),
7173
}
7274
}

tests/ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set -euf -o pipefail
1313
################
1414
RUST_BACKTRACE=1 cargo build
1515
RUST_BACKTRACE=1 cargo build --features testing
16+
RUST_BACKTRACE=1 cargo build --no-default-features
1617

1718
#################
1819
# Static checks #

0 commit comments

Comments
 (0)