-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of the filter that will route packets to Endpoints that have a matching connection_id to the auth token found in the dynamic metadata. Closes #8
- Loading branch information
1 parent
cc5dafc
commit 1636934
Showing
10 changed files
with
491 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# EndpointAuthentication | ||
|
||
The `EndpointAuthentication` filter's job is to ensure only authorised clients are able to send packets to Endpoints that | ||
they have access to. | ||
|
||
It does this via matching an authentication token found in the | ||
[Filter dynamic metadata]`(TODO: add link to dynamic metadata docs)`, and comparing it to Endpoint's connection_id | ||
values, and only letting packets through to those Endpoints if there is a match. | ||
|
||
Capturing the authentication token from an incoming packet can be implemented via the [CaptureByte](./capture_bytes.md) | ||
filter, with an example outlined below, or any other filter that populates the configured dynamic metadata key for the | ||
authentication token to reside. | ||
|
||
On the game client side the [ConcatenateBytes](./concatenate_bytes.md) filter can be used to add authentication tokens | ||
to outgoing packets. | ||
|
||
#### Filter name | ||
```text | ||
quilkin.extensions.filters.endpoint_authentication.v1alpha1.EndpointAuthentication | ||
``` | ||
|
||
### Configuration Examples | ||
```rust | ||
# let yaml = " | ||
local: | ||
port: 7000 | ||
filters: | ||
- name: quilkin.extensions.filters.capture_bytes.v1alpha1.CaptureBytes # This filter is often used in conjunction to capture the authentication token | ||
config: | ||
metadataKey: myapp.com/myownkey | ||
size: 3 | ||
remove: true | ||
- name: quilkin.extensions.filters.endpoint_authentication.v1alpha1.EndpointAuthentication | ||
config: | ||
metadataKey: myapp.com/myownkey | ||
server: | ||
endpoints: | ||
- name: Game Server No. 1 | ||
address: 127.0.0.1:26000 | ||
connection_ids: | ||
- MXg3aWp5Ng== # Authentication is provided by these ids, and matched against | ||
- OGdqM3YyaQ== # the value stored in Filter dynamic metadata | ||
- name: Game Server No. 2 | ||
address: 127.0.0.1:26001 | ||
connection_ids: | ||
- bmt1eTcweA== | ||
# "; | ||
# let config = quilkin::config::Config::from_reader(yaml.as_bytes()).unwrap(); | ||
# assert_eq!(config.filters.len(), 2); | ||
# quilkin::proxy::Builder::from(std::sync::Arc::new(config)).validate().unwrap(); | ||
``` | ||
|
||
View the [CaptureBytes](./capture_bytes.md) filter documentation for more details. | ||
|
||
### Configuration Options | ||
|
||
```yaml | ||
properties: | ||
metadataKey: | ||
type: string | ||
default: quilkin.dev/captured_bytes | ||
description: | | ||
The key under which the captured bytes are stored in the Filter invocation values. | ||
``` | ||
### Metrics | ||
* `quilkin_filter_EndpointAuthentication_packets_dropped` | ||
A counter of the total number of packets that have been dropped as they could not be authenticated against an | ||
Endpoint. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2020 Google LLC All Rights Reserved. | ||
* | ||
* 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 prometheus::core::{AtomicI64, GenericCounter}; | ||
use prometheus::Result as MetricsResult; | ||
use prometheus::{IntCounter, Registry}; | ||
|
||
use crate::metrics::{filter_opts, CollectorExt}; | ||
|
||
/// Register and manage metrics for this filter | ||
pub(super) struct Metrics { | ||
pub(super) packets_dropped_total: GenericCounter<AtomicI64>, | ||
} | ||
|
||
impl Metrics { | ||
pub(super) fn new(registry: &Registry) -> MetricsResult<Self> { | ||
Ok(Metrics { | ||
packets_dropped_total: IntCounter::with_opts(filter_opts( | ||
"packets_dropped", | ||
"EndpointAuthentication", | ||
"Total number of packets dropped due to invalid connection_id values.", | ||
))? | ||
.register(registry)?, | ||
}) | ||
} | ||
} |
Oops, something went wrong.