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

How to lower security guards for integration testing? #7981

Open
lowgear opened this issue Jan 6, 2025 · 11 comments
Open

How to lower security guards for integration testing? #7981

lowgear opened this issue Jan 6, 2025 · 11 comments
Assignees
Labels
Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. stale Status: Requires Reporter Clarification Type: Question

Comments

@lowgear
Copy link

lowgear commented Jan 6, 2025

Hello!

I am attempting to set up integration tests in my project.
I need to use per-RPC credentials for authorization but I would not like to set up my own root CA and actual SSL in my tests.

During my attempts I have figured out that grpc-go cares about client configuration security and integrity thus preventing me from setting up described configuration (specifically, from using grpc.WithPerRPCCredentials(oauth.TokenSource{...}) together with insecure.NewCredentials()).

What is the recommended way of accomplishing the described behavior in tests?

@purnesh42H
Copy link
Contributor

@eshitachandwani to look as current oncall

@eshitachandwani
Copy link
Member

eshitachandwani commented Jan 9, 2025

Hey @lowgear, you're correct that using grpc.WithPerRPCCredentials(oauth.TokenSource{...}) with insecure.NewCredentials() is not allowed because gRPC enforces secure transmission of tokens, requiring an underlying secure transport. To work around this, you can use credentials.NewClientTLSFromCert() with a nil certificate pool, like credentials.NewClientTLSFromCert(nil, ""). This creates TLS credentials using the system's default certificate pool, which works with servers that have certificates signed by trusted public CAs.
Let me know if you have any more questions.

@lowgear
Copy link
Author

lowgear commented Jan 9, 2025

I think I have not described my scenario clear enough. Let me correct myself.

In our project we make tests hermetic as possible. In particular, we set up all the components of the system on localhost during test preparation stage and the endpoint to which the connection is established during the test is a port on localhost too.
The tests are supposed to have reproducible results at any time thus it is not viable to have a certificate stored along with the tests sources as it will eventually expire because it will not be valid longer than the root certificate.
On the other hand issuing a certificate for each tests run does not sound good either.

So, unfortunately, using the system's default certificate pool is not helpful in my particular situation.

If more details are required I will be glad to provide.

@purnesh42H purnesh42H added the Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. label Jan 12, 2025
@purnesh42H
Copy link
Contributor

purnesh42H commented Jan 15, 2025

@lowgear its not clear what you mean by "it is not viable to have a certificate stored along with the tests sources as it will eventually expire because it will not be valid longer than the root certificate".

Regarding WithPerRPCCredentials, have you tried to look into following example https://github.com/grpc/grpc-go/blob/master/examples/features/authentication ? You can do something similar. Have the certificate stored in a local directory. The certificates used in example are created using openssl and i think its possible to set a long expiry date or no expiry.

You can take a look at other auth mechanisms here https://grpc.io/docs/guides/auth/

@purnesh42H
Copy link
Contributor

@lowgear just checking if you got a chance to try the approach in the example and if you need more clarification or help.

@lowgear
Copy link
Author

lowgear commented Jan 20, 2025

Okay, I have examined the example you have linked and yes, with such approach I can generate certificates for the purpose of testing.

But basically my question was if I can avoid doing exactly that - that's what I meant by "I would not like to set up my own root CA and actual SSL in my tests" :)

I guess the answer to my exact question is no.

But that brings up the question if such library as grpc-go should not be just inclined towards secure practices (default behaviour is secure but insecure one is achievable with specific set of prarameters) but completely restrict the use of insecure practices. I would not like discuss such question here but that is where it ends up.

@purnesh42H
Copy link
Contributor

purnesh42H commented Jan 22, 2025

Yeah I think you cannot easily and directly achieve true SSL/TLS authentication (with certificate verification) without setting up your own root CA and issuing certificates. I can ask other maintainers if there are workarounds but it would definitely not be recommended for integration tests as they should be close to real world scenarios where a client needs to be able to verify that the server's certificate was issued by a trusted Certificate Authority (CA).

@lowgear
Copy link
Author

lowgear commented Jan 23, 2025

Well, in our production it is common practice to terminate SSL at L7 balancer and then send unencrypted traffic to the backends.

As far as I know it is well known practice and a valid use of passing credentials over unencrypted connection (but surely only because of the trusted environment).

Copy link

This issue is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

@github-actions github-actions bot added the stale label Jan 29, 2025
@purnesh42H
Copy link
Contributor

@lowgear so the thing is oauth rpc credentials required transport security https://github.com/grpc/grpc-go/blob/master/credentials/oauth/oauth.go#L140 and that's why you are not able to use insecure transport credentials. In addition there is a security level check which checks if a connection's security level is greater than or equal to the specified one.

I tried to comment out these checks and tried the auth example with insecure transport purnesh42H/grpc-go@master...purnesh42H:grpc-go:use-insecrure-with-oauth and looks like that works. So, I think just for your testing you can implement your own custom credentials which doesn't require secure transport credentials and use that with oauth RPC credentials. However, this is not recommended for prod path.

@github-actions github-actions bot removed the stale label Jan 30, 2025
Copy link

github-actions bot commented Feb 5, 2025

This issue is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

@github-actions github-actions bot added the stale label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. stale Status: Requires Reporter Clarification Type: Question
Projects
None yet
Development

No branches or pull requests

3 participants