Skip to content
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

feat(inbound): Log traffic with the 'audit' policy #3068

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions linkerd/app/inbound/src/policy/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ pub fn cluster_unauthenticated(
)
}

pub fn audit(timeout: Duration) -> ServerPolicy {
mk(
"audit",
all_nets(),
Authentication::Unauthenticated,
timeout,
)
}

pub fn all_mtls_unauthenticated(timeout: Duration) -> ServerPolicy {
mk(
"all-tls-unauthenticated",
Expand Down
20 changes: 19 additions & 1 deletion linkerd/app/inbound/src/policy/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,25 @@ impl<T, N> HttpPolicyService<T, N> {
.iter()
.find(|a| super::is_authorized(a, self.connection.client, &self.connection.tls))
{
Some(authz) => authz,
Some(authz) => {
if authz.meta.is_audit() {
tracing::info!(
server.group = %labels.server.0.group(),
server.kind = %labels.server.0.kind(),
server.name = %labels.server.0.name(),
route.group = %labels.route.group(),
route.kind = %labels.route.kind(),
route.name = %labels.route.name(),
client.tls = ?self.connection.tls,
client.ip = %self.connection.client.ip(),
authz.group = %authz.meta.group(),
authz.kind = %authz.meta.kind(),
authz.name = %authz.meta.name(),
"Request allowed",
);
}
authz
}
None => {
tracing::info!(
server.group = %labels.server.0.group(),
Expand Down
13 changes: 13 additions & 0 deletions linkerd/app/inbound/src/policy/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ fn check_authorized(
{
for authz in &**authzs {
if super::is_authorized(authz, client_addr, tls) {
if authz.meta.is_audit() {
tracing::info!(
server.group = %server.meta.group(),
server.kind = %server.meta.kind(),
server.name = %server.meta.name(),
client.tls = ?tls,
client.ip = %client_addr.ip(),
authz.group = %authz.meta.group(),
authz.kind = %authz.meta.kind(),
authz.name = %authz.meta.name(),
"Request allowed",
);
}
return Ok(ServerPermit::new(dst, server, authz));
}
}
Expand Down
2 changes: 2 additions & 0 deletions linkerd/app/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,8 @@ fn parse_default_policy(
)
.into()),

"audit" => Ok(inbound::policy::defaults::audit(detect_timeout).into()),

name => Err(ParseError::InvalidPortPolicy(name.to_string())),
}
}
Expand Down
4 changes: 4 additions & 0 deletions linkerd/proxy/server-policy/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ impl Meta {
Self::Resource { group, .. } => group,
}
}

pub fn is_audit(&self) -> bool {
self.kind() == "default" && self.name() == "audit"
olix0r marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl std::cmp::PartialEq for Meta {
Expand Down
Loading