-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add HTTPS/TLS support to the auth proxy #2430
Add HTTPS/TLS support to the auth proxy #2430
Conversation
531bfe8
to
a2d8e6f
Compare
@jarhodes314 is the file transfer http service? Or are going to address that part in a different PR? |
Codecov Report
Additional details and impacted files
|
Not currently, although I should probably move some of the logic out of the auth proxy crate so it can be re-used there. Aside from some minor tweaks, this doesn’t contain anything new compared to #2397, it’s just a subset of that that should make merging the work less painful. |
Robot Results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The mapper fails to run with no privileged and no specific settings. Running as root it works using the main device certificate which is not the best settings.
curl --insecure https://127.0.0.1:8001/c8y/inventory/managedObjects
is working as expected. The--insecure
making sense as my device use a self signed certificate.curl http://127.0.0.1:8001/c8y/inventory/managedObjects
leads to a weird errorcurl: (1) Received HTTP/0.9 when not allowed
. Minor, but it would be good to serve a 404 not found on all HTTP requests.
crates/common/tedge_config/src/tedge_config_cli/tedge_config.rs
Outdated
Show resolved
Hide resolved
66b8277
to
e4c1f22
Compare
Should this be a 404, or should it be a 302 (temporary redirect) with the https URL in the location header? If we do want a redirect, I think 302 makes most sense, as there's no guarantee the HTTPS won't later be disabled (and if an application caches a 301, this can be really quite annoying to reverse). |
Indeed, a 302 redirect from HTTP to HTTPS might be more appropriate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to approve.
Remaining details:
- add the missing
tedge config
documentation for the two new settings. - clean
c8y_auth_proxy
dependencies
/// An optional [TlsStream], i.e. a stream of either TLS or non-TLS data | ||
/// | ||
/// This is useful for redirecting HTTP requests to HTTPS. | ||
pub enum MaybeTlsStream<I> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos!
When I asked to redirect HTTP requests to HTTPS, I didn't imagine a sec such a dance with pin
and streams.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the trait requirements for hyper
and axum
machinery are low level. But pin_project
makes it almost trivial
In order to avoid all these annoying typos warning in the cert and private key files, you can add them to https://github.com/thin-edge/thin-edge.io/blob/main/.typos.toml#L9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved. Well done!
cf90767
to
cb7907a
Compare
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
Signed-off-by: James Rhodes <[email protected]>
3ad6fa3
to
0153108
Compare
@didier-wenzek I have added certificate authentication to this PR, the most recent two commits are new to you, the rest have only trivial changes from rebasing since you approved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will be happy to commit. I still need some time to play with client authentication, though.
In order to avoid all these annoying typos warning in the cert and private key files, add an exception in https://github.com/thin-edge/thin-edge.io/blob/main/.typos.toml#L9
@@ -807,6 +828,33 @@ pub struct MqttAuthClientConfig { | |||
pub key_file: Utf8PathBuf, | |||
} | |||
|
|||
impl TEdgeConfigReaderHttpClientAuth { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have to understand how tedge config
works under the hood!
How is this impl TEdgeConfigReaderHttpClientAuth
connected to tedge_config.http.client.auth
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The top level tedge config that we interact with is TEdgeConfigReader
. This struct contains a struct for each config field, with the struct names generated by appending the field name to TEdgeConfigReader
(so tedge_config.http
has type TEdgeConfigReaderHttp
), and this continues recursively until a field has a value.
Because the data is stored within http.client.auth
, I have implemented this method on TEdgeConfigReaderHttpClientAuth
so it can be used as tedge_config.http.client.auth.identity()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. It's clearer.
Once HTTPS is enabled for the mapper, certificate-based authentication can also be enabled. | ||
The directory containing the certificates that the mapper will trust can be configured using `c8y.proxy.ca_path`, | ||
and the agent can be configured to use a trusted certificate using the `http.client.auth.cert_file` and `http.client.auth.key_file` | ||
setings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setings. | |
settings |
I observed an issue. Am I missing something? The mapper being configured to enforce certificate-based client authentication and the agent being given a local certificate, I cannot install a software which has to be downloaded form c8y:
I set the following
Note that |
I confirm that this is nicely working. The settings is simply not obvious. Things, I missed during my first testing session:
I will create a ticket to document these steps. |
Proposed changes
As #2397 is large and needs some significant changes from the agent's perspective, this PR separates out the changes to the auth proxy, which add the HTTPS support, but not (public-facing) support for client certificates, in an attempt to make some progress in merging the changes. Internally, all the support for certificate authentication exists, and the unit tests use this, but the built mapper will be unchanged apart from using HTTPS to serve the API.
Types of changes
Paste Link to the issue
#2363
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments