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

Move authentication logic out of the daphne crate #682

Merged
merged 3 commits into from
Oct 4, 2024

Conversation

mendess
Copy link
Collaborator

@mendess mendess commented Sep 18, 2024

Proposed changes:

remove any notion of authentication from crates/daphne

This results in:

  • DapAggregator::unauthorized_reason being removed
  • the generic parameter in DapRequest to be removed which in turn
  • causes the DapAggregator, DapLeader and DapHelper generic parameters to also be removed.
  • tests in this crate also no longer need to care about authentication, this can be seen in crates/daphne/src/roles/mod.rs, crates/daphne/src/taskprov.rs and crates/daphne/src/testing/mod.rs

Most of the diff in this PR is just removing the generic parameter from all these types

in crates/daphne-server

Introduce a new method to the DaphneService trait called check_bearer_token which can be used in the DapRequestExtractor to guarantee that all requests that are parsed by it are authenticated. A new UnauthenticatedDapRequestExtractor is also included for the cases where we want a DapRequest but don't want to require authentication. Which is the case for upload requests.

misc changes

handle_hpke_config_req no longer requires a full DapRequest as it only needs the DapVersion

Breaking API change

Unauthorized requests to the helper no longer produce DapAbort::UnauthorizedRequest, this is because this error requires a TaskId but the task_id is an optional in the DapRequest. I could make the task_id optional in UnauthorizedRequest but I believe the task_id in DapRequest should not be optional at all. This will be fixed in a future PR

@mendess mendess self-assigned this Sep 18, 2024
@mendess mendess marked this pull request as draft September 18, 2024 17:23
@mendess mendess force-pushed the mendess/take-auth-out-of-daphne branch 9 times, most recently from 614b827 to 831b84f Compare September 20, 2024 14:01
@mendess mendess marked this pull request as ready for review September 20, 2024 14:23
Copy link
Contributor

@cjpatton cjpatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decoupling authorization logic from the daphne crate is a good idea. But if we're taking the time to rework this code, I think we should try to think ahead to how we'd build a multitenant service.

crates/daphne-server/examples/configuration-helper.toml Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
@mendess
Copy link
Collaborator Author

mendess commented Sep 23, 2024

Decoupling authorization logic from the daphne crate is a good idea. But if we're taking the time to rework this code, I think we should try to think ahead to how we'd build a multitenant service.

designing for multi-tenancy is not an easy task and depends a lot on how the system is deployed. I believe the best way to design for multi-tenancy in this case is to not design at all. Our internal implementation already has some semblance of multi tenancy going on and it doesn't depend on this implementation to implement it

crates/daphne-server/src/roles/mod.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/roles/aggregator.rs Show resolved Hide resolved
@mendess mendess force-pushed the mendess/take-auth-out-of-daphne branch 3 times, most recently from 21d2e20 to b3de0a2 Compare September 30, 2024 17:39
crates/daphne-server/examples/configuration-helper.toml Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/roles/leader.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/roles/leader.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/roles/leader.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/roles/leader.rs Outdated Show resolved Hide resolved
@mendess mendess force-pushed the mendess/take-auth-out-of-daphne branch 2 times, most recently from 984e278 to 3081ded Compare October 1, 2024 09:07
@mendess mendess force-pushed the mendess/take-auth-out-of-daphne branch 3 times, most recently from 609bda2 to 7e1e246 Compare October 1, 2024 10:37
@mendess
Copy link
Collaborator Author

mendess commented Oct 1, 2024

One of the intentions of this PR is to distance taskprov from authentication. There are two methods by which an aggregator can determine if the request it receives is authorized:

  • static: defined in configuration, this allows for just one token (see peer_auth)
  • dynamic: stored in kv mapping (Role, TaskId) pairs to a token (see bearer_tokens)

@cjpatton
Copy link
Contributor

cjpatton commented Oct 1, 2024

One of the intentions of this PR is to distance taskprov from authentication. There are two methods by which an aggregator can determine if the request it receives is authorized:

* static: defined in configuration, this allows for just one token (see [peer_auth](https://github.com/cloudflare/daphne/blob/62036ff253606d661ad35e04c54ea28f1e50f90d/crates/daphne-service-utils/src/config.rs#L58))

* dynamic: stored in kv mapping (Role, TaskId) pairs to a token (see [bearer_tokens](https://github.com/cloudflare/daphne/blob/62036ff253606d661ad35e04c54ea28f1e50f90d/crates/daphne-server/src/roles/mod.rs#L42))

It's a good goal to decouple authentication logic from protocol logic, including taskprov, but I don't think this is the correct way to do it. What this is PR is missing is a notion of "task ownership". Right now whoever knows the peer_auth token has access to all tasks, not necessarily those it has configured. For example, a task we configure manually can be executed by the peer_auth token holder. I don't think this is what we want.

The current code has a notion of a "taskprov owner", who has access to all tasks (and only those tasks) configured via taskprov. On the other hand, it can't access a manually configured task unless it knows the bearer token for that task.

@mendess mendess requested a review from cjpatton October 1, 2024 15:08
@mendess mendess force-pushed the mendess/take-auth-out-of-daphne branch 2 times, most recently from 90e2ba1 to 6ff2f1d Compare October 1, 2024 17:26
Copy link
Contributor

@cjpatton cjpatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall. I believe there's one last authentication bug: if the peer presents a valid TLS certificate, it gets access to any task. Mutual TLS is only meant to be available for the taskprov owner at the moment.

.github/workflows/daphneci.yml Show resolved Hide resolved
crates/daphne-server/src/lib.rs Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/lib.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/router/mod.rs Show resolved Hide resolved
crates/daphne-server/src/router/mod.rs Outdated Show resolved Hide resolved
crates/daphne-service-utils/src/config.rs Outdated Show resolved Hide resolved
crates/daphne-service-utils/src/config.rs Outdated Show resolved Hide resolved
crates/daphne-service-utils/src/config.rs Outdated Show resolved Hide resolved
@mendess mendess force-pushed the mendess/take-auth-out-of-daphne branch 4 times, most recently from 24255a4 to 90d60cd Compare October 3, 2024 10:05
@mendess mendess requested a review from cjpatton October 3, 2024 11:11
Copy link
Contributor

@cjpatton cjpatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a few more small things, so here's an early 🦆 .

{
Ok(())
}
_ => reject(format_args!("using taskprov")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: If we don't match the first arm because the tokens don't match, then that's an authentication failure. If we don't match because we have a PeerBearerToken::Leader { .. } but a DapSender::Collector, then that's a bug, correct? It might be useful to handle the bug as a fatal error rather than an authentication failure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense. It's likely a configuration error

crates/daphne-server/src/roles/leader.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/roles/leader.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/roles/leader.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/router/mod.rs Outdated Show resolved Hide resolved
crates/daphne-server/src/router/mod.rs Outdated Show resolved Hide resolved
@mendess mendess force-pushed the mendess/take-auth-out-of-daphne branch from 90d60cd to b4bc6fd Compare October 3, 2024 15:46
@mendess mendess force-pushed the mendess/take-auth-out-of-daphne branch from b4bc6fd to 529e136 Compare October 3, 2024 15:48
@mendess mendess merged commit 11d8f3a into main Oct 4, 2024
4 checks passed
@mendess mendess deleted the mendess/take-auth-out-of-daphne branch October 4, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants