forked from istio/ztunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentity.rs
63 lines (56 loc) · 1.91 KB
/
identity.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::tls;
use std::str::Utf8Error;
use std::sync::Arc;
mod caclient;
pub use caclient::*;
pub mod manager;
pub use manager::*;
mod auth;
use crate::state::WorkloadInfo;
pub use auth::*;
#[cfg(any(test, feature = "testing"))]
pub mod mock {
pub use super::caclient::mock::CaClient;
pub use super::manager::mock::{
new_secret_manager, new_secret_manager_cfg, Config as SecretManagerConfig,
};
}
#[derive(thiserror::Error, Debug, Clone)]
pub enum Error {
#[error("failed to create CSR: {0}")]
Signing(Arc<tls::Error>),
#[error("signing gRPC error ({}): {}", .0.code(), .0.message())]
SigningRequest(#[from] Box<tonic::Status>),
#[error("failed to process string: {0}")]
Utf8(#[from] Utf8Error),
#[error("did not find expected SAN: {0}")]
SanError(Identity),
#[error("chain returned from CA is empty for: {0}")]
EmptyResponse(Identity),
#[error("invalid spiffe identity: {0}")]
Spiffe(String),
#[error("workload is unknown: {0}")]
UnknownWorkload(Arc<WorkloadInfo>),
#[error("the identity is no longer needed")]
Forgotten,
#[error("BUG: identity requested {0}, but only allowed {1:?}")]
BugInvalidIdentityRequest(Identity, Arc<WorkloadInfo>),
}
impl From<tls::Error> for Error {
fn from(value: tls::Error) -> Self {
Error::Signing(Arc::new(value))
}
}