Skip to content

Initial implementation of the library #1

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

Merged
merged 8 commits into from
Jun 15, 2021
Merged

Initial implementation of the library #1

merged 8 commits into from
Jun 15, 2021

Conversation

maxlambrecht
Copy link
Owner

@maxlambrecht maxlambrecht commented Jun 6, 2021

Initial commit defining and implementing the basic interface and SPIFFE types:

  • workload.proto and protobuf generated code
  • Workload API client with one-shot call methods
  • Certificate and PrivateKey types
  • X.509 SVID and bundle types
  • JWT SVID and bundle types
  • TrustDomain and SpiffeId types

Signed-off-by: Max Lambrecht [email protected]

…FE types:

- Workload API client with one-shot call methods
- Certificate and PrivateKey types
- X.509 SVID and bundle types
- JWT SVID and bundle types
- TrustDomain and SpiffeId types

Signed-off-by: Max Lambrecht <[email protected]>
@maxlambrecht maxlambrecht requested a review from hug-dev June 6, 2021 18:57
Signed-off-by: Max Lambrecht <[email protected]>
…ode and enum variants closer to where they belong.

Signed-off-by: Max Lambrecht <[email protected]>
Signed-off-by: Max Lambrecht <[email protected]>
Copy link
Collaborator

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

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

This is impressive work 👏 The amount of tests is really nice. I did not look at it in all details as I think this is pretty good for a first baseline release and provides the basis to use it correctly. Even more than that! We would be happy to try that with the Parsec project.

My knowledge of SPIFFE is also not too good for a thorough review but if you wanted I could take some time to analyse it properly.

let spiffe_id = SpiffeId::try_from("spiffe://example.org/my-service")?;

// fetch a jwt token for the provided SPIFFE-ID and with the target audience `service1.com`
let jwt_token = client.fetch_jwt_token(&["audience1", "audience2"], Some(&spiffe_id))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe my SPIFFE knowledge is a bit rusted by now but why is the SPIFFE ID needed as a parameter here? Could it be the case that the workload does not know its SPIFFE ID if its set by another entity during registration?

edit: ah I see, this is an Option in case you want the sub claim to be populated. In our case, we mainly use the fetch method for the workload to know which is its SPIFFE ID

Copy link
Owner Author

@maxlambrecht maxlambrecht Jun 14, 2021

Choose a reason for hiding this comment

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

The usual case would be to just pass None in the SPIFFE ID parameter and the Workload API will return a JWT token with the 'sub' claim set with the SPIFFE ID corresponding to the default identity (the first one).

If the workload has multiple identities mapped to it, there is the possibility to select which SPIFFE ID to request the token for.

In case it's requested a token with a SPIFFE ID that the workload it's not mapped with, the Workload API will return an empty response.

Makes sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes sense! Thank you for the explanation 👍

@@ -0,0 +1,152 @@
syntax = "proto3";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe instead of having a copy of the Workload API we could have spiffe/spiffe repo as a submodule and use spiffe/main/standards/workloadapi.proto directly!

Copy link
Owner Author

Choose a reason for hiding this comment

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

Not so sure about this, I'm not a big fan of git submodules 😁 I'd leave as it is and put more thinking on this later on.

@@ -0,0 +1,2283 @@
// This file is generated by rust-protobuf 2.23.0. Do not edit
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we generate it here, maybe it's not needed to have a build file? Would save some compilation time. We can re-generate it manually when the Workload API gets updated.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I removed the build file.

/// assert_eq!("example.org", spiffe_id.trust_domain().to_string());
/// assert_eq!("/path", spiffe_id.path());
/// ```
pub fn new(id: &str) -> Result<Self, SpiffeIdError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding the parsing and the validation of it as well 🙏

None => Err(ClientError::EmptyResponse),
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be very nice to have an abstraction for the ValidateJWTSVID call as well but I am happy to add it once this is merged 👌

Copy link
Owner Author

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

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

forgot a few

Cargo.toml Outdated
@@ -0,0 +1,37 @@
[package]
name = "rust-spiffe"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The spiffe name is free on crates.io so I guess this could just be "spiffe", when it will be used it will always be in a Rust context :)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good idea, it makes total sense!

Cargo.toml Outdated
description = "Rust client library implementation for SPIFFE"

[dependencies]
grpcio = { version = "0.6", default-features = false, features = ["protobuf-codec"] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you want to bump that to at least 0.8 in order to include tikv/grpc-rs#499? That would boost compilation time and also help us in Parsec 👍

Copy link
Owner Author

Choose a reason for hiding this comment

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

Sure! Bumped it to 0.9. For some reason it needs grpcio-sys = "0.9.0" specified as build-dependency, otherwise the build throws an error.

Bump 'grpcio' dependency to 0.9.

Signed-off-by: Max Lambrecht <[email protected]>
Signed-off-by: Max Lambrecht <[email protected]>
Copy link
Collaborator

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

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

Thanks 🌟 For me this is good enough to get started, make a first release so that we can try it and improve it incrementally!

@maxlambrecht
Copy link
Owner Author

Thanks 🌟 For me this is good enough to get started, make a first release so that we can try it and improve it incrementally!

Great! Thanks for your review, I really appreciate it! I'll merge this and publish the first release.

@maxlambrecht maxlambrecht merged commit dabc35e into main Jun 15, 2021
@maxlambrecht maxlambrecht deleted the pre/0.1.0 branch August 12, 2023 20:26
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