Skip to content

Commit 6931913

Browse files
feat(secret-providers): vault provider (#1450)
* feat: secrets provider module * feat: Add retry mechanism for Secrets * feat: Add vault SecretProvider --------- Co-authored-by: Daniel Orihuela Rodriguez <dorihuela@newrelic.com> Co-authored-by: danielorihuela <danielorihuela@users.noreply.github.com>
1 parent 62f843a commit 6931913

File tree

15 files changed

+971
-10
lines changed

15 files changed

+971
-10
lines changed

Cargo.lock

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

THIRD_PARTY_NOTICES.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,12 @@ Distributed under the following license(s):
22252225

22262226
* MIT
22272227

2228+
## tokio-tungstenite <https://crates.io/crates/tokio-tungstenite>
2229+
2230+
Distributed under the following license(s):
2231+
2232+
* MIT
2233+
22282234
## tokio-util <https://crates.io/crates/tokio-util>
22292235

22302236
Distributed under the following license(s):
@@ -2330,6 +2336,13 @@ Distributed under the following license(s):
23302336

23312337
* MIT
23322338

2339+
## tungstenite <https://crates.io/crates/tungstenite>
2340+
2341+
Distributed under the following license(s):
2342+
2343+
* MIT
2344+
* Apache-2.0
2345+
23332346
## typenum <https://crates.io/crates/typenum>
23342347

23352348
Distributed under the following license(s):
@@ -2397,6 +2410,13 @@ Distributed under the following license(s):
23972410
* MIT
23982411
* Apache-2.0
23992412

2413+
## utf-8 <https://crates.io/crates/utf-8>
2414+
2415+
Distributed under the following license(s):
2416+
2417+
* MIT
2418+
* Apache-2.0
2419+
24002420
## utf8_iter <https://crates.io/crates/utf8_iter>
24012421

24022422
Distributed under the following license(s):

agent-control/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ wrapper_with_default = { path = "../wrapper_with_default" }
4646
resource-detection = { path = "../resource-detection" }
4747

4848
# K8S subagent dependencies
49-
kube = { version = "1.1.0", features = ["runtime", "derive"] }
49+
kube = { version = "1.1.0", features = ["runtime", "derive", "ws"] }
5050
k8s-openapi = { version = "0.25.0", features = ["v1_30"] }
5151
either = { version = "1.15.0" }
5252

@@ -76,6 +76,7 @@ opentelemetry-appender-tracing = { version = "0.30.1", features = [
7676
] }
7777
async-trait = "0.1.86"
7878

79+
7980
[dev-dependencies]
8081
assert_cmd = { workspace = true }
8182
predicates = { workspace = true }
@@ -99,6 +100,7 @@ futures = "0.3.31"
99100
rcgen = { version = "0.14.0", features = ["crypto"] }
100101
rustls-pemfile = { version = "2.2.0" }
101102
rstest = "0.25.0"
103+
tokio-stream = { version = "0.1.17", features = ["net"] }
102104

103105
[build-dependencies]
104106
glob = "0.3.2"

agent-control/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test/k8s/integration-part1:
4848
.PHONY: test/k8s/integration-part2
4949
test/k8s/integration-part2:
5050
KUBECONFIG='./tests/k8s/.kubeconfig-dev' minikube update-context
51-
tilt ci --file ./tests/k8s/Tiltfile
51+
ENABLE_VAULT=true tilt ci --file ./tests/k8s/Tiltfile
5252
# reducing the number of threads to 1 forces the tests to run sequentially
5353
# We use this approach to split the k8s tests into two parts. We need to update it if this takes too long to run.
5454
cargo test k8s_ -- --skip k8s::scenarios --skip k8s::agent_control_cli --nocapture --ignored --test-threads=1

agent-control/src/agent_control/config.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::k8s::client::ClientConfig;
99
use crate::opamp::auth::config::AuthConfig;
1010
use crate::opamp::remote_config::OpampRemoteConfigError;
1111
use crate::opamp::remote_config::validators::signature::validator::SignatureValidatorConfig;
12+
use crate::secrets_provider::SecretsProvidersConfig;
1213
use crate::values::yaml_config::YAMLConfig;
1314
use crate::{
1415
agent_type::agent_type_id::AgentTypeID, instrumentation::config::InstrumentationConfig,
@@ -36,9 +37,7 @@ pub struct AgentControlConfig {
3637
/// fleet_control contains the OpAMP client configuration
3738
pub fleet_control: Option<OpAMPClientConfig>,
3839

39-
// We could make this field available only when #[cfg(feature = "k8s")] but it would over-complicate
40-
// the struct definition and usage. Making it optional should work no matter what features are enabled.
41-
/// k8s is a map containing the kubernetes-specific settings
40+
/// kubernetes-specific settings
4241
#[serde(default)]
4342
pub k8s: Option<K8sConfig>,
4443

@@ -60,6 +59,10 @@ pub struct AgentControlConfig {
6059
/// A "key-value store" intended to modify agent type definitions, loaded at start time.
6160
#[serde(default)]
6261
pub agent_type_var_constraints: VariableConstraints,
62+
63+
/// configuration for every secrets provider that the current AgentControl instance should be able to access
64+
#[serde(default)]
65+
pub secrets_providers: Option<SecretsProvidersConfig>,
6366
}
6467

6568
#[derive(Error, Debug)]

agent-control/src/agent_control/run/k8s.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::agent_control::AgentControl;
2-
use crate::agent_control::config::K8sConfig;
2+
use crate::agent_control::config::{AgentControlConfigError, K8sConfig};
33
use crate::agent_control::config_repository::repository::AgentControlConfigLoader;
44
use crate::agent_control::config_repository::store::AgentControlConfigStore;
55
use crate::agent_control::config_validator::RegistryDynamicConfigValidator;
@@ -23,6 +23,7 @@ use crate::opamp::instance_id::k8s::getter::{Identifiers, get_identifiers};
2323
use crate::opamp::operations::build_opamp_with_channel;
2424
use crate::opamp::remote_config::validators::SupportedRemoteConfigValidator;
2525
use crate::opamp::remote_config::validators::regexes::RegexValidator;
26+
use crate::secrets_provider::SecretsProvidersRegistry;
2627
use crate::sub_agent::effective_agents_assembler::LocalEffectiveAgentsAssembler;
2728
use crate::sub_agent::identity::AgentIdentity;
2829
use crate::sub_agent::k8s::builder::SupervisorBuilderK8s;
@@ -132,10 +133,21 @@ impl AgentControlRunner {
132133
let template_renderer = TemplateRenderer::default()
133134
.with_agent_control_variables(agent_control_variables.clone().into_iter());
134135

136+
let secrets_providers = if let Some(config) = &agent_control_config.secrets_providers {
137+
SecretsProvidersRegistry::try_from(config.clone()).map_err(|e| {
138+
AgentError::ConfigResolve(AgentControlConfigError::Load(format!(
139+
"Failed to load secrets providers: {e}"
140+
)))
141+
})?
142+
} else {
143+
HashMap::default()
144+
};
145+
135146
let agents_assembler = Arc::new(LocalEffectiveAgentsAssembler::new(
136147
self.agent_type_registry.clone(),
137148
template_renderer,
138149
self.agent_type_var_constraints,
150+
secrets_providers,
139151
));
140152

141153
let supervisor_builder =

agent-control/src/agent_control/run/on_host.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::agent_control::AgentControl;
2+
use crate::agent_control::config::AgentControlConfigError;
23
use crate::agent_control::config_repository::repository::AgentControlConfigLoader;
34
use crate::agent_control::config_repository::store::AgentControlConfigStore;
45
use crate::agent_control::config_validator::RegistryDynamicConfigValidator;
@@ -23,6 +24,7 @@ use crate::opamp::instance_id::on_host::storer::Storer;
2324
use crate::opamp::operations::build_opamp_with_channel;
2425
use crate::opamp::remote_config::validators::SupportedRemoteConfigValidator;
2526
use crate::opamp::remote_config::validators::regexes::RegexValidator;
27+
use crate::secrets_provider::SecretsProvidersRegistry;
2628
use crate::sub_agent::effective_agents_assembler::LocalEffectiveAgentsAssembler;
2729
use crate::sub_agent::identity::AgentIdentity;
2830
use crate::sub_agent::on_host::builder::SupervisortBuilderOnHost;
@@ -139,10 +141,21 @@ impl AgentControlRunner {
139141
)
140142
.with_agent_control_variables(agent_control_variables.clone().into_iter());
141143

144+
let secrets_providers = if let Some(config) = &agent_control_config.secrets_providers {
145+
SecretsProvidersRegistry::try_from(config.clone()).map_err(|e| {
146+
AgentError::ConfigResolve(AgentControlConfigError::Load(format!(
147+
"Failed to load secrets providers: {e}"
148+
)))
149+
})?
150+
} else {
151+
HashMap::default()
152+
};
153+
142154
let agents_assembler = Arc::new(LocalEffectiveAgentsAssembler::new(
143155
self.agent_type_registry.clone(),
144156
template_renderer,
145157
self.agent_type_var_constraints,
158+
secrets_providers,
146159
));
147160

148161
let supervisor_builder =

agent-control/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod http;
1515
pub mod instrumentation;
1616
pub mod k8s;
1717
pub mod opamp;
18+
pub mod secrets_provider;
1819
pub mod sub_agent;
1920
pub mod utils;
2021
pub mod values;

0 commit comments

Comments
 (0)