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

fix(auth): allow self-signed JWT for non-GDU universe domain #10831

Merged

Conversation

quartzmo
Copy link
Member

@quartzmo quartzmo commented Sep 5, 2024

No description provided.

@quartzmo quartzmo requested a review from a team as a code owner September 5, 2024 20:19
@@ -130,7 +130,7 @@ func (o *Options) resolveDetectOptions() *credentials.DetectOptions {
do := transport.CloneDetectOptions(o.DetectOpts)

// If scoped JWTs are enabled user provided an aud, allow self-signed JWT.
if (io != nil && io.EnableJWTWithScope) || do.Audience != "" {
if (io != nil && io.EnableJWTWithScope) || do.Audience != "" || !o.isUniverseDomainGDU() {
Copy link
Member

Choose a reason for hiding this comment

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

It is not clear to me this is the desired behavior. If a scope or auth is not present you can't really make a valid self-signed JWT. Instead of saying if nonGDU assume self-signed, maybe we should validate that it will be a self-signed JWT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I found the original logic from the previous auth. This logic may also be flawed, but it looks to me that it only validates 1) non-GDU and 2) service account.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, to me that looks flawed too. I think we could make this change. But does it fix any bug? If it does fix a real use case I am fine with it, but it is not clear to me that it does.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try to move this logic to a later stage at which 2) service account can be determined.

Copy link
Member

Choose a reason for hiding this comment

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

Even if it is a service account, you need a scope or an aud for the JWT. Do you have a use-case to test this against?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can theInternalOptions.DefaultScopes be used?

Copy link
Member

Choose a reason for hiding this comment

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

Only if jwtscope is enabled. Iirc not all apis support scoped JWTs. Aud JWTs work for anything though I believe.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll see if I can get some info about how self-signed JWTs are intended to be used with universe domain.

Copy link
Member Author

@quartzmo quartzmo Sep 6, 2024

Choose a reason for hiding this comment

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

My understanding is that non-GDU participating services must support self-signed JWTs, and my best guess is that the default scope(s) are good enough.

@quartzmo
Copy link
Member Author

quartzmo commented Sep 6, 2024

Manual testing in the PRPTST environment using SA JSON with private_key, this branch, and google.golang.org/api at HEAD to include googleapis/google-api-go-client#2773:

package main

import (
	"context"
	"log"

	"google.golang.org/api/compute/v1"
	"google.golang.org/api/option"
)

func main() {
	ctx := context.Background()

	tpcUniverse := "apis-tpczero.goog"

	computeService, err := compute.NewService(ctx, option.WithUniverseDomain(tpcUniverse), option.WithCredentialsFile("/Users/chrisdsmith/sa_keys/prptst.json"))
	if err != nil {
		log.Fatalf("[WARN] Error creating client compute: %s", err)

	}
	log.Printf("[INFO] Requesting instance creation")
	call, err := computeService.Instances.List("tpczero-system:bootstrap-libraries", "u-us-prp1-a").Do()
	if err != nil {
		log.Fatalf("[WARN] Error listing instances: %v", err)
	}
	log.Printf("[INFO] List instances operation: %d", len(call.Items))

}
➜  compute-apiary-ud-new-auth git:(main) ✗ go run main.go
2024/09/06 12:29:40 [INFO] Requesting instance creation
2024/09/06 12:29:41 [INFO] List instances operation: 3

Copy link
Member

@viacheslav-rostovtsev viacheslav-rostovtsev left a comment

Choose a reason for hiding this comment

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

Left some questions

auth/credentials/filetypes.go Outdated Show resolved Hide resolved
if opts.UseSelfSignedJWT {
return configureSelfSignedJWT(f, opts)
} else if ud != "" && ud != internalauth.DefaultUniverseDomain {
// For non-GDU universe domains, token exchange is impossible and services

Choose a reason for hiding this comment

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

this can now become
opts.UseSelfSignedJWT |= ud != "" && ud != internalauth.DefaultUniverseDomain

@quartzmo quartzmo merged commit f9869f7 into googleapis:main Sep 10, 2024
8 checks passed
@quartzmo quartzmo deleted the auth-self-signed-jwt-universe-domain branch September 10, 2024 18:01
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.

3 participants